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

FIWARE / contract-management / #68

29 Oct 2025 11:26AM UTC coverage: 1.686% (+0.04%) from 1.651%
#68

Pull #12

wistefan
fixes from pr review
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

0.0
/src/main/java/org/fiware/iam/tmforum/handlers/ProductOfferingEventHandler.java
1
package org.fiware.iam.tmforum.handlers;
2

3
import com.fasterxml.jackson.databind.ObjectMapper;
4
import io.micronaut.context.annotation.Requires;
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.configuration.GeneralProperties;
10
import org.fiware.iam.handlers.ProductOfferingHandler;
11
import org.fiware.iam.tmforum.productcatalog.model.*;
12
import reactor.core.publisher.Mono;
13

14
import java.util.List;
15
import java.util.Map;
16
import java.util.Optional;
17

18
/**
19
 * Handle all incoming events in connection to ProductOfferings
20
 */
21
@Requires(condition = GeneralProperties.TmForumCondition.class)
22
@RequiredArgsConstructor
23
@Singleton
24
@Slf4j
×
25
public class ProductOfferingEventHandler implements TMForumEventHandler {
26

27

28
    private static final String CREATE_EVENT = "ProductOfferingCreateEvent";
29
    private static final String DELETE_EVENT = "ProductOfferingDeleteEvent";
30
    private static final String STATE_CHANGE_EVENT = "ProductOfferingStateChangeEvent";
31

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

34

35
    private final ObjectMapper objectMapper;
36
    private final List<ProductOfferingHandler> productOfferingHandlers;
37

38
    @Override
39
    public boolean isEventTypeSupported(String eventType) {
NEW
40
        return SUPPORTED_EVENT_TYPES.contains(eventType);
×
41
    }
42

43
    @Override
44
    public Mono<HttpResponse<?>> handleEvent(String eventType, Map<String, Object> event) {
NEW
45
        return switch (eventType) {
×
NEW
46
            case CREATE_EVENT -> handleOfferingCreation(event);
×
NEW
47
            case STATE_CHANGE_EVENT -> handleOfferingStateChange(event);
×
NEW
48
            case DELETE_EVENT -> handleOfferingDeletion(event);
×
NEW
49
            default -> throw new IllegalArgumentException("Even type %s is not supported.".formatted(eventType));
×
50
        };
51
    }
52

53
    private Mono<HttpResponse<?>> handleOfferingCreation(Map<String, Object> event) {
NEW
54
        ProductOfferingCreateEventVO productOfferingCreateEventVO = objectMapper.convertValue(event, ProductOfferingCreateEventVO.class);
×
NEW
55
        ProductOfferingVO productOfferingVO = Optional.ofNullable(productOfferingCreateEventVO.getEvent())
×
NEW
56
                .map(ProductOfferingCreateEventPayloadVO::getProductOffering)
×
NEW
57
                .orElseThrow(() -> new IllegalArgumentException("The event does not contain a product offering."));
×
58

NEW
59
        if (productOfferingVO.getCategory() == null || productOfferingVO.getCategory().isEmpty()) {
×
NEW
60
            throw new IllegalArgumentException("Product offering does not have a category.");
×
61
        }
62

NEW
63
        List<Mono<HttpResponse<?>>> responses = productOfferingHandlers.stream()
×
NEW
64
                .map(handler -> handler.handleOfferingCreation(productOfferingVO))
×
NEW
65
                .toList();
×
66

NEW
67
        return zipToResponse(responses);
×
68

69
    }
70

71
    private Mono<HttpResponse<?>> handleOfferingStateChange(Map<String, Object> event) {
NEW
72
        ProductOfferingStateChangeEventVO productOfferingStateChangeEventVO = objectMapper.convertValue(event, ProductOfferingStateChangeEventVO.class);
×
NEW
73
        ProductOfferingVO productOfferingVO = Optional.ofNullable(productOfferingStateChangeEventVO.getEvent())
×
NEW
74
                .map(ProductOfferingStateChangeEventPayloadVO::getProductOffering)
×
NEW
75
                .orElseThrow(() -> new IllegalArgumentException("The event does not contain a product offering."));
×
76

NEW
77
        if (productOfferingVO.getCategory() == null || productOfferingVO.getCategory().isEmpty()) {
×
78
            // if no category is included, the offering is not part of a catalog anymore
NEW
79
            return deleteOffering(productOfferingVO);
×
80
        }
81

NEW
82
        List<Mono<HttpResponse<?>>> responses = productOfferingHandlers.stream()
×
NEW
83
                .map(handler -> handler.handleOfferingStateChange(productOfferingVO))
×
NEW
84
                .toList();
×
85

NEW
86
        return zipToResponse(responses);
×
87
    }
88

89

90
    private Mono<HttpResponse<?>> handleOfferingDeletion(Map<String, Object> event) {
91

NEW
92
        ProductOfferingDeleteEventVO productOfferingDeleteEventVO = objectMapper.convertValue(event, ProductOfferingDeleteEventVO.class);
×
NEW
93
        ProductOfferingVO productOfferingVO = Optional.ofNullable(productOfferingDeleteEventVO.getEvent())
×
NEW
94
                .map(ProductOfferingDeleteEventPayloadVO::getProductOffering)
×
NEW
95
                .orElseThrow(() -> new IllegalArgumentException("The event does not contain a product offering."));
×
96

NEW
97
        return deleteOffering(productOfferingVO);
×
98

99
    }
100

101
    private Mono<HttpResponse<?>> deleteOffering(ProductOfferingVO productOfferingVO) {
NEW
102
        List<Mono<HttpResponse<?>>> responses = productOfferingHandlers.stream()
×
NEW
103
                .map(handler -> handler.handleOfferingDeletion(productOfferingVO))
×
NEW
104
                .toList();
×
105

NEW
106
        return zipToResponse(responses);
×
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