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

FIWARE / contract-management / #43

25 Jun 2025 06:49AM UTC coverage: 1.744%. Remained the same
#43

Pull #7

wistefan
NPE and cleanup
Pull Request #7: add rp filter

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

67 existing lines in 2 files now uncovered.

588 of 33717 relevant lines covered (1.74%)

0.02 hits per line

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

3.7
/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)
×
36
                                .map(ovo ->
×
37
                                                getDidFromExternalReference(ovo.getExternalReference())
×
38
                                                                .or(() -> getDidFromPartyCharacteristics(ovo.getPartyCharacteristic()))
×
39
                                                                .orElseThrow(() -> new TMForumException("Could not find organizations DID (%s) in response.".formatted(organizationId)))
×
40
                                );
41
        }
42

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

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

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

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