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

FIWARE / contract-management / #36

09 Apr 2025 12:52PM UTC coverage: 1.745% (+0.8%) from 0.982%
#36

Pull #5

wistefan
fix tmf version
Pull Request #5: integrate contract negotiation

25 of 340 new or added lines in 12 files covered. (7.35%)

16673 existing lines in 365 files now uncovered.

588 of 33695 relevant lines covered (1.75%)

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/PriceMapper.java
1
package org.fiware.iam;
2

3
import io.micronaut.http.HttpResponse;
4
import jakarta.inject.Singleton;
5
import lombok.RequiredArgsConstructor;
6
import lombok.extern.slf4j.Slf4j;
7
import org.fiware.iam.exception.TMForumException;
8
import org.fiware.iam.tmforum.productcatalog.api.CatalogApiClient;
9
import org.fiware.iam.tmforum.productcatalog.api.ProductOfferingPriceApiClient;
10
import org.fiware.iam.tmforum.productcatalog.model.ProductOfferingPriceVO;
11
import org.fiware.iam.tmforum.quote.model.MoneyVO;
12
import org.fiware.iam.tmforum.quote.model.QuotePriceVO;
13
import org.fiware.rainbow.model.ObligationVO;
14
import reactor.core.publisher.Mono;
15

16
import java.util.*;
17

NEW
18
@Slf4j
×
19
@Singleton
20
@RequiredArgsConstructor
21
public class PriceMapper {
22

23
        private final ProductOfferingPriceApiClient productOfferingPriceApiClient;
24

25
        public static final String PAYMENT_ACTION = "odrl:use";
26
        private static final String PAY_AMOUNT_OPERATOR = "odrl:payAmount";
27
        private static final String ODRL_OPERATOR = "odrl:operator";
28
        private static final String ODRL_EQ = "odrl:eq";
29
        private static final String ODRL_RIGHT_OPERAND = "odrl:rightOperand";
30
        private static final String ODRL_LEFT_OPERAND = "odrl:leftOperand";
31
        private static final String ODRL_UNIT = "odrl:unit";
32
        private static final String ODRL_ELAPSED_TIME = "odrl:elapsedTime";
33
        private static final String VALUE_KEY = "@value";
34
        private static final String TYPE_KEY = "@type";
35
        private static final String DECIMAL_TYPE = "xsd:decimal";
36
        private static final String DURATION_TYPE = "xsd:duration";
37

38

39
        private static final String PRICE_TYPE_RECURRING = "recurring";
40
        private static final String PRICE_TYPE_ONE_TIME = "oneTime";
41

42
        public Mono<List<Object>> toObligationConstraints(QuotePriceVO priceVO) {
43

NEW
44
                List<Object> constraints = new ArrayList<>();
×
45

NEW
46
                if (priceVO.getPrice() != null) {
×
NEW
47
                        MoneyVO moneyVO = priceVO.getPrice().getTaxIncludedAmount();
×
NEW
48
                        constraints.add(getPaymentConstraint(moneyVO.getValue(), moneyVO.getUnit()));
×
49
                }
50

NEW
51
                if (priceVO.getPriceAlteration() != null && !priceVO.getPriceAlteration().isEmpty()) {
×
NEW
52
                        log.warn("Price alteration not supported at the moment.");
×
53
                }
NEW
54
                if (priceVO.getProductOfferingPrice() != null) {
×
NEW
55
                        return productOfferingPriceApiClient
×
NEW
56
                                        .retrieveProductOfferingPrice(priceVO.getProductOfferingPrice().getId(), null)
×
NEW
57
                                        .map(HttpResponse::body)
×
NEW
58
                                        .map(pop -> {
×
NEW
59
                                                List<Object> popConstraint = new ArrayList<>();
×
NEW
60
                                                getPeriod(pop).ifPresent(popConstraint::add);
×
NEW
61
                                                popConstraint.add(getAmount(pop));
×
NEW
62
                                                return popConstraint;
×
63
                                        })
NEW
64
                                        .map(pcs -> {
×
NEW
65
                                                pcs.addAll(constraints);
×
NEW
66
                                                return pcs;
×
67
                                        })
NEW
68
                                        .onErrorMap(t -> new TMForumException(String.format("Was not able to retrieve the offeringPrice %s.", priceVO.getProductOfferingPrice().getId()), t));
×
69
                }
70

NEW
71
                return Mono.just(constraints);
×
72
        }
73

74
        private Map<String, Object> getAmount(ProductOfferingPriceVO pop) {
NEW
75
                return getPaymentConstraint(pop.getPrice().getValue(), pop.getPrice().getUnit());
×
76
        }
77

78
        private Optional<Map<String, Object>> getPeriod(ProductOfferingPriceVO pop) {
NEW
79
                return switch (pop.getPriceType()) {
×
NEW
80
                        case PRICE_TYPE_RECURRING -> Optional.of(Map.of(ODRL_LEFT_OPERAND, ODRL_ELAPSED_TIME,
×
81
                                        ODRL_OPERATOR, ODRL_EQ,
NEW
82
                                        ODRL_RIGHT_OPERAND, Map.of(TYPE_KEY, DURATION_TYPE, VALUE_KEY, getChargePeriod(pop))));
×
NEW
83
                        case PRICE_TYPE_ONE_TIME -> Optional.empty();
×
84
                        default ->
NEW
85
                                        throw new TMForumException(String.format("Price type is not supported: %s.", pop.getPriceType()));
×
86
                };
87
        }
88

89
        private String getChargePeriod(ProductOfferingPriceVO priceVO) {
NEW
90
                String typeIndicator = switch (priceVO.getRecurringChargePeriodType()) {
×
NEW
91
                        case "monthly", "month" -> "M";
×
NEW
92
                        case "weekly", "week" -> "W";
×
93
                        default ->
NEW
94
                                        throw new TMForumException(String.format("Charge period type is not supported: %s.", priceVO.getRecurringChargePeriodType()));
×
95
                };
96

NEW
97
                return String.format("P%s%s", priceVO.getRecurringChargePeriodLength(), typeIndicator);
×
98
        }
99

100
        private Map<String, Object> getPaymentConstraint(Float amount, String unit) {
NEW
101
                return Map.of(ODRL_LEFT_OPERAND, PAY_AMOUNT_OPERATOR,
×
102
                                ODRL_OPERATOR, ODRL_EQ,
NEW
103
                                ODRL_RIGHT_OPERAND, Map.of(VALUE_KEY, amount.toString(), TYPE_KEY, DECIMAL_TYPE));
×
104
        }
105
}
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