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

FIWARE / contract-management / #53

11 Aug 2025 05:56AM UTC coverage: 1.654% (-0.2%) from 1.815%
#53

push

web-flow
Merge pull request #8 from FIWARE/support-multiple-creds

Support multiple creds

2 of 70 new or added lines in 3 files covered. (2.86%)

25 existing lines in 3 files now uncovered.

558 of 33742 relevant lines covered (1.65%)

0.02 hits per line

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

0.0
/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.http.HttpResponse;
6
import jakarta.inject.Singleton;
7
import lombok.RequiredArgsConstructor;
8
import lombok.extern.slf4j.Slf4j;
9
import org.fiware.iam.til.model.CredentialsVO;
10
import org.fiware.iam.tmforum.productcatalog.api.ProductOfferingApiClient;
11
import org.fiware.iam.tmforum.productcatalog.api.ProductSpecificationApiClient;
12
import org.fiware.iam.tmforum.productcatalog.model.ProductSpecificationRefVO;
13
import org.fiware.iam.tmforum.productcatalog.model.*;
14
import org.fiware.iam.tmforum.productorder.model.ProductOfferingRefVO;
15
import org.fiware.iam.tmforum.productorder.model.*;
16
import org.fiware.iam.tmforum.quote.api.QuoteApiClient;
17
import org.fiware.iam.tmforum.quote.model.QuoteItemVO;
18
import org.fiware.iam.tmforum.quote.model.QuoteStateTypeVO;
19
import org.fiware.iam.tmforum.quote.model.QuoteVO;
20
import reactor.core.publisher.Mono;
21

22
import java.util.List;
23
import java.util.Objects;
24
import java.util.stream.Stream;
25

26
@Singleton
NEW
27
@Slf4j
×
28
@RequiredArgsConstructor
29
public class CredentialsConfigResolver {
30

31
        private static final String CREDENTIALS_CONFIG_KEY = "credentialsConfiguration";
32
        private static final String QUOTE_DELETE_ACTION = "delete";
33

34
        private final ProductOfferingApiClient productOfferingApiClient;
35
        private final ProductSpecificationApiClient productSpecificationApiClient;
36
        private final QuoteApiClient quoteApiClient;
37
        private final ObjectMapper objectMapper;
38

39
        public Mono<List<CredentialsVO>> getCredentialsConfig(ProductOrderVO productOrder) {
NEW
40
                log.info("Get config.");
×
NEW
41
                if (productOrder.getQuote() != null && !productOrder.getQuote().isEmpty()) {
×
NEW
42
                        return getCredentialsConfigFromQuote(productOrder.getQuote());
×
43
                }
NEW
44
                log.info("No quote found, take the original offer from the order item.");
×
NEW
45
                List<Mono<List<CredentialsVO>>> credentialsVOMonoList = productOrder.getProductOrderItem()
×
NEW
46
                                .stream()
×
NEW
47
                                .filter(poi -> poi.getAction() == OrderItemActionTypeVO.ADD || poi.getAction() == OrderItemActionTypeVO.MODIFY)
×
NEW
48
                                .map(ProductOrderItemVO::getProductOffering)
×
NEW
49
                                .map(ProductOfferingRefVO::getId)
×
NEW
50
                                .map(this::getCredentialsConfigFromOffer)
×
NEW
51
                                .toList();
×
52

NEW
53
                return zipMonoList(credentialsVOMonoList);
×
54
        }
55

56
        private Mono<List<CredentialsVO>> zipMonoList(List<Mono<List<CredentialsVO>>> monoList) {
NEW
57
                return Mono.zip(monoList, results -> Stream.of(results).map(r -> (List<CredentialsVO>) r).flatMap(List::stream).toList());
×
58

59
        }
60

61
        private Mono<List<CredentialsVO>> getCredentialsConfigFromOffer(String offerId) {
NEW
62
                return productOfferingApiClient
×
NEW
63
                                .retrieveProductOffering(offerId, null)
×
NEW
64
                                .map(HttpResponse::body)
×
NEW
65
                                .map(ProductOfferingVO::getProductSpecification)
×
NEW
66
                                .map(ProductSpecificationRefVO::getId)
×
NEW
67
                                .flatMap(specId -> productSpecificationApiClient.retrieveProductSpecification(specId, null))
×
NEW
68
                                .map(HttpResponse::body)
×
NEW
69
                                .map(ProductSpecificationVO::getProductSpecCharacteristic)
×
NEW
70
                                .map(this::getCredentialsConfigFromPSC);
×
71
        }
72

73
        private Mono<List<CredentialsVO>> getCredentialsConfigFromQuote(List<QuoteRefVO> quoteRefVOS) {
NEW
74
                return zipMonoList(quoteRefVOS.stream()
×
NEW
75
                                .map(QuoteRefVO::getId)
×
NEW
76
                                .map(quoteId -> quoteApiClient.retrieveQuote(quoteId, null)
×
NEW
77
                                                .map(HttpResponse::body)
×
NEW
78
                                                .filter(quoteVO -> quoteVO.getState() == QuoteStateTypeVO.ACCEPTED)
×
NEW
79
                                                .map(QuoteVO::getQuoteItem)
×
NEW
80
                                                .flatMap(quoteItemList -> {
×
NEW
81
                                                        List<Mono<List<CredentialsVO>>> configMonos = quoteItemList.stream()
×
NEW
82
                                                                        .filter(item -> item.getState().equals(QuoteStateTypeVO.ACCEPTED.getValue()))
×
NEW
83
                                                                        .filter(item -> !item.getAction().equals(QUOTE_DELETE_ACTION))
×
NEW
84
                                                                        .map(QuoteItemVO::getProductOffering)
×
NEW
85
                                                                        .map(org.fiware.iam.tmforum.quote.model.ProductOfferingRefVO::getId)
×
NEW
86
                                                                        .map(this::getCredentialsConfigFromOffer)
×
NEW
87
                                                                        .toList();
×
NEW
88
                                                        return zipMonoList(configMonos);
×
89
                                                }))
NEW
90
                                .toList());
×
91
        }
92

93
        private List<CredentialsVO> getCredentialsConfigFromPSC(List<ProductSpecificationCharacteristicVO> pscList) {
NEW
94
                return pscList.stream()
×
NEW
95
                                .filter(psc -> psc.getValueType().equals(CREDENTIALS_CONFIG_KEY))
×
NEW
96
                                .findFirst()
×
NEW
97
                                .map(productSpecificationCharacteristicVO -> productSpecificationCharacteristicVO
×
NEW
98
                                                .getProductSpecCharacteristicValue()
×
NEW
99
                                                .stream()
×
NEW
100
                                                .map(CharacteristicValueSpecificationVO::getValue)
×
NEW
101
                                                .map(value -> {
×
102
                                                        try {
NEW
103
                                                                List<CredentialsVO> credentialsVOS = objectMapper.convertValue(value, new TypeReference<List<CredentialsVO>>() {
×
104
                                                                });
NEW
105
                                                                log.info("Config is {}", credentialsVOS);
×
NEW
106
                                                                return credentialsVOS;
×
NEW
107
                                                        } catch (IllegalArgumentException iae) {
×
NEW
108
                                                                log.warn("The characteristic value is invalid.", iae);
×
NEW
109
                                                                return null;
×
110
                                                        }
111
                                                })
NEW
112
                                                .filter(Objects::nonNull)
×
NEW
113
                                                .flatMap(List::stream)
×
NEW
114
                                                .toList()).orElseGet(List::of);
×
115
        }
116
}
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