aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2024-06-27 15:35:37 +0100
committerToineSiebelink <toine.siebelink@est.tech>2024-06-27 15:44:20 +0100
commitdf31bcf92002b2b7cba9b1187e68995c2af53cf0 (patch)
tree573819320b93f1ac78c90e1db7801a840c1d0291 /cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api
parent3ae991156d5b6bc3215eae73a03dfc588e691bf7 (diff)
move lcm/common events classes
-moved api.impl.events.lcm to impl.inventory.sync.lcm -moved most api.impl.events class to utils.events (remaining classes in api.impl.events belong to cmsubscrption and Priyank wil take care of those) Issue-ID: CPS-2258 Change-Id: I1818194e708aa0d9c713b470e878997c2f26fb13 Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpDatastoreRequestHandler.java2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpPassthroughResourceRequestHandler.java2
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/NcmpEvent.java66
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avc/ncmptoclient/AvcEventPublisher.java82
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/consumer/CmNotificationSubscriptionDmiOutEventConsumer.java4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/consumer/CmNotificationSubscriptionNcmpInEventConsumer.java4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventHeaderMapper.java36
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventType.java38
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandler.java55
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerAsyncHelper.java79
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImpl.java208
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCreator.java131
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCreatorHelper.java227
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsService.java74
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/mapper/CloudEventMapper.java61
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/DataOperationEventCreator.java2
16 files changed, 7 insertions, 1064 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpDatastoreRequestHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpDatastoreRequestHandler.java
index 302ba449c7..95453a71da 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpDatastoreRequestHandler.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpDatastoreRequestHandler.java
@@ -24,7 +24,7 @@ import java.util.Map;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.models.CmResourceAddress;
-import org.onap.cps.ncmp.utils.TopicValidator;
+import org.onap.cps.ncmp.utils.events.TopicValidator;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpPassthroughResourceRequestHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpPassthroughResourceRequestHandler.java
index 0fd32501c3..0867ab44a5 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpPassthroughResourceRequestHandler.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NcmpPassthroughResourceRequestHandler.java
@@ -34,7 +34,7 @@ import org.onap.cps.ncmp.api.models.CmResourceAddress;
import org.onap.cps.ncmp.api.models.DataOperationRequest;
import org.onap.cps.ncmp.exceptions.OperationNotSupportedException;
import org.onap.cps.ncmp.exceptions.PayloadTooLargeException;
-import org.onap.cps.ncmp.utils.TopicValidator;
+import org.onap.cps.ncmp.utils.events.TopicValidator;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/NcmpEvent.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/NcmpEvent.java
deleted file mode 100644
index 248db9805c..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/NcmpEvent.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2023-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.api.impl.events;
-
-import io.cloudevents.CloudEvent;
-import io.cloudevents.core.builder.CloudEventBuilder;
-import java.net.URI;
-import java.util.Map;
-import java.util.UUID;
-import lombok.Builder;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.cps.ncmp.api.impl.utils.EventDateTimeFormatter;
-import org.onap.cps.ncmp.api.impl.utils.context.CpsApplicationContext;
-import org.onap.cps.utils.JsonObjectMapper;
-
-@Builder
-public class NcmpEvent {
-
- private Object data;
- private Map<String, String> extensions;
- private String type;
- @Builder.Default
- private static final String CLOUD_EVENT_SPEC_VERSION_V1 = "1.0.0";
- @Builder.Default
- private static final String CLOUD_EVENT_SOURCE = "NCMP";
-
- /**
- * Creates ncmp cloud event with provided attributes.
- *
- * @return Cloud Event
- */
- public CloudEvent asCloudEvent() {
- final JsonObjectMapper jsonObjectMapper = CpsApplicationContext.getCpsBean(JsonObjectMapper.class);
- final CloudEventBuilder cloudEventBuilder = CloudEventBuilder.v1()
- .withId(UUID.randomUUID().toString())
- .withSource(URI.create(CLOUD_EVENT_SOURCE))
- .withType(type)
- .withDataSchema(URI.create("urn:cps:" + type + ":" + CLOUD_EVENT_SPEC_VERSION_V1))
- .withTime(EventDateTimeFormatter.toIsoOffsetDateTime(
- EventDateTimeFormatter.getCurrentIsoFormattedDateTime()))
- .withData(jsonObjectMapper.asJsonBytes(data));
- extensions.entrySet().stream()
- .filter(extensionEntry -> StringUtils.isNotBlank(extensionEntry.getValue()))
- .forEach(extensionEntry ->
- cloudEventBuilder.withExtension(extensionEntry.getKey(), extensionEntry.getValue()));
- return cloudEventBuilder.build();
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avc/ncmptoclient/AvcEventPublisher.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avc/ncmptoclient/AvcEventPublisher.java
deleted file mode 100644
index 7afe606f4f..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avc/ncmptoclient/AvcEventPublisher.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2023-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.api.impl.events.avc.ncmptoclient;
-
-import io.cloudevents.CloudEvent;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import lombok.RequiredArgsConstructor;
-import org.onap.cps.events.EventsPublisher;
-import org.onap.cps.ncmp.api.impl.events.NcmpEvent;
-import org.onap.cps.ncmp.events.avc.ncmp_to_client.Avc;
-import org.onap.cps.ncmp.events.avc.ncmp_to_client.AvcEvent;
-import org.onap.cps.ncmp.events.avc.ncmp_to_client.Data;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-
-@Service
-@RequiredArgsConstructor
-public class AvcEventPublisher {
-
- private final EventsPublisher<CloudEvent> eventsPublisher;
-
- @Value("${app.ncmp.avc.cm-events-topic}")
- private String avcTopic;
-
- /**
- * Publish attribute value change event.
- *
- * @param eventKey id of the cmHandle being registered
- */
- public void publishAvcEvent(final String eventKey, final String attributeName,
- final String oldAttributeValue, final String newAttributeValue) {
- final AvcEvent avcEvent = buildAvcEvent(attributeName, oldAttributeValue, newAttributeValue);
-
- final Map<String, String> extensions = createAvcEventExtensions(eventKey);
- final CloudEvent avcCloudEvent =
- NcmpEvent.builder().type(AvcEvent.class.getTypeName())
- .data(avcEvent).extensions(extensions).build().asCloudEvent();
-
- eventsPublisher.publishCloudEvent(avcTopic, eventKey, avcCloudEvent);
- }
-
- private AvcEvent buildAvcEvent(final String attributeName,
- final String oldAttributeValue,
- final String newAttributeValue) {
- final Avc avc = new Avc();
- avc.setAttributeName(attributeName);
- avc.setOldAttributeValue(oldAttributeValue);
- avc.setNewAttributeValue(newAttributeValue);
-
- final Data payload = new Data();
- payload.setAttributeValueChange(Collections.singletonList(avc));
- final AvcEvent avcEvent = new AvcEvent();
- avcEvent.setData(payload);
- return avcEvent;
- }
-
- private Map<String, String> createAvcEventExtensions(final String eventKey) {
- final Map<String, String> extensions = new HashMap<>();
- extensions.put("correlationid", eventKey);
- return extensions;
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/consumer/CmNotificationSubscriptionDmiOutEventConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/consumer/CmNotificationSubscriptionDmiOutEventConsumer.java
index 051949c5e8..978a4cdfe2 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/consumer/CmNotificationSubscriptionDmiOutEventConsumer.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/consumer/CmNotificationSubscriptionDmiOutEventConsumer.java
@@ -22,7 +22,7 @@ package org.onap.cps.ncmp.api.impl.events.cmsubscription.consumer;
import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_DATA_SUBSCRIPTION_ACCEPTED;
import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_DATA_SUBSCRIPTION_REJECTED;
-import static org.onap.cps.ncmp.api.impl.events.mapper.CloudEventMapper.toTargetEvent;
+import static org.onap.cps.ncmp.utils.events.CloudEventMapper.toTargetEvent;
import io.cloudevents.CloudEvent;
import java.util.Map;
@@ -120,4 +120,4 @@ public class CmNotificationSubscriptionDmiOutEventConsumer {
&& ncmpResponseStatus.getMessage()
.equals(cmNotificationSubscriptionDmiOutData.getStatusMessage());
}
-} \ No newline at end of file
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/consumer/CmNotificationSubscriptionNcmpInEventConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/consumer/CmNotificationSubscriptionNcmpInEventConsumer.java
index fb3388c117..65f4ee8c89 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/consumer/CmNotificationSubscriptionNcmpInEventConsumer.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/cmsubscription/consumer/CmNotificationSubscriptionNcmpInEventConsumer.java
@@ -20,7 +20,7 @@
package org.onap.cps.ncmp.api.impl.events.cmsubscription.consumer;
-import static org.onap.cps.ncmp.api.impl.events.mapper.CloudEventMapper.toTargetEvent;
+import static org.onap.cps.ncmp.utils.events.CloudEventMapper.toTargetEvent;
import io.cloudevents.CloudEvent;
import java.util.List;
@@ -67,4 +67,4 @@ public class CmNotificationSubscriptionNcmpInEventConsumer {
cmNotificationSubscriptionHandlerService.processSubscriptionDeleteRequest(subscriptionId, predicates);
}
}
-} \ No newline at end of file
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventHeaderMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventHeaderMapper.java
deleted file mode 100644
index f7707d9f76..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventHeaderMapper.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2023 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.api.impl.events.lcm;
-
-import org.mapstruct.Mapper;
-import org.onap.cps.ncmp.events.lcm.v1.LcmEvent;
-import org.onap.cps.ncmp.events.lcm.v1.LcmEventHeader;
-
-@Mapper(componentModel = "spring")
-public interface LcmEventHeaderMapper {
-
- /**
- * Mapper for converting incoming {@link LcmEvent} to outgoing {@link LcmEventHeader}.
- */
-
- LcmEventHeader toLcmEventHeader(LcmEvent lcmEvent);
-
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventType.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventType.java
deleted file mode 100644
index a8d00f7e31..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventType.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 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.api.impl.events.lcm;
-
-public enum LcmEventType {
-
- CREATE("create"), UPDATE("update"), DELETE("delete");
-
- private final String eventName;
-
- private final String eventTypeTemplate = "org.onap.ncmp.cmhandle-lcm-event.%s";
-
- LcmEventType(final String eventName) {
- this.eventName = String.format(eventTypeTemplate, eventName);
- }
-
- public String getEventType() {
- return this.eventName;
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandler.java
deleted file mode 100644
index 3a49957864..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandler.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 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.api.impl.events.lcm;
-
-import java.util.Collection;
-import java.util.Map;
-import org.onap.cps.ncmp.impl.inventory.models.CmHandleState;
-import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle;
-
-/**
- * The implementation of it should handle the persisting of composite state and delegate the request to publish the
- * corresponding lcm event.
- */
-public interface LcmEventsCmHandleStateHandler {
-
- /**
- * Updates the composite state of cmHandle based on cmHandleState.
- *
- * @param yangModelCmHandle cm handle represented as yang model
- * @param targetCmHandleState target cm handle state
- */
- void updateCmHandleState(final YangModelCmHandle yangModelCmHandle, final CmHandleState targetCmHandleState);
-
- /**
- * Updates the composite state of cmHandle based on cmHandleState in batch.
- *
- * @param cmHandleStatePerCmHandle Map of Yang Model Cm Handle and corresponding cm handle state.
- */
- void updateCmHandleStateBatch(final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle);
-
- /**
- * Sets the initial state of cmHandles to ADVISED.
- *
- * @param yangModelCmHandles List of Yang Model Cm Handle.
- */
- void initiateStateAdvised(Collection<YangModelCmHandle> yangModelCmHandles);
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerAsyncHelper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerAsyncHelper.java
deleted file mode 100644
index af745caa44..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerAsyncHelper.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2023 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.api.impl.events.lcm;
-
-import java.util.Collection;
-import lombok.RequiredArgsConstructor;
-import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle;
-import org.onap.cps.ncmp.events.lcm.v1.LcmEvent;
-import org.onap.cps.ncmp.events.lcm.v1.LcmEventHeader;
-import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle;
-import org.onap.cps.ncmp.impl.utils.YangDataConverter;
-import org.springframework.scheduling.annotation.Async;
-import org.springframework.stereotype.Service;
-
-@Service
-@RequiredArgsConstructor
-public class LcmEventsCmHandleStateHandlerAsyncHelper {
-
- private final LcmEventsCreator lcmEventsCreator;
- private final LcmEventsService lcmEventsService;
-
- /**
- * Publish LCM Event in asynchronous manner.
- *
- * @param targetNcmpServiceCmHandle target NcmpServiceCmHandle
- * @param currentNcmpServiceCmHandle current NcmpServiceCmHandle
- */
- @Async("notificationExecutor")
- public void publishLcmEventAsynchronously(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
- final NcmpServiceCmHandle currentNcmpServiceCmHandle) {
- publishLcmEvent(targetNcmpServiceCmHandle, currentNcmpServiceCmHandle);
- }
-
- /**
- * Publish LcmEvent in batches and in asynchronous manner.
- *
- * @param cmHandleTransitionPairs Pair of existing and modified cm handle represented as YangModelCmHandle
- */
- @Async("notificationExecutor")
- public void publishLcmEventBatchAsynchronously(
- final Collection<LcmEventsCmHandleStateHandlerImpl.CmHandleTransitionPair> cmHandleTransitionPairs) {
- cmHandleTransitionPairs.forEach(cmHandleTransitionPair -> publishLcmEvent(
- toNcmpServiceCmHandle(cmHandleTransitionPair.getTargetYangModelCmHandle()),
- toNcmpServiceCmHandle(cmHandleTransitionPair.getCurrentYangModelCmHandle())));
- }
-
- private void publishLcmEvent(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
- final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
- final String cmHandleId = targetNcmpServiceCmHandle.getCmHandleId();
- final LcmEventHeader lcmEventHeader =
- lcmEventsCreator.populateLcmEventHeader(cmHandleId, targetNcmpServiceCmHandle,
- existingNcmpServiceCmHandle);
- final LcmEvent lcmEvent =
- lcmEventsCreator.populateLcmEvent(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
- lcmEventsService.publishLcmEvent(cmHandleId, lcmEvent, lcmEventHeader);
- }
-
- private static NcmpServiceCmHandle toNcmpServiceCmHandle(final YangModelCmHandle yangModelCmHandle) {
- return YangDataConverter.toNcmpServiceCmHandle(yangModelCmHandle);
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImpl.java
deleted file mode 100644
index 4376014f36..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCmHandleStateHandlerImpl.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022-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.api.impl.events.lcm;
-
-import static org.onap.cps.ncmp.impl.inventory.models.CmHandleState.ADVISED;
-import static org.onap.cps.ncmp.impl.inventory.models.CmHandleState.DELETED;
-import static org.onap.cps.ncmp.impl.inventory.models.CmHandleState.LOCKED;
-import static org.onap.cps.ncmp.impl.inventory.models.CmHandleState.READY;
-
-import io.micrometer.core.annotation.Timed;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.RequiredArgsConstructor;
-import lombok.Setter;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.inventory.models.CompositeState;
-import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle;
-import org.onap.cps.ncmp.impl.inventory.CompositeStateUtils;
-import org.onap.cps.ncmp.impl.inventory.InventoryPersistence;
-import org.onap.cps.ncmp.impl.inventory.models.CmHandleState;
-import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle;
-import org.onap.cps.ncmp.impl.utils.YangDataConverter;
-import org.springframework.stereotype.Service;
-
-@Slf4j
-@Service
-@RequiredArgsConstructor
-public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleStateHandler {
-
- private final InventoryPersistence inventoryPersistence;
- private final LcmEventsCmHandleStateHandlerAsyncHelper lcmEventsCmHandleStateHandlerAsyncHelper;
-
- @Override
- public void updateCmHandleState(final YangModelCmHandle updatedYangModelCmHandle,
- final CmHandleState targetCmHandleState) {
-
- final CompositeState compositeState = updatedYangModelCmHandle.getCompositeState();
-
- if (isCompositeStateSame(compositeState, targetCmHandleState)) {
- log.debug("CmHandle with id : {} already in state : {}", updatedYangModelCmHandle.getId(),
- targetCmHandleState);
- } else {
- final YangModelCmHandle currentYangModelCmHandle = YangModelCmHandle.deepCopyOf(updatedYangModelCmHandle);
- updateToSpecifiedCmHandleState(updatedYangModelCmHandle, targetCmHandleState);
- persistCmHandle(updatedYangModelCmHandle, currentYangModelCmHandle);
- lcmEventsCmHandleStateHandlerAsyncHelper.publishLcmEventAsynchronously(
- toNcmpServiceCmHandle(updatedYangModelCmHandle),
- toNcmpServiceCmHandle(currentYangModelCmHandle));
- }
- }
-
- @Override
- @Timed(value = "cps.ncmp.cmhandle.state.update.batch",
- description = "Time taken to update a batch of cm handle states")
- public void updateCmHandleStateBatch(final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle) {
- final Collection<CmHandleTransitionPair> cmHandleTransitionPairs =
- prepareCmHandleTransitionBatch(cmHandleStatePerCmHandle);
- persistCmHandleBatch(cmHandleTransitionPairs);
- lcmEventsCmHandleStateHandlerAsyncHelper.publishLcmEventBatchAsynchronously(cmHandleTransitionPairs);
- }
-
- @Override
- public void initiateStateAdvised(final Collection<YangModelCmHandle> yangModelCmHandles) {
- final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle = new HashMap<>(yangModelCmHandles.size());
- for (final YangModelCmHandle yangModelCmHandle : yangModelCmHandles) {
- cmHandleStatePerCmHandle.put(yangModelCmHandle, ADVISED);
- }
- updateCmHandleStateBatch(cmHandleStatePerCmHandle);
- }
-
- private Collection<CmHandleTransitionPair> prepareCmHandleTransitionBatch(
- final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle) {
- final List<CmHandleTransitionPair> cmHandleTransitionPairs = new ArrayList<>(cmHandleStatePerCmHandle.size());
- cmHandleStatePerCmHandle.forEach((yangModelCmHandle, targetCmHandleState) -> {
-
- final CompositeState compositeState = yangModelCmHandle.getCompositeState();
-
- if (isCompositeStateSame(compositeState, targetCmHandleState)) {
- log.debug("CmHandle with id : {} already in state : {}", yangModelCmHandle.getId(),
- targetCmHandleState);
- } else {
- final CmHandleTransitionPair cmHandleTransitionPair = new CmHandleTransitionPair();
- cmHandleTransitionPair.setCurrentYangModelCmHandle(YangModelCmHandle.deepCopyOf(yangModelCmHandle));
- updateToSpecifiedCmHandleState(yangModelCmHandle, targetCmHandleState);
- cmHandleTransitionPair.setTargetYangModelCmHandle(yangModelCmHandle);
- cmHandleTransitionPairs.add(cmHandleTransitionPair);
- }
- });
- return cmHandleTransitionPairs;
- }
-
-
- private void persistCmHandle(final YangModelCmHandle targetYangModelCmHandle,
- final YangModelCmHandle currentYangModelCmHandle) {
- if (isNew(currentYangModelCmHandle.getCompositeState())) {
- log.debug("Registering a new cm handle {}", targetYangModelCmHandle.getId());
- inventoryPersistence.saveCmHandle(targetYangModelCmHandle);
- } else if (isDeleted(targetYangModelCmHandle.getCompositeState())) {
- log.info("CmHandle with Id : {} is DELETED", targetYangModelCmHandle.getId());
- } else {
- inventoryPersistence.saveCmHandleState(targetYangModelCmHandle.getId(),
- targetYangModelCmHandle.getCompositeState());
- }
- }
-
- private void persistCmHandleBatch(final Collection<CmHandleTransitionPair> cmHandleTransitionPairs) {
-
- final List<YangModelCmHandle> newCmHandles = new ArrayList<>();
- final Map<String, CompositeState> compositeStatePerCmHandleId = new LinkedHashMap<>();
-
- cmHandleTransitionPairs.forEach(cmHandleTransitionPair -> {
- if (isNew(cmHandleTransitionPair.getCurrentYangModelCmHandle().getCompositeState()
- )) {
- newCmHandles.add(cmHandleTransitionPair.getTargetYangModelCmHandle());
- } else if (!isDeleted(cmHandleTransitionPair.getTargetYangModelCmHandle().getCompositeState())) {
- compositeStatePerCmHandleId.put(cmHandleTransitionPair.getTargetYangModelCmHandle().getId(),
- cmHandleTransitionPair.getTargetYangModelCmHandle().getCompositeState());
- }
- });
-
- inventoryPersistence.saveCmHandleBatch(newCmHandles);
- inventoryPersistence.saveCmHandleStateBatch(compositeStatePerCmHandleId);
-
- }
-
- private void updateToSpecifiedCmHandleState(final YangModelCmHandle yangModelCmHandle,
- final CmHandleState targetCmHandleState) {
-
- if (READY == targetCmHandleState) {
- setInitialStates(yangModelCmHandle);
- } else if (ADVISED == targetCmHandleState) {
- if (yangModelCmHandle.getCompositeState() == null) {
- registerNewCmHandle(yangModelCmHandle);
- } else if (yangModelCmHandle.getCompositeState().getCmHandleState() == LOCKED) {
- retryCmHandle(yangModelCmHandle);
- }
- } else {
- setCmHandleState(yangModelCmHandle, targetCmHandleState);
- }
- }
-
- private void setInitialStates(final YangModelCmHandle yangModelCmHandle) {
- CompositeStateUtils.setInitialDataStoreSyncState(yangModelCmHandle.getCompositeState());
- CompositeStateUtils.setCompositeState(READY, yangModelCmHandle.getCompositeState());
- }
-
- private void retryCmHandle(final YangModelCmHandle yangModelCmHandle) {
- CompositeStateUtils.setCompositeStateForRetry(yangModelCmHandle.getCompositeState());
- }
-
- private void registerNewCmHandle(final YangModelCmHandle yangModelCmHandle) {
- yangModelCmHandle.setCompositeState(new CompositeState());
- setCmHandleState(yangModelCmHandle, ADVISED);
- }
-
- private void setCmHandleState(final YangModelCmHandle yangModelCmHandle, final CmHandleState targetCmHandleState) {
- CompositeStateUtils.setCompositeState(targetCmHandleState, yangModelCmHandle.getCompositeState());
- }
-
- private boolean isNew(final CompositeState existingCompositeState) {
- return (existingCompositeState == null);
- }
-
- private boolean isDeleted(final CompositeState targetCompositeState) {
- return targetCompositeState.getCmHandleState() == DELETED;
- }
-
- private boolean isCompositeStateSame(final CompositeState compositeState, final CmHandleState targetCmHandleState) {
- return (compositeState != null && compositeState.getCmHandleState() == targetCmHandleState);
- }
-
- private NcmpServiceCmHandle toNcmpServiceCmHandle(final YangModelCmHandle yangModelCmHandle) {
- return YangDataConverter.toNcmpServiceCmHandle(yangModelCmHandle);
- }
-
- @Getter
- @Setter
- @NoArgsConstructor
- static class CmHandleTransitionPair {
-
- private YangModelCmHandle currentYangModelCmHandle;
- private YangModelCmHandle targetYangModelCmHandle;
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCreator.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCreator.java
deleted file mode 100644
index 4231c99678..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCreator.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022-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.api.impl.events.lcm;
-
-import java.util.UUID;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.RequiredArgsConstructor;
-import lombok.Setter;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.impl.utils.EventDateTimeFormatter;
-import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle;
-import org.onap.cps.ncmp.events.lcm.v1.Event;
-import org.onap.cps.ncmp.events.lcm.v1.LcmEvent;
-import org.onap.cps.ncmp.events.lcm.v1.LcmEventHeader;
-import org.onap.cps.ncmp.events.lcm.v1.Values;
-import org.springframework.stereotype.Component;
-
-
-/**
- * LcmEventsCreator to create LcmEvent based on relevant operation.
- */
-@Slf4j
-@Component
-@RequiredArgsConstructor
-public class LcmEventsCreator {
-
- private final LcmEventHeaderMapper lcmEventHeaderMapper;
-
- /**
- * Populate Lifecycle Management Event.
- *
- * @param cmHandleId cm handle identifier
- * @param targetNcmpServiceCmHandle target ncmp service cmhandle
- * @param existingNcmpServiceCmHandle existing ncmp service cmhandle
- * @return Populated LcmEvent
- */
- public LcmEvent populateLcmEvent(final String cmHandleId, final NcmpServiceCmHandle targetNcmpServiceCmHandle,
- final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
- return createLcmEvent(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
- }
-
- /**
- * Populate Lifecycle Management Event Header.
- *
- * @param cmHandleId cm handle identifier
- * @param targetNcmpServiceCmHandle target ncmp service cmhandle
- * @param existingNcmpServiceCmHandle existing ncmp service cmhandle
- * @return Populated LcmEventHeader
- */
- public LcmEventHeader populateLcmEventHeader(final String cmHandleId,
- final NcmpServiceCmHandle targetNcmpServiceCmHandle,
- final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
- return createLcmEventHeader(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
- }
-
- private LcmEvent createLcmEvent(final String cmHandleId, final NcmpServiceCmHandle targetNcmpServiceCmHandle,
- final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
- final LcmEventType lcmEventType =
- LcmEventsCreatorHelper.determineEventType(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
- final LcmEvent lcmEvent = lcmEventHeader(cmHandleId, lcmEventType);
- lcmEvent.setEvent(
- lcmEventPayload(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle, lcmEventType));
- return lcmEvent;
- }
-
- private LcmEventHeader createLcmEventHeader(final String cmHandleId,
- final NcmpServiceCmHandle targetNcmpServiceCmHandle,
- final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
- final LcmEventType lcmEventType =
- LcmEventsCreatorHelper.determineEventType(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
- final LcmEvent lcmEventWithHeaderInformation = lcmEventHeader(cmHandleId, lcmEventType);
- return lcmEventHeaderMapper.toLcmEventHeader(lcmEventWithHeaderInformation);
- }
-
- private Event lcmEventPayload(final String eventCorrelationId, final NcmpServiceCmHandle targetNcmpServiceCmHandle,
- final NcmpServiceCmHandle existingNcmpServiceCmHandle, final LcmEventType lcmEventType) {
- final Event event = new Event();
- event.setCmHandleId(eventCorrelationId);
- event.setAlternateId(targetNcmpServiceCmHandle.getAlternateId());
- event.setModuleSetTag(targetNcmpServiceCmHandle.getModuleSetTag());
- event.setDataProducerIdentifier(targetNcmpServiceCmHandle.getDataProducerIdentifier());
- final CmHandleValuesHolder cmHandleValuesHolder =
- LcmEventsCreatorHelper.determineEventValues(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle,
- lcmEventType);
- event.setOldValues(cmHandleValuesHolder.getOldValues());
- event.setNewValues(cmHandleValuesHolder.getNewValues());
-
- return event;
- }
-
- private LcmEvent lcmEventHeader(final String eventCorrelationId, final LcmEventType lcmEventType) {
- final LcmEvent lcmEvent = new LcmEvent();
- lcmEvent.setEventId(UUID.randomUUID().toString());
- lcmEvent.setEventCorrelationId(eventCorrelationId);
- lcmEvent.setEventTime(EventDateTimeFormatter.getCurrentIsoFormattedDateTime());
- lcmEvent.setEventSource("org.onap.ncmp");
- lcmEvent.setEventType(lcmEventType.getEventType());
- lcmEvent.setEventSchema("org.onap.ncmp:cmhandle-lcm-event");
- lcmEvent.setEventSchemaVersion("1.0");
- return lcmEvent;
- }
-
- @NoArgsConstructor
- @Getter
- @Setter
- static class CmHandleValuesHolder {
-
- private Values oldValues;
- private Values newValues;
- }
-
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCreatorHelper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCreatorHelper.java
deleted file mode 100644
index 7c7a9722ce..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsCreatorHelper.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 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.api.impl.events.lcm;
-
-import static org.onap.cps.ncmp.api.impl.events.lcm.LcmEventType.CREATE;
-import static org.onap.cps.ncmp.api.impl.events.lcm.LcmEventType.DELETE;
-import static org.onap.cps.ncmp.api.impl.events.lcm.LcmEventType.UPDATE;
-import static org.onap.cps.ncmp.impl.inventory.models.CmHandleState.DELETED;
-
-import com.google.common.collect.MapDifference;
-import com.google.common.collect.Maps;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle;
-import org.onap.cps.ncmp.events.lcm.v1.Values;
-
-/**
- * LcmEventsCreatorHelper has helper methods to create LcmEvent.
- * Determine the lcm event type i.e create,update and delete.
- * Based on lcm event type create the LcmEvent payload.
- */
-@Slf4j
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public class LcmEventsCreatorHelper {
-
- /**
- * Determining the event type based on the composite state.
- *
- * @param targetNcmpServiceCmHandle target ncmpServiceCmHandle
- * @param existingNcmpServiceCmHandle existing ncmpServiceCmHandle
- * @return Event Type
- */
- public static LcmEventType determineEventType(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
- final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
-
- if (existingNcmpServiceCmHandle.getCompositeState() == null) {
- return CREATE;
- } else if (targetNcmpServiceCmHandle.getCompositeState().getCmHandleState() == DELETED) {
- return DELETE;
- }
- return UPDATE;
- }
-
- /**
- * Determine the cmhandle value difference pair.Contains the difference in the form of oldValues and newValues.
- *
- * @param targetNcmpServiceCmHandle target ncmpServiceCmHandle
- * @param existingNcmpServiceCmHandle existing ncmpServiceCmHandle
- * @param lcmEventType lcm event type
- * @return Lcm Event Value difference pair
- */
- public static LcmEventsCreator.CmHandleValuesHolder determineEventValues(
- final NcmpServiceCmHandle targetNcmpServiceCmHandle, final NcmpServiceCmHandle existingNcmpServiceCmHandle,
- final LcmEventType lcmEventType) {
-
- if (CREATE == lcmEventType) {
- return determineCreateEventValues(targetNcmpServiceCmHandle);
- } else if (UPDATE == lcmEventType) {
- return determineUpdateEventValues(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
- }
- return new LcmEventsCreator.CmHandleValuesHolder();
-
- }
-
- private static LcmEventsCreator.CmHandleValuesHolder determineCreateEventValues(
- final NcmpServiceCmHandle ncmpServiceCmHandle) {
- final LcmEventsCreator.CmHandleValuesHolder cmHandleValuesHolder = new LcmEventsCreator.CmHandleValuesHolder();
- cmHandleValuesHolder.setNewValues(new Values());
- cmHandleValuesHolder.getNewValues().setDataSyncEnabled(getDataSyncEnabledFlag(ncmpServiceCmHandle));
- cmHandleValuesHolder.getNewValues()
- .setCmHandleState(mapCmHandleStateToLcmEventCmHandleState(ncmpServiceCmHandle));
- cmHandleValuesHolder.getNewValues().setCmHandleProperties(List.of(ncmpServiceCmHandle.getPublicProperties()));
- return cmHandleValuesHolder;
- }
-
- private static LcmEventsCreator.CmHandleValuesHolder determineUpdateEventValues(
- final NcmpServiceCmHandle targetNcmpServiceCmHandle,
- final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
-
- final boolean hasDataSyncFlagEnabledChanged =
- hasDataSyncEnabledFlagChanged(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
- final boolean hasCmHandleStateChanged =
- hasCmHandleStateChanged(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle);
- final boolean arePublicCmHandlePropertiesEqual =
- arePublicCmHandlePropertiesEqual(targetNcmpServiceCmHandle.getPublicProperties(),
- existingNcmpServiceCmHandle.getPublicProperties());
-
- final LcmEventsCreator.CmHandleValuesHolder cmHandleValuesHolder = new LcmEventsCreator.CmHandleValuesHolder();
-
- if (hasDataSyncFlagEnabledChanged || hasCmHandleStateChanged || (!arePublicCmHandlePropertiesEqual)) {
- cmHandleValuesHolder.setOldValues(new Values());
- cmHandleValuesHolder.setNewValues(new Values());
- } else {
- return cmHandleValuesHolder;
- }
-
- if (hasDataSyncFlagEnabledChanged) {
- setDataSyncEnabledFlag(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle, cmHandleValuesHolder);
- }
-
- if (hasCmHandleStateChanged) {
- setCmHandleStateChange(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle, cmHandleValuesHolder);
- }
-
- if (!arePublicCmHandlePropertiesEqual) {
- setPublicCmHandlePropertiesChange(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle,
- cmHandleValuesHolder);
- }
-
- return cmHandleValuesHolder;
-
- }
-
- private static void setDataSyncEnabledFlag(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
- final NcmpServiceCmHandle existingNcmpServiceCmHandle,
- final LcmEventsCreator.CmHandleValuesHolder cmHandleValuesHolder) {
-
- cmHandleValuesHolder.getOldValues().setDataSyncEnabled(getDataSyncEnabledFlag(existingNcmpServiceCmHandle));
- cmHandleValuesHolder.getNewValues().setDataSyncEnabled(getDataSyncEnabledFlag(targetNcmpServiceCmHandle));
-
- }
-
- private static void setCmHandleStateChange(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
- final NcmpServiceCmHandle existingNcmpServiceCmHandle,
- final LcmEventsCreator.CmHandleValuesHolder cmHandleValuesHolder) {
- cmHandleValuesHolder.getOldValues()
- .setCmHandleState(mapCmHandleStateToLcmEventCmHandleState(existingNcmpServiceCmHandle));
- cmHandleValuesHolder.getNewValues()
- .setCmHandleState(mapCmHandleStateToLcmEventCmHandleState(targetNcmpServiceCmHandle));
- }
-
- private static void setPublicCmHandlePropertiesChange(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
- final NcmpServiceCmHandle existingNcmpServiceCmHandle,
- final LcmEventsCreator.CmHandleValuesHolder cmHandleValuesHolder) {
-
- final Map<String, Map<String, String>> publicCmHandlePropertiesDifference =
- getPublicCmHandlePropertiesDifference(targetNcmpServiceCmHandle.getPublicProperties(),
- existingNcmpServiceCmHandle.getPublicProperties());
- cmHandleValuesHolder.getOldValues()
- .setCmHandleProperties(List.of(publicCmHandlePropertiesDifference.get("oldValues")));
- cmHandleValuesHolder.getNewValues()
- .setCmHandleProperties(List.of(publicCmHandlePropertiesDifference.get("newValues")));
-
- }
-
- private static Values.CmHandleState mapCmHandleStateToLcmEventCmHandleState(
- final NcmpServiceCmHandle ncmpServiceCmHandle) {
- return Values.CmHandleState.fromValue(ncmpServiceCmHandle.getCompositeState().getCmHandleState().name());
- }
-
- private static Boolean getDataSyncEnabledFlag(final NcmpServiceCmHandle ncmpServiceCmHandle) {
- return ncmpServiceCmHandle.getCompositeState().getDataSyncEnabled();
- }
-
- private static boolean hasDataSyncEnabledFlagChanged(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
- final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
-
- final Boolean targetDataSyncFlag = targetNcmpServiceCmHandle.getCompositeState().getDataSyncEnabled();
- final Boolean existingDataSyncFlag = existingNcmpServiceCmHandle.getCompositeState().getDataSyncEnabled();
-
- if (targetDataSyncFlag == null) {
- return existingDataSyncFlag != null;
- }
-
- return !targetDataSyncFlag.equals(existingDataSyncFlag);
- }
-
- private static boolean hasCmHandleStateChanged(final NcmpServiceCmHandle targetNcmpServiceCmHandle,
- final NcmpServiceCmHandle existingNcmpServiceCmHandle) {
-
- return targetNcmpServiceCmHandle.getCompositeState().getCmHandleState()
- != existingNcmpServiceCmHandle.getCompositeState().getCmHandleState();
- }
-
- private static boolean arePublicCmHandlePropertiesEqual(final Map<String, String> targetCmHandleProperties,
- final Map<String, String> existingCmHandleProperties) {
- if (targetCmHandleProperties.size() != existingCmHandleProperties.size()) {
- return false;
- }
-
- return targetCmHandleProperties.equals(existingCmHandleProperties);
- }
-
- private static Map<String, Map<String, String>> getPublicCmHandlePropertiesDifference(
- final Map<String, String> targetCmHandleProperties, final Map<String, String> existingCmHandleProperties) {
- final Map<String, Map<String, String>> oldAndNewPropertiesDifferenceMap = new HashMap<>(2);
-
- final MapDifference<String, String> cmHandlePropertiesDifference =
- Maps.difference(targetCmHandleProperties, existingCmHandleProperties);
-
- final Map<String, String> newValues = new HashMap<>(cmHandlePropertiesDifference.entriesOnlyOnLeft());
- final Map<String, String> oldValues = new HashMap<>(cmHandlePropertiesDifference.entriesOnlyOnRight());
-
- cmHandlePropertiesDifference.entriesDiffering().keySet().forEach(cmHandlePropertyName -> {
- oldValues.put(cmHandlePropertyName, existingCmHandleProperties.get(cmHandlePropertyName));
- newValues.put(cmHandlePropertyName, targetCmHandleProperties.get(cmHandlePropertyName));
- });
-
- oldAndNewPropertiesDifferenceMap.put("oldValues", oldValues);
- oldAndNewPropertiesDifferenceMap.put("newValues", newValues);
-
- return oldAndNewPropertiesDifferenceMap;
- }
-
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsService.java
deleted file mode 100644
index f51b58c3ef..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/lcm/LcmEventsService.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022-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.api.impl.events.lcm;
-
-import io.micrometer.core.annotation.Timed;
-import java.util.Map;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.events.EventsPublisher;
-import org.onap.cps.ncmp.events.lcm.v1.LcmEvent;
-import org.onap.cps.ncmp.events.lcm.v1.LcmEventHeader;
-import org.onap.cps.utils.JsonObjectMapper;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.kafka.KafkaException;
-import org.springframework.stereotype.Service;
-
-/**
- * LcmEventsService to call the publisher and publish on the dedicated topic.
- */
-
-@Slf4j
-@Service
-@RequiredArgsConstructor
-public class LcmEventsService {
-
- private final EventsPublisher<LcmEvent> eventsPublisher;
- private final JsonObjectMapper jsonObjectMapper;
-
- @Value("${app.lcm.events.topic:ncmp-events}")
- private String topicName;
-
- @Value("${notification.enabled:true}")
- private boolean notificationsEnabled;
-
- /**
- * Publish the LcmEvent with header to the public topic.
- *
- * @param cmHandleId Cm Handle Id
- * @param lcmEvent Lcm Event
- * @param lcmEventHeader Lcm Event Header
- */
- @Timed(value = "cps.ncmp.lcm.events.publish", description = "Time taken to publish a LCM event")
- public void publishLcmEvent(final String cmHandleId, final LcmEvent lcmEvent, final LcmEventHeader lcmEventHeader) {
- if (notificationsEnabled) {
- try {
- final Map<String, Object> lcmEventHeadersMap =
- jsonObjectMapper.convertToValueType(lcmEventHeader, Map.class);
- eventsPublisher.publishEvent(topicName, cmHandleId, lcmEventHeadersMap, lcmEvent);
- } catch (final KafkaException e) {
- log.error("Unable to publish message to topic : {} and cause : {}", topicName, e.getMessage());
- }
- } else {
- log.debug("Notifications disabled.");
- }
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/mapper/CloudEventMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/mapper/CloudEventMapper.java
deleted file mode 100644
index 4120970e52..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/mapper/CloudEventMapper.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (c) 2023 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.api.impl.events.mapper;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import io.cloudevents.CloudEvent;
-import io.cloudevents.core.CloudEventUtils;
-import io.cloudevents.core.data.PojoCloudEventData;
-import io.cloudevents.jackson.PojoCloudEventDataMapper;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public class CloudEventMapper {
-
- private static final ObjectMapper objectMapper = new ObjectMapper();
-
- /**
- * Generic method to map cloud event data to target event class object.
- *
- * @param cloudEvent input cloud event
- * @param targetEventClass target event class
- * @param <T> target event class type
- * @return mapped target event
- */
- public static <T> T toTargetEvent(final CloudEvent cloudEvent, final Class<T> targetEventClass) {
- PojoCloudEventData<T> mappedCloudEvent = null;
-
- try {
- mappedCloudEvent =
- CloudEventUtils.mapData(cloudEvent, PojoCloudEventDataMapper.from(objectMapper, targetEventClass));
-
- } catch (final RuntimeException runtimeException) {
- log.error("Unable to map cloud event to target event class type : {} with cause : {}", targetEventClass,
- runtimeException.getMessage());
- }
-
- return mappedCloudEvent == null ? null : mappedCloudEvent.getValue();
- }
-
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/DataOperationEventCreator.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/DataOperationEventCreator.java
index 42bad89f52..68b14349df 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/DataOperationEventCreator.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/data/operation/DataOperationEventCreator.java
@@ -29,11 +29,11 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.api.NcmpResponseStatus;
-import org.onap.cps.ncmp.api.impl.events.NcmpEvent;
import org.onap.cps.ncmp.api.impl.operations.DmiDataOperation;
import org.onap.cps.ncmp.events.async1_0_0.Data;
import org.onap.cps.ncmp.events.async1_0_0.DataOperationEvent;
import org.onap.cps.ncmp.events.async1_0_0.Response;
+import org.onap.cps.ncmp.utils.events.NcmpEvent;
import org.springframework.util.MultiValueMap;
@Slf4j