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

FIWARE / contract-management / #40

16 Jun 2025 10:56AM UTC coverage: 1.744% (-0.001%) from 1.745%
#40

Pull #6

wistefan
fix ci
Pull Request #6: get from ref

0 of 21 new or added lines in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

588 of 33706 relevant lines covered (1.74%)

0.02 hits per line

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

3.85
/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) {
33
                return apiClient.retrieveOrganization(organizationId, FIELD_NAME_PARTY_CHARACTERISTIC)
×
34
                                .filter(response -> response.getStatus().equals(HttpStatus.OK))
×
35
                                .map(HttpResponse::body)
×
NEW
36
                                .map(ovo ->
×
NEW
37
                                                getDidFromExternalReference(ovo.getExternalReference())
×
NEW
38
                                                                .or(() -> getDidFromPartyCharacteristics(ovo.getPartyCharacteristic()))
×
UNCOV
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) {
NEW
44
                if (characteristicVOS == null) {
×
NEW
45
                        return Optional.empty();
×
46
                }
NEW
47
                return characteristicVOS.stream()
×
NEW
48
                                .filter(entry -> PARTY_CHARACTERISTIC_DID.equals(entry.getName()))
×
NEW
49
                                .map(CharacteristicVO::getValue)
×
NEW
50
                                .filter(e -> e instanceof String)
×
NEW
51
                                .map(e -> (String) e)
×
NEW
52
                                .filter(this::isDid)
×
NEW
53
                                .findAny();
×
54
        }
55

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

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

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