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

FIWARE / contract-management / #45

25 Jun 2025 07:26AM UTC coverage: 1.744%. Remained the same
#45

Pull #7

wistefan
improve logging
Pull Request #7: add rp filter

0 of 19 new or added lines in 2 files covered. (0.0%)

588 of 33716 relevant lines covered (1.74%)

0.02 hits per line

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

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

3
import io.micronaut.http.HttpResponse;
4
import io.micronaut.http.HttpStatus;
5
import jakarta.inject.Singleton;
6
import lombok.RequiredArgsConstructor;
7
import lombok.extern.slf4j.Slf4j;
8
import org.fiware.iam.exception.TMForumException;
9
import org.fiware.iam.tmforum.party.api.OrganizationApiClient;
10
import org.fiware.iam.tmforum.party.model.CharacteristicVO;
11
import org.fiware.iam.tmforum.party.model.ExternalReferenceVO;
12
import org.fiware.iam.tmforum.party.model.OrganizationVO;
13
import reactor.core.publisher.Mono;
14

15
import java.util.Collection;
16
import java.util.List;
17
import java.util.Optional;
18
import java.util.stream.Stream;
19

20
@Singleton
21
@Slf4j
1✔
22
@RequiredArgsConstructor
23
public class OrganizationResolver {
24
        private static final String PARTY_CHARACTERISTIC_DID = "did";
25
        private static final String FIELD_NAME_PARTY_CHARACTERISTIC = "partyCharacteristic";
26
        private static final String EXTERNAL_REFERENCE_IDM_ID = "idm_id";
27
        private static final String DID = "did";
28

29
        private final OrganizationApiClient apiClient;
30

31
        //TODO Cache me if you can
32
        public Mono<String> getDID(String organizationId) {
NEW
33
                return apiClient.retrieveOrganization(organizationId, null)
×
34
                                .filter(response -> response.getStatus().equals(HttpStatus.OK))
×
35
                                .map(HttpResponse::body)
×
NEW
36
                                .map(ovo -> {
×
NEW
37
                                                        String did = getDidFromExternalReference(ovo.getExternalReference())
×
NEW
38
                                                                        .or(() -> getDidFromPartyCharacteristics(ovo.getPartyCharacteristic()))
×
NEW
39
                                                                        .orElseThrow(() -> new TMForumException("Could not find organizations DID (%s) in response.".formatted(organizationId)));
×
NEW
40
                                                        log.info("Did is {}", did);
×
NEW
41
                                                        return did;
×
42
                                                }
43
                                );
44
        }
45

46
        private Optional<String> getDidFromPartyCharacteristics(List<CharacteristicVO> characteristicVOS) {
47
                if (characteristicVOS == null) {
×
48
                        return Optional.empty();
×
49
                }
50
                return characteristicVOS.stream()
×
51
                                .filter(entry -> PARTY_CHARACTERISTIC_DID.equals(entry.getName()))
×
52
                                .map(CharacteristicVO::getValue)
×
53
                                .filter(e -> e instanceof String)
×
54
                                .map(e -> (String) e)
×
55
                                .filter(this::isDid)
×
56
                                .findAny();
×
57
        }
58

59
        private Optional<String> getDidFromExternalReference(List<ExternalReferenceVO> externalReferenceVOList) {
NEW
60
                log.warn("External refs {}", externalReferenceVOList);
×
61
                if (externalReferenceVOList == null) {
×
62
                        return Optional.empty();
×
63
                }
64
                return externalReferenceVOList.stream()
×
65
                                .filter(ervo -> ervo.getExternalReferenceType().equals(EXTERNAL_REFERENCE_IDM_ID))
×
66
                                .map(ExternalReferenceVO::getName)
×
67
                                .filter(this::isDid)
×
68
                                .findFirst();
×
69
        }
70

71
        private boolean isDid(String id) {
72
                String[] idParts = id.split(":");
×
73
                return idParts.length >= 3 && idParts[0].equals(DID);
×
74
        }
75
}
76

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

© 2026 Coveralls, Inc