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

FIWARE / contract-management / #48

06 Aug 2025 11:35AM UTC coverage: 1.655% (-0.2%) from 1.815%
#48

Pull #8

wistefan
fixes
Pull Request #8: Support multiple creds

2 of 60 new or added lines in 3 files covered. (3.33%)

25 existing lines in 3 files now uncovered.

558 of 33725 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
                if (productOrder.getQuote() != null && !productOrder.getQuote().isEmpty()) {
×
NEW
41
                        return getCredentialsConfigFromQuote(productOrder.getQuote());
×
42
                }
NEW
43
                log.debug("No quote found, take the original offer from the order item.");
×
NEW
44
                List<Mono<List<CredentialsVO>>> credentialsVOMonoList = productOrder.getProductOrderItem()
×
NEW
45
                                .stream()
×
NEW
46
                                .filter(poi -> poi.getAction() == OrderItemActionTypeVO.ADD || poi.getAction() == OrderItemActionTypeVO.MODIFY)
×
NEW
47
                                .map(ProductOrderItemVO::getProductOffering)
×
NEW
48
                                .map(ProductOfferingRefVO::getId)
×
NEW
49
                                .map(this::getCredentialsConfigFromOffer)
×
NEW
50
                                .toList();
×
51

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

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

58
        }
59

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

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

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