• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FIWARE / contract-management / #91

22 Apr 2026 06:29AM UTC coverage: 1.776% (+0.1%) from 1.681%
#91

push

web-flow
Merge pull request #23 from FIWARE/fix/proxy

fix(proxy): do not require proxyHost and proxyPort when proxy is disabled

20 of 136 new or added lines in 11 files covered. (14.71%)

1 existing line in 1 file now uncovered.

621 of 34976 relevant lines covered (1.78%)

0.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

2.27
/src/main/java/org/fiware/iam/tmforum/OrganizationResolver.java
1
package org.fiware.iam.tmforum;
2

3
import com.fasterxml.jackson.databind.ObjectMapper;
4
import io.micronaut.context.annotation.Requires;
5
import io.micronaut.context.annotation.Value;
6
import io.micronaut.http.HttpResponse;
7
import io.micronaut.http.HttpStatus;
8
import jakarta.inject.Singleton;
9
import lombok.RequiredArgsConstructor;
10
import lombok.extern.slf4j.Slf4j;
11
import org.fiware.iam.configuration.GeneralProperties;
12
import org.fiware.iam.domain.ContractManagement;
13
import org.fiware.iam.exception.TMForumException;
14
import org.fiware.iam.tmforum.party.api.OrganizationApiClient;
15
import org.fiware.iam.tmforum.party.model.CharacteristicVO;
16
import org.fiware.iam.tmforum.party.model.ExternalReferenceVO;
17
import reactor.core.publisher.Mono;
18

19
import java.util.List;
20
import java.util.Optional;
21

22
@Requires(condition = GeneralProperties.TmForumCondition.class)
23
@Singleton
24
@Slf4j
1✔
25
@RequiredArgsConstructor
26
public class OrganizationResolver {
27

28
    @Value("${general.organization.provider.role:provider}")
29
    private String PROVIDER_ROLE;
30

31
    private static final String PARTY_CHARACTERISTIC_DID = "did";
32
    private static final String FIELD_NAME_CONTRACT_MANAGEMENT = "contractManagement";
33
    private static final String EXTERNAL_REFERENCE_IDM_ID = "idm_id";
34
    private static final String DID = "did";
35

36
    private final GeneralProperties generalProperties;
37
    private final ObjectMapper objectMapper;
38
    private final OrganizationApiClient apiClient;
39

40
    //TODO Cache me if you can
41
    public Mono<String> getDID(String organizationId) {
42
        return apiClient.retrieveOrganization(organizationId, null)
×
43
                .filter(response -> response.getStatus().equals(HttpStatus.OK))
×
44
                .map(HttpResponse::body)
×
45
                .map(ovo -> {
×
46
                            String did = getDidFromExternalReference(ovo.getExternalReference())
×
47
                                    .or(() -> getDidFromPartyCharacteristics(ovo.getPartyCharacteristic()))
×
48
                                    .orElseThrow(() -> new TMForumException("Could not find organizations DID (%s) in response.".formatted(organizationId)));
×
49
                            log.debug("Did is {}", did);
×
50
                            return did;
×
51
                        }
52
                );
53
    }
54

55
    public Mono<ContractManagement> getContractManagement(String organizationId) {
56
        return getDID(organizationId)
×
57
                .flatMap(did -> {
×
58
                    if (did.equals(generalProperties.getDid())) {
×
59
                        return Mono.just(new ContractManagement(true));
×
60
                    } else {
61
                        return apiClient.retrieveOrganization(organizationId, null)
×
62
                                .filter(response -> response.getStatus().equals(HttpStatus.OK))
×
63
                                .map(HttpResponse::body)
×
64
                                .map(ovo ->
×
65
                                        ovo.getPartyCharacteristic()
×
66
                                                .stream()
×
67
                                                .filter(pc -> pc.getName().equals(FIELD_NAME_CONTRACT_MANAGEMENT))
×
68
                                                .map(CharacteristicVO::getValue)
×
69
                                                .map(pcv -> objectMapper.convertValue(pcv, ContractManagement.class))
×
70
                                                .findAny()
×
71
                                                .orElse(new ContractManagement(true))
×
72
                                );
73
                    }
74
                });
75
    }
76

77
    public boolean hasProviderRole(String role) {
NEW
78
        return PROVIDER_ROLE.equalsIgnoreCase(role);
×
79
    }
80

81
    private Optional<String> getDidFromPartyCharacteristics(List<CharacteristicVO> characteristicVOS) {
82
        if (characteristicVOS == null) {
×
83
            return Optional.empty();
×
84
        }
85
        return characteristicVOS.stream()
×
86
                .filter(entry -> PARTY_CHARACTERISTIC_DID.equals(entry.getName()))
×
87
                .map(CharacteristicVO::getValue)
×
88
                .filter(e -> e instanceof String)
×
89
                .map(e -> (String) e)
×
90
                .filter(this::isDid)
×
91
                .findAny();
×
92
    }
93

94
    private Optional<String> getDidFromExternalReference(List<ExternalReferenceVO> externalReferenceVOList) {
95
        if (externalReferenceVOList == null) {
×
96
            return Optional.empty();
×
97
        }
98
        return externalReferenceVOList.stream()
×
99
                .filter(ervo -> ervo.getExternalReferenceType().equals(EXTERNAL_REFERENCE_IDM_ID))
×
100
                .map(ExternalReferenceVO::getName)
×
101
                .filter(this::isDid)
×
102
                .findFirst();
×
103
    }
104

105
    private boolean isDid(String id) {
106
        String[] idParts = id.split(":");
×
107
        return idParts.length >= 3 && idParts[0].equals(DID);
×
108
    }
109
}
110

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc