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

FIWARE / contract-management / #9

21 Sep 2023 09:02AM UTC coverage: 0.196%. First build
#9

Pull #1

pulledtim
api update
Pull Request #1: init

138 of 138 new or added lines in 10 files covered. (100.0%)

29 of 14769 relevant lines covered (0.2%)

0.0 hits per line

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

26.67
/src/main/java/org/fiware/iam/tmforum/NotificationSubscriber.java
1
package org.fiware.iam.tmforum;
2

3
import io.micronaut.context.annotation.Value;
4
import io.micronaut.context.event.ApplicationEventListener;
5
import io.micronaut.http.HttpResponse;
6
import io.micronaut.runtime.server.event.ServerStartupEvent;
7
import io.micronaut.scheduling.TaskScheduler;
8
import jakarta.inject.Singleton;
9
import lombok.RequiredArgsConstructor;
10
import lombok.extern.slf4j.Slf4j;
11
import org.fiware.iam.tmforum.product.client.api.EventsSubscriptionApiClient;
12
import org.fiware.iam.tmforum.product.client.model.EventSubscriptionInputVO;
13
import org.fiware.iam.tmforum.product.client.model.EventSubscriptionVO;
14

15
import java.time.Duration;
16

17
import static org.fiware.iam.tmforum.product.server.api.NotificationListenersClientSideApi.PATH_LISTEN_TO_PRODUCT_ORDER_CREATE_EVENT;
18

19
@Singleton
20
@RequiredArgsConstructor
1✔
21
@Slf4j
1✔
22
public class NotificationSubscriber implements ApplicationEventListener<ServerStartupEvent> {
23

24
    private final EventsSubscriptionApiClient eventsSubscriptionApi;
25

26
    private final TaskScheduler taskScheduler;
27

28
    @Value("${general.basepath:}")
29
    private String controllerPath;
30

31

32
    @Value("${general.port:8080}")
33
    private String servicePort;
34

35
    @Value("${general.name:contract-management}")
36
    private String serviceUrl;
37

38
    /**
39
     * Register a subscription at the TM Forum API service after startup. Using the
40
     * {@link io.micronaut.scheduling.annotation.Scheduled} annotation resulted in start
41
     * failure like https://stackoverflow.com/q/77075901/4341660
42
     * @param event
43
     */
44
    @Override
45
    public void onApplicationEvent(ServerStartupEvent event) {
46
        //TODO Fixed rate should be better fit if we don't have an option to check if the subscription still exists
47
        taskScheduler.schedule(Duration.ofSeconds(10), () -> {
1✔
48
            try {
49
                String callbackUrl = String.format("http://%s:%s%s%s", serviceUrl, servicePort, controllerPath, PATH_LISTEN_TO_PRODUCT_ORDER_CREATE_EVENT);
×
50
                log.info("Attempting to register subscription with callback {}", callbackUrl);
×
51

52
                EventSubscriptionInputVO subscription = new EventSubscriptionInputVO()
×
53
                        .callback(callbackUrl)
×
54
                        .query("eventType=ProductOrderCreateEvent"); //TODO define query
×
55
                HttpResponse<EventSubscriptionVO> eventSubscriptionVOHttpResponse = eventsSubscriptionApi.registerListener(subscription);
×
56
                log.info("Got reply {} and status {}", eventSubscriptionVOHttpResponse.body(), eventSubscriptionVOHttpResponse.getStatus());
×
57
            } catch (Exception e) {
×
58
                log.error("Could not create subscription in TM Forum API", e);
×
59
            }
×
60
        });
×
61
    }
1✔
62
}
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