• 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

1.49
/src/main/java/org/fiware/iam/tmforum/CredentialsConfigResolver.java
1
package org.fiware.iam.tmforum;
2

3
import com.fasterxml.jackson.core.type.TypeReference;
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
import io.micronaut.context.annotation.Requires;
6
import io.micronaut.http.HttpResponse;
7
import jakarta.inject.Singleton;
8
import lombok.RequiredArgsConstructor;
9
import lombok.extern.slf4j.Slf4j;
10
import org.fiware.iam.configuration.GeneralProperties;
11
import org.fiware.iam.domain.ContractManagement;
12
import org.fiware.iam.til.model.CredentialsVO;
13
import org.fiware.iam.tmforum.productcatalog.api.ProductOfferingApiClient;
14
import org.fiware.iam.tmforum.productcatalog.api.ProductSpecificationApiClient;
15
import org.fiware.iam.tmforum.productcatalog.model.ProductSpecificationRefVO;
16
import org.fiware.iam.tmforum.productcatalog.model.RelatedPartyVO;
17
import org.fiware.iam.tmforum.productcatalog.model.*;
18
import org.fiware.iam.tmforum.productorder.model.ProductOfferingRefVO;
19
import org.fiware.iam.tmforum.productorder.model.*;
20
import org.fiware.iam.tmforum.quote.api.QuoteApiClient;
21
import org.fiware.iam.tmforum.quote.model.QuoteItemVO;
22
import org.fiware.iam.tmforum.quote.model.QuoteStateTypeVO;
23
import org.fiware.iam.tmforum.quote.model.QuoteVO;
24
import reactor.core.publisher.Mono;
25

26
import java.util.List;
27
import java.util.Objects;
28
import java.util.Optional;
29
import java.util.stream.Stream;
30

