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

FIWARE / contract-management / #29

02 Apr 2025 12:35PM UTC coverage: 1.242% (+0.3%) from 0.982%
#29

Pull #5

wistefan
fix testing
Pull Request #5: integrate contract negotiation

3 of 127 new or added lines in 5 files covered. (2.36%)

1 existing line in 1 file now uncovered.

417 of 33568 relevant lines covered (1.24%)

0.01 hits per line

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

77.78
/src/main/java/org/fiware/iam/tmforum/TMForumAdapter.java
1
package org.fiware.iam.tmforum;
2

3
import com.fasterxml.jackson.databind.ObjectMapper;
4
import io.micronaut.http.HttpResponse;
5
import jakarta.inject.Singleton;
6
import lombok.RequiredArgsConstructor;
7
import lombok.extern.slf4j.Slf4j;
8
import org.fiware.iam.exception.RainbowException;
9
import org.fiware.iam.exception.TMForumException;
10
import org.fiware.iam.tmforum.agreement.api.AgreementApiClient;
11
import org.fiware.iam.tmforum.agreement.model.*;
12
import org.fiware.iam.tmforum.productorder.api.ProductOrderApiClient;
13
import org.fiware.iam.tmforum.productorder.model.AgreementRefVO;
14
import org.fiware.iam.tmforum.productorder.model.ProductOrderUpdateVO;
15
import org.fiware.iam.tmforum.productorder.model.ProductOrderVO;
16
import org.fiware.iam.tmforum.quote.api.QuoteApiClient;
17
import org.fiware.iam.tmforum.quote.model.QuoteUpdateVO;
18
import org.fiware.iam.tmforum.quote.model.QuoteVO;
19
import org.fiware.rainbow.model.NegotiationProcessVO;
20
import reactor.core.publisher.Mono;
21

22
import java.util.List;
23
import java.util.Objects;
24

25
/**
26
 * Adapter to handle communication with TMForum APIs.
27
 */
28
@Singleton
29
@RequiredArgsConstructor
30
@Slf4j
1✔
31
public class TMForumAdapter {
32

33
        public static final String DATA_SPACE_PROTOCOL_AGREEMENT_ID = "Data-Space-Protocol-Agreement-Id";
34

35
        private final ObjectMapper objectMapper;
36

37
        private final ProductOrderApiClient productOrderApiClient;
38
        private final AgreementApiClient agreementApiClient;
39
        private final QuoteApiClient quoteApiClient;
40

41
        /**
42
         * Create a TMForum Agreement and connect it with product order its coming from.
43
         */
44
        public Mono<String> createAgreement(String productOrderId, String productOfferingId, String agreementId, List<RelatedPartyTmfVO> relatedParties) {
45
                AgreementItemTmfVO agreementItemTmfVO = new AgreementItemTmfVO()
1✔
46
                                .addProductItem(
1✔
47
                                                new ProductRefTmfVO()
48
                                                                .id(productOrderId))
1✔
49
                                .addProductOfferingItem(
1✔
50
                                                new ProductOfferingRefTmfVO()
51
                                                                .id(productOfferingId));
1✔
52
                CharacteristicTmfVO characteristicTmfVO = new CharacteristicTmfVO()
1✔
53
                                .name(DATA_SPACE_PROTOCOL_AGREEMENT_ID)
1✔
54
                                .value(agreementId);
1✔
55
                AgreementCreateTmfVO agreementCreateTmfVO = new AgreementCreateTmfVO()
1✔
56
                                .characteristic(List.of(characteristicTmfVO))
1✔
57
                                .engagedParty(relatedParties)
1✔
58
                                // prevent empty refs
59
                                .agreementSpecification(null)
1✔
60
                                .addAgreementItemItem(agreementItemTmfVO);
1✔
61

62
                return agreementApiClient
1✔
63
                                .createAgreement(agreementCreateTmfVO)
1✔
64
                                .map(HttpResponse::body)
1✔
65
                                .map(AgreementTmfVO::getId)
1✔
66
                                .onErrorMap(t -> {
1✔
67
                                        throw new TMForumException("Was not able to create agreement", t);
1✔
68
                                });
69
        }
70

71

72
        /**
73
         * Add the id of agreements(from rainbow) to the given product order
74
         */
75
        public Mono<ProductOrderVO> addAgreementToOrder(String productOrderId, List<String> agreementIds) {
76
                List<AgreementRefVO> agreementRefVOS = agreementIds.stream()
1✔
77
                                .map(id -> new AgreementRefVO().id(id))
1✔
78
                                .toList();
1✔
79
                ProductOrderUpdateVO productOrderUpdateVO = new ProductOrderUpdateVO().agreement(agreementRefVOS);
1✔
80
                return productOrderApiClient
1✔
81
                                .patchProductOrder(productOrderId, productOrderUpdateVO)
1✔
82
                                .map(HttpResponse::body)
1✔
83
                                .onErrorMap(t -> new TMForumException("Was not able to update the product order"));
1✔
84
        }
85

86
        /**
87
         * Update the externalId of a quote.
88
         */
89
        public Mono<QuoteVO> updateExternalId(QuoteVO quoteVO, String externalId) {
NEW
90
                QuoteUpdateVO quoteUpdateVO = objectMapper.convertValue(quoteVO.externalId(externalId), QuoteUpdateVO.class);
×
NEW
91
                return quoteApiClient.patchQuote(quoteVO.getId(), quoteUpdateVO)
×
NEW
92
                                .onErrorMap(t -> new TMForumException(String.format("Was not able to update the quote %s.", quoteVO.getId()), t))
×
NEW
93
                                .map(HttpResponse::body);
×
94

95

96
        }
97

98
        /**
99
         * Return the quote with the given id.
100
         */
101
        public Mono<QuoteVO> getQuoteById(String id) {
NEW
102
                return quoteApiClient.retrieveQuote(id, null)
×
NEW
103
                                .onErrorMap(t -> {
×
NEW
104
                                        throw new TMForumException(String.format("Was not able to get the quote %s.", id), t);
×
105
                                })
NEW
106
                                .map(HttpResponse::body);
×
107
        }
108

109
}
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