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

FIWARE / contract-management / #69

30 Oct 2025 07:38AM UTC coverage: 1.686% (+0.04%) from 1.651%
#69

Pull #12

wistefan
improve organization creation and cleanup
Pull Request #12: Support for central marketplace and policy creation

117 of 1238 new or added lines in 31 files covered. (9.45%)

5 existing lines in 2 files now uncovered.

587 of 34807 relevant lines covered (1.69%)

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
import static org.fiware.iam.tmforum.OrganizationResolver.PROVIDER_ROLE;
32

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

39
    private static final String CREDENTIALS_CONFIG_KEY = "credentialsConfiguration";
40
    private static final String QUOTE_DELETE_ACTION = "delete";
41

42
    private final ObjectMapper objectMapper;
43
    private final OrganizationResolver organizationResolver;
44

45
    private final ProductOfferingApiClient productOfferingApiClient;
46
    private final ProductSpecificationApiClient productSpecificationApiClient;
47
    private final QuoteApiClient quoteApiClient;
48

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

NEW
62
        return zipMonoListCC(credentialsVOMonoList);
×
63
    }
64

65
    private Mono<List<CredentialConfig>> zipMonoListCC(List<Mono<CredentialConfig>> monoList) {
NEW
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) {
NEW
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

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

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

100

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

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