diff options
author | Lee Anjella Macabuhay <lee.anjella.macabuhay@est.tech> | 2024-07-08 14:06:48 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2024-07-08 14:06:48 +0000 |
commit | 58d670b117a72aa34617a97442b3898516efe12d (patch) | |
tree | 52b0ec100726d461c535340a2751a0d09c3fb7a9 /cps-ncmp-service/src/main | |
parent | 8b6882c68290520fe238562d0bd3739de61beaef (diff) | |
parent | f3bfc359a12501b6f4a734d2566d115dc43136b0 (diff) |
Merge "Remove Mappers and Events Facade"
Diffstat (limited to 'cps-ncmp-service/src/main')
6 files changed, 24 insertions, 169 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/EventsFacade.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/EventsFacade.java deleted file mode 100644 index fbe21267d9..0000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/EventsFacade.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (c) 2024 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.cps.ncmp.impl.cmnotificationsubscription; - -import lombok.RequiredArgsConstructor; -import org.onap.cps.ncmp.impl.cmnotificationsubscription.dmi.DmiInEventProducer; -import org.onap.cps.ncmp.impl.cmnotificationsubscription.ncmp.NcmpOutEventProducer; -import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_client.NcmpOutEvent; -import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_dmi.DmiInEvent; -import org.springframework.stereotype.Component; - -@Component -@RequiredArgsConstructor -public class EventsFacade { - private final NcmpOutEventProducer ncmpOutEventProducer; - private final DmiInEventProducer dmiInEventProducer; - - /** - * Publish the event to the client who requested the subscription with key as subscription id and event is Cloud - * Event compliant. - * - * @param subscriptionId Cm Subscription id - * @param eventType Type of event - * @param ncmpOutEvent Cm Notification Subscription Event for the - * client - * @param isScheduledEvent Determines if the event is to be scheduled - * or published now - */ - public void publishNcmpOutEvent(final String subscriptionId, final String eventType, - final NcmpOutEvent ncmpOutEvent, final boolean isScheduledEvent) { - ncmpOutEventProducer.publishNcmpOutEvent(subscriptionId, eventType, ncmpOutEvent, isScheduledEvent); - } - - /** - * Publish the event to the provided dmi plugin with key as subscription id and the event is in Cloud Event format. - * - * @param subscriptionId Cm Subscription id - * @param dmiPluginName Dmi Plugin Name - * @param eventType Type of event - * @param dmiInEvent Cm Notification Subscription event for Dmi - */ - public void publishDmiInEvent(final String subscriptionId, final String dmiPluginName, - final String eventType, final DmiInEvent dmiInEvent) { - dmiInEventProducer.publishDmiInEvent(subscriptionId, - dmiPluginName, eventType, dmiInEvent); - } -} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/MappersFacade.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/MappersFacade.java deleted file mode 100644 index e79b4e6441..0000000000 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/MappersFacade.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.cps.ncmp.impl.cmnotificationsubscription; - -import java.util.List; -import java.util.Map; -import lombok.RequiredArgsConstructor; -import org.onap.cps.ncmp.impl.cmnotificationsubscription.dmi.DmiInEventMapper; -import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionDetails; -import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionPredicate; -import org.onap.cps.ncmp.impl.cmnotificationsubscription.ncmp.NcmpOutEventMapper; -import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_client.NcmpOutEvent; -import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_dmi.DmiInEvent; -import org.springframework.stereotype.Component; - -@Component -@RequiredArgsConstructor -public class MappersFacade { - - private final DmiInEventMapper dmiInEventMapper; - private final NcmpOutEventMapper ncmpOutEventMapper; - - /** - * Mapper to form a request for the DMI Plugin for the Cm Notification Subscription. - * - * @param dmiCmSubscriptionPredicates Collection of Cm Notification Subscription predicates - * @return cm notification subscription dmi in event - */ - public DmiInEvent toDmiInEvent( - final List<DmiCmSubscriptionPredicate> dmiCmSubscriptionPredicates) { - return dmiInEventMapper.toDmiInEvent(dmiCmSubscriptionPredicates); - } - - /** - * Mapper to form a response for the client for the Cm Notification Subscription. - * - * @param subscriptionId Cm Notification Subscription id - * @param dmiSubscriptionsPerDmi contains CmNotificationSubscriptionDetails per dmi plugin - * @return CmNotificationSubscriptionNcmpOutEvent to sent back to the client - */ - public NcmpOutEvent toNcmpOutEvent(final String subscriptionId, - final Map<String, DmiCmSubscriptionDetails> dmiSubscriptionsPerDmi) { - return ncmpOutEventMapper.toNcmpOutEvent(subscriptionId, - dmiSubscriptionsPerDmi); - } - - /** - * Mapper to form a rejected response for the client for the Cm Notification Subscription Request. - * - * @param subscriptionId subscription id - * @param rejectedTargetFilters list of rejected target filters for the subscription request - * @return to sent back to the client - */ - public NcmpOutEvent toNcmpOutEventForRejectedRequest( - final String subscriptionId, final List<String> rejectedTargetFilters) { - return ncmpOutEventMapper.toNcmpOutEventForRejectedRequest( - subscriptionId, rejectedTargetFilters); - } -} diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiOutEventConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiOutEventConsumer.java index 2a45818624..20ccf528ed 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiOutEventConsumer.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/dmi/DmiOutEventConsumer.java @@ -30,11 +30,11 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.onap.cps.ncmp.api.NcmpResponseStatus; -import org.onap.cps.ncmp.impl.cmnotificationsubscription.EventsFacade; -import org.onap.cps.ncmp.impl.cmnotificationsubscription.MappersFacade; import org.onap.cps.ncmp.impl.cmnotificationsubscription.cache.DmiCacheHandler; import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.CmSubscriptionStatus; import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionDetails; +import org.onap.cps.ncmp.impl.cmnotificationsubscription.ncmp.NcmpOutEventMapper; +import org.onap.cps.ncmp.impl.cmnotificationsubscription.ncmp.NcmpOutEventProducer; import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.dmi_to_ncmp.Data; import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.dmi_to_ncmp.DmiOutEvent; import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_client.NcmpOutEvent; @@ -47,8 +47,8 @@ import org.springframework.stereotype.Component; public class DmiOutEventConsumer { private final DmiCacheHandler dmiCacheHandler; - private final EventsFacade eventsFacade; - private final MappersFacade mappersFacade; + private final NcmpOutEventProducer ncmpOutEventProducer; + private final NcmpOutEventMapper ncmpOutEventMapper; private static final String CM_SUBSCRIPTION_CORRELATION_ID_SEPARATOR = "#"; @@ -101,12 +101,9 @@ public class DmiOutEventConsumer { } private void handleEventsStatusPerDmi(final String subscriptionId, final String eventType) { - final Map<String, DmiCmSubscriptionDetails> dmiSubscriptionsPerDmi = - dmiCacheHandler.get(subscriptionId); - final NcmpOutEvent ncmpOutEvent = mappersFacade.toNcmpOutEvent(subscriptionId, - dmiSubscriptionsPerDmi); - eventsFacade.publishNcmpOutEvent(subscriptionId, eventType, - ncmpOutEvent, false); + final Map<String, DmiCmSubscriptionDetails> dmiSubscriptionsPerDmi = dmiCacheHandler.get(subscriptionId); + final NcmpOutEvent ncmpOutEvent = ncmpOutEventMapper.toNcmpOutEvent(subscriptionId, dmiSubscriptionsPerDmi); + ncmpOutEventProducer.publishNcmpOutEvent(subscriptionId, eventType, ncmpOutEvent, false); } private boolean checkStatusCodeAndMessage(final NcmpResponseStatus ncmpResponseStatus, diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/CmSubscriptionHandlerImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/CmSubscriptionHandlerImpl.java index e225b705d7..9d33d25816 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/CmSubscriptionHandlerImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/CmSubscriptionHandlerImpl.java @@ -26,9 +26,9 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; -import org.onap.cps.ncmp.impl.cmnotificationsubscription.EventsFacade; -import org.onap.cps.ncmp.impl.cmnotificationsubscription.MappersFacade; import org.onap.cps.ncmp.impl.cmnotificationsubscription.cache.DmiCacheHandler; +import org.onap.cps.ncmp.impl.cmnotificationsubscription.dmi.DmiInEventMapper; +import org.onap.cps.ncmp.impl.cmnotificationsubscription.dmi.DmiInEventProducer; import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.CmSubscriptionStatus; import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionDetails; import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionPredicate; @@ -44,8 +44,10 @@ public class CmSubscriptionHandlerImpl implements CmSubscriptionHandler { private final CmSubscriptionPersistenceService cmSubscriptionPersistenceService; private final CmSubscriptionComparator cmSubscriptionComparator; - private final MappersFacade mappersFacade; - private final EventsFacade eventsFacade; + private final NcmpOutEventMapper ncmpOutEventMapper; + private final DmiInEventMapper dmiInEventMapper; + private final NcmpOutEventProducer ncmpOutEventProducer; + private final DmiInEventProducer dmiInEventProducer; private final DmiCacheHandler dmiCacheHandler; @Override @@ -67,16 +69,16 @@ public class CmSubscriptionHandlerImpl implements CmSubscriptionHandler { } private void scheduleNcmpOutEventResponse(final String subscriptionId, final String eventType) { - eventsFacade.publishNcmpOutEvent(subscriptionId, eventType, null, true); + ncmpOutEventProducer.publishNcmpOutEvent(subscriptionId, eventType, null, true); } private void rejectAndPublishCreateRequest(final String subscriptionId, final List<Predicate> predicates) { final Set<String> subscriptionTargetFilters = predicates.stream().flatMap(predicate -> predicate.getTargetFilter().stream()) .collect(Collectors.toSet()); - final NcmpOutEvent ncmpOutEvent = mappersFacade.toNcmpOutEventForRejectedRequest(subscriptionId, + final NcmpOutEvent ncmpOutEvent = ncmpOutEventMapper.toNcmpOutEventForRejectedRequest(subscriptionId, new ArrayList<>(subscriptionTargetFilters)); - eventsFacade.publishNcmpOutEvent(subscriptionId, "subscriptionCreateResponse", ncmpOutEvent, false); + ncmpOutEventProducer.publishNcmpOutEvent(subscriptionId, "subscriptionCreateResponse", ncmpOutEvent, false); } private void handleNewCmSubscription(final String subscriptionId) { @@ -97,8 +99,8 @@ public class CmSubscriptionHandlerImpl implements CmSubscriptionHandler { private void publishDmiInEventPerDmi(final String subscriptionId, final String dmiPluginName, final List<DmiCmSubscriptionPredicate> dmiCmSubscriptionPredicates) { - final DmiInEvent dmiInEvent = mappersFacade.toDmiInEvent(dmiCmSubscriptionPredicates); - eventsFacade.publishDmiInEvent(subscriptionId, dmiPluginName, + final DmiInEvent dmiInEvent = dmiInEventMapper.toDmiInEvent(dmiCmSubscriptionPredicates); + dmiInEventProducer.publishDmiInEvent(subscriptionId, dmiPluginName, "subscriptionCreateRequest", dmiInEvent); } @@ -112,9 +114,9 @@ public class CmSubscriptionHandlerImpl implements CmSubscriptionHandler { final Map<String, DmiCmSubscriptionDetails> dmiSubscriptionsPerDmi = dmiCacheHandler.get(subscriptionId); dmiSubscriptionsPerDmi.forEach((dmiPluginName, dmiSubscriptionDetails) -> { - final DmiInEvent dmiInEvent = mappersFacade.toDmiInEvent( + final DmiInEvent dmiInEvent = dmiInEventMapper.toDmiInEvent( dmiSubscriptionDetails.getDmiCmSubscriptionPredicates()); - eventsFacade.publishDmiInEvent(subscriptionId, dmiPluginName, + dmiInEventProducer.publishDmiInEvent(subscriptionId, dmiPluginName, "subscriptionDeleteRequest", dmiInEvent); }); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducer.java index 92800f4af1..01d720937f 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducer.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventProducer.java @@ -33,7 +33,6 @@ import java.util.concurrent.TimeUnit; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.events.EventsPublisher; -import org.onap.cps.ncmp.impl.cmnotificationsubscription.MappersFacade; import org.onap.cps.ncmp.impl.cmnotificationsubscription.cache.DmiCacheHandler; import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_client.NcmpOutEvent; import org.onap.cps.utils.JsonObjectMapper; @@ -55,7 +54,7 @@ public class NcmpOutEventProducer { private final EventsPublisher<CloudEvent> eventsPublisher; private final JsonObjectMapper jsonObjectMapper; - private final MappersFacade mappersFacade; + private final NcmpOutEventMapper ncmpOutEventMapper; private final DmiCacheHandler dmiCacheHandler; private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); private static final Map<String, ScheduledFuture<?>> scheduledTasksPerSubscriptionId = new ConcurrentHashMap<>(); @@ -88,7 +87,7 @@ public class NcmpOutEventProducer { private ScheduledFuture<?> scheduleAndPublishNcmpOutEvent(final String subscriptionId, final String eventType) { final NcmpOutEventPublishingTask ncmpOutEventPublishingTask = new NcmpOutEventPublishingTask(ncmpOutEventTopic, subscriptionId, eventType, eventsPublisher, - jsonObjectMapper, mappersFacade, dmiCacheHandler); + jsonObjectMapper, ncmpOutEventMapper, dmiCacheHandler); return scheduledExecutorService.schedule(ncmpOutEventPublishingTask, dmiOutEventTimeoutInMs, TimeUnit.MILLISECONDS); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventPublishingTask.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventPublishingTask.java index 5636237566..f8f253d275 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventPublishingTask.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/cmnotificationsubscription/ncmp/NcmpOutEventPublishingTask.java @@ -27,7 +27,6 @@ import java.util.Map; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.events.EventsPublisher; -import org.onap.cps.ncmp.impl.cmnotificationsubscription.MappersFacade; import org.onap.cps.ncmp.impl.cmnotificationsubscription.cache.DmiCacheHandler; import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionDetails; import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_client.NcmpOutEvent; @@ -42,7 +41,7 @@ public class NcmpOutEventPublishingTask implements Runnable { private final String eventType; private final EventsPublisher<CloudEvent> eventsPublisher; private final JsonObjectMapper jsonObjectMapper; - private final MappersFacade mappersFacade; + private final NcmpOutEventMapper ncmpOutEventMapper; private final DmiCacheHandler dmiCacheHandler; /** @@ -53,7 +52,7 @@ public class NcmpOutEventPublishingTask implements Runnable { public void run() { final Map<String, DmiCmSubscriptionDetails> dmiSubscriptionsPerDmi = dmiCacheHandler.get(subscriptionId); - final NcmpOutEvent ncmpOutEvent = mappersFacade.toNcmpOutEvent(subscriptionId, + final NcmpOutEvent ncmpOutEvent = ncmpOutEventMapper.toNcmpOutEvent(subscriptionId, dmiSubscriptionsPerDmi); eventsPublisher.publishCloudEvent(topicName, subscriptionId, buildAndGetNcmpOutEventAsCloudEvent(jsonObjectMapper, subscriptionId, eventType, |