31
@Requires(condition = GeneralProperties.TmForumCondition.class)
32
@Singleton
33
@Slf4j
×
34
@RequiredArgsConstructor
35
public class CredentialsConfigResolver {
36

37
    private static final String CREDENTIALS_CONFIG_KEY = "credentialsConfiguration";
38
    private static final String QUOTE_DELETE_ACTION = "delete";
39

40
    private final ObjectMapper objectMapper;
41
    private final OrganizationResolver organizationResolver;
42

43
    private final ProductOfferingApiClient productOfferingApiClient;
44
    private final ProductSpecificationApiClient productSpecificationApiClient;
45
    private final QuoteApiClient quoteApiClient;
46
    private final OrganizationResolver orgResolver;
47

48
    public Mono<List<CredentialConfig>> getCredentialsConfig(ProductOrderVO productOrder) {
49
        if (productOrder.getQuote() != null && !productOrder.getQuote().isEmpty()) {
×
50
            return getCredentialsConfigFromQuote(productOrder.getQuote());
×
51
        }
52
        log.debug("No quote found, take the original offer from the order item.");
×
53
        List<Mono<CredentialConfig>> credentialsVOMonoList = productOrder.getProductOrderItem()
×
54
                .stream()
×
55
                .filter(poi -> poi.getAction() == OrderItemActionTypeVO.ADD || poi.getAction() == OrderItemActionTypeVO.MODIFY)
×
56
                .map(ProductOrderItemVO::getProductOffering)
×
57
                .map(ProductOfferingRefVO::getId)
×
58
                .map(this::getCredentialsConfigFromOffer)
×
59
                .toList();
×
60

61
        return zipMonoListCC(credentialsVOMonoList);
×
62
    }
63

64

65
    private Mono<List<CredentialConfig>> zipMonoListCC(List<Mono<CredentialConfig>> monoList) {
66
        return Mono.zip(monoList, results -> Stream.of(results).map(r -> (CredentialConfig) r).toList());
×
67

68
    }
69

70
    private Mono<List<CredentialConfig>> zipMonoList(List<Mono<List<CredentialConfig>>> monoList) {
71
        return Mono.zip(monoList, results -> Stream.of(results).map(r -> (List<CredentialConfig>) r).flatMap(List::stream).toList());
×
72

73
    }
74

75
    private Mono<CredentialConfig> getCredentialsConfigFromOffer(String offerId) {
76

77
        return productOfferingApiClient
×
78
                .retrieveProductOffering(offerId, null)
×
79
                .map(HttpResponse::body)
×
80
                .map(ProductOfferingVO::getProductSpecification)
×
81
                .map(ProductSpecificationRefVO::getId)
×
82
                .flatMap(specId -> productSpecificationApiClient.retrieveProductSpecification(specId, null))
×
83
                .map(HttpResponse::body)
×
84
                .flatMap(psvo -> {
×
85
                    List<CredentialsVO> credentialsVOS = getCredentialsConfigFromPSC(psvo.getProductSpecCharacteristic());
×
86

87
                    Optional<String> partyId = Optional.ofNullable(psvo.getRelatedParty())
×
88
                            .orElse(List.of())
×
89
                            .stream()
×
NEW
90
                            .filter(relatedPartyVO -> orgResolver.hasProviderRole(relatedPartyVO.getRole()))
×
91
                            .map(RelatedPartyVO::getId)
×
92
                            .findAny();
×
93
                    return partyId.map(string ->
×
94
                                    organizationResolver.getContractManagement(string)
×
95
                                            .map(cm -> new CredentialConfig(cm, credentialsVOS)))
×
96
                            .orElseGet(() -> Mono.just(new CredentialConfig(new ContractManagement(true), credentialsVOS)));
×
97
                });
98
    }
99

100

101
    private Mono<List<CredentialConfig>> getCredentialsConfigFromQuote(List<QuoteRefVO> quoteRefVOS) {
102
        return zipMonoList(quoteRefVOS.stream()
×
103
                .map(QuoteRefVO::getId)
×
104
                .map(quoteId -> quoteApiClient.retrieveQuote(quoteId, null)
×
105
                        .map(HttpResponse::body)
×
106
                        .filter(quoteVO -> quoteVO.getState() == QuoteStateTypeVO.ACCEPTED)
×
107
                        .map(QuoteVO::getQuoteItem)
×
108
                        .flatMap(quoteItemList -> {
×
109
                            List<Mono<CredentialConfig>> configMonos = quoteItemList.stream()
×
110
                                    .filter(item -> item.getState().equals(QuoteStateTypeVO.ACCEPTED.getValue()))
×
111
                                    .filter(item -> !item.getAction().equals(QUOTE_DELETE_ACTION))
×
112
                                    .map(QuoteItemVO::getProductOffering)
×
113
                                    .map(org.fiware.iam.tmforum.quote.model.ProductOfferingRefVO::getId)
×
114
                                    .map(this::getCredentialsConfigFromOffer)
×
115
                                    .toList();
×
116
                            return zipMonoListCC(configMonos);
×
117
                        }))
118
                .toList());
×
119
    }
120

121
    private List<CredentialsVO> getCredentialsConfigFromPSC(List<ProductSpecificationCharacteristicVO> pscList) {
122
        return pscList.stream()
×
123
                .filter(psc -> psc.getValueType().equals(CREDENTIALS_CONFIG_KEY))
×
124
                .findFirst()
×
125
                .map(productSpecificationCharacteristicVO -> productSpecificationCharacteristicVO
×
126
                        .getProductSpecCharacteristicValue()
×
127
                        .stream()
×
128
                        .map(CharacteristicValueSpecificationVO::getValue)
×
129
                        .map(value -> {
×
130
                            try {
131
                                List<CredentialsVO> credentialsVOS = objectMapper.convertValue(value, new TypeReference<List<CredentialsVO>>() {
×
132
                                });
133
                                log.debug("Config is {}", credentialsVOS);
×
134
                                return credentialsVOS;
×
135
                            } catch (IllegalArgumentException iae) {
×
136
                                log.warn("The characteristic value is invalid.", iae);
×
137
                                return null;
×
138
                            }
139
                        })
140
                        .filter(Objects::nonNull)
×
141
                        .flatMap(List::stream)
×
142
                        .toList()).orElseGet(List::of);
×
143
    }
144

145
    public record CredentialConfig(ContractManagement contractManagement, List<CredentialsVO> credentialsVOS) {
1✔
146
    }
147
}
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