diff --git a/.github/workflows/conformance-test.yaml b/.github/workflows/conformance-test.yaml index 096691ae..f261d696 100644 --- a/.github/workflows/conformance-test.yaml +++ b/.github/workflows/conformance-test.yaml @@ -12,7 +12,7 @@ jobs: matrix: # product-catalog is not included, since the tests currently are not accessible. # customer-management, customer-bill-management, product-ordering-management is not included, since the tests contain invalid references. - module: [ party-catalog, product-inventory, resource-catalog, resource-function-activation, resource-inventory, service-catalog ] + module: [ party-catalog, party-role, product-inventory, resource-catalog, resource-function-activation, resource-inventory, service-catalog ] steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/parallel-test.yml b/.github/workflows/parallel-test.yml index c5c800a8..9b66a947 100644 --- a/.github/workflows/parallel-test.yml +++ b/.github/workflows/parallel-test.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - module: [ customer-bill-management, customer-management, party-catalog, product-catalog, product-inventory, product-ordering-management, resource-catalog, resource-function-activation, resource-inventory, service-catalog ] + module: [ customer-bill-management, customer-management, party-catalog, party-role, product-catalog, product-inventory, product-ordering-management, resource-catalog, resource-function-activation, resource-inventory, service-catalog ] steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/test-caches.yaml b/.github/workflows/test-caches.yaml index ea1016cc..8c3ef428 100644 --- a/.github/workflows/test-caches.yaml +++ b/.github/workflows/test-caches.yaml @@ -31,4 +31,4 @@ jobs: - name: Execute tests id: test run: | - mvn clean test integration-test verify -Dcache=${{matrix.cache}} \ No newline at end of file + mvn clean test integration-test verify -Dbroker=scorpio -Dcache=${{matrix.cache}} \ No newline at end of file diff --git a/account/src/main/java/org/fiware/tmforum/account/TMForumMapper.java b/account/src/main/java/org/fiware/tmforum/account/TMForumMapper.java index c393c06b..d5ba6773 100644 --- a/account/src/main/java/org/fiware/tmforum/account/TMForumMapper.java +++ b/account/src/main/java/org/fiware/tmforum/account/TMForumMapper.java @@ -1,12 +1,10 @@ package org.fiware.tmforum.account; -import org.fiware.tmforum.common.domain.subscription.Subscription; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; import org.fiware.tmforum.common.mapping.IdHelper; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.fiware.tmforum.common.domain.TimePeriod; -import io.github.wistefan.mapping.MappingException; -import org.fiware.tmforum.common.mapping.IdHelper; import org.fiware.account.model.*; import org.fiware.tmforum.account.domain.*; import java.net.MalformedURLException; @@ -125,7 +123,7 @@ public interface TMForumMapper { SettlementAccountVO map(SettlementAccountUpdateVO settlementAccountUpdateVO, String id); @Mapping(target = "query", source = "rawQuery") - EventSubscriptionVO map(Subscription subscription); + EventSubscriptionVO map(TMForumSubscription subscription); TimePeriod map(TimePeriodVO value); diff --git a/account/src/main/java/org/fiware/tmforum/account/rest/BillFormatApiController.java b/account/src/main/java/org/fiware/tmforum/account/rest/BillFormatApiController.java index 79eaa3df..686b606b 100644 --- a/account/src/main/java/org/fiware/tmforum/account/rest/BillFormatApiController.java +++ b/account/src/main/java/org/fiware/tmforum/account/rest/BillFormatApiController.java @@ -4,21 +4,20 @@ import io.micronaut.http.annotation.Controller; import lombok.extern.slf4j.Slf4j; import org.fiware.account.api.BillFormatApi; -import org.fiware.account.api.BillFormatApi; import org.fiware.account.model.BillFormatCreateVO; import org.fiware.account.model.BillFormatUpdateVO; import org.fiware.account.model.BillFormatVO; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.account.TMForumMapper; +import org.fiware.tmforum.account.domain.BillFormat; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; import org.fiware.tmforum.common.validation.ReferencedEntity; -import org.fiware.tmforum.account.TMForumMapper; -import org.fiware.tmforum.account.domain.BillFormat; import reactor.core.publisher.Mono; import javax.annotation.Nullable; @@ -33,7 +32,8 @@ public class BillFormatApiController extends AbstractApiController i private final TMForumMapper tmForumMapper; public BillFormatApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository productBillFormatRepository, TMForumMapper tmForumMapper, EventHandler eventHandler) { + TmForumRepository productBillFormatRepository, TMForumMapper tmForumMapper, + TMForumEventHandler eventHandler) { super(queryParser, validationService, productBillFormatRepository, eventHandler); this.tmForumMapper = tmForumMapper; } diff --git a/account/src/main/java/org/fiware/tmforum/account/rest/BillPresentationMediaApiController.java b/account/src/main/java/org/fiware/tmforum/account/rest/BillPresentationMediaApiController.java index a3282330..e3b7869a 100644 --- a/account/src/main/java/org/fiware/tmforum/account/rest/BillPresentationMediaApiController.java +++ b/account/src/main/java/org/fiware/tmforum/account/rest/BillPresentationMediaApiController.java @@ -7,17 +7,17 @@ import org.fiware.account.model.BillPresentationMediaCreateVO; import org.fiware.account.model.BillPresentationMediaUpdateVO; import org.fiware.account.model.BillPresentationMediaVO; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.account.TMForumMapper; +import org.fiware.tmforum.account.domain.BillPresentationMedia; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; import org.fiware.tmforum.common.validation.ReferencedEntity; -import org.fiware.tmforum.account.TMForumMapper; -import org.fiware.tmforum.account.domain.BillPresentationMedia; import reactor.core.publisher.Mono; import javax.annotation.Nullable; @@ -32,7 +32,8 @@ public class BillPresentationMediaApiController extends AbstractApiController EVENT_GROUPS = List.of(EVENT_GROUP_BILL_FORMAT, /*EVENT_GROUP_BILLING_ACCOUNT,*/ EVENT_GROUP_BILLING_CYCLE_SPECIFICATION, EVENT_GROUP_BILL_PRESENTATION_MEDIA, EVENT_GROUP_FINANCIAL_ACCOUNT, EVENT_GROUP_PARTY_ACCOUNT, EVENT_GROUP_SETTLEMENT_ACCOUNT); + private static final Map> ENTITY_NAME_TO_ENTITY_CLASS_MAPPING = Map.ofEntries( + entry(BillFormat.TYPE_BILLF, BillFormat.class), + entry(BillingAccount.TYPE_BILLINGAC, BillingAccount.class), + entry(BillingCycleSpecification.TYPE_BILLCL, BillingCycleSpecification.class), + entry(BillPresentationMedia.TYPE_BILLPM, BillPresentationMedia.class), + entry(FinancialAccount.TYPE_FINANCIALAC, FinancialAccount.class), + entry(PartyAccount.TYPE_PARTYAC, PartyAccount.class), + entry(SettlementAccount.TYPE_SETTLEMENTAC, SettlementAccount.class) + ); public EventSubscriptionApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, TMForumMapper tmForumMapper, EventHandler eventHandler) { - super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, eventHandler); + TmForumRepository repository, TMForumMapper tmForumMapper, + TMForumEventHandler tmForumEventHandler, NgsiLdEventHandler ngsiLdEventHandler, + GeneralProperties generalProperties, EntityVOMapper entityVOMapper) { + super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, + ENTITY_NAME_TO_ENTITY_CLASS_MAPPING, tmForumEventHandler, ngsiLdEventHandler, + generalProperties, entityVOMapper); this.tmForumMapper = tmForumMapper; } @Override public Mono> registerListener( @NonNull EventSubscriptionInputVO eventSubscriptionInputVO) { - Subscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), + TMForumSubscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), eventSubscriptionInputVO.getQuery(), EVENT_GROUPS); return create(subscription) diff --git a/account/src/main/java/org/fiware/tmforum/account/rest/FinancialAccountApiController.java b/account/src/main/java/org/fiware/tmforum/account/rest/FinancialAccountApiController.java index 0c6321d9..27a9e31e 100644 --- a/account/src/main/java/org/fiware/tmforum/account/rest/FinancialAccountApiController.java +++ b/account/src/main/java/org/fiware/tmforum/account/rest/FinancialAccountApiController.java @@ -7,23 +7,22 @@ import org.fiware.account.model.FinancialAccountCreateVO; import org.fiware.account.model.FinancialAccountUpdateVO; import org.fiware.account.model.FinancialAccountVO; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.account.TMForumMapper; +import org.fiware.tmforum.account.domain.FinancialAccount; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; import org.fiware.tmforum.common.validation.ReferencedEntity; -import org.fiware.tmforum.account.TMForumMapper; -import org.fiware.tmforum.account.domain.FinancialAccount; import reactor.core.publisher.Mono; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; -import java.util.Optional; import java.util.UUID; @Slf4j @@ -33,7 +32,8 @@ public class FinancialAccountApiController extends AbstractApiController provideBillFormatUpdates() { return testEntries.stream(); } - - @Disabled - @ParameterizedTest - @MethodSource("provideInvalidUpdates") - public void patchBillFormat400(String message, BillFormatUpdateVO invalidUpdateVO) throws Exception { - this.message = message; - this.billFormatUpdateVO = invalidUpdateVO; - patchBillFormat400(); - } @Override public void patchBillFormat400() throws Exception { diff --git a/account/src/test/java/org/fiware/tmforum/account/BillPresentationMediaApiIT.java b/account/src/test/java/org/fiware/tmforum/account/BillPresentationMediaApiIT.java index 1304115a..fbcaf069 100644 --- a/account/src/test/java/org/fiware/tmforum/account/BillPresentationMediaApiIT.java +++ b/account/src/test/java/org/fiware/tmforum/account/BillPresentationMediaApiIT.java @@ -4,18 +4,17 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.micronaut.http.HttpResponse; import io.micronaut.http.HttpStatus; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.fiware.ngsi.api.EntitiesApiClient; import io.micronaut.test.annotation.MockBean; import io.micronaut.test.extensions.junit5.annotation.MicronautTest; -import org.fiware.account.api.BillPresentationMediaApiTestSpec; import org.fiware.account.api.BillPresentationMediaApiTestClient; +import org.fiware.account.api.BillPresentationMediaApiTestSpec; +import org.fiware.account.model.*; +import org.fiware.ngsi.api.EntitiesApiClient; import org.fiware.tmforum.account.domain.BillPresentationMedia; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; -import org.fiware.account.model.*; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -23,7 +22,6 @@ import org.junit.jupiter.params.provider.MethodSource; import reactor.core.publisher.Mono; -import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -59,13 +57,12 @@ protected String getEntityType() { return BillPresentationMedia.TYPE_BILLPM; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/account/src/test/java/org/fiware/tmforum/account/BillingAccountApiIT.java b/account/src/test/java/org/fiware/tmforum/account/BillingAccountApiIT.java index 9d3e61cc..ac190727 100644 --- a/account/src/test/java/org/fiware/tmforum/account/BillingAccountApiIT.java +++ b/account/src/test/java/org/fiware/tmforum/account/BillingAccountApiIT.java @@ -9,11 +9,10 @@ import org.fiware.account.api.BillingAccountApiTestSpec; import org.fiware.account.model.*; import org.fiware.ngsi.api.EntitiesApiClient; -import org.fiware.tmforum.account.domain.BillStructure; import org.fiware.tmforum.account.domain.BillingAccount; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -22,7 +21,6 @@ import org.junit.jupiter.params.provider.MethodSource; import reactor.core.publisher.Mono; -import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -57,13 +55,12 @@ protected String getEntityType() { return BillingAccount.TYPE_BILLINGAC; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/account/src/test/java/org/fiware/tmforum/account/BillingCycleSpecificationApiIT.java b/account/src/test/java/org/fiware/tmforum/account/BillingCycleSpecificationApiIT.java index 14dad9f3..997a902b 100644 --- a/account/src/test/java/org/fiware/tmforum/account/BillingCycleSpecificationApiIT.java +++ b/account/src/test/java/org/fiware/tmforum/account/BillingCycleSpecificationApiIT.java @@ -5,15 +5,15 @@ import io.micronaut.http.HttpStatus; import io.micronaut.test.annotation.MockBean; import io.micronaut.test.extensions.junit5.annotation.MicronautTest; -import org.fiware.account.model.*; -import org.fiware.ngsi.api.EntitiesApiClient; import org.fiware.account.api.BillingCycleSpecificationApiTestClient; import org.fiware.account.api.BillingCycleSpecificationApiTestSpec; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.account.model.*; +import org.fiware.ngsi.api.EntitiesApiClient; +import org.fiware.tmforum.account.domain.BillingCycleSpecification; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; -import org.fiware.tmforum.account.domain.BillingCycleSpecification; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -56,13 +56,12 @@ protected String getEntityType() { return BillingCycleSpecification.TYPE_BILLCL; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/account/src/test/java/org/fiware/tmforum/account/FinancialAccountApiIT.java b/account/src/test/java/org/fiware/tmforum/account/FinancialAccountApiIT.java index f13157f2..eb984b15 100644 --- a/account/src/test/java/org/fiware/tmforum/account/FinancialAccountApiIT.java +++ b/account/src/test/java/org/fiware/tmforum/account/FinancialAccountApiIT.java @@ -12,7 +12,7 @@ import org.fiware.tmforum.account.domain.FinancialAccount; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -21,7 +21,6 @@ import org.junit.jupiter.params.provider.MethodSource; import reactor.core.publisher.Mono; -import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -57,13 +56,12 @@ protected String getEntityType() { return FinancialAccount.TYPE_FINANCIALAC; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/account/src/test/java/org/fiware/tmforum/account/PartyAccountApiIT.java b/account/src/test/java/org/fiware/tmforum/account/PartyAccountApiIT.java index 5f6113b0..0064aa46 100644 --- a/account/src/test/java/org/fiware/tmforum/account/PartyAccountApiIT.java +++ b/account/src/test/java/org/fiware/tmforum/account/PartyAccountApiIT.java @@ -9,11 +9,10 @@ import org.fiware.account.api.PartyAccountApiTestSpec; import org.fiware.account.model.*; import org.fiware.ngsi.api.EntitiesApiClient; -import org.fiware.tmforum.account.domain.BillStructure; import org.fiware.tmforum.account.domain.PartyAccount; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -22,7 +21,6 @@ import org.junit.jupiter.params.provider.MethodSource; import reactor.core.publisher.Mono; -import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -57,13 +55,12 @@ protected String getEntityType() { return PartyAccount.TYPE_PARTYAC; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/account/src/test/java/org/fiware/tmforum/account/SettlementAccountApiIT.java b/account/src/test/java/org/fiware/tmforum/account/SettlementAccountApiIT.java index 105289bb..9a5bc0b8 100644 --- a/account/src/test/java/org/fiware/tmforum/account/SettlementAccountApiIT.java +++ b/account/src/test/java/org/fiware/tmforum/account/SettlementAccountApiIT.java @@ -9,11 +9,10 @@ import org.fiware.account.api.SettlementAccountApiTestSpec; import org.fiware.account.model.*; import org.fiware.ngsi.api.EntitiesApiClient; -import org.fiware.tmforum.account.domain.BillStructure; import org.fiware.tmforum.account.domain.SettlementAccount; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -22,7 +21,6 @@ import org.junit.jupiter.params.provider.MethodSource; import reactor.core.publisher.Mono; -import java.time.Instant; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -57,13 +55,12 @@ protected String getEntityType() { return SettlementAccount.TYPE_SETTLEMENTAC; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/account/src/test/resources/application.yaml b/account/src/test/resources/application.yaml index dcea27df..052cc73d 100644 --- a/account/src/test/resources/application.yaml +++ b/account/src/test/resources/application.yaml @@ -37,3 +37,4 @@ loggers: general: contextUrl: https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld serverHost: http://localhost:8632 + basePath: /tmf-api/account/v4 \ No newline at end of file diff --git a/agreement/src/main/java/org/fiware/tmforum/agreement/TMForumMapper.java b/agreement/src/main/java/org/fiware/tmforum/agreement/TMForumMapper.java index 1e5ee181..ce9fd5d3 100644 --- a/agreement/src/main/java/org/fiware/tmforum/agreement/TMForumMapper.java +++ b/agreement/src/main/java/org/fiware/tmforum/agreement/TMForumMapper.java @@ -4,7 +4,7 @@ import org.fiware.tmforum.agreement.domain.Agreement; import org.fiware.tmforum.agreement.domain.AgreementSpecification; import org.fiware.tmforum.common.domain.TimePeriod; -import org.fiware.tmforum.common.domain.subscription.Subscription; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; import org.fiware.tmforum.common.mapping.IdHelper; import org.mapstruct.Mapper; import org.mapstruct.Mapping; @@ -43,7 +43,7 @@ public interface TMForumMapper { AgreementSpecificationVO map(AgreementSpecification agreementspecUpdateVO); @Mapping(target = "query", source = "rawQuery") - EventSubscriptionVO map(Subscription subscription); + EventSubscriptionVO map(TMForumSubscription subscription); TimePeriod map(TimePeriodVO value); diff --git a/agreement/src/main/java/org/fiware/tmforum/agreement/rest/AgreementController.java b/agreement/src/main/java/org/fiware/tmforum/agreement/rest/AgreementController.java index f4e09ddc..adc7602d 100644 --- a/agreement/src/main/java/org/fiware/tmforum/agreement/rest/AgreementController.java +++ b/agreement/src/main/java/org/fiware/tmforum/agreement/rest/AgreementController.java @@ -1,34 +1,32 @@ package org.fiware.tmforum.agreement.rest; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -import javax.annotation.Nullable; - +import io.micronaut.core.annotation.NonNull; +import io.micronaut.http.HttpResponse; +import io.micronaut.http.annotation.Controller; +import lombok.extern.slf4j.Slf4j; import org.fiware.agreement.api.AgreementApi; import org.fiware.agreement.model.AgreementCreateVO; import org.fiware.agreement.model.AgreementUpdateVO; import org.fiware.agreement.model.AgreementVO; import org.fiware.tmforum.agreement.TMForumMapper; import org.fiware.tmforum.agreement.domain.Agreement; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; import org.fiware.tmforum.common.validation.ReferencedEntity; - -import io.micronaut.core.annotation.NonNull; -import io.micronaut.http.HttpResponse; -import io.micronaut.http.annotation.Controller; -import lombok.extern.slf4j.Slf4j; import reactor.core.publisher.Mono; +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + @Slf4j @Controller("${general.basepath:/}") public class AgreementController extends AbstractApiController implements AgreementApi { @@ -36,7 +34,7 @@ public class AgreementController extends AbstractApiController implem private final TMForumMapper tmForumMapper; public AgreementController(QueryParser queryParser, ReferenceValidationService validationService, TmForumRepository partyRepository, - TMForumMapper tmForumMapper, EventHandler eventHandler) { + TMForumMapper tmForumMapper, TMForumEventHandler eventHandler) { super(queryParser, validationService, partyRepository, eventHandler); this.tmForumMapper = tmForumMapper; } diff --git a/agreement/src/main/java/org/fiware/tmforum/agreement/rest/AgreementSpecController.java b/agreement/src/main/java/org/fiware/tmforum/agreement/rest/AgreementSpecController.java index 53cfd56f..155c1f6f 100644 --- a/agreement/src/main/java/org/fiware/tmforum/agreement/rest/AgreementSpecController.java +++ b/agreement/src/main/java/org/fiware/tmforum/agreement/rest/AgreementSpecController.java @@ -1,34 +1,32 @@ package org.fiware.tmforum.agreement.rest; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -import javax.annotation.Nullable; - +import io.micronaut.core.annotation.NonNull; +import io.micronaut.http.HttpResponse; +import io.micronaut.http.annotation.Controller; +import lombok.extern.slf4j.Slf4j; import org.fiware.agreement.api.AgreementSpecificationApi; import org.fiware.agreement.model.AgreementSpecificationCreateVO; import org.fiware.agreement.model.AgreementSpecificationUpdateVO; import org.fiware.agreement.model.AgreementSpecificationVO; import org.fiware.tmforum.agreement.TMForumMapper; import org.fiware.tmforum.agreement.domain.AgreementSpecification; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; import org.fiware.tmforum.common.validation.ReferencedEntity; - -import io.micronaut.core.annotation.NonNull; -import io.micronaut.http.HttpResponse; -import io.micronaut.http.annotation.Controller; -import lombok.extern.slf4j.Slf4j; import reactor.core.publisher.Mono; +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + @Slf4j @Controller("${general.basepath:/}") public class AgreementSpecController extends AbstractApiController @@ -37,7 +35,7 @@ public class AgreementSpecController extends AbstractApiController EVENT_GROUPS = List.of( EVENT_GROUP_AGREEMENT, EVENT_GROUP_AGREEMENT_SPECIFICATION); + private static final Map> ENTITY_NAME_TO_ENTITY_CLASS_MAPPING = Map.ofEntries( + entry(Agreement.TYPE_AG, Agreement.class), + entry(AgreementSpecification.TYPE_AGSP, AgreementSpecification.class) + ); public EventSubscriptionApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, TMForumMapper tmForumMapper, EventHandler eventHandler) { - super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, eventHandler); + TmForumRepository repository, TMForumMapper tmForumMapper, + TMForumEventHandler tmForumEventHandler, NgsiLdEventHandler ngsiLdEventHandler, + GeneralProperties generalProperties, EntityVOMapper entityVOMapper) { + super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, + ENTITY_NAME_TO_ENTITY_CLASS_MAPPING, tmForumEventHandler, ngsiLdEventHandler, + generalProperties, entityVOMapper); this.tmForumMapper = tmForumMapper; } @Override public Mono> registerListener( @NonNull EventSubscriptionInputVO eventSubscriptionInputVO) { - Subscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), + TMForumSubscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), eventSubscriptionInputVO.getQuery(), EVENT_GROUPS); return create(subscription) diff --git a/agreement/src/test/java/org/fiware/tmforum/agreement/AgreementApiIT.java b/agreement/src/test/java/org/fiware/tmforum/agreement/AgreementApiIT.java index 79470654..1bb5119b 100644 --- a/agreement/src/test/java/org/fiware/tmforum/agreement/AgreementApiIT.java +++ b/agreement/src/test/java/org/fiware/tmforum/agreement/AgreementApiIT.java @@ -12,7 +12,7 @@ import org.fiware.tmforum.agreement.domain.Agreement; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -62,13 +62,12 @@ protected String getEntityType() { return Agreement.TYPE_AG; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/agreement/src/test/java/org/fiware/tmforum/agreement/AgreementSpecificationApiIT.java b/agreement/src/test/java/org/fiware/tmforum/agreement/AgreementSpecificationApiIT.java index 247afefb..b7aad898 100644 --- a/agreement/src/test/java/org/fiware/tmforum/agreement/AgreementSpecificationApiIT.java +++ b/agreement/src/test/java/org/fiware/tmforum/agreement/AgreementSpecificationApiIT.java @@ -1,51 +1,38 @@ package org.fiware.tmforum.agreement; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.time.Instant; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; - +import com.fasterxml.jackson.databind.ObjectMapper; +import io.micronaut.http.HttpResponse; +import io.micronaut.http.HttpStatus; import io.micronaut.test.annotation.MockBean; +import io.micronaut.test.extensions.junit5.annotation.MicronautTest; import org.fiware.agreement.api.AgreementApiTestSpec; import org.fiware.agreement.api.AgreementSpecificationApiTestClient; -import org.fiware.agreement.model.AgreementSpecificationCreateVO; -import org.fiware.agreement.model.AgreementSpecificationCreateVOTestExample; -import org.fiware.agreement.model.AgreementSpecificationRelationshipVOTestExample; -import org.fiware.agreement.model.AgreementSpecificationUpdateVO; -import org.fiware.agreement.model.AgreementSpecificationUpdateVOTestExample; -import org.fiware.agreement.model.AgreementSpecificationVO; -import org.fiware.agreement.model.AgreementSpecificationVOTestExample; -import org.fiware.agreement.model.CategoryRefVO; -import org.fiware.agreement.model.CategoryRefVOTestExample; -import org.fiware.agreement.model.RelatedPartyVOTestExample; -import org.fiware.agreement.model.TimePeriodVO; -import org.fiware.agreement.model.TimePeriodVOTestExample; +import org.fiware.agreement.model.*; import org.fiware.ngsi.api.EntitiesApiClient; import org.fiware.tmforum.agreement.domain.AgreementSpecification; -import org.fiware.tmforum.common.notification.EventHandler; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import reactor.core.publisher.Mono; -import com.fasterxml.jackson.databind.ObjectMapper; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; -import io.micronaut.http.HttpResponse; -import io.micronaut.http.HttpStatus; -import io.micronaut.test.extensions.junit5.annotation.MicronautTest; -import reactor.core.publisher.Mono; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; @MicronautTest(packages = { "org.fiware.tmforum.agreement" }) public class AgreementSpecificationApiIT extends AbstractApiIT implements AgreementApiTestSpec { @@ -75,13 +62,12 @@ protected String getEntityType() { return AgreementSpecification.TYPE_AGSP; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/agreement/src/test/resources/application.yaml b/agreement/src/test/resources/application.yaml index fde4f97e..5e857146 100644 --- a/agreement/src/test/resources/application.yaml +++ b/agreement/src/test/resources/application.yaml @@ -35,4 +35,6 @@ loggers: --- general: - contextUrl: https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld \ No newline at end of file + contextUrl: https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld + serverHost: http://localhost:8632 + basePath: /tmf-api/agreement/v4 \ No newline at end of file diff --git a/common/pom.xml b/common/pom.xml index c0b00846..ad1dda56 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -128,6 +128,12 @@ resilience4j-reactor ${version.io.github.resilience4j.resilience4j-reactor} + + + com.google.guava + guava + ${version.com.google.guava} + \ No newline at end of file diff --git a/common/src/main/java/org/fiware/tmforum/common/CommonConstants.java b/common/src/main/java/org/fiware/tmforum/common/CommonConstants.java index e8adb3c3..a7ac9dea 100644 --- a/common/src/main/java/org/fiware/tmforum/common/CommonConstants.java +++ b/common/src/main/java/org/fiware/tmforum/common/CommonConstants.java @@ -24,6 +24,11 @@ private CommonConstants() { */ public static final String ENTITIES_CACHE_NAME = "entities"; + /** + * Name for the tmforum-subscriptions cache + */ + public static final String TMFORUM_SUBSCRIPTIONS_CACHE_NAME = "tmforum-subscriptions"; + /** * Name for the subscriptions cache */ diff --git a/common/src/main/java/org/fiware/tmforum/common/caching/ClientTrackingRedisCache.java b/common/src/main/java/org/fiware/tmforum/common/caching/ClientTrackingRedisCache.java index fefd77e8..12f64dd7 100644 --- a/common/src/main/java/org/fiware/tmforum/common/caching/ClientTrackingRedisCache.java +++ b/common/src/main/java/org/fiware/tmforum/common/caching/ClientTrackingRedisCache.java @@ -36,6 +36,7 @@ protected RedisKeyCommands getRedisKeyCommands(StatefulConnectio sync.clientTracking(TrackingArgs.Builder.enabled() .bcast() .prefixes(CommonConstants.SUBSCRIPTIONS_CACHE_NAME) + .prefixes(CommonConstants.TMFORUM_SUBSCRIPTIONS_CACHE_NAME) .prefixes(CommonConstants.ENTITIES_CACHE_NAME) .noloop()); commands = sync; diff --git a/common/src/main/java/org/fiware/tmforum/common/configuration/GeneralProperties.java b/common/src/main/java/org/fiware/tmforum/common/configuration/GeneralProperties.java index 303f8456..e459373c 100644 --- a/common/src/main/java/org/fiware/tmforum/common/configuration/GeneralProperties.java +++ b/common/src/main/java/org/fiware/tmforum/common/configuration/GeneralProperties.java @@ -20,7 +20,12 @@ public class GeneralProperties { /** * Base path for the controllers to be deployed at. If nothing is set, the project-individual defaults will be used */ - private String basePath; + private String basepath; + + /** + * Root URL of the server to be used in the ngsild-subscription callbacks + */ + private String serverHost; /** * Tenant to be used by the tmforum api. @@ -35,12 +40,12 @@ public class GeneralProperties { /** * Character used in target NGSI-LD broker for making - * or queries between mutiple parameters + * or queries between multiple parameters */ private String ngsildOrQueryKey=","; /** - * Whether to enclose queries using bracets or not + * Whether to enclose queries using brackets or not */ private Boolean encloseQuery=false; } diff --git a/common/src/main/java/org/fiware/tmforum/common/domain/subscription/Endpoint.java b/common/src/main/java/org/fiware/tmforum/common/domain/subscription/Endpoint.java new file mode 100644 index 00000000..9fe32558 --- /dev/null +++ b/common/src/main/java/org/fiware/tmforum/common/domain/subscription/Endpoint.java @@ -0,0 +1,30 @@ +package org.fiware.tmforum.common.domain.subscription; + +import io.github.wistefan.mapping.annotations.AttributeGetter; +import io.github.wistefan.mapping.annotations.AttributeSetter; +import io.github.wistefan.mapping.annotations.AttributeType; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +import java.net.URI; +import java.util.List; + +@RequiredArgsConstructor +@AllArgsConstructor +public class Endpoint { + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY, targetName = "uri")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY, targetName = "uri")})) + private URI uri; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY, targetName = "accept")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY, targetName = "accept")})) + private String accept; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY_LIST, targetName = "receiverInfo")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY_LIST, targetName = "receiverInfo")})) + private List receiverInfo; + +} \ No newline at end of file diff --git a/common/src/main/java/org/fiware/tmforum/common/domain/subscription/EntityInfo.java b/common/src/main/java/org/fiware/tmforum/common/domain/subscription/EntityInfo.java new file mode 100644 index 00000000..257f25cc --- /dev/null +++ b/common/src/main/java/org/fiware/tmforum/common/domain/subscription/EntityInfo.java @@ -0,0 +1,30 @@ +package org.fiware.tmforum.common.domain.subscription; + +import io.github.wistefan.mapping.annotations.AttributeGetter; +import io.github.wistefan.mapping.annotations.AttributeSetter; +import io.github.wistefan.mapping.annotations.AttributeType; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +import java.net.URI; + +@EqualsAndHashCode +@RequiredArgsConstructor +public class EntityInfo { + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY, targetName = "type")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY, targetName = "type")})) + private String type; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY, targetName = "id")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY, targetName = "id")})) + private URI id; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY, targetName = "idPattern")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY, targetName = "idPattern")})) + private String idPattern; + +} + diff --git a/common/src/main/java/org/fiware/tmforum/common/domain/subscription/KeyValuePair.java b/common/src/main/java/org/fiware/tmforum/common/domain/subscription/KeyValuePair.java new file mode 100644 index 00000000..d269e756 --- /dev/null +++ b/common/src/main/java/org/fiware/tmforum/common/domain/subscription/KeyValuePair.java @@ -0,0 +1,23 @@ +package org.fiware.tmforum.common.domain.subscription; + +import io.github.wistefan.mapping.annotations.AttributeGetter; +import io.github.wistefan.mapping.annotations.AttributeSetter; +import io.github.wistefan.mapping.annotations.AttributeType; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@RequiredArgsConstructor +@AllArgsConstructor +public class KeyValuePair { + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY, targetName = "key")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY, targetName = "key")})) + private String key; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY, targetName = "value")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY, targetName = "value")})) + private String value; + +} diff --git a/common/src/main/java/org/fiware/tmforum/common/domain/subscription/NotificationParams.java b/common/src/main/java/org/fiware/tmforum/common/domain/subscription/NotificationParams.java new file mode 100644 index 00000000..33f00294 --- /dev/null +++ b/common/src/main/java/org/fiware/tmforum/common/domain/subscription/NotificationParams.java @@ -0,0 +1,30 @@ +package org.fiware.tmforum.common.domain.subscription; + +import io.github.wistefan.mapping.annotations.AttributeGetter; +import io.github.wistefan.mapping.annotations.AttributeSetter; +import io.github.wistefan.mapping.annotations.AttributeType; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +import java.util.Set; + +@EqualsAndHashCode +@RequiredArgsConstructor +public class NotificationParams { + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY_LIST, targetName = "attributes") })) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY_LIST, targetName = "attributes") })) + private Set attributes; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY, targetName = "format")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY, targetName = "format")})) + private String format; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY, targetName = "endpoint")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY, targetName = "endpoint", + targetClass = Endpoint.class)})) + private Endpoint endpoint; + +} \ No newline at end of file diff --git a/common/src/main/java/org/fiware/tmforum/common/domain/subscription/Subscription.java b/common/src/main/java/org/fiware/tmforum/common/domain/subscription/Subscription.java index 164bd61f..8d51fc09 100644 --- a/common/src/main/java/org/fiware/tmforum/common/domain/subscription/Subscription.java +++ b/common/src/main/java/org/fiware/tmforum/common/domain/subscription/Subscription.java @@ -1,54 +1,70 @@ package org.fiware.tmforum.common.domain.subscription; -import io.github.wistefan.mapping.annotations.AttributeGetter; -import io.github.wistefan.mapping.annotations.AttributeSetter; -import io.github.wistefan.mapping.annotations.AttributeType; -import io.github.wistefan.mapping.annotations.MappingEnabled; +import io.github.wistefan.mapping.annotations.*; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; -import org.fiware.tmforum.common.domain.EntityWithId; +import org.fiware.tmforum.common.mapping.IdHelper; import java.net.URI; import java.util.List; +import java.util.Set; -@EqualsAndHashCode(callSuper = true) +@EqualsAndHashCode @MappingEnabled(entityType = Subscription.TYPE_SUBSCRIPTION) -public class Subscription extends EntityWithId { - public static final String TYPE_SUBSCRIPTION = "tm-forum-subscription"; - - @Getter(onMethod = @__({ @AttributeGetter(value = AttributeType.PROPERTY, targetName = "callback") })) - @Setter(onMethod = @__({ @AttributeSetter(value = AttributeType.PROPERTY, targetName = "callback") })) - private URI callback; - - @Getter(onMethod = @__({ @AttributeGetter(value = AttributeType.PROPERTY, targetName = "query") })) - @Setter(onMethod = @__({ @AttributeSetter(value = AttributeType.PROPERTY, targetName = "query") })) - private String query; - - @Getter(onMethod = @__({ @AttributeGetter(value = AttributeType.PROPERTY, targetName = "rawQuery") })) - @Setter(onMethod = @__({ @AttributeSetter(value = AttributeType.PROPERTY, targetName = "rawQuery") })) - private String rawQuery; - - @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY_LIST, targetName = "eventTypes") })) - @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY_LIST, targetName = "eventTypes", targetClass = String.class) })) - private List eventTypes; - - @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY_LIST, targetName = "entities") })) - @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY_LIST, targetName = "entities", targetClass = String.class) })) - private List entities; - - @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY_LIST, targetName = "fields") })) - @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY_LIST, targetName = "fields", targetClass = String.class) })) - private List fields; - - /** - * Empty constructor for cache serialization and deserialization - */ - public Subscription() { - super(TYPE_SUBSCRIPTION, null); - } - - public Subscription(String id) { - super(TYPE_SUBSCRIPTION, id); - } +public class Subscription { + public static final String TYPE_SUBSCRIPTION = "Subscription"; + + /** + * Type of the subscription + */ + @Getter(onMethod = @__({ @EntityType})) + private final String type; + + /** + * ID of the subscription. This is the id part of "urn:ngsi-ld:TYPE:ID" + */ + @Ignore + @Getter(onMethod = @__({ @EntityId })) + @Setter + private URI id; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY, targetName = "q")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY, targetName = "q")})) + private String q; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY, targetName = "notification")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY, targetName = "notification", + targetClass = NotificationParams.class)})) + private NotificationParams notification; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY_LIST, targetName = "entities")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY_LIST, targetName = "entities", + targetClass = EntityInfo.class)})) + private List entities; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY, targetName = "name")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY, targetName = "name")})) + private String name; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY, targetName = "description")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY, targetName = "description")})) + private String description; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY_LIST, targetName = "watchedAttributes")})) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY_LIST, targetName = "watchedAttributes")})) + private Set watchedAttributes; + + public Subscription(String id) { + this.type = TYPE_SUBSCRIPTION; + if (IdHelper.isNgsiLdId(id)) { + this.id = URI.create(id); + } else { + this.id = IdHelper.toNgsiLd(id, TYPE_SUBSCRIPTION); + } + } + + public Subscription() { + this.type = TYPE_SUBSCRIPTION; + } } diff --git a/common/src/main/java/org/fiware/tmforum/common/domain/subscription/TMForumSubscription.java b/common/src/main/java/org/fiware/tmforum/common/domain/subscription/TMForumSubscription.java new file mode 100644 index 00000000..bb2ffd2c --- /dev/null +++ b/common/src/main/java/org/fiware/tmforum/common/domain/subscription/TMForumSubscription.java @@ -0,0 +1,59 @@ +package org.fiware.tmforum.common.domain.subscription; + +import io.github.wistefan.mapping.annotations.AttributeGetter; +import io.github.wistefan.mapping.annotations.AttributeSetter; +import io.github.wistefan.mapping.annotations.AttributeType; +import io.github.wistefan.mapping.annotations.MappingEnabled; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import org.fiware.tmforum.common.domain.EntityWithId; + +import java.net.URI; +import java.util.List; + +@EqualsAndHashCode(callSuper = true) +@MappingEnabled(entityType = TMForumSubscription.TYPE_TM_FORUM_SUBSCRIPTION) +public class TMForumSubscription extends EntityWithId { + public static final String TYPE_TM_FORUM_SUBSCRIPTION = "tm-forum-subscription"; + + @Getter(onMethod = @__({ @AttributeGetter(value = AttributeType.PROPERTY, targetName = "callback") })) + @Setter(onMethod = @__({ @AttributeSetter(value = AttributeType.PROPERTY, targetName = "callback") })) + private URI callback; + + @Getter(onMethod = @__({ @AttributeGetter(value = AttributeType.PROPERTY, targetName = "query") })) + @Setter(onMethod = @__({ @AttributeSetter(value = AttributeType.PROPERTY, targetName = "query") })) + private String query; + + @Getter(onMethod = @__({ @AttributeGetter(value = AttributeType.PROPERTY, targetName = "rawQuery") })) + @Setter(onMethod = @__({ @AttributeSetter(value = AttributeType.PROPERTY, targetName = "rawQuery") })) + private String rawQuery; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY_LIST, targetName = "eventTypes") })) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY_LIST, targetName = "eventTypes", targetClass = String.class) })) + private List eventTypes; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY_LIST, targetName = "entities") })) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY_LIST, targetName = "entities", targetClass = String.class) })) + private List entities; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY_LIST, targetName = "fields") })) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY_LIST, targetName = "fields", targetClass = String.class) })) + private List fields; + + @Getter(onMethod = @__({@AttributeGetter(value = AttributeType.PROPERTY, targetName = "subscription") })) + @Setter(onMethod = @__({@AttributeSetter(value = AttributeType.PROPERTY, targetName = "subscription", + targetClass = Subscription.class) })) + private Subscription subscription; + + /** + * Empty constructor for cache serialization and deserialization + */ + public TMForumSubscription() { + super(TYPE_TM_FORUM_SUBSCRIPTION, null); + } + + public TMForumSubscription(String id) { + super(TYPE_TM_FORUM_SUBSCRIPTION, id); + } +} diff --git a/common/src/main/java/org/fiware/tmforum/common/exception/EventHandlingException.java b/common/src/main/java/org/fiware/tmforum/common/exception/EventHandlingException.java index 4b789c22..076538ed 100644 --- a/common/src/main/java/org/fiware/tmforum/common/exception/EventHandlingException.java +++ b/common/src/main/java/org/fiware/tmforum/common/exception/EventHandlingException.java @@ -1,3 +1,9 @@ package org.fiware.tmforum.common.exception; -public class EventHandlingException extends RuntimeException {} +public class EventHandlingException extends RuntimeException { + public EventHandlingException() {} + + public EventHandlingException(String message) { + super(message); + } +} diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/EventConstants.java b/common/src/main/java/org/fiware/tmforum/common/notification/EventConstants.java index a73e468b..e61c6266 100644 --- a/common/src/main/java/org/fiware/tmforum/common/notification/EventConstants.java +++ b/common/src/main/java/org/fiware/tmforum/common/notification/EventConstants.java @@ -6,6 +6,10 @@ import static java.util.Map.entry; public class EventConstants { + public final static String NOTIFICATION_FORMAT = "normalized"; + public final static String NOTIFICATION_PAYLOAD_MIME_TYPE = "application/json"; + public final static String SUBSCRIPTION_CALLBACK_PATH = "/callback"; + public final static String EVENT_GROUP_PRODUCT = "Product"; public final static String EVENT_GROUP_CATALOG = "Catalog"; public final static String EVENT_GROUP_CATEGORY = "Category"; diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/EventDetails.java b/common/src/main/java/org/fiware/tmforum/common/notification/EventDetails.java new file mode 100644 index 00000000..cb167c8d --- /dev/null +++ b/common/src/main/java/org/fiware/tmforum/common/notification/EventDetails.java @@ -0,0 +1,6 @@ +package org.fiware.tmforum.common.notification; + +import java.time.Instant; + +public record EventDetails(String entityType, String eventType, Instant eventTime, String payloadName) { +} diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/EventHandler.java b/common/src/main/java/org/fiware/tmforum/common/notification/EventHandler.java index 94dde01b..568e51fd 100644 --- a/common/src/main/java/org/fiware/tmforum/common/notification/EventHandler.java +++ b/common/src/main/java/org/fiware/tmforum/common/notification/EventHandler.java @@ -1,117 +1,34 @@ package org.fiware.tmforum.common.notification; import io.github.wistefan.mapping.EntityVOMapper; -import io.micronaut.cache.annotation.Cacheable; -import io.micronaut.context.annotation.Bean; import lombok.RequiredArgsConstructor; -import org.fiware.ngsi.model.EntityVO; -import org.fiware.tmforum.common.CommonConstants; import org.fiware.tmforum.common.domain.subscription.Event; -import org.fiware.tmforum.common.domain.subscription.Subscription; -import org.fiware.tmforum.common.exception.EventHandlingException; -import org.fiware.tmforum.common.notification.command.*; -import org.fiware.tmforum.common.querying.QueryParser; -import org.fiware.tmforum.common.querying.SubscriptionQueryResolver; -import org.fiware.tmforum.common.repository.TmForumRepository; -import org.fiware.tmforum.common.util.StringUtils; -import reactor.core.publisher.Mono; -import java.lang.reflect.InvocationTargetException; -import java.time.Instant; -import java.util.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; -import static org.fiware.tmforum.common.CommonConstants.DEFAULT_OFFSET; -import static org.fiware.tmforum.common.notification.EventConstants.*; - -@Bean @RequiredArgsConstructor -public class EventHandler { - - private final QueryParser queryParser; - private final TmForumRepository repository; - private final NotificationSender notificationSender; - private final SubscriptionQueryResolver subscriptionQueryResolver; - private final EntityVOMapper entityVOMapper; - - @Cacheable(CommonConstants.SUBSCRIPTIONS_CACHE_NAME) - public Mono> getSubscriptions(String entityType, String eventType) { - return repository.findEntities( - DEFAULT_OFFSET, - 100, - Subscription.TYPE_SUBSCRIPTION, - Subscription.class, - queryParser.toNgsiLdQuery(Subscription.class, - String.format("entities=%s&eventTypes=%s", entityType, eventType)) - ); - } - - private Mono handle(T entity, EventDetails eventDetails, Command command) { - return getSubscriptions(eventDetails.entityType, eventDetails.eventType) - .doOnNext(subscriptions -> { - List notifications = new ArrayList<>(); - subscriptions.forEach(subscription -> { - if (command.execute(subscription.getQuery())) { - Event event = createEvent(eventDetails.eventType, applyFieldsFilter(entity, subscription.getFields()), - eventDetails.payloadName); - notifications.add(new Notification(subscription.getCallback(), event)); - } - }); - notificationSender.sendNotifications(notifications); - }) - .then(); - } - - public Mono handleCreateEvent(T entity) { - try { - EventDetails eventDetails = new EventDetails<>(entity, CREATE_EVENT_SUFFIX); - Command command = new CreateEventCommand<>(subscriptionQueryResolver, entity, eventDetails.payloadName); - return handle(entity, eventDetails, command); - } catch (EventHandlingException e) { - return Mono.empty(); - } - } - - public Mono handleUpdateEvent(T newState, T oldState) { - try { - EventDetails eventDetails1 = new EventDetails<>(newState, ATTRIBUTE_VALUE_CHANGE_EVENT_SUFFIX); - Command command1 = new AttributeValueChangeEventCommand<>( - subscriptionQueryResolver, newState, oldState, eventDetails1.payloadName); - Mono attrUpdateMono = handle(newState, eventDetails1, command1); - - - EventDetails eventDetails2 = new EventDetails<>(newState, STATE_CHANGE_EVENT_SUFFIX); - Command command2 = new StateChangeEventCommand<>(newState, oldState); - Mono stateChangeMono = handle(newState, eventDetails2, command2); - - return attrUpdateMono.then(stateChangeMono); - } catch (EventHandlingException e) { - return Mono.empty(); - } - } +public abstract class EventHandler { - public Mono handleDeleteEvent(EntityVO entityVO) { - try { - EventDetails eventDetails = new EventDetails<>(entityVO, DELETE_EVENT_SUFFIX); - Command command = new DeleteCommand(); - return handle(entityVO, eventDetails, command); - } catch (EventHandlingException e) { - return Mono.empty(); - } - } + protected final NotificationSender notificationSender; + protected final EntityVOMapper entityVOMapper; - private Event createEvent(String eventType, Map payload, String payloadName) { + protected Event createEvent(EventDetails eventDetails, Map payload) { Event event = new Event(); - event.setEventType(eventType); + event.setEventType(eventDetails.eventType()); event.setEventId(UUID.randomUUID().toString()); - event.setEvent(Map.of(payloadName, payload)); - event.setEventTime(Instant.now()); + event.setEvent(Map.of(eventDetails.payloadName(), payload)); + event.setEventTime(eventDetails.eventTime()); return event; } - private Map applyFieldsFilter(T entity, List fields) { + protected Map applyFieldsFilter(T entity, List fields) { Map entityMap = entityVOMapper.convertEntityToMap(entity); + if (fields != null && !fields.isEmpty()) { Map filteredMap = new HashMap<>(); fields.forEach(field -> { @@ -124,36 +41,4 @@ private Map applyFieldsFilter(T entity, List fields) return entityMap; } } - - private static class EventDetails { - String entityType; - String eventType; - String payloadName; - - public EventDetails(T entity, String eventSuffix) { - entityType = getEntityType(entity); - init(eventSuffix); - } - - public EventDetails(EntityVO entityVO, String eventSuffix) { - entityType = entityVO.getType(); - init(eventSuffix); - } - - private String getEntityType(T entity) { - try { - return entity.getClass().getMethod("getType").invoke(entity).toString(); - } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { - return ""; - } - } - - private void init(String eventSuffix) { - if (entityType.equals(Subscription.TYPE_SUBSCRIPTION)) { - throw new EventHandlingException(); - } - eventType = StringUtils.toCamelCase(entityType) + eventSuffix; - payloadName = StringUtils.decapitalize(StringUtils.getEventGroupName(eventType)); - } - } } diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/NgsiLdEventHandler.java b/common/src/main/java/org/fiware/tmforum/common/notification/NgsiLdEventHandler.java new file mode 100644 index 00000000..65286f30 --- /dev/null +++ b/common/src/main/java/org/fiware/tmforum/common/notification/NgsiLdEventHandler.java @@ -0,0 +1,67 @@ +package org.fiware.tmforum.common.notification; + +import com.google.common.base.CaseFormat; +import io.github.wistefan.mapping.EntityVOMapper; +import io.micronaut.context.annotation.Bean; +import org.fiware.ngsi.model.EntityVO; +import org.fiware.ngsi.model.NotificationVO; +import org.fiware.ngsi.model.SubscriptionVO; +import org.fiware.tmforum.common.notification.checkers.ngsild.*; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.net.URI; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@Bean +public class NgsiLdEventHandler extends EventHandler { + private static final List NGSI_LD_EVENT_CHECKERS = List.of( + new CreateNgsiLdEventChecker(), + new AttributeValueChangeNgsiLdEventChecker(), + new StateChangeNgsiLdEventChecker(), + new DeleteNgsiLdEventChecker() + ); + + public NgsiLdEventHandler(NotificationSender notificationSender, EntityVOMapper entityVOMapper) { + super(notificationSender, entityVOMapper); + } + + public Mono handle(NotificationVO notificationVO, SubscriptionVO subscriptionVO, + Map> entityNameToEntityClassMapping) { + List> notifications = notificationVO.getData().stream().flatMap(entityVO -> + NGSI_LD_EVENT_CHECKERS.stream().filter(eventChecker -> eventChecker.wasFired(entityVO)) + .map(eventChecker -> createNotification( + entityVO, eventChecker.eventTypeSuffix(), notificationVO.getNotifiedAt(), + subscriptionVO.getWatchedAttributes() == null ? List.of() : new ArrayList<>( + subscriptionVO.getWatchedAttributes()), + URI.create(subscriptionVO.getNotification().getEndpoint().getReceiverInfo().get(0).getValue()), + entityNameToEntityClassMapping))).toList(); + + return Flux.fromIterable(notifications).flatMap(x -> x).collectList() + .flatMap(notificationSender::sendNotifications); + } + + private Mono createNotification(EntityVO payload, String eventTypeSuffix, Instant eventTime, + List selectedFields, URI listenerCallback, + Map> entityNameToEntityClassMapping) { + if (payload.getType() == null) { + payload.setType(entityNameToEntityClassMapping.keySet().iterator().next()); + } + EventDetails eventDetails = makeEventDetails(payload.getType(), eventTypeSuffix, eventTime); + + return entityVOMapper.fromEntityVO(payload, entityNameToEntityClassMapping.get(eventDetails.entityType())) + .map(entity -> new TMForumNotification(listenerCallback, createEvent(eventDetails, applyFieldsFilter( + entity, selectedFields)))); + } + + private EventDetails makeEventDetails(String entityType, String eventTypeSuffix, Instant eventTime) { + String payloadName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, entityType); + return new EventDetails(entityType, + CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, entityType) + eventTypeSuffix, + eventTime, payloadName); + } + +} diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/NotificationSender.java b/common/src/main/java/org/fiware/tmforum/common/notification/NotificationSender.java index f993c3fd..867f8346 100644 --- a/common/src/main/java/org/fiware/tmforum/common/notification/NotificationSender.java +++ b/common/src/main/java/org/fiware/tmforum/common/notification/NotificationSender.java @@ -28,13 +28,13 @@ public class NotificationSender { .failAfterMaxAttempts(true) .build()); - private Mono> sendToClient(Notification notification) { + private Mono> sendToClient(TMForumNotification notification) { HttpRequest req = HttpRequest.POST(notification.callback(), notification.event()) .header(HttpHeaders.CONTENT_TYPE, "application/json"); return Mono.fromDirect(this.httpClient.exchange(req, Object.class)); } - public void sendNotifications(List notifications) { + public Mono sendNotifications(List notifications) { notifications .forEach(notification -> { Retry retry = RETRY_REGISTRY @@ -44,5 +44,6 @@ public void sendNotifications(List notifications) { .doOnError(e -> log.warn("Was not able to deliver notification {}.", notification, e)) .subscribe(); }); + return Mono.empty(); } } diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/TMForumEventHandler.java b/common/src/main/java/org/fiware/tmforum/common/notification/TMForumEventHandler.java new file mode 100644 index 00000000..776ed5a5 --- /dev/null +++ b/common/src/main/java/org/fiware/tmforum/common/notification/TMForumEventHandler.java @@ -0,0 +1,111 @@ +package org.fiware.tmforum.common.notification; + +import com.google.common.base.CaseFormat; +import io.github.wistefan.mapping.EntityVOMapper; +import io.micronaut.cache.annotation.Cacheable; +import io.micronaut.context.annotation.Bean; +import org.fiware.tmforum.common.CommonConstants; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; +import org.fiware.tmforum.common.exception.EventHandlingException; +import org.fiware.tmforum.common.notification.checkers.tmforum.AttributeValueChangeTmForumEventChecker; +import org.fiware.tmforum.common.notification.checkers.tmforum.CreateTmForumEventChecker; +import org.fiware.tmforum.common.notification.checkers.tmforum.StateChangeTmForumEventChecker; +import org.fiware.tmforum.common.notification.checkers.tmforum.TmForumEventChecker; +import org.fiware.tmforum.common.querying.QueryParser; +import org.fiware.tmforum.common.querying.SubscriptionQueryResolver; +import org.fiware.tmforum.common.repository.TmForumRepository; +import reactor.core.publisher.Mono; + +import java.lang.reflect.InvocationTargetException; +import java.time.Instant; +import java.util.List; + +import static org.fiware.tmforum.common.CommonConstants.DEFAULT_OFFSET; +import static org.fiware.tmforum.common.notification.EventConstants.*; + +@Bean +public class TMForumEventHandler extends EventHandler { + + private final QueryParser queryParser; + private final SubscriptionQueryResolver subscriptionQueryResolver; + private final TmForumRepository repository; + + public TMForumEventHandler(QueryParser queryParser, SubscriptionQueryResolver subscriptionQueryResolver, + NotificationSender notificationSender, EntityVOMapper entityVOMapper, + TmForumRepository repository) { + super(notificationSender, entityVOMapper); + this.queryParser = queryParser; + this.subscriptionQueryResolver = subscriptionQueryResolver; + this.repository = repository; + } + + @Cacheable(CommonConstants.TMFORUM_SUBSCRIPTIONS_CACHE_NAME) + public Mono> getSubscriptions(EventDetails eventDetails) { + return repository.findEntities( + DEFAULT_OFFSET, + 100, + TMForumSubscription.TYPE_TM_FORUM_SUBSCRIPTION, + TMForumSubscription.class, + queryParser.toNgsiLdQuery(TMForumSubscription.class, + String.format("entities=%s&eventTypes=%s", eventDetails.entityType(), eventDetails.eventType())) + ); + } + + private Mono handle(T entity, EventDetails eventDetails, TmForumEventChecker eventChecker) { + return getSubscriptions(eventDetails) + .map(subscriptions -> subscriptions.stream() + .filter(subscription -> eventChecker.wasFired(subscription.getQuery())) + .map(subscription -> new TMForumNotification(subscription.getCallback(), + createEvent(eventDetails, applyFieldsFilter(entity, subscription.getFields())))) + .toList()).flatMap(notificationSender::sendNotifications); + } + + public Mono handleCreateEvent(T entity) { + try { + EventDetails eventDetails = makeEventDetails(entity, CREATE_EVENT_SUFFIX); + TmForumEventChecker tmForumEventChecker = new CreateTmForumEventChecker<>(subscriptionQueryResolver, entity, + eventDetails.payloadName()); + return handle(entity, eventDetails, tmForumEventChecker); + } catch (EventHandlingException e) { + return Mono.empty(); + } + } + + public Mono handleUpdateEvent(T newState, T oldState) { + try { + EventDetails eventDetails1 = makeEventDetails(newState, ATTRIBUTE_VALUE_CHANGE_EVENT_SUFFIX); + TmForumEventChecker eventChecker1 = new AttributeValueChangeTmForumEventChecker<>( + subscriptionQueryResolver, newState, oldState, eventDetails1.payloadName()); + Mono attrUpdateMono = handle(newState, eventDetails1, eventChecker1); + + + EventDetails eventDetails2 = makeEventDetails(newState, STATE_CHANGE_EVENT_SUFFIX); + TmForumEventChecker eventChecker2 = new StateChangeTmForumEventChecker<>(newState, oldState); + Mono stateChangeMono = handle(newState, eventDetails2, eventChecker2); + + return attrUpdateMono.then(stateChangeMono); + } catch (EventHandlingException e) { + return Mono.empty(); + } + } + + private EventDetails makeEventDetails(T entity, String eventSuffix) { + String entityType = getEntityType(entity); + if (entityType.equals(TMForumSubscription.TYPE_TM_FORUM_SUBSCRIPTION)) { + throw new EventHandlingException(); + } + Instant eventTime = Instant.now(); + String payloadName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, entityType); + String eventType = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, payloadName) + eventSuffix; + return new EventDetails(entityType, eventType, eventTime, payloadName); + } + + private String getEntityType(T entity) { + try { + return entity.getClass().getMethod("getType").invoke(entity).toString(); + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + return ""; + } + } + +} diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/Notification.java b/common/src/main/java/org/fiware/tmforum/common/notification/TMForumNotification.java similarity index 67% rename from common/src/main/java/org/fiware/tmforum/common/notification/Notification.java rename to common/src/main/java/org/fiware/tmforum/common/notification/TMForumNotification.java index 3cfb2004..4aeedcc3 100644 --- a/common/src/main/java/org/fiware/tmforum/common/notification/Notification.java +++ b/common/src/main/java/org/fiware/tmforum/common/notification/TMForumNotification.java @@ -4,4 +4,4 @@ import java.net.URI; -public record Notification(URI callback, Event event) {} +public record TMForumNotification(URI callback, Event event) {} diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/checkers/ngsild/AttributeValueChangeNgsiLdEventChecker.java b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/ngsild/AttributeValueChangeNgsiLdEventChecker.java new file mode 100644 index 00000000..d397b591 --- /dev/null +++ b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/ngsild/AttributeValueChangeNgsiLdEventChecker.java @@ -0,0 +1,16 @@ +package org.fiware.tmforum.common.notification.checkers.ngsild; + +import org.fiware.ngsi.model.EntityVO; +import org.fiware.tmforum.common.notification.EventConstants; + +public class AttributeValueChangeNgsiLdEventChecker implements NgsiLdEventChecker { + @Override + public boolean wasFired(EntityVO entityVO) { + return false; + } + + @Override + public String eventTypeSuffix() { + return EventConstants.ATTRIBUTE_VALUE_CHANGE_EVENT_SUFFIX; + } +} diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/checkers/ngsild/CreateNgsiLdEventChecker.java b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/ngsild/CreateNgsiLdEventChecker.java new file mode 100644 index 00000000..7a04e1c1 --- /dev/null +++ b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/ngsild/CreateNgsiLdEventChecker.java @@ -0,0 +1,16 @@ +package org.fiware.tmforum.common.notification.checkers.ngsild; + +import org.fiware.ngsi.model.EntityVO; +import org.fiware.tmforum.common.notification.EventConstants; + +public class CreateNgsiLdEventChecker implements NgsiLdEventChecker { + @Override + public boolean wasFired(EntityVO entityVO) { + return false; + } + + @Override + public String eventTypeSuffix() { + return EventConstants.CREATE_EVENT_SUFFIX; + } +} diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/checkers/ngsild/DeleteNgsiLdEventChecker.java b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/ngsild/DeleteNgsiLdEventChecker.java new file mode 100644 index 00000000..b0b75502 --- /dev/null +++ b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/ngsild/DeleteNgsiLdEventChecker.java @@ -0,0 +1,17 @@ +package org.fiware.tmforum.common.notification.checkers.ngsild; + +import org.fiware.ngsi.model.EntityVO; +import org.fiware.tmforum.common.notification.EventConstants; + +public class DeleteNgsiLdEventChecker implements NgsiLdEventChecker { + + @Override + public boolean wasFired(EntityVO entityVO) { + return entityVO.getDeletedAt() != null; + } + + @Override + public String eventTypeSuffix() { + return EventConstants.DELETE_EVENT_SUFFIX; + } +} diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/checkers/ngsild/NgsiLdEventChecker.java b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/ngsild/NgsiLdEventChecker.java new file mode 100644 index 00000000..88956633 --- /dev/null +++ b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/ngsild/NgsiLdEventChecker.java @@ -0,0 +1,8 @@ +package org.fiware.tmforum.common.notification.checkers.ngsild; + +import org.fiware.ngsi.model.EntityVO; + +public interface NgsiLdEventChecker { + boolean wasFired(EntityVO entityVO); + String eventTypeSuffix(); +} diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/checkers/ngsild/StateChangeNgsiLdEventChecker.java b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/ngsild/StateChangeNgsiLdEventChecker.java new file mode 100644 index 00000000..f5133143 --- /dev/null +++ b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/ngsild/StateChangeNgsiLdEventChecker.java @@ -0,0 +1,16 @@ +package org.fiware.tmforum.common.notification.checkers.ngsild; + +import org.fiware.ngsi.model.EntityVO; +import org.fiware.tmforum.common.notification.EventConstants; + +public class StateChangeNgsiLdEventChecker implements NgsiLdEventChecker { + @Override + public boolean wasFired(EntityVO entityVO) { + return false; + } + + @Override + public String eventTypeSuffix() { + return EventConstants.STATE_CHANGE_EVENT_SUFFIX; + } +} diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/command/AttributeValueChangeEventCommand.java b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/tmforum/AttributeValueChangeTmForumEventChecker.java similarity index 68% rename from common/src/main/java/org/fiware/tmforum/common/notification/command/AttributeValueChangeEventCommand.java rename to common/src/main/java/org/fiware/tmforum/common/notification/checkers/tmforum/AttributeValueChangeTmForumEventChecker.java index 28e54112..51803a28 100644 --- a/common/src/main/java/org/fiware/tmforum/common/notification/command/AttributeValueChangeEventCommand.java +++ b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/tmforum/AttributeValueChangeTmForumEventChecker.java @@ -1,17 +1,17 @@ -package org.fiware.tmforum.common.notification.command; +package org.fiware.tmforum.common.notification.checkers.tmforum; import lombok.RequiredArgsConstructor; import org.fiware.tmforum.common.querying.SubscriptionQueryResolver; @RequiredArgsConstructor -public class AttributeValueChangeEventCommand implements Command { +public class AttributeValueChangeTmForumEventChecker implements TmForumEventChecker { private final SubscriptionQueryResolver subscriptionQueryResolver; private final T newState; private final T oldState; private final String payloadName; @Override - public boolean execute(String query) { + public boolean wasFired(String query) { return subscriptionQueryResolver.doesQueryMatchUpdateEvent(query, newState, oldState, payloadName); } } diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/command/CreateEventCommand.java b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/tmforum/CreateTmForumEventChecker.java similarity index 68% rename from common/src/main/java/org/fiware/tmforum/common/notification/command/CreateEventCommand.java rename to common/src/main/java/org/fiware/tmforum/common/notification/checkers/tmforum/CreateTmForumEventChecker.java index 4a42bc9d..e83b684f 100644 --- a/common/src/main/java/org/fiware/tmforum/common/notification/command/CreateEventCommand.java +++ b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/tmforum/CreateTmForumEventChecker.java @@ -1,16 +1,16 @@ -package org.fiware.tmforum.common.notification.command; +package org.fiware.tmforum.common.notification.checkers.tmforum; import lombok.RequiredArgsConstructor; import org.fiware.tmforum.common.querying.SubscriptionQueryResolver; @RequiredArgsConstructor -public class CreateEventCommand implements Command { +public class CreateTmForumEventChecker implements TmForumEventChecker { private final SubscriptionQueryResolver subscriptionQueryResolver; private final T entity; private final String payloadName; @Override - public boolean execute(String query) { + public boolean wasFired(String query) { return subscriptionQueryResolver.doesQueryMatchCreateEvent(query, entity, payloadName); } } diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/command/StateChangeEventCommand.java b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/tmforum/StateChangeTmForumEventChecker.java similarity index 86% rename from common/src/main/java/org/fiware/tmforum/common/notification/command/StateChangeEventCommand.java rename to common/src/main/java/org/fiware/tmforum/common/notification/checkers/tmforum/StateChangeTmForumEventChecker.java index 47be4c40..a57f368c 100644 --- a/common/src/main/java/org/fiware/tmforum/common/notification/command/StateChangeEventCommand.java +++ b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/tmforum/StateChangeTmForumEventChecker.java @@ -1,16 +1,16 @@ -package org.fiware.tmforum.common.notification.command; +package org.fiware.tmforum.common.notification.checkers.tmforum; import lombok.RequiredArgsConstructor; import java.lang.reflect.InvocationTargetException; @RequiredArgsConstructor -public class StateChangeEventCommand implements Command { +public class StateChangeTmForumEventChecker implements TmForumEventChecker { private final T newState; private final T oldState; @Override - public boolean execute(String query) { + public boolean wasFired(String query) { return hasEntityStateChanged(oldState, newState); } diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/checkers/tmforum/TmForumEventChecker.java b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/tmforum/TmForumEventChecker.java new file mode 100644 index 00000000..7dd28c8a --- /dev/null +++ b/common/src/main/java/org/fiware/tmforum/common/notification/checkers/tmforum/TmForumEventChecker.java @@ -0,0 +1,5 @@ +package org.fiware.tmforum.common.notification.checkers.tmforum; + +public interface TmForumEventChecker { + boolean wasFired(String query); +} diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/command/Command.java b/common/src/main/java/org/fiware/tmforum/common/notification/command/Command.java deleted file mode 100644 index fa897954..00000000 --- a/common/src/main/java/org/fiware/tmforum/common/notification/command/Command.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.fiware.tmforum.common.notification.command; - -@FunctionalInterface -public interface Command { - boolean execute(String query); -} diff --git a/common/src/main/java/org/fiware/tmforum/common/notification/command/DeleteCommand.java b/common/src/main/java/org/fiware/tmforum/common/notification/command/DeleteCommand.java deleted file mode 100644 index 27e6eb5a..00000000 --- a/common/src/main/java/org/fiware/tmforum/common/notification/command/DeleteCommand.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.fiware.tmforum.common.notification.command; - -public class DeleteCommand implements Command { - @Override - public boolean execute(String query) { - return true; - } -} diff --git a/common/src/main/java/org/fiware/tmforum/common/repository/BrokerBackedEntitiesRepository.java b/common/src/main/java/org/fiware/tmforum/common/repository/BrokerBackedEntitiesRepository.java index fd02669e..7845323a 100644 --- a/common/src/main/java/org/fiware/tmforum/common/repository/BrokerBackedEntitiesRepository.java +++ b/common/src/main/java/org/fiware/tmforum/common/repository/BrokerBackedEntitiesRepository.java @@ -21,7 +21,7 @@ public class BrokerBackedEntitiesRepository extends NgsiLdBaseRepository impleme public BrokerBackedEntitiesRepository(GeneralProperties generalProperties, EntitiesApiClient entitiesApi) { // only used for retrieval, so no such mappers required - super(generalProperties, entitiesApi, null, null, null); + super(generalProperties, entitiesApi, null, null, null, null); } @Override diff --git a/common/src/main/java/org/fiware/tmforum/common/repository/BrokerBackedReferencesRepository.java b/common/src/main/java/org/fiware/tmforum/common/repository/BrokerBackedReferencesRepository.java index 200e2701..18ddc1df 100644 --- a/common/src/main/java/org/fiware/tmforum/common/repository/BrokerBackedReferencesRepository.java +++ b/common/src/main/java/org/fiware/tmforum/common/repository/BrokerBackedReferencesRepository.java @@ -19,7 +19,7 @@ public class BrokerBackedReferencesRepository extends NgsiLdBaseRepository imple public BrokerBackedReferencesRepository(GeneralProperties generalProperties, EntitiesApiClient entitiesApi) { // only used for retrieval, so no such mappers required - super(generalProperties, entitiesApi, null, null, null); + super(generalProperties, entitiesApi, null, null, null, null); } /** diff --git a/common/src/main/java/org/fiware/tmforum/common/repository/NgsiLdBaseRepository.java b/common/src/main/java/org/fiware/tmforum/common/repository/NgsiLdBaseRepository.java index ade41cfc..5b0676a5 100644 --- a/common/src/main/java/org/fiware/tmforum/common/repository/NgsiLdBaseRepository.java +++ b/common/src/main/java/org/fiware/tmforum/common/repository/NgsiLdBaseRepository.java @@ -9,11 +9,15 @@ import io.micronaut.http.client.exceptions.HttpClientResponseException; import lombok.RequiredArgsConstructor; import org.fiware.ngsi.api.EntitiesApiClient; +import org.fiware.ngsi.api.SubscriptionsApiClient; import org.fiware.ngsi.model.EntityFragmentVO; import org.fiware.ngsi.model.EntityVO; +import org.fiware.ngsi.model.SubscriptionVO; import org.fiware.tmforum.common.CommonConstants; import org.fiware.tmforum.common.caching.EntityIdKeyGenerator; import org.fiware.tmforum.common.configuration.GeneralProperties; +import org.fiware.tmforum.common.domain.subscription.Subscription; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; import org.fiware.tmforum.common.exception.DeletionException; import org.fiware.tmforum.common.exception.DeletionExceptionReason; import org.fiware.tmforum.common.exception.NgsiLdRepositoryException; @@ -27,13 +31,15 @@ import java.util.stream.Stream; /** - * Base-Repository implementation for using the NGSI-LD API as a storage backend. Supports caching and asynchronous retrieval of entities. + * Base-Repository implementation for using the NGSI-LD API as a storage backend. Supports caching and asynchronous + * retrieval of entities and subscriptions. */ @RequiredArgsConstructor public abstract class NgsiLdBaseRepository { protected final GeneralProperties generalProperties; protected final EntitiesApiClient entitiesApi; + protected final SubscriptionsApiClient subscriptionsApi; protected final JavaObjectMapper javaObjectMapper; protected final NGSIMapper ngsiMapper; protected final EntityVOMapper entityVOMapper; @@ -55,6 +61,17 @@ public Mono createEntity(EntityVO entityVO, String ngsiLDTenant) { return entitiesApi.createEntity(entityVO, ngsiLDTenant); } + /** + * Create a subscription at the broker and cache it. + * + * @param subscriptionVO the subscription to be created + * @param ngsiLDTenant tenant the subscription belongs to + * @return completable with the result + */ + public Mono createSubscription(SubscriptionVO subscriptionVO, String ngsiLDTenant) { + return subscriptionsApi.createSubscription(subscriptionVO, ngsiLDTenant); + } + /** * Retrieve entity from the broker or from the cache if they are available there. * @@ -66,6 +83,13 @@ public Mono retrieveEntityById(URI entityId) { return asyncRetrieveEntityById(entityId, generalProperties.getTenant(), null, null, null, getLinkHeader()); } + @Cacheable(CommonConstants.SUBSCRIPTIONS_CACHE_NAME) + public Mono retrieveSubscriptionById(URI subscriptionId) { + return subscriptionsApi + .retrieveSubscriptionById(subscriptionId) + .onErrorResume(this::handleClientSubscriptionException); + } + /** * Patch an entity, using the "overwrite" option. * @@ -89,6 +113,16 @@ public Mono createDomainEntity(T domainEntity) { return createEntity(javaObjectMapper.toEntityVO(domainEntity), generalProperties.getTenant()); } + /** + * Create a domain subscription + * + * @param domainSubscription the subscription to be created + * @return an empty mono + */ + public Mono createDomainSubscription(Subscription domainSubscription) { + return createSubscription(entityVOMapper.toSubscriptionVO(domainSubscription), generalProperties.getTenant()); + } + /** * Update a domain entity * @@ -123,9 +157,41 @@ public Mono deleteDomainEntity(URI id) { } /** - * Helper method for combining a stream of entites to a single mono. + * Delete a domain subscription + * + * @param tmForumSubscriptionId id of the tm-forum-subscription to delete the related ngsild-subscription + * @return an empty mono + */ + public Mono deleteDomainSubscriptionByTmForumSubscription(URI tmForumSubscriptionId) { + return retrieveEntityById(tmForumSubscriptionId) + .flatMap(entityVO -> entityVOMapper.fromEntityVO(entityVO, TMForumSubscription.class)) + .flatMap(tmForumSubscription -> + deleteDomainSubscription(tmForumSubscription.getSubscription().getId())); + } + + /** + * Delete a domain subscription + * + * @param subscriptionId id of the ngsild-subscription to be deleted + * @return an empty mono + */ + @CacheInvalidate(value = CommonConstants.SUBSCRIPTIONS_CACHE_NAME) + public Mono deleteDomainSubscription(URI subscriptionId) { + return subscriptionsApi.removeSubscription(subscriptionId) + .onErrorResume(t -> { + if (t instanceof HttpClientResponseException e && e.getStatus().equals(HttpStatus.NOT_FOUND)) { + throw new DeletionException(String.format("Was not able to delete %s, since it does not exist.", + subscriptionId), DeletionExceptionReason.NOT_FOUND); + } + throw new DeletionException(String.format("Was not able to delete %s.", subscriptionId), + t, DeletionExceptionReason.UNKNOWN); + }); + } + + /** + * Helper method for combining a stream of entities to a single mono. * - * @param entityVOStream stream of entites + * @param entityVOStream stream of entities * @param targetClass target class to map them * @param type of the target * @return a mono, emitting a list of mapped entities @@ -143,10 +209,17 @@ protected Mono> zipToList(Stream entityVOStream, Class private Mono asyncRetrieveEntityById(URI entityId, String ngSILDTenant, String attrs, String type, String options, String link) { return entitiesApi .retrieveEntityById(entityId, ngSILDTenant, attrs, type, options, link) - .onErrorResume(this::handleClientException); + .onErrorResume(this::handleClientEntityException); + } + + private Mono handleClientEntityException(Throwable e) { + if (e instanceof HttpClientResponseException httpException && httpException.getStatus().equals(HttpStatus.NOT_FOUND)) { + return Mono.empty(); + } + throw new NgsiLdRepositoryException("Was not able to successfully call the broker.", Optional.of(e)); } - private Mono handleClientException(Throwable e) { + private Mono handleClientSubscriptionException(Throwable e) { if (e instanceof HttpClientResponseException httpException && httpException.getStatus().equals(HttpStatus.NOT_FOUND)) { return Mono.empty(); } diff --git a/common/src/main/java/org/fiware/tmforum/common/repository/TmForumRepository.java b/common/src/main/java/org/fiware/tmforum/common/repository/TmForumRepository.java index 1846b35b..14536716 100644 --- a/common/src/main/java/org/fiware/tmforum/common/repository/TmForumRepository.java +++ b/common/src/main/java/org/fiware/tmforum/common/repository/TmForumRepository.java @@ -3,6 +3,7 @@ import io.github.wistefan.mapping.EntityVOMapper; import io.github.wistefan.mapping.JavaObjectMapper; import org.fiware.ngsi.api.EntitiesApiClient; +import org.fiware.ngsi.api.SubscriptionsApiClient; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; @@ -17,9 +18,9 @@ public class TmForumRepository extends NgsiLdBaseRepository { public TmForumRepository(GeneralProperties generalProperties, EntitiesApiClient entitiesApi, - EntityVOMapper entityVOMapper, NGSIMapper ngsiMapper, - JavaObjectMapper javaObjectMapper) { - super(generalProperties, entitiesApi, javaObjectMapper, ngsiMapper, entityVOMapper); + SubscriptionsApiClient subscriptionsApi, EntityVOMapper entityVOMapper, + NGSIMapper ngsiMapper, JavaObjectMapper javaObjectMapper) { + super(generalProperties, entitiesApi, subscriptionsApi, javaObjectMapper, ngsiMapper, entityVOMapper); } public Mono get(URI id, Class entityClass) { diff --git a/common/src/main/java/org/fiware/tmforum/common/rest/AbstractApiController.java b/common/src/main/java/org/fiware/tmforum/common/rest/AbstractApiController.java index 6323a2f9..ec200502 100644 --- a/common/src/main/java/org/fiware/tmforum/common/rest/AbstractApiController.java +++ b/common/src/main/java/org/fiware/tmforum/common/rest/AbstractApiController.java @@ -6,11 +6,11 @@ import io.micronaut.http.context.ServerRequestContext; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.fiware.tmforum.common.notification.EventHandler; import org.fiware.tmforum.common.domain.EntityWithId; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -36,7 +36,7 @@ public abstract class AbstractApiController { protected final QueryParser queryParser; protected final ReferenceValidationService validationService; protected final TmForumRepository repository; - private final EventHandler eventHandler; + protected final TMForumEventHandler eventHandler; protected Mono getCheckingMono(T entityToCheck, List> referencedEntities) { Mono checkingMono = Mono.just(entityToCheck); @@ -80,15 +80,8 @@ protected Mono> delete(String id) { throw new TmForumException("Did not receive a valid id, such entity cannot exist.", TmForumExceptionReason.NOT_FOUND); } - - URI idUri = URI.create(id); - return repository.retrieveEntityById(idUri) - .switchIfEmpty(Mono.error(new TmForumException("No such entity exists.", - TmForumExceptionReason.NOT_FOUND))) - .flatMap(entityVO -> - repository.deleteDomainEntity(idUri) - .then(eventHandler.handleDeleteEvent(entityVO)) - .then(Mono.just(HttpResponse.noContent()))); + return repository.deleteDomainEntity(URI.create(id)) + .then(Mono.just(HttpResponse.noContent())); } protected Mono> list(Integer offset, Integer limit, String type, Class entityClass) { @@ -143,7 +136,8 @@ protected Mono patch(String id, T updatedObject, Mono checkingMono, Class< }) .flatMap(entity -> repository.updateDomainEntity(id, updatedObject) .then(repository.get(idUri, entityClass)) - .flatMap(updatedState -> eventHandler.handleUpdateEvent(updatedState, old.get()) + .flatMap(updatedState -> eventHandler.handleUpdateEvent( + updatedState, old.get()) .then(Mono.just(updatedState)) ) ); diff --git a/common/src/main/java/org/fiware/tmforum/common/rest/AbstractSubscriptionApiController.java b/common/src/main/java/org/fiware/tmforum/common/rest/AbstractSubscriptionApiController.java index 8946a9d9..73b2414d 100644 --- a/common/src/main/java/org/fiware/tmforum/common/rest/AbstractSubscriptionApiController.java +++ b/common/src/main/java/org/fiware/tmforum/common/rest/AbstractSubscriptionApiController.java @@ -1,13 +1,24 @@ package org.fiware.tmforum.common.rest; +import com.fasterxml.jackson.core.JsonProcessingException; +import io.github.wistefan.mapping.EntityVOMapper; import io.micronaut.cache.annotation.CacheInvalidate; +import io.micronaut.core.annotation.NonNull; import io.micronaut.http.HttpResponse; +import io.micronaut.http.annotation.Body; +import io.micronaut.http.annotation.Consumes; +import io.micronaut.http.annotation.Post; +import io.micronaut.http.client.exceptions.HttpClientResponseException; import lombok.extern.slf4j.Slf4j; +import org.fiware.ngsi.model.NotificationVO; import org.fiware.tmforum.common.CommonConstants; -import org.fiware.tmforum.common.domain.subscription.Subscription; +import org.fiware.tmforum.common.configuration.GeneralProperties; +import org.fiware.tmforum.common.domain.subscription.*; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.common.notification.EventConstants; +import org.fiware.tmforum.common.notification.NgsiLdEventHandler; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.querying.SubscriptionQuery; import org.fiware.tmforum.common.querying.SubscriptionQueryParser; @@ -18,45 +29,78 @@ import java.net.URI; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; -import static org.fiware.tmforum.common.CommonConstants.DEFAULT_OFFSET; - @Slf4j -public abstract class AbstractSubscriptionApiController extends AbstractApiController { +public abstract class AbstractSubscriptionApiController extends AbstractApiController { + private static final String RECEIVER_INFO_LISTENER_ENDPOINT = "Listener-Endpoint"; + private final Map eventGroupToEntityNameMapping; + private final Map> entityNameToEntityClassMapping; + private final GeneralProperties generalProperties; + protected final EntityVOMapper entityVOMapper; + private final NgsiLdEventHandler ngsiLdEventHandler; - public AbstractSubscriptionApiController(QueryParser queryParser, ReferenceValidationService validationService, TmForumRepository repository, - Map eventGroupToEntityNameMapping, EventHandler eventHandler) { - super(queryParser, validationService, repository, eventHandler); + public AbstractSubscriptionApiController( + QueryParser queryParser, ReferenceValidationService validationService, TmForumRepository repository, + Map eventGroupToEntityNameMapping, Map> entityNameToEntityClassMapping, + TMForumEventHandler tmForumEventHandler, NgsiLdEventHandler ngsiLdEventHandler, + GeneralProperties generalProperties, EntityVOMapper entityVOMapper) { + super(queryParser, validationService, repository, tmForumEventHandler); this.eventGroupToEntityNameMapping = eventGroupToEntityNameMapping; + this.entityNameToEntityClassMapping = entityNameToEntityClassMapping; + this.generalProperties = generalProperties; + this.entityVOMapper = entityVOMapper; + this.ngsiLdEventHandler = ngsiLdEventHandler; } - @CacheInvalidate(value = CommonConstants.SUBSCRIPTIONS_CACHE_NAME, all = true) - protected Mono create(Subscription subscription) { - return findExistingSubscription(subscription) - .switchIfEmpty(create(Mono.just(subscription), Subscription.class)); + @CacheInvalidate(value = CommonConstants.TMFORUM_SUBSCRIPTIONS_CACHE_NAME, all = true) + protected Mono create(TMForumSubscription tmForumSubscription) { + return findExistingTMForumSubscription(tmForumSubscription) + .switchIfEmpty( + create(Mono.just(tmForumSubscription.getSubscription())) + .then(create(Mono.just(tmForumSubscription), TMForumSubscription.class))); + } + + private Mono create(Mono subscriptionMono) { + return subscriptionMono + .flatMap(checkedResult -> repository.createDomainSubscription(checkedResult) + .then(Mono.just(checkedResult))) + .onErrorMap(t -> { + if (t instanceof HttpClientResponseException e) { + return switch (e.getStatus()) { + case CONFLICT -> new TmForumException( + String.format("Conflict on creating the subscription: %s", e.getMessage()), + TmForumExceptionReason.CONFLICT); + case BAD_REQUEST -> new TmForumException( + String.format("Did not receive a valid subscription: %s.", e.getMessage()), + TmForumExceptionReason.INVALID_DATA); + default -> new TmForumException( + String.format("Unspecified downstream error: %s", e.getMessage()), + TmForumExceptionReason.UNKNOWN); + }; + } else { + return t; + } + }) + .cast(Subscription.class); } - private Mono findExistingSubscription(Subscription subscription) { - String query = String.format(queryParser.toNgsiLdQuery(Subscription.class, "callback=%s&rawQuery=%s"), + private Mono findExistingTMForumSubscription(TMForumSubscription subscription) { + String query = String.format(queryParser.toNgsiLdQuery(TMForumSubscription.class, "callback=%s&rawQuery=%s"), subscription.getCallback(), subscription.getRawQuery()); - return repository.findEntities(DEFAULT_OFFSET, 1, Subscription.TYPE_SUBSCRIPTION, - Subscription.class, query) + return repository.findEntities(CommonConstants.DEFAULT_OFFSET, 1, TMForumSubscription.TYPE_TM_FORUM_SUBSCRIPTION, + TMForumSubscription.class, query) .flatMap(list -> list.isEmpty() ? Mono.empty() : Mono.error(new TmForumException("Such subscription already exists.", TmForumExceptionReason.CONFLICT))); } - protected Subscription buildSubscription(String callback, String query, List eventGroups) { + protected TMForumSubscription buildSubscription(String callback, String query, List eventGroups) { log.debug(query); SubscriptionQuery subscriptionQuery = SubscriptionQueryParser.parse(query, eventGroups); - - String subId = UUID.randomUUID().toString(); - Subscription subscription = new Subscription(subId); - subscription.setRawQuery(query != null ? query : ""); - subscription.setEventTypes(subscriptionQuery.getEventTypes()); - subscription.setEntities(subscriptionQuery.getEventGroups().stream() + List entities = subscriptionQuery.getEventGroups().stream() .map(eventGroup -> { if (eventGroupToEntityNameMapping.containsKey(eventGroup)) { return eventGroupToEntityNameMapping.get(eventGroup); @@ -64,16 +108,73 @@ protected Subscription buildSubscription(String callback, String query, List entities) { + Subscription subscription = new Subscription(UUID.randomUUID().toString()); + subscription.setQ(subscriptionQuery.getQuery()); + subscription.setEntities(entities.stream().map(entityType -> { + EntityInfo entityInfo = new EntityInfo(); + entityInfo.setType(entityType); + return entityInfo; + }).toList()); + subscription.setNotification(buildNotificationParams(callback, subscriptionQuery)); return subscription; } + private NotificationParams buildNotificationParams(String callback, SubscriptionQuery subscriptionQuery) { + NotificationParams notificationParams = new NotificationParams(); + notificationParams.setAttributes(Set.copyOf(subscriptionQuery.getFields())); + notificationParams.setFormat(EventConstants.NOTIFICATION_FORMAT); + notificationParams.setEndpoint( + new Endpoint( + getCallbackURI(), + EventConstants.NOTIFICATION_PAYLOAD_MIME_TYPE, + List.of(new KeyValuePair(RECEIVER_INFO_LISTENER_ENDPOINT, callback)))); + return notificationParams; + } + @Override - @CacheInvalidate(value = CommonConstants.SUBSCRIPTIONS_CACHE_NAME, all = true) + @CacheInvalidate(value = CommonConstants.TMFORUM_SUBSCRIPTIONS_CACHE_NAME, all = true) protected Mono> delete(String id) { - return super.delete(id); + return repository.deleteDomainSubscriptionByTmForumSubscription(URI.create(id)) + .then(super.delete(id)); + } + + private URI getCallbackURI() { + return URI.create(generalProperties.getServerHost() + generalProperties.getBasepath() + + EventConstants.SUBSCRIPTION_CALLBACK_PATH); + } + + @Post(EventConstants.SUBSCRIPTION_CALLBACK_PATH) + @Consumes({"application/json;charset=utf-8"}) + public Mono> callback(@NonNull @Body String payload) { + log.debug("Callback for NGSI-LD subscription"); + + try { + NotificationVO notificationVO = this.entityVOMapper.readNotificationFromJSON(payload); + + log.debug(String.format("Callback for subscription %s with notification %s", notificationVO.getSubscriptionId(), payload)); + + assert !notificationVO.getData().isEmpty(); + + return this.repository.retrieveSubscriptionById(notificationVO.getSubscriptionId()) + .flatMap(subscriptionVO -> ngsiLdEventHandler.handle(notificationVO, subscriptionVO, + entityNameToEntityClassMapping)) + .then(Mono.just(HttpResponse.noContent())); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } } } diff --git a/common/src/main/java/org/fiware/tmforum/common/util/StringUtils.java b/common/src/main/java/org/fiware/tmforum/common/util/StringUtils.java index 1abb037e..3df0c7bd 100644 --- a/common/src/main/java/org/fiware/tmforum/common/util/StringUtils.java +++ b/common/src/main/java/org/fiware/tmforum/common/util/StringUtils.java @@ -2,39 +2,7 @@ import org.fiware.tmforum.common.notification.EventConstants; -import java.util.Arrays; - public class StringUtils { - public static String toCamelCase(String dashedLowerCase) { - if (dashedLowerCase == null || dashedLowerCase.isEmpty()) { - return ""; - } - return String.join("", Arrays.stream(dashedLowerCase.split("-")) - .map(StringUtils::capitalize).toList()); - } - - public static String decapitalize(String string) { - if (string == null || string.isEmpty()) { - return string; - } - - char[] c = string.toCharArray(); - c[0] = Character.toLowerCase(c[0]); - - return new String(c); - } - - public static String capitalize(String string) { - if (string == null || string.isEmpty()) { - return string; - } - - char[] c = string.toCharArray(); - c[0] = Character.toUpperCase(c[0]); - - return new String(c); - } - public static String getEventGroupName(String eventType) { return eventType .replace(EventConstants.CREATE_EVENT_SUFFIX, "") diff --git a/customer-bill-management/src/main/java/org/fiware/tmforum/customerbillmanagement/rest/AppliedCustomerBillingRateApiController.java b/customer-bill-management/src/main/java/org/fiware/tmforum/customerbillmanagement/rest/AppliedCustomerBillingRateApiController.java index c95458ec..0f92d8a1 100644 --- a/customer-bill-management/src/main/java/org/fiware/tmforum/customerbillmanagement/rest/AppliedCustomerBillingRateApiController.java +++ b/customer-bill-management/src/main/java/org/fiware/tmforum/customerbillmanagement/rest/AppliedCustomerBillingRateApiController.java @@ -7,10 +7,10 @@ import lombok.extern.slf4j.Slf4j; import org.fiware.customerbillmanagement.api.AppliedCustomerBillingRateApi; import org.fiware.customerbillmanagement.model.AppliedCustomerBillingRateVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -31,7 +31,7 @@ public class AppliedCustomerBillingRateApiController extends AbstractApiControll public AppliedCustomerBillingRateApiController( QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, TMForumMapper tmForumMapper, EventHandler eventHandler) { + TmForumRepository repository, TMForumMapper tmForumMapper, TMForumEventHandler eventHandler) { super(queryParser, validationService, repository, eventHandler); this.tmForumMapper = tmForumMapper; } diff --git a/customer-bill-management/src/main/java/org/fiware/tmforum/customerbillmanagement/rest/CustomerBillApiController.java b/customer-bill-management/src/main/java/org/fiware/tmforum/customerbillmanagement/rest/CustomerBillApiController.java index e2bcf62a..b2175eb4 100644 --- a/customer-bill-management/src/main/java/org/fiware/tmforum/customerbillmanagement/rest/CustomerBillApiController.java +++ b/customer-bill-management/src/main/java/org/fiware/tmforum/customerbillmanagement/rest/CustomerBillApiController.java @@ -8,12 +8,12 @@ import org.fiware.customerbillmanagement.api.CustomerBillApi; import org.fiware.customerbillmanagement.model.CustomerBillUpdateVO; import org.fiware.customerbillmanagement.model.CustomerBillVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.domain.TaxItem; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -36,7 +36,7 @@ public class CustomerBillApiController extends AbstractApiController imple public CustomerApiController(QueryParser queryParser, ReferenceValidationService validationService, TmForumRepository customerManagementRepository, - TMForumMapper tmForumMapper, EventHandler eventHandler) { + TMForumMapper tmForumMapper, TMForumEventHandler eventHandler) { super(queryParser, validationService, customerManagementRepository, eventHandler); this.tmForumMapper = tmForumMapper; } diff --git a/customer-management/src/main/java/org/fiware/tmforum/customermanagement/rest/EventSubscriptionApiController.java b/customer-management/src/main/java/org/fiware/tmforum/customermanagement/rest/EventSubscriptionApiController.java index 641278f7..e2c7e93d 100644 --- a/customer-management/src/main/java/org/fiware/tmforum/customermanagement/rest/EventSubscriptionApiController.java +++ b/customer-management/src/main/java/org/fiware/tmforum/customermanagement/rest/EventSubscriptionApiController.java @@ -1,5 +1,6 @@ package org.fiware.tmforum.customermanagement.rest; +import io.github.wistefan.mapping.EntityVOMapper; import io.micronaut.core.annotation.NonNull; import io.micronaut.http.HttpResponse; import io.micronaut.http.annotation.Controller; @@ -7,9 +8,11 @@ import org.fiware.customermanagement.api.EventsSubscriptionApi; import org.fiware.customermanagement.model.EventSubscriptionInputVO; import org.fiware.customermanagement.model.EventSubscriptionVO; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.common.configuration.GeneralProperties; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; +import org.fiware.tmforum.common.notification.NgsiLdEventHandler; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.querying.QueryParser; -import org.fiware.tmforum.common.domain.subscription.Subscription; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractSubscriptionApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -31,17 +34,24 @@ public class EventSubscriptionApiController extends AbstractSubscriptionApiContr entry(EVENT_GROUP_CUSTOMER, Customer.TYPE_CUSTOMER) ); private static final List EVENT_GROUPS = List.of(EVENT_GROUP_CUSTOMER); + private static final Map> ENTITY_NAME_TO_ENTITY_CLASS_MAPPING = Map.ofEntries( + entry(Customer.TYPE_CUSTOMER, Customer.class) + ); public EventSubscriptionApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, TMForumMapper tmForumMapper, EventHandler eventHandler) { - super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, eventHandler); + TmForumRepository repository, TMForumMapper tmForumMapper, + TMForumEventHandler tmForumEventHandler, NgsiLdEventHandler ngsiLdEventHandler, + GeneralProperties generalProperties, EntityVOMapper entityVOMapper) { + super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, + ENTITY_NAME_TO_ENTITY_CLASS_MAPPING, tmForumEventHandler, ngsiLdEventHandler, + generalProperties, entityVOMapper); this.tmForumMapper = tmForumMapper; } @Override public Mono> registerListener( @NonNull EventSubscriptionInputVO eventSubscriptionInputVO) { - Subscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), + TMForumSubscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), eventSubscriptionInputVO.getQuery(), EVENT_GROUPS); return create(subscription) diff --git a/customer-management/src/test/java/org/fiware/tmforum/customermanagement/CustomerApiIT.java b/customer-management/src/test/java/org/fiware/tmforum/customermanagement/CustomerApiIT.java index f1823f87..9c0ae7b4 100644 --- a/customer-management/src/test/java/org/fiware/tmforum/customermanagement/CustomerApiIT.java +++ b/customer-management/src/test/java/org/fiware/tmforum/customermanagement/CustomerApiIT.java @@ -7,25 +7,11 @@ import io.micronaut.test.extensions.junit5.annotation.MicronautTest; import org.fiware.customermanagement.api.CustomerApiTestClient; import org.fiware.customermanagement.api.CustomerApiTestSpec; -import org.fiware.customermanagement.model.AccountRefVOTestExample; -import org.fiware.customermanagement.model.AgreementRefVOTestExample; -import org.fiware.customermanagement.model.CharacteristicVOTestExample; -import org.fiware.customermanagement.model.ContactMediumVOTestExample; -import org.fiware.customermanagement.model.CreditProfileVOTestExample; -import org.fiware.customermanagement.model.CustomerCreateVO; -import org.fiware.customermanagement.model.CustomerCreateVOTestExample; -import org.fiware.customermanagement.model.CustomerUpdateVO; -import org.fiware.customermanagement.model.CustomerUpdateVOTestExample; -import org.fiware.customermanagement.model.CustomerVO; -import org.fiware.customermanagement.model.CustomerVOTestExample; -import org.fiware.customermanagement.model.PaymentMethodRefVOTestExample; -import org.fiware.customermanagement.model.RelatedPartyVOTestExample; -import org.fiware.customermanagement.model.TimePeriodVO; -import org.fiware.customermanagement.model.TimePeriodVOTestExample; +import org.fiware.customermanagement.model.*; import org.fiware.ngsi.api.EntitiesApiClient; -import org.fiware.tmforum.common.notification.EventHandler; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.fiware.tmforum.customermanagement.domain.Customer; import org.junit.jupiter.api.Disabled; @@ -70,13 +56,12 @@ public CustomerApiIT(CustomerApiTestClient customerApiTestClient, EntitiesApiCli this.objectMapper = objectMapper; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/customer-management/src/test/resources/application.yaml b/customer-management/src/test/resources/application.yaml index fde4f97e..aa62a2db 100644 --- a/customer-management/src/test/resources/application.yaml +++ b/customer-management/src/test/resources/application.yaml @@ -35,4 +35,6 @@ loggers: --- general: - contextUrl: https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld \ No newline at end of file + contextUrl: https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld + serverHost: http://localhost:8632 + basePath: /tmf-api/customerManagement/v4 \ No newline at end of file diff --git a/party-catalog/src/main/java/org/fiware/tmforum/party/TMForumMapper.java b/party-catalog/src/main/java/org/fiware/tmforum/party/TMForumMapper.java index 746159f1..30f25730 100644 --- a/party-catalog/src/main/java/org/fiware/tmforum/party/TMForumMapper.java +++ b/party-catalog/src/main/java/org/fiware/tmforum/party/TMForumMapper.java @@ -3,7 +3,7 @@ import io.github.wistefan.mapping.MappingException; import org.fiware.party.model.*; import org.fiware.tmforum.common.domain.TimePeriod; -import org.fiware.tmforum.common.domain.subscription.Subscription; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; import org.fiware.tmforum.common.mapping.IdHelper; import org.fiware.tmforum.party.domain.individual.Individual; import org.fiware.tmforum.party.domain.individual.LanguageAbility; @@ -52,7 +52,7 @@ public interface TMForumMapper { LanguageAbilityVO map(LanguageAbility languageAbility); @Mapping(target = "query", source = "rawQuery") - EventSubscriptionVO map(Subscription subscription); + EventSubscriptionVO map(TMForumSubscription subscription); default OrganizationParentRelationshipVO map(OrganizationParentRelationship organizationParentRelationship) { if (organizationParentRelationship == null) { diff --git a/party-catalog/src/main/java/org/fiware/tmforum/party/rest/AbstractPartyApiController.java b/party-catalog/src/main/java/org/fiware/tmforum/party/rest/AbstractPartyApiController.java index d86c6f27..24819a16 100644 --- a/party-catalog/src/main/java/org/fiware/tmforum/party/rest/AbstractPartyApiController.java +++ b/party-catalog/src/main/java/org/fiware/tmforum/party/rest/AbstractPartyApiController.java @@ -1,14 +1,14 @@ package org.fiware.tmforum.party.rest; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; +import org.fiware.tmforum.common.domain.TaxDefinition; +import org.fiware.tmforum.common.domain.TaxExemptionCertificate; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; -import org.fiware.tmforum.common.domain.TaxDefinition; -import org.fiware.tmforum.common.domain.TaxExemptionCertificate; import java.util.HashSet; import java.util.List; @@ -17,7 +17,7 @@ public class AbstractPartyApiController extends AbstractApiController { public AbstractPartyApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, EventHandler eventHandler) { + TmForumRepository repository, TMForumEventHandler eventHandler) { super(queryParser, validationService, repository, eventHandler); } diff --git a/party-catalog/src/main/java/org/fiware/tmforum/party/rest/EventSubscriptionApiController.java b/party-catalog/src/main/java/org/fiware/tmforum/party/rest/EventSubscriptionApiController.java index 83013b78..79bb7128 100644 --- a/party-catalog/src/main/java/org/fiware/tmforum/party/rest/EventSubscriptionApiController.java +++ b/party-catalog/src/main/java/org/fiware/tmforum/party/rest/EventSubscriptionApiController.java @@ -1,5 +1,6 @@ package org.fiware.tmforum.party.rest; +import io.github.wistefan.mapping.EntityVOMapper; import io.micronaut.core.annotation.NonNull; import io.micronaut.http.HttpResponse; import io.micronaut.http.annotation.Controller; @@ -7,9 +8,11 @@ import org.fiware.party.api.EventsSubscriptionApi; import org.fiware.party.model.EventSubscriptionInputVO; import org.fiware.party.model.EventSubscriptionVO; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.common.configuration.GeneralProperties; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; +import org.fiware.tmforum.common.notification.NgsiLdEventHandler; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.querying.QueryParser; -import org.fiware.tmforum.common.domain.subscription.Subscription; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractSubscriptionApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -34,17 +37,26 @@ public class EventSubscriptionApiController extends AbstractSubscriptionApiContr entry(EVENT_GROUP_ORGANIZATION, Organization.TYPE_ORGANIZATION) ); private static final List EVENT_GROUPS = List.of(EVENT_GROUP_INDIVIDUAL, EVENT_GROUP_ORGANIZATION); + private static final Map> ENTITY_NAME_TO_ENTITY_CLASS_MAPPING = Map.ofEntries( + entry(Individual.TYPE_INDIVIDUAL, Individual.class), + entry(Organization.TYPE_ORGANIZATION, Organization.class) + ); public EventSubscriptionApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, TMForumMapper tmForumMapper, EventHandler eventHandler) { - super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, eventHandler); + TmForumRepository repository, TMForumMapper tmForumMapper, + TMForumEventHandler tmForumEventHandler, NgsiLdEventHandler ngsiLdEventHandler, + GeneralProperties generalProperties, + EntityVOMapper entityVOMapper) { + super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, + ENTITY_NAME_TO_ENTITY_CLASS_MAPPING, tmForumEventHandler, ngsiLdEventHandler, + generalProperties, entityVOMapper); this.tmForumMapper = tmForumMapper; } @Override public Mono> registerListener( @NonNull EventSubscriptionInputVO eventSubscriptionInputVO) { - Subscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), + TMForumSubscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), eventSubscriptionInputVO.getQuery(), EVENT_GROUPS); return create(subscription) diff --git a/party-catalog/src/main/java/org/fiware/tmforum/party/rest/IndividualApiController.java b/party-catalog/src/main/java/org/fiware/tmforum/party/rest/IndividualApiController.java index 3d9334a1..2e051dbc 100644 --- a/party-catalog/src/main/java/org/fiware/tmforum/party/rest/IndividualApiController.java +++ b/party-catalog/src/main/java/org/fiware/tmforum/party/rest/IndividualApiController.java @@ -8,11 +8,11 @@ import org.fiware.party.model.IndividualCreateVO; import org.fiware.party.model.IndividualUpdateVO; import org.fiware.party.model.IndividualVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.validation.ReferenceValidationService; import org.fiware.tmforum.common.validation.ReferencedEntity; @@ -23,11 +23,7 @@ import javax.annotation.Nullable; import javax.validation.Valid; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.UUID; +import java.util.*; @Slf4j @Controller("${general.basepath:/}") @@ -36,7 +32,7 @@ public class IndividualApiController extends AbstractPartyApiController implements PartyRoleApi{ +public class PartyRoleController extends AbstractApiController implements PartyRoleApi { private final TMForumMapper tmForumMapper; - public PartyRoleController(QueryParser queryParser, ReferenceValidationService validationService, TMForumMapper mapper,TmForumRepository repository, EventHandler eventHandler) { + public PartyRoleController(QueryParser queryParser, ReferenceValidationService validationService, + TMForumMapper mapper, TmForumRepository repository, TMForumEventHandler eventHandler) { super(queryParser, validationService, repository, eventHandler); this.tmForumMapper = mapper; } diff --git a/party-role/src/test/resources/application.yaml b/party-role/src/test/resources/application.yaml index 22124573..b85bf11e 100644 --- a/party-role/src/test/resources/application.yaml +++ b/party-role/src/test/resources/application.yaml @@ -36,4 +36,5 @@ loggers: --- general: contextUrl: https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld - serverHost: http://localhost:8632 \ No newline at end of file + serverHost: http://localhost:8632 + basePath: /tmf-api/partyRole/v4 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2d3a254d..50f33db3 100644 --- a/pom.xml +++ b/pom.xml @@ -81,6 +81,7 @@ 1.4.2.Final 1.18.22 + 31.1-jre 3.1.0 @@ -92,7 +93,7 @@ 3.1.0 - 0.5.0 + 1.1.0 5.4.0 diff --git a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/TMForumMapper.java b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/TMForumMapper.java index 1c751cf6..b4850b0a 100644 --- a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/TMForumMapper.java +++ b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/TMForumMapper.java @@ -2,7 +2,7 @@ import io.github.wistefan.mapping.MappingException; import org.fiware.productcatalog.model.*; -import org.fiware.tmforum.common.domain.subscription.Subscription; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; import org.fiware.tmforum.common.mapping.IdHelper; import org.fiware.tmforum.product.Category; import org.fiware.tmforum.product.ProductOffering; @@ -100,7 +100,7 @@ public interface TMForumMapper { ProductSpecificationVO map(ProductSpecificationUpdateVO productSpecificationUpdateVO, String id); @Mapping(target = "query", source = "rawQuery") - EventSubscriptionVO map(Subscription subscription); + EventSubscriptionVO map(TMForumSubscription subscription); default URL map(String value) { if (value == null) { diff --git a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/AbstractProductCatalogApiController.java b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/AbstractProductCatalogApiController.java index 65e3d08e..7902e609 100644 --- a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/AbstractProductCatalogApiController.java +++ b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/AbstractProductCatalogApiController.java @@ -1,9 +1,9 @@ package org.fiware.tmforum.productcatalog.rest; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -19,7 +19,7 @@ public class AbstractProductCatalogApiController extends AbstractApiControlle public AbstractProductCatalogApiController( QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, EventHandler eventHandler) { + TmForumRepository repository, TMForumEventHandler eventHandler) { super(queryParser, validationService, repository, eventHandler); } diff --git a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/CatalogApiController.java b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/CatalogApiController.java index 69f5289c..56412ecf 100644 --- a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/CatalogApiController.java +++ b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/CatalogApiController.java @@ -7,11 +7,11 @@ import org.fiware.productcatalog.model.CatalogCreateVO; import org.fiware.productcatalog.model.CatalogUpdateVO; import org.fiware.productcatalog.model.CatalogVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -32,7 +32,7 @@ public class CatalogApiController extends AbstractApiController impleme private final TMForumMapper tmForumMapper; public CatalogApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository productCatalogRepository, TMForumMapper tmForumMapper, EventHandler eventHandler) { + TmForumRepository productCatalogRepository, TMForumMapper tmForumMapper, TMForumEventHandler eventHandler) { super(queryParser, validationService, productCatalogRepository, eventHandler); this.tmForumMapper = tmForumMapper; } diff --git a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/CategoryApiController.java b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/CategoryApiController.java index 7b5ca722..0e44d808 100644 --- a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/CategoryApiController.java +++ b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/CategoryApiController.java @@ -8,11 +8,11 @@ import org.fiware.productcatalog.model.CategoryCreateVO; import org.fiware.productcatalog.model.CategoryUpdateVO; import org.fiware.productcatalog.model.CategoryVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -36,7 +36,7 @@ public class CategoryApiController extends AbstractApiController imple public CategoryApiController(QueryParser queryParser, ReferenceValidationService validationService, TmForumRepository productCatalogRepository, - TMForumMapper tmForumMapper, Clock clock, EventHandler eventHandler) { + TMForumMapper tmForumMapper, Clock clock, TMForumEventHandler eventHandler) { super(queryParser, validationService, productCatalogRepository, eventHandler); this.tmForumMapper = tmForumMapper; this.clock = clock; diff --git a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/EventSubscriptionApiController.java b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/EventSubscriptionApiController.java index 9e1ebdf8..140ada0a 100644 --- a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/EventSubscriptionApiController.java +++ b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/EventSubscriptionApiController.java @@ -1,5 +1,6 @@ package org.fiware.tmforum.productcatalog.rest; +import io.github.wistefan.mapping.EntityVOMapper; import io.micronaut.core.annotation.NonNull; import io.micronaut.http.HttpResponse; import io.micronaut.http.annotation.Controller; @@ -7,9 +8,11 @@ import org.fiware.productcatalog.api.EventsSubscriptionApi; import org.fiware.productcatalog.model.EventSubscriptionInputVO; import org.fiware.productcatalog.model.EventSubscriptionVO; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.common.configuration.GeneralProperties; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; +import org.fiware.tmforum.common.notification.NgsiLdEventHandler; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.querying.QueryParser; -import org.fiware.tmforum.common.domain.subscription.Subscription; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractSubscriptionApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -40,17 +43,28 @@ public class EventSubscriptionApiController extends AbstractSubscriptionApiContr ); private static final List EVENT_GROUPS = List.of(EVENT_GROUP_CATALOG, EVENT_GROUP_CATEGORY, EVENT_GROUP_PRODUCT_OFFERING, EVENT_GROUP_PRODUCT_OFFERING_PRICE, EVENT_GROUP_PRODUCT_SPECIFICATION); + private static final Map> ENTITY_NAME_TO_ENTITY_CLASS_MAPPING = Map.ofEntries( + entry(Catalog.TYPE_CATALOG, Catalog.class), + entry(Category.TYPE_CATEGORY, Category.class), + entry(ProductOffering.TYPE_PRODUCT_OFFERING, ProductOffering.class), + entry(ProductOfferingPrice.TYPE_PRODUCT_OFFERING_PRICE, ProductOfferingPrice.class), + entry(ProductSpecification.TYPE_PRODUCT_SPECIFICATION, ProductSpecification.class) + ); public EventSubscriptionApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, TMForumMapper tmForumMapper, EventHandler eventHandler) { - super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, eventHandler); + TmForumRepository repository, TMForumMapper tmForumMapper, + TMForumEventHandler tmForumEventHandler, NgsiLdEventHandler ngsiLdEventHandler, + GeneralProperties generalProperties, EntityVOMapper entityVOMapper) { + super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, + ENTITY_NAME_TO_ENTITY_CLASS_MAPPING, tmForumEventHandler, ngsiLdEventHandler, + generalProperties, entityVOMapper); this.tmForumMapper = tmForumMapper; } @Override public Mono> registerListener( @NonNull EventSubscriptionInputVO eventSubscriptionInputVO) { - Subscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), + TMForumSubscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), eventSubscriptionInputVO.getQuery(), EVENT_GROUPS); return create(subscription) diff --git a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/ProductOfferingApiController.java b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/ProductOfferingApiController.java index 1f112107..77bf787f 100644 --- a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/ProductOfferingApiController.java +++ b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/ProductOfferingApiController.java @@ -8,11 +8,11 @@ import org.fiware.productcatalog.model.ProductOfferingCreateVO; import org.fiware.productcatalog.model.ProductOfferingUpdateVO; import org.fiware.productcatalog.model.ProductOfferingVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.validation.ReferenceValidationService; import org.fiware.tmforum.common.validation.ReferencedEntity; @@ -36,7 +36,7 @@ public class ProductOfferingApiController extends AbstractProductCatalogApiContr public ProductOfferingApiController(QueryParser queryParser, ReferenceValidationService validationService, TmForumRepository productCatalogRepository, TMForumMapper tmForumMapper, - Clock clock, EventHandler eventHandler) { + Clock clock, TMForumEventHandler eventHandler) { super(queryParser, validationService, productCatalogRepository, eventHandler); this.tmForumMapper = tmForumMapper; this.clock = clock; diff --git a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/ProductOfferingPriceApiController.java b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/ProductOfferingPriceApiController.java index 7dbfb785..b9c40425 100644 --- a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/ProductOfferingPriceApiController.java +++ b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/ProductOfferingPriceApiController.java @@ -8,12 +8,12 @@ import org.fiware.productcatalog.model.ProductOfferingPriceCreateVO; import org.fiware.productcatalog.model.ProductOfferingPriceUpdateVO; import org.fiware.productcatalog.model.ProductOfferingPriceVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.domain.TaxItem; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.validation.ReferenceValidationService; import org.fiware.tmforum.common.validation.ReferencedEntity; @@ -23,12 +23,7 @@ import reactor.core.publisher.Mono; import java.time.Clock; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; +import java.util.*; @Slf4j @Controller("${general.basepath:/}") @@ -40,7 +35,7 @@ public class ProductOfferingPriceApiController extends AbstractProductCatalogApi public ProductOfferingPriceApiController(QueryParser queryParser, ReferenceValidationService validationService, TmForumRepository productCatalogRepository, TMForumMapper tmForumMapper, - Clock clock, EventHandler eventHandler) { + Clock clock, TMForumEventHandler eventHandler) { super(queryParser, validationService, productCatalogRepository, eventHandler); this.tmForumMapper = tmForumMapper; this.clock = clock; diff --git a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/ProductSpecificationApiController.java b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/ProductSpecificationApiController.java index fa05eae9..e0ae5474 100644 --- a/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/ProductSpecificationApiController.java +++ b/product-catalog/src/main/java/org/fiware/tmforum/productcatalog/rest/ProductSpecificationApiController.java @@ -8,11 +8,11 @@ import org.fiware.productcatalog.model.ProductSpecificationCreateVO; import org.fiware.productcatalog.model.ProductSpecificationUpdateVO; import org.fiware.productcatalog.model.ProductSpecificationVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.validation.ReferenceValidationService; import org.fiware.tmforum.common.validation.ReferencedEntity; @@ -22,12 +22,7 @@ import reactor.core.publisher.Mono; import java.time.Clock; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; +import java.util.*; @Slf4j @Controller("${general.basepath:/}") @@ -39,7 +34,7 @@ public class ProductSpecificationApiController extends AbstractProductCatalogApi public ProductSpecificationApiController(QueryParser queryParser, ReferenceValidationService validationService, TmForumRepository productCatalogRepository, TMForumMapper tmForumMapper, - Clock clock, EventHandler eventHandler) { + Clock clock, TMForumEventHandler eventHandler) { super(queryParser, validationService, productCatalogRepository, eventHandler); this.tmForumMapper = tmForumMapper; this.clock = clock; diff --git a/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/CatalogApiIT.java b/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/CatalogApiIT.java index 8d60775a..67c8492c 100644 --- a/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/CatalogApiIT.java +++ b/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/CatalogApiIT.java @@ -8,21 +8,10 @@ import org.fiware.ngsi.api.EntitiesApiClient; import org.fiware.productcatalog.api.CatalogApiTestClient; import org.fiware.productcatalog.api.CatalogApiTestSpec; -import org.fiware.productcatalog.model.CatalogCreateVO; -import org.fiware.productcatalog.model.CatalogCreateVOTestExample; -import org.fiware.productcatalog.model.CatalogUpdateVO; -import org.fiware.productcatalog.model.CatalogUpdateVOTestExample; -import org.fiware.productcatalog.model.CatalogVO; -import org.fiware.productcatalog.model.CatalogVOTestExample; -import org.fiware.productcatalog.model.CategoryRefVO; -import org.fiware.productcatalog.model.CategoryRefVOTestExample; -import org.fiware.productcatalog.model.RelatedPartyVO; -import org.fiware.productcatalog.model.RelatedPartyVOTestExample; -import org.fiware.productcatalog.model.TimePeriodVO; -import org.fiware.productcatalog.model.TimePeriodVOTestExample; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.productcatalog.model.*; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.fiware.tmforum.productcatalog.domain.Catalog; import org.junit.jupiter.api.Disabled; @@ -62,13 +51,12 @@ public CatalogApiIT(CatalogApiTestClient catalogApiTestClient, EntitiesApiClient this.catalogApiTestClient = catalogApiTestClient; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/CategoryApiIT.java b/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/CategoryApiIT.java index 74bf67d6..e66f6dd0 100644 --- a/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/CategoryApiIT.java +++ b/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/CategoryApiIT.java @@ -8,21 +8,10 @@ import org.fiware.ngsi.api.EntitiesApiClient; import org.fiware.productcatalog.api.CategoryApiTestClient; import org.fiware.productcatalog.api.CategoryApiTestSpec; -import org.fiware.productcatalog.model.CategoryCreateVO; -import org.fiware.productcatalog.model.CategoryCreateVOTestExample; -import org.fiware.productcatalog.model.CategoryVO; -import org.fiware.productcatalog.model.CategoryVOTestExample; -import org.fiware.productcatalog.model.CategoryRefVO; -import org.fiware.productcatalog.model.CategoryRefVOTestExample; -import org.fiware.productcatalog.model.CategoryUpdateVO; -import org.fiware.productcatalog.model.CategoryUpdateVOTestExample; -import org.fiware.productcatalog.model.ProductOfferingRefVO; -import org.fiware.productcatalog.model.ProductOfferingRefVOTestExample; -import org.fiware.productcatalog.model.TimePeriodVO; -import org.fiware.productcatalog.model.TimePeriodVOTestExample; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.productcatalog.model.*; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.fiware.tmforum.product.Category; import org.junit.jupiter.api.Disabled; @@ -70,13 +59,12 @@ public Clock clock() { return clock; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/EventSubscriptionApiIT.java b/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/EventSubscriptionApiIT.java index 686aedf2..5d2895d5 100644 --- a/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/EventSubscriptionApiIT.java +++ b/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/EventSubscriptionApiIT.java @@ -13,7 +13,7 @@ import org.fiware.productcatalog.model.EventSubscriptionVO; import org.fiware.productcatalog.model.EventSubscriptionVOTestExample; import org.fiware.tmforum.common.configuration.GeneralProperties; -import org.fiware.tmforum.common.domain.subscription.Subscription; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; import org.fiware.tmforum.common.exception.ErrorDetails; import org.fiware.tmforum.common.test.AbstractApiIT; import org.junit.jupiter.api.Disabled; @@ -54,7 +54,7 @@ public EventSubscriptionApiIT(EventsSubscriptionApiTestClient eventsSubscription @Override protected String getEntityType() { - return Subscription.TYPE_SUBSCRIPTION; + return TMForumSubscription.TYPE_TM_FORUM_SUBSCRIPTION; } @ParameterizedTest diff --git a/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/ProductOfferingApiIT.java b/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/ProductOfferingApiIT.java index 51843cac..087ea8fc 100644 --- a/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/ProductOfferingApiIT.java +++ b/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/ProductOfferingApiIT.java @@ -10,9 +10,9 @@ import org.fiware.productcatalog.api.ProductOfferingApiTestSpec; import org.fiware.productcatalog.api.ProductSpecificationApiTestClient; import org.fiware.productcatalog.model.*; -import org.fiware.tmforum.common.notification.EventHandler; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.fiware.tmforum.product.ProductOffering; import org.junit.jupiter.api.Disabled; @@ -63,13 +63,12 @@ public Clock clock() { return clock; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/ProductOfferingPriceApiIT.java b/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/ProductOfferingPriceApiIT.java index 56f13eac..d4d957aa 100644 --- a/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/ProductOfferingPriceApiIT.java +++ b/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/ProductOfferingPriceApiIT.java @@ -8,26 +8,10 @@ import org.fiware.ngsi.api.EntitiesApiClient; import org.fiware.productcatalog.api.ProductOfferingPriceApiTestClient; import org.fiware.productcatalog.api.ProductOfferingPriceApiTestSpec; -import org.fiware.productcatalog.model.BundledProductOfferingPriceRelationshipVOTestExample; -import org.fiware.productcatalog.model.ConstraintRefVOTestExample; -import org.fiware.productcatalog.model.PlaceRefVOTestExample; -import org.fiware.productcatalog.model.PricingLogicAlgorithmVO; -import org.fiware.productcatalog.model.PricingLogicAlgorithmVOTestExample; -import org.fiware.productcatalog.model.ProductOfferingPriceCreateVO; -import org.fiware.productcatalog.model.ProductOfferingPriceCreateVOTestExample; -import org.fiware.productcatalog.model.ProductOfferingPriceRelationshipVOTestExample; -import org.fiware.productcatalog.model.ProductOfferingPriceUpdateVO; -import org.fiware.productcatalog.model.ProductOfferingPriceUpdateVOTestExample; -import org.fiware.productcatalog.model.ProductOfferingPriceVO; -import org.fiware.productcatalog.model.ProductOfferingPriceVOTestExample; -import org.fiware.productcatalog.model.ProductSpecificationCharacteristicValueUseVOTestExample; -import org.fiware.productcatalog.model.TaxItemVO; -import org.fiware.productcatalog.model.TaxItemVOTestExample; -import org.fiware.productcatalog.model.TimePeriodVO; -import org.fiware.productcatalog.model.TimePeriodVOTestExample; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.productcatalog.model.*; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.fiware.tmforum.product.ProductOfferingPrice; import org.junit.jupiter.api.Disabled; @@ -75,13 +59,12 @@ public Clock clock() { return clock; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/ProductSpecificationApiIT.java b/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/ProductSpecificationApiIT.java index 272e3ef8..28e30a4c 100644 --- a/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/ProductSpecificationApiIT.java +++ b/product-catalog/src/test/java/org/fiware/tmforum/productcatalog/ProductSpecificationApiIT.java @@ -8,24 +8,10 @@ import org.fiware.ngsi.api.EntitiesApiClient; import org.fiware.productcatalog.api.ProductSpecificationApiTestClient; import org.fiware.productcatalog.api.ProductSpecificationApiTestSpec; -import org.fiware.productcatalog.model.BundledProductSpecificationVOTestExample; -import org.fiware.productcatalog.model.ProductSpecificationCharacteristicRelationshipVOTestExample; -import org.fiware.productcatalog.model.ProductSpecificationCharacteristicVOTestExample; -import org.fiware.productcatalog.model.ProductSpecificationCreateVO; -import org.fiware.productcatalog.model.ProductSpecificationCreateVOTestExample; -import org.fiware.productcatalog.model.ProductSpecificationRelationshipVOTestExample; -import org.fiware.productcatalog.model.ProductSpecificationUpdateVO; -import org.fiware.productcatalog.model.ProductSpecificationUpdateVOTestExample; -import org.fiware.productcatalog.model.ProductSpecificationVO; -import org.fiware.productcatalog.model.ProductSpecificationVOTestExample; -import org.fiware.productcatalog.model.RelatedPartyVOTestExample; -import org.fiware.productcatalog.model.ResourceSpecificationRefVOTestExample; -import org.fiware.productcatalog.model.ServiceSpecificationRefVOTestExample; -import org.fiware.productcatalog.model.TimePeriodVO; -import org.fiware.productcatalog.model.TimePeriodVOTestExample; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.productcatalog.model.*; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.fiware.tmforum.product.ProductSpecification; import org.junit.jupiter.api.Disabled; @@ -73,13 +59,12 @@ public Clock clock() { return clock; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/product-catalog/src/test/resources/application.yaml b/product-catalog/src/test/resources/application.yaml index fde4f97e..955a19a5 100644 --- a/product-catalog/src/test/resources/application.yaml +++ b/product-catalog/src/test/resources/application.yaml @@ -35,4 +35,6 @@ loggers: --- general: - contextUrl: https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld \ No newline at end of file + contextUrl: https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld + serverHost: http://localhost:8632 + basePath: /tmf-api/productCatalog/v4 \ No newline at end of file diff --git a/product-inventory/src/main/java/org/fiware/tmforum/productinventory/TMForumMapper.java b/product-inventory/src/main/java/org/fiware/tmforum/productinventory/TMForumMapper.java index fe747f1c..e6fa5f37 100644 --- a/product-inventory/src/main/java/org/fiware/tmforum/productinventory/TMForumMapper.java +++ b/product-inventory/src/main/java/org/fiware/tmforum/productinventory/TMForumMapper.java @@ -2,7 +2,7 @@ import io.github.wistefan.mapping.MappingException; import org.fiware.productinventory.model.*; -import org.fiware.tmforum.common.domain.subscription.Subscription; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; import org.fiware.tmforum.common.mapping.IdHelper; import org.fiware.tmforum.product.Product; import org.fiware.tmforum.product.RelatedProductOrderItemRef; @@ -46,7 +46,7 @@ default URL map(String value) { } @Mapping(target = "query", source = "rawQuery") - EventSubscriptionVO map(Subscription subscription); + EventSubscriptionVO map(TMForumSubscription subscription); default String map(URL value) { if (value == null) { diff --git a/product-inventory/src/main/java/org/fiware/tmforum/productinventory/rest/EventSubscriptionApiController.java b/product-inventory/src/main/java/org/fiware/tmforum/productinventory/rest/EventSubscriptionApiController.java index c6245ef3..255f3fcf 100644 --- a/product-inventory/src/main/java/org/fiware/tmforum/productinventory/rest/EventSubscriptionApiController.java +++ b/product-inventory/src/main/java/org/fiware/tmforum/productinventory/rest/EventSubscriptionApiController.java @@ -1,5 +1,6 @@ package org.fiware.tmforum.productinventory.rest; +import io.github.wistefan.mapping.EntityVOMapper; import io.micronaut.core.annotation.NonNull; import io.micronaut.http.HttpResponse; import io.micronaut.http.annotation.Controller; @@ -7,9 +8,11 @@ import org.fiware.productinventory.api.EventsSubscriptionApi; import org.fiware.productinventory.model.EventSubscriptionInputVO; import org.fiware.productinventory.model.EventSubscriptionVO; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.common.configuration.GeneralProperties; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; +import org.fiware.tmforum.common.notification.NgsiLdEventHandler; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.querying.QueryParser; -import org.fiware.tmforum.common.domain.subscription.Subscription; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractSubscriptionApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -31,17 +34,24 @@ public class EventSubscriptionApiController extends AbstractSubscriptionApiContr entry(EVENT_GROUP_PRODUCT, Product.TYPE_PRODUCT) ); private static final List EVENT_GROUPS = List.of(EVENT_GROUP_PRODUCT); + private static final Map> ENTITY_NAME_TO_ENTITY_CLASS_MAPPING = Map.ofEntries( + entry(Product.TYPE_PRODUCT, Product.class) + ); public EventSubscriptionApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, TMForumMapper tmForumMapper, EventHandler eventHandler) { - super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, eventHandler); + TmForumRepository repository, TMForumMapper tmForumMapper, + TMForumEventHandler tmForumEventHandler, NgsiLdEventHandler ngsiLdEventHandler, + GeneralProperties generalProperties, EntityVOMapper entityVOMapper) { + super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, + ENTITY_NAME_TO_ENTITY_CLASS_MAPPING, tmForumEventHandler, ngsiLdEventHandler, + generalProperties, entityVOMapper); this.tmForumMapper = tmForumMapper; } @Override public Mono> registerListener( @NonNull EventSubscriptionInputVO eventSubscriptionInputVO) { - Subscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), + TMForumSubscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), eventSubscriptionInputVO.getQuery(), EVENT_GROUPS); return create(subscription) @@ -53,4 +63,5 @@ public Mono> registerListener( public Mono> unregisterListener(@NonNull String id) { return delete(id); } + } diff --git a/product-inventory/src/main/java/org/fiware/tmforum/productinventory/rest/ProductApiController.java b/product-inventory/src/main/java/org/fiware/tmforum/productinventory/rest/ProductApiController.java index 2fcc48dd..a89c4d15 100644 --- a/product-inventory/src/main/java/org/fiware/tmforum/productinventory/rest/ProductApiController.java +++ b/product-inventory/src/main/java/org/fiware/tmforum/productinventory/rest/ProductApiController.java @@ -9,12 +9,12 @@ import org.fiware.productinventory.model.ProductCreateVO; import org.fiware.productinventory.model.ProductUpdateVO; import org.fiware.productinventory.model.ProductVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.domain.BillingAccountRef; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -32,7 +32,7 @@ public class ProductApiController extends AbstractApiController impleme private final TMForumMapper tmForumMapper; public ProductApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, TMForumMapper tmForumMapper, EventHandler eventHandler) { + TmForumRepository repository, TMForumMapper tmForumMapper, TMForumEventHandler eventHandler) { super(queryParser, validationService, repository, eventHandler); this.tmForumMapper = tmForumMapper; } diff --git a/product-inventory/src/test/java/org/fiware/tmforum/productinventory/EventSubscriptionApiIT.java b/product-inventory/src/test/java/org/fiware/tmforum/productinventory/EventSubscriptionApiIT.java index 20e8eecd..5f90fe6e 100644 --- a/product-inventory/src/test/java/org/fiware/tmforum/productinventory/EventSubscriptionApiIT.java +++ b/product-inventory/src/test/java/org/fiware/tmforum/productinventory/EventSubscriptionApiIT.java @@ -13,7 +13,7 @@ import org.fiware.productinventory.model.EventSubscriptionVO; import org.fiware.productinventory.model.EventSubscriptionVOTestExample; import org.fiware.tmforum.common.configuration.GeneralProperties; -import org.fiware.tmforum.common.domain.subscription.Subscription; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; import org.fiware.tmforum.common.exception.ErrorDetails; import org.fiware.tmforum.common.test.AbstractApiIT; import org.junit.jupiter.api.Disabled; @@ -53,7 +53,7 @@ public EventSubscriptionApiIT(EventsSubscriptionApiTestClient eventsSubscription @Override protected String getEntityType() { - return Subscription.TYPE_SUBSCRIPTION; + return TMForumSubscription.TYPE_TM_FORUM_SUBSCRIPTION; } @ParameterizedTest diff --git a/product-inventory/src/test/java/org/fiware/tmforum/productinventory/ProductApiIT.java b/product-inventory/src/test/java/org/fiware/tmforum/productinventory/ProductApiIT.java index d9901aba..48beed20 100644 --- a/product-inventory/src/test/java/org/fiware/tmforum/productinventory/ProductApiIT.java +++ b/product-inventory/src/test/java/org/fiware/tmforum/productinventory/ProductApiIT.java @@ -8,33 +8,10 @@ import org.fiware.ngsi.api.EntitiesApiClient; import org.fiware.productinventory.api.ProductApiTestClient; import org.fiware.productinventory.api.ProductApiTestSpec; -import org.fiware.productinventory.model.AgreementItemRefVOTestExample; -import org.fiware.productinventory.model.BillingAccountRefVOTestExample; -import org.fiware.productinventory.model.CharacteristicVOTestExample; -import org.fiware.productinventory.model.PriceAlterationVOTestExample; -import org.fiware.productinventory.model.ProductCreateVO; -import org.fiware.productinventory.model.ProductCreateVOTestExample; -import org.fiware.productinventory.model.ProductOfferingPriceRefVOTestExample; -import org.fiware.productinventory.model.ProductOfferingRefVOTestExample; -import org.fiware.productinventory.model.ProductPriceVO; -import org.fiware.productinventory.model.ProductPriceVOTestExample; -import org.fiware.productinventory.model.ProductRefOrValueVOTestExample; -import org.fiware.productinventory.model.ProductRelationshipVOTestExample; -import org.fiware.productinventory.model.ProductSpecificationRefVOTestExample; -import org.fiware.productinventory.model.ProductStatusTypeVO; -import org.fiware.productinventory.model.ProductTermVOTestExample; -import org.fiware.productinventory.model.ProductUpdateVO; -import org.fiware.productinventory.model.ProductUpdateVOTestExample; -import org.fiware.productinventory.model.ProductVO; -import org.fiware.productinventory.model.ProductVOTestExample; -import org.fiware.productinventory.model.RelatedPartyVOTestExample; -import org.fiware.productinventory.model.RelatedPlaceRefOrValueVOTestExample; -import org.fiware.productinventory.model.RelatedProductOrderItemVOTestExample; -import org.fiware.productinventory.model.ResourceRefVOTestExample; -import org.fiware.productinventory.model.ServiceRefVOTestExample; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.productinventory.model.*; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.fiware.tmforum.common.test.ArgumentPair; import org.fiware.tmforum.product.Product; @@ -45,7 +22,6 @@ import org.junit.jupiter.params.provider.MethodSource; import reactor.core.publisher.Mono; - import java.net.URI; import java.time.Instant; import java.util.ArrayList; @@ -78,13 +54,12 @@ public ProductApiIT(ProductApiTestClient productApiTestClient, EntitiesApiClient this.productApiTestClient = productApiTestClient; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/product-inventory/src/test/resources/application.yaml b/product-inventory/src/test/resources/application.yaml index 2381def1..ef87afe8 100644 --- a/product-inventory/src/test/resources/application.yaml +++ b/product-inventory/src/test/resources/application.yaml @@ -36,4 +36,7 @@ loggers: --- general: contextUrl: https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld - serverHost: http://localhost:8632 \ No newline at end of file + serverHost: http://localhost:8632 + basePath: /tmf-api/productInventory/v4 + basePath: /tmf-api/productInventory/v4 + serverUrl: http://localhost \ No newline at end of file diff --git a/product-ordering-management/src/main/java/org/fiware/tmforum/productordering/TMForumMapper.java b/product-ordering-management/src/main/java/org/fiware/tmforum/productordering/TMForumMapper.java index f1007649..cbe7debb 100644 --- a/product-ordering-management/src/main/java/org/fiware/tmforum/productordering/TMForumMapper.java +++ b/product-ordering-management/src/main/java/org/fiware/tmforum/productordering/TMForumMapper.java @@ -2,7 +2,7 @@ import io.github.wistefan.mapping.MappingException; import org.fiware.productordering.model.*; -import org.fiware.tmforum.common.domain.subscription.Subscription; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; import org.fiware.tmforum.common.mapping.IdHelper; import org.fiware.tmforum.productordering.domain.*; import org.mapstruct.Mapper; @@ -77,7 +77,7 @@ public interface TMForumMapper { TaskStateTypeVO map(TaskState taskState); @Mapping(target = "query", source = "rawQuery") - EventSubscriptionVO map(Subscription subscription); + EventSubscriptionVO map(TMForumSubscription subscription); default URL map(String value) { if (value == null) { diff --git a/product-ordering-management/src/main/java/org/fiware/tmforum/productordering/rest/CancelProductOrderApiController.java b/product-ordering-management/src/main/java/org/fiware/tmforum/productordering/rest/CancelProductOrderApiController.java index c78adbd6..ff246cce 100644 --- a/product-ordering-management/src/main/java/org/fiware/tmforum/productordering/rest/CancelProductOrderApiController.java +++ b/product-ordering-management/src/main/java/org/fiware/tmforum/productordering/rest/CancelProductOrderApiController.java @@ -8,11 +8,11 @@ import org.fiware.productordering.api.CancelProductOrderApi; import org.fiware.productordering.model.CancelProductOrderCreateVO; import org.fiware.productordering.model.CancelProductOrderVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -33,7 +33,7 @@ public class CancelProductOrderApiController extends AbstractApiController EVENT_GROUPS = List.of( EVENT_GROUP_CANCEL_PRODUCT_ORDER, EVENT_GROUP_PRODUCT_ORDER); + private static final Map> ENTITY_NAME_TO_ENTITY_CLASS_MAPPING = Map.ofEntries( + entry(CancelProductOrder.TYPE_CANCEL_PRODUCT_ORDER, CancelProductOrder.class), + entry(ProductOrder.TYPE_PRODUCT_ORDER, ProductOrder.class) + ); public EventSubscriptionApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, TMForumMapper tmForumMapper, EventHandler eventHandler) { - super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, eventHandler); + TmForumRepository repository, TMForumMapper tmForumMapper, + TMForumEventHandler tmForumEventHandler, NgsiLdEventHandler ngsiLdEventHandler, + GeneralProperties generalProperties, EntityVOMapper entityVOMapper) { + super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, + ENTITY_NAME_TO_ENTITY_CLASS_MAPPING, tmForumEventHandler, ngsiLdEventHandler, + generalProperties, entityVOMapper); this.tmForumMapper = tmForumMapper; } @Override public Mono> registerListener( @NonNull EventSubscriptionInputVO eventSubscriptionInputVO) { - Subscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), + TMForumSubscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), eventSubscriptionInputVO.getQuery(), EVENT_GROUPS); return create(subscription) diff --git a/product-ordering-management/src/main/java/org/fiware/tmforum/productordering/rest/ProductOrderingApiController.java b/product-ordering-management/src/main/java/org/fiware/tmforum/productordering/rest/ProductOrderingApiController.java index eb03eaa4..a05b148f 100644 --- a/product-ordering-management/src/main/java/org/fiware/tmforum/productordering/rest/ProductOrderingApiController.java +++ b/product-ordering-management/src/main/java/org/fiware/tmforum/productordering/rest/ProductOrderingApiController.java @@ -3,35 +3,29 @@ import io.micronaut.core.annotation.NonNull; import io.micronaut.core.annotation.Nullable; import io.micronaut.http.HttpResponse; -import io.micronaut.http.annotation.*; +import io.micronaut.http.annotation.Controller; import lombok.extern.slf4j.Slf4j; import org.fiware.productordering.api.ProductOrderApi; import org.fiware.productordering.model.ProductOrderCreateVO; import org.fiware.productordering.model.ProductOrderUpdateVO; import org.fiware.productordering.model.ProductOrderVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; import org.fiware.tmforum.common.validation.ReferencedEntity; import org.fiware.tmforum.product.PriceAlteration; -import org.fiware.tmforum.product.ProductRefOrValue; import org.fiware.tmforum.productordering.TMForumMapper; import org.fiware.tmforum.productordering.domain.ProductOrder; import org.fiware.tmforum.productordering.domain.ProductOrderItem; import reactor.core.publisher.Mono; -import java.net.URI; import java.time.Clock; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; @Slf4j @@ -42,7 +36,7 @@ public class ProductOrderingApiController extends AbstractApiController EVENT_GROUPS = List.of( EVENT_GROUP_RESOURCE_CANDIDATE, EVENT_GROUP_RESOURCE_CATALOG, EVENT_GROUP_RESOURCE_CATEGORY, EVENT_GROUP_RESOURCE_SPECIFICATION); + private static final Map> ENTITY_NAME_TO_ENTITY_CLASS_MAPPING = Map.ofEntries( + entry(ResourceCandidate.TYPE_RESOURCE_CANDIDATE, ResourceCandidate.class), + entry(ResourceCatalog.TYPE_RESOURCE_CATALOG, ResourceCatalog.class), + entry(ResourceCategory.TYPE_RESOURCE_CATEGORY, ResourceCategory.class), + entry(ResourceSpecification.TYPE_RESOURCE_SPECIFICATION, ResourceSpecification.class) + ); public EventSubscriptionApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, TMForumMapper tmForumMapper, EventHandler eventHandler) { - super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, eventHandler); + TmForumRepository repository, TMForumMapper tmForumMapper, + TMForumEventHandler tmForumEventHandler, NgsiLdEventHandler ngsiLdEventHandler, + GeneralProperties generalProperties, EntityVOMapper entityVOMapper) { + super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, + ENTITY_NAME_TO_ENTITY_CLASS_MAPPING, tmForumEventHandler, ngsiLdEventHandler, + generalProperties, entityVOMapper); this.tmForumMapper = tmForumMapper; } @Override public Mono> registerListener( @NonNull EventSubscriptionInputVO eventSubscriptionInputVO) { - Subscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), + TMForumSubscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), eventSubscriptionInputVO.getQuery(), EVENT_GROUPS); return create(subscription) diff --git a/resource-catalog/src/main/java/org/fiware/tmforum/resourcecatalog/rest/ResourceCandidateApiController.java b/resource-catalog/src/main/java/org/fiware/tmforum/resourcecatalog/rest/ResourceCandidateApiController.java index 8c33c0bf..93288aad 100644 --- a/resource-catalog/src/main/java/org/fiware/tmforum/resourcecatalog/rest/ResourceCandidateApiController.java +++ b/resource-catalog/src/main/java/org/fiware/tmforum/resourcecatalog/rest/ResourceCandidateApiController.java @@ -9,11 +9,11 @@ import org.fiware.resourcecatalog.model.ResourceCandidateCreateVO; import org.fiware.resourcecatalog.model.ResourceCandidateUpdateVO; import org.fiware.resourcecatalog.model.ResourceCandidateVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -38,7 +38,7 @@ public class ResourceCandidateApiController extends AbstractApiController EVENT_GROUPS = List.of(EVENT_GROUP_HEAL,EVENT_GROUP_MIGRATE, EVENT_GROUP_MONITOR, EVENT_GROUP_RESOURCE_FUNCTION, EVENT_GROUP_SCALE); + private static final Map> ENTITY_NAME_TO_ENTITY_CLASS_MAPPING = Map.ofEntries( + entry(Heal.TYPE_HEAL, Heal.class), + entry(Migrate.TYPE_MIGRATE, Migrate.class), + entry(Monitor.TYPE_MONITOR, Monitor.class), + entry(ResourceFunction.TYPE_RESOURCE_FUNCTION, ResourceFunction.class), + entry(Scale.TYPE_SCALE, Scale.class) + ); public EventSubscriptionApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, TMForumMapper tmForumMapper, EventHandler eventHandler) { - super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, eventHandler); + TmForumRepository repository, TMForumMapper tmForumMapper, + TMForumEventHandler tmForumEventHandler, NgsiLdEventHandler ngsiLdEventHandler, + GeneralProperties generalProperties, EntityVOMapper entityVOMapper) { + super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, + ENTITY_NAME_TO_ENTITY_CLASS_MAPPING, tmForumEventHandler, ngsiLdEventHandler, + generalProperties, entityVOMapper); this.tmForumMapper = tmForumMapper; } @Override public Mono> registerListener( @NonNull EventSubscriptionInputVO eventSubscriptionInputVO) { - Subscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), + TMForumSubscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), eventSubscriptionInputVO.getQuery(), EVENT_GROUPS); return create(subscription) diff --git a/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/HealApiController.java b/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/HealApiController.java index 756d6bb2..0ced52f0 100644 --- a/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/HealApiController.java +++ b/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/HealApiController.java @@ -5,11 +5,11 @@ import org.fiware.resourcefunction.api.HealApi; import org.fiware.resourcefunction.model.HealCreateVO; import org.fiware.resourcefunction.model.HealVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -30,7 +30,7 @@ public class HealApiController extends AbstractApiController implements He private final TMForumMapper tmForumMapper; public HealApiController(QueryParser queryParser, ReferenceValidationService validationService, TmForumRepository resourceCatalogRepository, - TMForumMapper tmForumMapper, EventHandler eventHandler) { + TMForumMapper tmForumMapper, TMForumEventHandler eventHandler) { super(queryParser, validationService, resourceCatalogRepository, eventHandler); this.tmForumMapper = tmForumMapper; } diff --git a/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/MigrateApiController.java b/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/MigrateApiController.java index 418ba99e..98ef3075 100644 --- a/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/MigrateApiController.java +++ b/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/MigrateApiController.java @@ -5,11 +5,11 @@ import org.fiware.resourcefunction.api.MigrateApi; import org.fiware.resourcefunction.model.MigrateCreateVO; import org.fiware.resourcefunction.model.MigrateVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -31,7 +31,7 @@ public class MigrateApiController extends AbstractApiController impleme public MigrateApiController(QueryParser queryParser, ReferenceValidationService validationService, TmForumRepository resourceCatalogRepository, - TMForumMapper tmForumMapper, EventHandler eventHandler) { + TMForumMapper tmForumMapper, TMForumEventHandler eventHandler) { super(queryParser, validationService, resourceCatalogRepository, eventHandler); this.tmForumMapper = tmForumMapper; } diff --git a/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/MonitorApiController.java b/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/MonitorApiController.java index 43f5c7c6..87718854 100644 --- a/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/MonitorApiController.java +++ b/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/MonitorApiController.java @@ -4,10 +4,10 @@ import io.micronaut.http.annotation.Controller; import org.fiware.resourcefunction.api.MonitorApi; import org.fiware.resourcefunction.model.MonitorVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -26,7 +26,7 @@ public class MonitorApiController extends AbstractApiController impleme public MonitorApiController(QueryParser queryParser, ReferenceValidationService validationService, TmForumRepository resourceCatalogRepository, - TMForumMapper tmForumMapper, EventHandler eventHandler) { + TMForumMapper tmForumMapper, TMForumEventHandler eventHandler) { super(queryParser, validationService, resourceCatalogRepository, eventHandler); this.tmForumMapper = tmForumMapper; } diff --git a/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/ResourceFunctionApiController.java b/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/ResourceFunctionApiController.java index f9204d44..b83f61d2 100644 --- a/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/ResourceFunctionApiController.java +++ b/resource-function-activation/src/main/java/org/fiware/tmforum/resourcefunction/rest/ResourceFunctionApiController.java @@ -8,11 +8,11 @@ import org.fiware.resourcefunction.model.ResourceFunctionCreateVO; import org.fiware.resourcefunction.model.ResourceFunctionUpdateVO; import org.fiware.resourcefunction.model.ResourceFunctionVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -37,7 +37,7 @@ public class ResourceFunctionApiController extends AbstractApiController implements private final TMForumMapper tmForumMapper; public ScaleApiController(QueryParser queryParser, ReferenceValidationService validationService, TmForumRepository resourceCatalogRepository, - TMForumMapper tmForumMapper, EventHandler eventHandler) { + TMForumMapper tmForumMapper, TMForumEventHandler eventHandler) { super(queryParser, validationService, resourceCatalogRepository, eventHandler); this.tmForumMapper = tmForumMapper; } diff --git a/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/HealApiIT.java b/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/HealApiIT.java index 54187d37..0148db45 100644 --- a/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/HealApiIT.java +++ b/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/HealApiIT.java @@ -8,17 +8,10 @@ import org.fiware.ngsi.api.EntitiesApiClient; import org.fiware.resourcefunction.api.HealApiTestClient; import org.fiware.resourcefunction.api.HealApiTestSpec; -import org.fiware.resourcefunction.model.CharacteristicVOTestExample; -import org.fiware.resourcefunction.model.HealCreateVO; -import org.fiware.resourcefunction.model.HealCreateVOTestExample; -import org.fiware.resourcefunction.model.HealPolicyRefVOTestExample; -import org.fiware.resourcefunction.model.HealVO; -import org.fiware.resourcefunction.model.HealVOTestExample; -import org.fiware.resourcefunction.model.ResourceFunctionRefVOTestExample; -import org.fiware.resourcefunction.model.TaskStateTypeVO; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.resourcefunction.model.*; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.fiware.tmforum.resourcefunction.domain.Heal; import org.junit.jupiter.api.Disabled; @@ -57,13 +50,12 @@ public HealApiIT(HealApiTestClient healApiTestClient, EntitiesApiClient entities this.healApiTestClient = healApiTestClient; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/MigrateApiIT.java b/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/MigrateApiIT.java index d7437558..72a967cc 100644 --- a/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/MigrateApiIT.java +++ b/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/MigrateApiIT.java @@ -8,18 +8,10 @@ import org.fiware.ngsi.api.EntitiesApiClient; import org.fiware.resourcefunction.api.MigrateApiTestClient; import org.fiware.resourcefunction.api.MigrateApiTestSpec; -import org.fiware.resourcefunction.model.CharacteristicVOTestExample; -import org.fiware.resourcefunction.model.ConnectionPointRefVOTestExample; -import org.fiware.resourcefunction.model.MigrateCreateVO; -import org.fiware.resourcefunction.model.MigrateCreateVOTestExample; -import org.fiware.resourcefunction.model.MigrateVO; -import org.fiware.resourcefunction.model.MigrateVOTestExample; -import org.fiware.resourcefunction.model.PlaceRefVOTestExample; -import org.fiware.resourcefunction.model.ResourceFunctionRefVOTestExample; -import org.fiware.resourcefunction.model.TaskStateTypeVO; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.resourcefunction.model.*; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.fiware.tmforum.resourcefunction.domain.Migrate; import org.junit.jupiter.api.Disabled; @@ -30,11 +22,7 @@ import reactor.core.publisher.Mono; import java.net.URI; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -59,13 +47,12 @@ public MigrateApiIT(MigrateApiTestClient migrateApiTestClient, EntitiesApiClient this.migrateApiTestClient = migrateApiTestClient; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/ResourceFunctionApiIT.java b/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/ResourceFunctionApiIT.java index e4027e33..5eee9804 100644 --- a/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/ResourceFunctionApiIT.java +++ b/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/ResourceFunctionApiIT.java @@ -8,37 +8,10 @@ import org.fiware.ngsi.api.EntitiesApiClient; import org.fiware.resourcefunction.api.ResourceFunctionApiTestClient; import org.fiware.resourcefunction.api.ResourceFunctionApiTestSpec; -import org.fiware.resourcefunction.model.AttachmentRefOrValueVOTestExample; -import org.fiware.resourcefunction.model.CharacteristicRelationshipVOTestExample; -import org.fiware.resourcefunction.model.CharacteristicVOTestExample; -import org.fiware.resourcefunction.model.ConnectionPointRefVOTestExample; -import org.fiware.resourcefunction.model.ConnectionVOTestExample; -import org.fiware.resourcefunction.model.ConstraintRefVOTestExample; -import org.fiware.resourcefunction.model.FeatureRelationshipVOTestExample; -import org.fiware.resourcefunction.model.FeatureVOTestExample; -import org.fiware.resourcefunction.model.NoteVOTestExample; -import org.fiware.resourcefunction.model.RelatedPartyVOTestExample; -import org.fiware.resourcefunction.model.RelatedPlaceRefOrValueVOTestExample; -import org.fiware.resourcefunction.model.ResourceAdministrativeStateTypeVO; -import org.fiware.resourcefunction.model.ResourceFunctionCreateVO; -import org.fiware.resourcefunction.model.ResourceFunctionCreateVOTestExample; -import org.fiware.resourcefunction.model.ResourceFunctionUpdateVO; -import org.fiware.resourcefunction.model.ResourceFunctionUpdateVOTestExample; -import org.fiware.resourcefunction.model.ResourceFunctionVO; -import org.fiware.resourcefunction.model.ResourceFunctionVOTestExample; -import org.fiware.resourcefunction.model.ResourceGraphRefVOTestExample; -import org.fiware.resourcefunction.model.ResourceGraphRelationshipVOTestExample; -import org.fiware.resourcefunction.model.ResourceGraphVOTestExample; -import org.fiware.resourcefunction.model.ResourceOperationalStateTypeVO; -import org.fiware.resourcefunction.model.ResourceRefOrValueVOTestExample; -import org.fiware.resourcefunction.model.ResourceRelationshipVOTestExample; -import org.fiware.resourcefunction.model.ResourceSpecificationRefVOTestExample; -import org.fiware.resourcefunction.model.ResourceStatusTypeVO; -import org.fiware.resourcefunction.model.ResourceUsageStateTypeVO; -import org.fiware.resourcefunction.model.ScheduleRefVOTestExample; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.resourcefunction.model.*; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.fiware.tmforum.resourcefunction.domain.ResourceFunction; import org.junit.jupiter.api.Disabled; @@ -50,11 +23,7 @@ import java.net.URI; import java.time.Instant; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -80,13 +49,12 @@ public ResourceFunctionApiIT(ResourceFunctionApiTestClient resourceFunctionApiTe this.resourceFunctionApiTestClient = resourceFunctionApiTestClient; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/ScaleApiIT.java b/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/ScaleApiIT.java index b40cc50a..25c13671 100644 --- a/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/ScaleApiIT.java +++ b/resource-function-activation/src/test/java/org/fiware/tmforum/resourcefunction/ScaleApiIT.java @@ -8,16 +8,10 @@ import org.fiware.ngsi.api.EntitiesApiClient; import org.fiware.resourcefunction.api.ScaleApiTestClient; import org.fiware.resourcefunction.api.ScaleApiTestSpec; -import org.fiware.resourcefunction.model.ResourceFunctionRefVOTestExample; -import org.fiware.resourcefunction.model.ScaleCreateVO; -import org.fiware.resourcefunction.model.ScaleCreateVOTestExample; -import org.fiware.resourcefunction.model.ScaleVO; -import org.fiware.resourcefunction.model.ScaleVOTestExample; -import org.fiware.resourcefunction.model.ScheduleRefVOTestExample; -import org.fiware.resourcefunction.model.TaskStateTypeVO; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.resourcefunction.model.*; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.fiware.tmforum.resourcefunction.domain.Scale; import org.junit.jupiter.api.Disabled; @@ -55,13 +49,12 @@ public ScaleApiIT(ScaleApiTestClient scaleApiTestClient, EntitiesApiClient entit this.scaleApiTestClient = scaleApiTestClient; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/resource-function-activation/src/test/resources/application.yaml b/resource-function-activation/src/test/resources/application.yaml index 2381def1..219ca8f0 100644 --- a/resource-function-activation/src/test/resources/application.yaml +++ b/resource-function-activation/src/test/resources/application.yaml @@ -36,4 +36,5 @@ loggers: --- general: contextUrl: https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld - serverHost: http://localhost:8632 \ No newline at end of file + serverHost: http://localhost:8632 + basePath: /tmf-api/resourceFunctionActivation/v4 \ No newline at end of file diff --git a/resource-inventory/src/main/java/org/fiware/tmforum/resourceinventory/TMForumMapper.java b/resource-inventory/src/main/java/org/fiware/tmforum/resourceinventory/TMForumMapper.java index 3ea51f35..b0e37557 100644 --- a/resource-inventory/src/main/java/org/fiware/tmforum/resourceinventory/TMForumMapper.java +++ b/resource-inventory/src/main/java/org/fiware/tmforum/resourceinventory/TMForumMapper.java @@ -5,7 +5,7 @@ import org.fiware.resourceinventory.model.ResourceCreateVO; import org.fiware.resourceinventory.model.ResourceUpdateVO; import org.fiware.resourceinventory.model.ResourceVO; -import org.fiware.tmforum.common.domain.subscription.Subscription; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; import org.fiware.tmforum.common.mapping.IdHelper; import org.fiware.tmforum.resource.Resource; import org.mapstruct.Mapper; @@ -35,7 +35,7 @@ public interface TMForumMapper { Resource map(ResourceUpdateVO resourceUpdateVO, String id); @Mapping(target = "query", source = "rawQuery") - EventSubscriptionVO map(Subscription subscription); + EventSubscriptionVO map(TMForumSubscription subscription); default URL map(String value) { if (value == null) { diff --git a/resource-inventory/src/main/java/org/fiware/tmforum/resourceinventory/rest/EventSubscriptionApiController.java b/resource-inventory/src/main/java/org/fiware/tmforum/resourceinventory/rest/EventSubscriptionApiController.java index 9c0a8a65..d64532a1 100644 --- a/resource-inventory/src/main/java/org/fiware/tmforum/resourceinventory/rest/EventSubscriptionApiController.java +++ b/resource-inventory/src/main/java/org/fiware/tmforum/resourceinventory/rest/EventSubscriptionApiController.java @@ -1,5 +1,6 @@ package org.fiware.tmforum.resourceinventory.rest; +import io.github.wistefan.mapping.EntityVOMapper; import io.micronaut.core.annotation.NonNull; import io.micronaut.http.HttpResponse; import io.micronaut.http.annotation.Controller; @@ -7,9 +8,11 @@ import org.fiware.resourceinventory.api.EventsSubscriptionApi; import org.fiware.resourceinventory.model.EventSubscriptionInputVO; import org.fiware.resourceinventory.model.EventSubscriptionVO; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.common.configuration.GeneralProperties; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; +import org.fiware.tmforum.common.notification.NgsiLdEventHandler; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.querying.QueryParser; -import org.fiware.tmforum.common.domain.subscription.Subscription; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractSubscriptionApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -31,17 +34,24 @@ public class EventSubscriptionApiController extends AbstractSubscriptionApiContr entry(EVENT_GROUP_RESOURCE, Resource.TYPE_RESOURCE) ); private static final List EVENT_GROUPS = List.of(EVENT_GROUP_RESOURCE); + private static final Map> ENTITY_NAME_TO_ENTITY_CLASS_MAPPING = Map.ofEntries( + entry(Resource.TYPE_RESOURCE, Resource.class) + ); public EventSubscriptionApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, TMForumMapper tmForumMapper, EventHandler eventHandler) { - super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, eventHandler); + TmForumRepository repository, TMForumMapper tmForumMapper, + TMForumEventHandler tmForumEventHandler, NgsiLdEventHandler ngsiLdEventHandler, + GeneralProperties generalProperties, EntityVOMapper entityVOMapper) { + super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, + ENTITY_NAME_TO_ENTITY_CLASS_MAPPING, tmForumEventHandler, ngsiLdEventHandler, + generalProperties, entityVOMapper); this.tmForumMapper = tmForumMapper; } @Override public Mono> registerListener( @NonNull EventSubscriptionInputVO eventSubscriptionInputVO) { - Subscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), + TMForumSubscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), eventSubscriptionInputVO.getQuery(), EVENT_GROUPS); return create(subscription) diff --git a/resource-inventory/src/main/java/org/fiware/tmforum/resourceinventory/rest/ResourceApiController.java b/resource-inventory/src/main/java/org/fiware/tmforum/resourceinventory/rest/ResourceApiController.java index 9a35b726..94d88e23 100644 --- a/resource-inventory/src/main/java/org/fiware/tmforum/resourceinventory/rest/ResourceApiController.java +++ b/resource-inventory/src/main/java/org/fiware/tmforum/resourceinventory/rest/ResourceApiController.java @@ -9,31 +9,21 @@ import org.fiware.resourceinventory.model.ResourceCreateVO; import org.fiware.resourceinventory.model.ResourceUpdateVO; import org.fiware.resourceinventory.model.ResourceVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; import org.fiware.tmforum.common.validation.ReferencedEntity; -import org.fiware.tmforum.resource.Characteristic; -import org.fiware.tmforum.resource.CharacteristicRelationship; -import org.fiware.tmforum.resource.Feature; -import org.fiware.tmforum.resource.FeatureRelationship; -import org.fiware.tmforum.resource.Note; -import org.fiware.tmforum.resource.Resource; -import org.fiware.tmforum.resource.ResourceRelationship; +import org.fiware.tmforum.resource.*; import org.fiware.tmforum.resourceinventory.TMForumMapper; import reactor.core.publisher.Mono; import java.net.URI; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.UUID; +import java.util.*; @Slf4j @Controller("${general.basepath:/}") @@ -43,7 +33,7 @@ public class ResourceApiController extends AbstractApiController imple public ResourceApiController(QueryParser queryParser, ReferenceValidationService validationService, TmForumRepository resourceInventoryRepository, - TMForumMapper tmForumMapper, EventHandler eventHandler) { + TMForumMapper tmForumMapper, TMForumEventHandler eventHandler) { super(queryParser, validationService, resourceInventoryRepository, eventHandler); this.tmForumMapper = tmForumMapper; } diff --git a/resource-inventory/src/test/java/org/fiware/tmforum/resourceinventory/ResourceApiIT.java b/resource-inventory/src/test/java/org/fiware/tmforum/resourceinventory/ResourceApiIT.java index e9476dc1..a73822a3 100644 --- a/resource-inventory/src/test/java/org/fiware/tmforum/resourceinventory/ResourceApiIT.java +++ b/resource-inventory/src/test/java/org/fiware/tmforum/resourceinventory/ResourceApiIT.java @@ -8,29 +8,10 @@ import org.fiware.ngsi.api.EntitiesApiClient; import org.fiware.resourceinventory.api.ResourceApiTestClient; import org.fiware.resourceinventory.api.ResourceApiTestSpec; -import org.fiware.resourceinventory.model.CharacteristicRelationshipVOTestExample; -import org.fiware.resourceinventory.model.CharacteristicVO; -import org.fiware.resourceinventory.model.CharacteristicVOTestExample; -import org.fiware.resourceinventory.model.FeatureRelationshipVOTestExample; -import org.fiware.resourceinventory.model.FeatureVO; -import org.fiware.resourceinventory.model.FeatureVOTestExample; -import org.fiware.resourceinventory.model.NoteVO; -import org.fiware.resourceinventory.model.NoteVOTestExample; -import org.fiware.resourceinventory.model.RelatedPartyVOTestExample; -import org.fiware.resourceinventory.model.RelatedPlaceRefOrValueVOTestExample; -import org.fiware.resourceinventory.model.ResourceCreateVO; -import org.fiware.resourceinventory.model.ResourceCreateVOTestExample; -import org.fiware.resourceinventory.model.ResourceOperationalStateTypeVO; -import org.fiware.resourceinventory.model.ResourceSpecificationRefVOTestExample; -import org.fiware.resourceinventory.model.ResourceStatusTypeVO; -import org.fiware.resourceinventory.model.ResourceUpdateVO; -import org.fiware.resourceinventory.model.ResourceUpdateVOTestExample; -import org.fiware.resourceinventory.model.ResourceUsageStateTypeVO; -import org.fiware.resourceinventory.model.ResourceVO; -import org.fiware.resourceinventory.model.ResourceVOTestExample; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.resourceinventory.model.*; import org.fiware.tmforum.common.configuration.GeneralProperties; import org.fiware.tmforum.common.exception.ErrorDetails; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.test.AbstractApiIT; import org.fiware.tmforum.common.test.ArgumentPair; import org.fiware.tmforum.resource.Resource; @@ -73,13 +54,12 @@ public ResourceApiIT(ResourceApiTestClient resourceApiTestClient, EntitiesApiCli this.resourceApiTestClient = resourceApiTestClient; } - @MockBean(EventHandler.class) - public EventHandler eventHandler() { - EventHandler eventHandler = mock(EventHandler.class); + @MockBean(TMForumEventHandler.class) + public TMForumEventHandler eventHandler() { + TMForumEventHandler eventHandler = mock(TMForumEventHandler.class); when(eventHandler.handleCreateEvent(any())).thenReturn(Mono.empty()); when(eventHandler.handleUpdateEvent(any(), any())).thenReturn(Mono.empty()); - when(eventHandler.handleDeleteEvent(any())).thenReturn(Mono.empty()); return eventHandler; } diff --git a/resource-inventory/src/test/resources/application.yaml b/resource-inventory/src/test/resources/application.yaml index 2381def1..845f655d 100644 --- a/resource-inventory/src/test/resources/application.yaml +++ b/resource-inventory/src/test/resources/application.yaml @@ -36,4 +36,5 @@ loggers: --- general: contextUrl: https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld - serverHost: http://localhost:8632 \ No newline at end of file + serverHost: http://localhost:8632 + basePath: /tmf-api/resourceInventoryManagement/v4 \ No newline at end of file diff --git a/service-catalog/src/main/java/org/fiware/tmforum/servicecatalog/TMForumMapper.java b/service-catalog/src/main/java/org/fiware/tmforum/servicecatalog/TMForumMapper.java index caf70341..7851cecb 100644 --- a/service-catalog/src/main/java/org/fiware/tmforum/servicecatalog/TMForumMapper.java +++ b/service-catalog/src/main/java/org/fiware/tmforum/servicecatalog/TMForumMapper.java @@ -2,7 +2,7 @@ import io.github.wistefan.mapping.MappingException; import org.fiware.servicecatalog.model.*; -import org.fiware.tmforum.common.domain.subscription.Subscription; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; import org.fiware.tmforum.common.mapping.IdHelper; import org.fiware.tmforum.resource.ResourceSpecificationRef; import org.fiware.tmforum.service.ServiceCandidate; @@ -77,7 +77,7 @@ public interface TMForumMapper { ServiceSpecification map(ServiceSpecificationUpdateVO serviceSpecificationUpdateVO, String id); @Mapping(target = "query", source = "rawQuery") - EventSubscriptionVO map(Subscription subscription); + EventSubscriptionVO map(TMForumSubscription subscription); default URL map(String value) { if (value == null) { diff --git a/service-catalog/src/main/java/org/fiware/tmforum/servicecatalog/rest/EventSubscriptionApiController.java b/service-catalog/src/main/java/org/fiware/tmforum/servicecatalog/rest/EventSubscriptionApiController.java index 0639796f..3a9c605d 100644 --- a/service-catalog/src/main/java/org/fiware/tmforum/servicecatalog/rest/EventSubscriptionApiController.java +++ b/service-catalog/src/main/java/org/fiware/tmforum/servicecatalog/rest/EventSubscriptionApiController.java @@ -1,5 +1,6 @@ package org.fiware.tmforum.servicecatalog.rest; +import io.github.wistefan.mapping.EntityVOMapper; import io.micronaut.core.annotation.NonNull; import io.micronaut.http.HttpResponse; import io.micronaut.http.annotation.Controller; @@ -7,9 +8,11 @@ import org.fiware.servicecatalog.api.EventsSubscriptionApi; import org.fiware.servicecatalog.model.EventSubscriptionInputVO; import org.fiware.servicecatalog.model.EventSubscriptionVO; -import org.fiware.tmforum.common.notification.EventHandler; +import org.fiware.tmforum.common.configuration.GeneralProperties; +import org.fiware.tmforum.common.domain.subscription.TMForumSubscription; +import org.fiware.tmforum.common.notification.NgsiLdEventHandler; +import org.fiware.tmforum.common.notification.TMForumEventHandler; import org.fiware.tmforum.common.querying.QueryParser; -import org.fiware.tmforum.common.domain.subscription.Subscription; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractSubscriptionApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -38,17 +41,27 @@ public class EventSubscriptionApiController extends AbstractSubscriptionApiContr ); private static final List EVENT_GROUPS = List.of(EVENT_GROUP_SERVICE_CANDIDATE, EVENT_GROUP_SERVICE_CATALOG, EVENT_GROUP_SERVICE_CATEGORY, EVENT_GROUP_SERVICE_SPECIFICATION); + private static final Map> ENTITY_NAME_TO_ENTITY_CLASS_MAPPING = Map.ofEntries( + entry(ServiceCandidate.TYPE_SERVICE_CANDIDATE, ServiceCandidate.class), + entry(ServiceCatalog.TYPE_SERVICE_CATALOG, ServiceCatalog.class), + entry(ServiceCategory.TYPE_SERVICE_CATEGORY, ServiceCategory.class), + entry(ServiceSpecification.TYPE_SERVICE_SPECIFICATION, ServiceSpecification.class) + ); public EventSubscriptionApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, TMForumMapper tmForumMapper, EventHandler eventHandler) { - super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, eventHandler); + TmForumRepository repository, TMForumMapper tmForumMapper, + TMForumEventHandler tmForumEventHandler, NgsiLdEventHandler ngsiLdEventHandler, + GeneralProperties generalProperties, EntityVOMapper entityVOMapper) { + super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, + ENTITY_NAME_TO_ENTITY_CLASS_MAPPING, tmForumEventHandler, ngsiLdEventHandler, + generalProperties, entityVOMapper); this.tmForumMapper = tmForumMapper; } @Override public Mono> registerListener( @NonNull EventSubscriptionInputVO eventSubscriptionInputVO) { - Subscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), + TMForumSubscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), eventSubscriptionInputVO.getQuery(), EVENT_GROUPS); return create(subscription) diff --git a/service-catalog/src/main/java/org/fiware/tmforum/servicecatalog/rest/ServiceCandidateApiController.java b/service-catalog/src/main/java/org/fiware/tmforum/servicecatalog/rest/ServiceCandidateApiController.java index 77a629a6..17c373ca 100644 --- a/service-catalog/src/main/java/org/fiware/tmforum/servicecatalog/rest/ServiceCandidateApiController.java +++ b/service-catalog/src/main/java/org/fiware/tmforum/servicecatalog/rest/ServiceCandidateApiController.java @@ -9,11 +9,11 @@ import org.fiware.servicecatalog.model.ServiceCandidateCreateVO; import org.fiware.servicecatalog.model.ServiceCandidateUpdateVO; import org.fiware.servicecatalog.model.ServiceCandidateVO; -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; @@ -38,7 +38,7 @@ public class ServiceCandidateApiController extends AbstractApiController EVENT_GROUPS = List.of( EVENT_GROUP_USAGE, EVENT_GROUP_USAGE_SPECIFICATION); + private static final Map> ENTITY_NAME_TO_ENTITY_CLASS_MAPPING = Map.ofEntries( + entry(Usage.TYPE_U, Usage.class), + entry(UsageSpecification.TYPE_USP, UsageSpecification.class) + ); public EventSubscriptionApiController(QueryParser queryParser, ReferenceValidationService validationService, - TmForumRepository repository, TMForumMapper tmForumMapper, EventHandler eventHandler) { - super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, eventHandler); + TmForumRepository repository, TMForumMapper tmForumMapper, + TMForumEventHandler tmForumEventHandler, NgsiLdEventHandler ngsiLdEventHandler, + GeneralProperties generalProperties, EntityVOMapper entityVOMapper) { + super(queryParser, validationService, repository, EVENT_GROUP_TO_ENTITY_NAME_MAPPING, + ENTITY_NAME_TO_ENTITY_CLASS_MAPPING, tmForumEventHandler, ngsiLdEventHandler, + generalProperties, entityVOMapper); this.tmForumMapper = tmForumMapper; } @Override public Mono> registerListener( @NonNull EventSubscriptionInputVO eventSubscriptionInputVO) { - Subscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), + TMForumSubscription subscription = buildSubscription(eventSubscriptionInputVO.getCallback(), eventSubscriptionInputVO.getQuery(), EVENT_GROUPS); return create(subscription) diff --git a/usage-management/src/main/java/org/fiware/tmforum/usagemanagement/rest/UsageController.java b/usage-management/src/main/java/org/fiware/tmforum/usagemanagement/rest/UsageController.java index f6dd4c01..d5db4f79 100644 --- a/usage-management/src/main/java/org/fiware/tmforum/usagemanagement/rest/UsageController.java +++ b/usage-management/src/main/java/org/fiware/tmforum/usagemanagement/rest/UsageController.java @@ -1,34 +1,32 @@ package org.fiware.tmforum.usagemanagement.rest; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -import javax.annotation.Nullable; - -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; -import org.fiware.usagemanagement.api.UsageApi; -import org.fiware.usagemanagement.model.UsageCreateVO; -import org.fiware.usagemanagement.model.UsageUpdateVO; -import org.fiware.usagemanagement.model.UsageVO; -import org.fiware.tmforum.usagemanagement.TMForumMapper; -import org.fiware.tmforum.usagemanagement.domain.Usage; +import io.micronaut.core.annotation.NonNull; +import io.micronaut.http.HttpResponse; +import io.micronaut.http.annotation.Controller; +import lombok.extern.slf4j.Slf4j; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; import org.fiware.tmforum.common.validation.ReferencedEntity; - -import io.micronaut.core.annotation.NonNull; -import io.micronaut.http.HttpResponse; -import io.micronaut.http.annotation.Controller; -import lombok.extern.slf4j.Slf4j; +import org.fiware.tmforum.usagemanagement.TMForumMapper; +import org.fiware.tmforum.usagemanagement.domain.Usage; +import org.fiware.usagemanagement.api.UsageApi; +import org.fiware.usagemanagement.model.UsageCreateVO; +import org.fiware.usagemanagement.model.UsageUpdateVO; +import org.fiware.usagemanagement.model.UsageVO; import reactor.core.publisher.Mono; +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + @Slf4j @Controller("${general.basepath:/}") public class UsageController extends AbstractApiController implements UsageApi { @@ -36,7 +34,7 @@ public class UsageController extends AbstractApiController implements Usa private final TMForumMapper tmForumMapper; public UsageController(QueryParser queryParser, ReferenceValidationService validationService, TmForumRepository partyRepository, - TMForumMapper tmForumMapper, EventHandler eventHandler) { + TMForumMapper tmForumMapper, TMForumEventHandler eventHandler) { super(queryParser, validationService, partyRepository, eventHandler); this.tmForumMapper = tmForumMapper; } diff --git a/usage-management/src/main/java/org/fiware/tmforum/usagemanagement/rest/UsageSpecificationController.java b/usage-management/src/main/java/org/fiware/tmforum/usagemanagement/rest/UsageSpecificationController.java index 523e0f79..75141071 100644 --- a/usage-management/src/main/java/org/fiware/tmforum/usagemanagement/rest/UsageSpecificationController.java +++ b/usage-management/src/main/java/org/fiware/tmforum/usagemanagement/rest/UsageSpecificationController.java @@ -1,34 +1,31 @@ package org.fiware.tmforum.usagemanagement.rest; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -import javax.annotation.Nullable; - -import org.fiware.tmforum.common.notification.EventHandler; -import org.fiware.tmforum.common.querying.QueryParser; -import org.fiware.usagemanagement.api.UsageSpecificationApi; -import org.fiware.usagemanagement.model.UsageSpecificationCreateVO; -import org.fiware.usagemanagement.model.UsageSpecificationUpdateVO; -import org.fiware.usagemanagement.model.UsageSpecificationVO; -import org.fiware.tmforum.usagemanagement.TMForumMapper; -import org.fiware.tmforum.usagemanagement.domain.UsageSpecification; +import io.micronaut.core.annotation.NonNull; +import io.micronaut.http.HttpResponse; +import io.micronaut.http.annotation.Controller; +import lombok.extern.slf4j.Slf4j; import org.fiware.tmforum.common.exception.TmForumException; import org.fiware.tmforum.common.exception.TmForumExceptionReason; import org.fiware.tmforum.common.mapping.IdHelper; +import org.fiware.tmforum.common.notification.TMForumEventHandler; +import org.fiware.tmforum.common.querying.QueryParser; import org.fiware.tmforum.common.repository.TmForumRepository; import org.fiware.tmforum.common.rest.AbstractApiController; import org.fiware.tmforum.common.validation.ReferenceValidationService; import org.fiware.tmforum.common.validation.ReferencedEntity; - -import io.micronaut.core.annotation.NonNull; -import io.micronaut.http.HttpResponse; -import io.micronaut.http.annotation.Controller; -import lombok.extern.slf4j.Slf4j; +import org.fiware.tmforum.usagemanagement.TMForumMapper; +import org.fiware.tmforum.usagemanagement.domain.UsageSpecification; +import org.fiware.usagemanagement.api.UsageSpecificationApi; +import org.fiware.usagemanagement.model.UsageSpecificationCreateVO; +import org.fiware.usagemanagement.model.UsageSpecificationUpdateVO; +import org.fiware.usagemanagement.model.UsageSpecificationVO; import reactor.core.publisher.Mono; +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + @Slf4j @Controller("${general.basepath:/}") @@ -38,7 +35,7 @@ public class UsageSpecificationController extends AbstractApiController