diff options
author | mpriyank <priyank.maheshwari@est.tech> | 2022-07-21 16:38:55 +0100 |
---|---|---|
committer | mpriyank <priyank.maheshwari@est.tech> | 2022-08-04 10:16:46 +0100 |
commit | eaa94ffea1871c04b5db95e4619c2a8b4e6bc166 (patch) | |
tree | 08b7224992bbbd36a0de92cfbc4fe4bf23b89720 /cps-ncmp-service/src/main/java/org | |
parent | 7dfc3a01f327654d64451865ac05b819c5583b27 (diff) |
LcmEvent state handler refactoring
- State handler will now handle new structure of LcmEvent.
- We have 3 types of events i.e create, update and delete.
- Introduced the LcmEventCreatorHelper to delegate some of the
responsibility of event creation based on event type and the state.
- New tests and existing refactoring
- Code rebased
- Refactored name as per group code review
- Code rebase with other commits
- Used copy constructor for deep copy operation of NcmpServiceCmhandle
and CompositeState
- UPCOMING : Related user stories to trigger the event publishing using
state handler.
Issue-ID: CPS-1128
Change-Id: I94b5a87d37d6a174c017ee0aa37cd0f0f74ba084
Signed-off-by: mpriyank <priyank.maheshwari@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main/java/org')
6 files changed, 351 insertions, 27 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventType.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventType.java new file mode 100644 index 0000000000..f793dedb8d --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventType.java @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 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.event.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/event/lcm/LcmEventsCmHandleStateHandlerImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImpl.java index 9027a6eb0d..fd46ee8604 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCmHandleStateHandlerImpl.java @@ -30,6 +30,7 @@ import lombok.extern.slf4j.Slf4j; import org.onap.cps.ncmp.api.impl.utils.YangDataConverter; import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle; import org.onap.cps.ncmp.api.inventory.CmHandleState; +import org.onap.cps.ncmp.api.inventory.CompositeState; import org.onap.cps.ncmp.api.inventory.CompositeStateUtils; import org.onap.cps.ncmp.api.inventory.InventoryPersistence; import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; @@ -45,15 +46,20 @@ public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleState private final LcmEventsCreator lcmEventsCreator; private final LcmEventsService lcmEventsService; - @Override public void updateCmHandleState(final YangModelCmHandle yangModelCmHandle, final CmHandleState targetCmHandleState) { - if (yangModelCmHandle.getCompositeState().getCmHandleState() == targetCmHandleState) { + + final CompositeState compositeState = yangModelCmHandle.getCompositeState(); + + if (compositeState != null && compositeState.getCmHandleState() == targetCmHandleState) { log.debug("CmHandle with id : {} already in state : {}", yangModelCmHandle.getId(), targetCmHandleState); } else { + final NcmpServiceCmHandle existingNcmpServiceCmHandle = + new NcmpServiceCmHandle(toNcmpServiceCmHandle(yangModelCmHandle)); updateToSpecifiedCmHandleState(yangModelCmHandle, targetCmHandleState); - publishLcmEvent(yangModelCmHandle); + final NcmpServiceCmHandle targetNcmpServiceCmHandle = toNcmpServiceCmHandle(yangModelCmHandle); + publishLcmEvent(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle); } } @@ -66,10 +72,10 @@ public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleState .accept(yangModelCmHandle.getCompositeState()); inventoryPersistence.saveCmHandleState(yangModelCmHandle.getId(), yangModelCmHandle.getCompositeState()); } else if (ADVISED == targetCmHandleState) { - if (yangModelCmHandle.getCompositeState().getCmHandleState() == LOCKED) { - retryCmHandle(yangModelCmHandle); - } else { + if (yangModelCmHandle.getCompositeState() == null) { registerNewCmHandle(yangModelCmHandle); + } else if (yangModelCmHandle.getCompositeState().getCmHandleState() == LOCKED) { + retryCmHandle(yangModelCmHandle); } } else if (DELETED == targetCmHandleState) { setCmHandleState(yangModelCmHandle, targetCmHandleState); @@ -84,20 +90,21 @@ public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleState } private void registerNewCmHandle(final YangModelCmHandle yangModelCmHandle) { + yangModelCmHandle.setCompositeState(new CompositeState()); setCmHandleState(yangModelCmHandle, ADVISED); inventoryPersistence.saveCmHandle(yangModelCmHandle); } - private void publishLcmEvent(final YangModelCmHandle yangModelCmHandle) { - final NcmpServiceCmHandle ncmpServiceCmHandle = - YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle(yangModelCmHandle); - final String cmHandleId = ncmpServiceCmHandle.getCmHandleId(); - final LcmEvent lcmEvent = lcmEventsCreator.populateLcmEvent(cmHandleId); + private void publishLcmEvent(final NcmpServiceCmHandle targetNcmpServiceCmHandle, + final NcmpServiceCmHandle existingNcmpServiceCmHandle) { + final String cmHandleId = targetNcmpServiceCmHandle.getCmHandleId(); + final LcmEvent lcmEvent = + lcmEventsCreator.populateLcmEvent(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle); lcmEventsService.publishLcmEvent(cmHandleId, lcmEvent); } private void updateAndSaveCmHandleState(final YangModelCmHandle yangModelCmHandle, - final CmHandleState targetCmHandleState) { + final CmHandleState targetCmHandleState) { setCmHandleState(yangModelCmHandle, targetCmHandleState); inventoryPersistence.saveCmHandleState(yangModelCmHandle.getId(), yangModelCmHandle.getCompositeState()); } @@ -105,4 +112,8 @@ public class LcmEventsCmHandleStateHandlerImpl implements LcmEventsCmHandleState private void setCmHandleState(final YangModelCmHandle yangModelCmHandle, final CmHandleState targetCmHandleState) { CompositeStateUtils.setCompositeState(targetCmHandleState).accept(yangModelCmHandle.getCompositeState()); } + + private NcmpServiceCmHandle toNcmpServiceCmHandle(final YangModelCmHandle yangModelCmHandle) { + return YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle(yangModelCmHandle); + } } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreator.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreator.java index 085494aef2..aef1ed9bd0 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreator.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreator.java @@ -21,10 +21,15 @@ package org.onap.cps.ncmp.api.impl.event.lcm; import java.util.UUID; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.onap.cps.ncmp.api.impl.utils.EventDateTimeFormatter; +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; import org.onap.ncmp.cmhandle.event.lcm.Event; import org.onap.ncmp.cmhandle.event.lcm.LcmEvent; +import org.onap.ncmp.cmhandle.event.lcm.Values; import org.springframework.stereotype.Component; @@ -36,37 +41,60 @@ import org.springframework.stereotype.Component; public class LcmEventsCreator { /** - * Populate LcmEvent. + * Populate Lifecycle Management Event. * - * @param cmHandleId Cm Handle Identifier - * @return Populated Lcm 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) { - return createLcmEvent(cmHandleId); + public LcmEvent populateLcmEvent(final String cmHandleId, final NcmpServiceCmHandle targetNcmpServiceCmHandle, + final NcmpServiceCmHandle existingNcmpServiceCmHandle) { + return createLcmEvent(cmHandleId, targetNcmpServiceCmHandle, existingNcmpServiceCmHandle); } - private LcmEvent createLcmEvent(final String cmHandleId) { - final LcmEvent lcmEvent = lcmEventHeader(cmHandleId); - lcmEvent.setEvent(lcmEventPayload(cmHandleId)); + 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 Event lcmEventPayload(final String eventCorrelationId) { + private Event lcmEventPayload(final String eventCorrelationId, final NcmpServiceCmHandle targetNcmpServiceCmHandle, + final NcmpServiceCmHandle existingNcmpServiceCmHandle, final LcmEventType lcmEventType) { final Event event = new Event(); event.setCmHandleId(eventCorrelationId); + final CmHandleValuesHolder cmHandleValuesHolder = + LcmEventsCreatorHelper.determineEventValues(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle, + lcmEventType); + event.setOldValues(cmHandleValuesHolder.getOldValues()); + event.setNewValues(cmHandleValuesHolder.getNewValues()); + return event; } - private LcmEvent lcmEventHeader(final String eventCorrelationId) { + 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.getCurrentDateTime()); lcmEvent.setEventSource("org.onap.ncmp"); - lcmEvent.setEventType("org.onap.ncmp.cmhandle-lcm-event"); + lcmEvent.setEventType(lcmEventType.getEventType()); lcmEvent.setEventSchema("org.onap.ncmp:cmhandle-lcm-event"); - lcmEvent.setEventSchemaVersion("v1"); + lcmEvent.setEventSchemaVersion("1.0"); return lcmEvent; } -} + @NoArgsConstructor + @Getter + @Setter + static class CmHandleValuesHolder { + + private Values oldValues; + private Values newValues; + } + +}
\ No newline at end of file diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreatorHelper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreatorHelper.java new file mode 100644 index 0000000000..1f2cf97fe9 --- /dev/null +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/event/lcm/LcmEventsCreatorHelper.java @@ -0,0 +1,221 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 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.event.lcm; + +import static org.onap.cps.ncmp.api.impl.event.lcm.LcmEventType.CREATE; +import static org.onap.cps.ncmp.api.impl.event.lcm.LcmEventType.DELETE; +import static org.onap.cps.ncmp.api.impl.event.lcm.LcmEventType.UPDATE; +import static org.onap.cps.ncmp.api.inventory.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.models.NcmpServiceCmHandle; +import org.onap.ncmp.cmhandle.event.lcm.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 isDataSyncFlagEnabledChanged = + isDataSyncEnabledFlagChanged(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle); + final boolean isCmHandleStateChanged = + isCmHandleStateChanged(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle); + final boolean isPublicCmHandlePropertiesEqual = + isPublicCmHandlePropertiesEqual(targetNcmpServiceCmHandle.getPublicProperties(), + existingNcmpServiceCmHandle.getPublicProperties()); + + final LcmEventsCreator.CmHandleValuesHolder cmHandleValuesHolder = new LcmEventsCreator.CmHandleValuesHolder(); + + if (isDataSyncFlagEnabledChanged || isCmHandleStateChanged || (!isPublicCmHandlePropertiesEqual)) { + cmHandleValuesHolder.setOldValues(new Values()); + cmHandleValuesHolder.setNewValues(new Values()); + } else { + return cmHandleValuesHolder; + } + + if (isDataSyncFlagEnabledChanged) { + setDataSyncEnabledFlag(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle, cmHandleValuesHolder); + } + + if (isCmHandleStateChanged) { + setCmHandleStateChange(targetNcmpServiceCmHandle, existingNcmpServiceCmHandle, cmHandleValuesHolder); + } + + if (!isPublicCmHandlePropertiesEqual) { + 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 isDataSyncEnabledFlagChanged(final NcmpServiceCmHandle targetNcmpServiceCmHandle, + final NcmpServiceCmHandle existingNcmpServiceCmHandle) { + + return !targetNcmpServiceCmHandle.getCompositeState().getDataSyncEnabled() + .equals(existingNcmpServiceCmHandle.getCompositeState().getDataSyncEnabled()); + } + + private static boolean isCmHandleStateChanged(final NcmpServiceCmHandle targetNcmpServiceCmHandle, + final NcmpServiceCmHandle existingNcmpServiceCmHandle) { + + return targetNcmpServiceCmHandle.getCompositeState().getCmHandleState() + != existingNcmpServiceCmHandle.getCompositeState().getCmHandleState(); + } + + private static boolean isPublicCmHandlePropertiesEqual(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/inventory/CompositeState.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java index e8fcaabe91..bf448c568f 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CompositeState.java @@ -57,8 +57,21 @@ public class CompositeState { /** * Date and Time in the format of yyyy-MM-dd'T'HH:mm:ss.SSSZ */ - private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter - .ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + private static final DateTimeFormatter dateTimeFormatter = + DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + + /** + * Composite State copy constructor. + * + * @param compositeState Composite State + */ + public CompositeState(final CompositeState compositeState) { + this.cmHandleState = compositeState.getCmHandleState(); + this.lockReason = compositeState.getLockReason(); + this.lastUpdateTime = compositeState.getLastUpdateTime(); + this.dataSyncEnabled = compositeState.getDataSyncEnabled(); + this.dataStores = compositeState.getDataStores(); + } /** diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/NcmpServiceCmHandle.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/NcmpServiceCmHandle.java index 963b484ed7..ae40d330ba 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/NcmpServiceCmHandle.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/NcmpServiceCmHandle.java @@ -23,6 +23,7 @@ package org.onap.cps.ncmp.api.models; import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.annotation.Nulls; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.Map; import lombok.Getter; import lombok.NoArgsConstructor; @@ -51,4 +52,16 @@ public class NcmpServiceCmHandle { @JsonSetter(nulls = Nulls.AS_EMPTY) private CompositeState compositeState; + /** + * NcmpServiceCmHandle copy constructor. + * + * @param ncmpServiceCmHandle Ncmp Service CmHandle + */ + public NcmpServiceCmHandle(final NcmpServiceCmHandle ncmpServiceCmHandle) { + this.cmHandleId = ncmpServiceCmHandle.getCmHandleId(); + this.dmiProperties = new LinkedHashMap<>(ncmpServiceCmHandle.getDmiProperties()); + this.publicProperties = new LinkedHashMap<>(ncmpServiceCmHandle.getPublicProperties()); + this.compositeState = ncmpServiceCmHandle.getCompositeState() != null ? new CompositeState( + ncmpServiceCmHandle.getCompositeState()) : null; + } } |