• 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

0.0
/src/main/java/org/fiware/iam/tmforum/handlers/QuoteEventHandler.java
1
package org.fiware.iam.tmforum.handlers;
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.dsp.RainbowAdapter;
9
import org.fiware.iam.exception.RainbowException;
10
import org.fiware.iam.tmforum.TMForumAdapter;
11
import org.fiware.iam.tmforum.quote.api.QuoteApiClient;
12
import org.fiware.iam.tmforum.quote.model.*;
13
import org.fiware.rainbow.api.ContractApiClient;
14
import org.fiware.rainbow.model.*;
15
import reactor.core.publisher.Mono;
16

17
import java.util.List;
18
import java.util.Map;
19
import java.util.UUID;
20

21
/**
22
 * Handle all incoming events in connection to Quote
23
 */
24
@RequiredArgsConstructor
25
@Singleton
NEW
26
@Slf4j
×
27
public class QuoteEventHandler implements EventHandler {
28

29
        private static final String URN_UUID_TEMPLATE = "urn:uuid:%s";
30

31
        private static final String CREATE_EVENT = "QuoteCreateEvent";
32
        private static final String DELETE_EVENT = "QuoteDeleteEvent";
33
        private static final String STATE_CHANGE_EVENT = "QuoteStateChangeEvent";
34
        private static final String ATTRIBUTE_CHANGE_EVENT = "QuoteAttributeValueChangeEvent";
35

NEW
36
        private static final List<String> SUPPORTED_EVENT_TYPES = List.of(CREATE_EVENT, DELETE_EVENT, STATE_CHANGE_EVENT, ATTRIBUTE_CHANGE_EVENT);
×
37

38
        private final ObjectMapper objectMapper;
39
        private final ContractApiClient contractApiClient;
40
        private final TMForumAdapter tmForumAdapter;
41
        private final RainbowAdapter rainbowAdapter;
42

43

44
        @Override
45
        public boolean isEventTypeSupported(String eventType) {
NEW
46
                return SUPPORTED_EVENT_TYPES.contains(eventType);
×
47
        }
48

49
        @Override
50
        public Mono<HttpResponse<?>> handleEvent(String eventType, Map<String, Object> event) {
NEW
51
                return switch (eventType) {
×
NEW
52
                        case CREATE_EVENT -> handleQuoteCreation(event);
×
NEW
53
                        case STATE_CHANGE_EVENT, ATTRIBUTE_CHANGE_EVENT -> handleQuoteStateChange(event);
×
NEW
54
                        case DELETE_EVENT -> handleQuoteDeletion(event);
×
NEW
55
                        default -> throw new IllegalArgumentException("Even type %s is not supported.".formatted(eventType));
×
56
                };
57
        }
58

59
        private Mono<HttpResponse<?>> handleQuoteCreation(Map<String, Object> event) {
NEW
60
                QuoteCreateEventVO quoteCreateEventVO = objectMapper.convertValue(event, QuoteCreateEventVO.class);
×
NEW
61
                QuoteVO quoteVO = quoteCreateEventVO.getEvent()
×
NEW
62
                                .getQuote();
×
NEW
63
                NegotiationRequestVO negotiationRequestVO = quoteVO
×
NEW
64
                                .getQuoteItem()
×
NEW
65
                                .stream().map(QuoteItemVO::getProductOffering)
×
NEW
66
                                .map(ProductOfferingRefVO::getId)
×
NEW
67
                                .findFirst()
×
NEW
68
                                .map(offerId -> new NegotiationRequestVO()
×
NEW
69
                                                .dspaceColonCallbackAddress("http://something.org")
×
NEW
70
                                                .dspaceColonConsumerPid(String.format(URN_UUID_TEMPLATE, UUID.randomUUID()))
×
NEW
71
                                                .dspaceColonOffer(new OfferVO()
×
NEW
72
                                                                .atId(offerId)
×
NEW
73
                                                                .odrlColonTarget("urn:some:urn")
×
NEW
74
                                                                .odrlColonPermission(List.of(new PermissionVO()
×
NEW
75
                                                                                .odrlColonAction("odrl:use")))))
×
NEW
76
                                .orElseThrow(() -> new IllegalArgumentException("The event does not reference an offer."));
×
77

NEW
78
                return rainbowAdapter
×
NEW
79
                                .createNegotiationRequest(negotiationRequestVO)
×
NEW
80
                                .flatMap(id -> tmForumAdapter.updateExternalId(quoteVO, id))
×
NEW
81
                                .map(t -> HttpResponse.noContent());
×
82
        }
83

84
        private Mono<HttpResponse<?>> handleQuoteStateChange(Map<String, Object> event) {
NEW
85
                QuoteStateChangeEventVO quoteStateChangeEventVO = objectMapper.convertValue(event, QuoteStateChangeEventVO.class);
×
NEW
86
                QuoteVO quoteVO = quoteStateChangeEventVO.getEvent()
×
NEW
87
                                .getQuote();
×
88

NEW
89
                QuoteStateTypeVO quoteStateTypeVO = quoteVO.getState();
×
NEW
90
                return switch (quoteStateTypeVO) {
×
91
                        case APPROVED ->
NEW
92
                                        rainbowAdapter.updateNegotiationProcessByProviderId(quoteVO.getExternalId(), "dspace:OFFERED")
×
NEW
93
                                                        .map(t -> HttpResponse.noContent());
×
94
                        case ACCEPTED ->
NEW
95
                                        rainbowAdapter.updateNegotiationProcessByProviderId(quoteVO.getExternalId(), "dspace:AGREED")
×
NEW
96
                                                        .map(t -> HttpResponse.noContent());
×
NEW
97
                        default -> Mono.just(HttpResponse.badRequest());
×
98
                };
99
        }
100

101
        private Mono<HttpResponse<?>> handleQuoteDeletion(Map<String, Object> event) {
NEW
102
                QuoteDeleteEventVO quoteDeleteEventVO = objectMapper.convertValue(event, QuoteDeleteEventVO.class);
×
NEW
103
                QuoteVO quoteVO = quoteDeleteEventVO.getEvent()
×
NEW
104
                                .getQuote();
×
105

NEW
106
                if (quoteVO.getExternalId() == null && !quoteVO.getExternalId().isEmpty()) {
×
NEW
107
                        return rainbowAdapter.updateNegotiationProcessByProviderId(quoteVO.getExternalId(), "dspace:TERMINATED")
×
NEW
108
                                        .map(t -> HttpResponse.noContent());
×
109
                }
110

NEW
111
                return Mono.just(HttpResponse.noContent());
×
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