diff options
author | 2022-07-04 22:49:41 +0100 | |
---|---|---|
committer | 2022-07-05 17:33:52 +0100 | |
commit | 43c8d0fee7a900af2b7ca6adcb42037243a47a5a (patch) | |
tree | aad31e6184e44f413f27ad353776fb558f7eb727 /cps-ncmp-service/src/main | |
parent | 2aab13b140cbb13fc7ab880b576c75f42a774415 (diff) |
Move persistence methods from NCMPproperty handler
Issue-ID: CPS-1117
Signed-off-by: emaclee <lee.anjella.macabuhay@est.tech>
Change-Id: If6a0c620970a2a34a601267c6610f85e4bc07f60
Diffstat (limited to 'cps-ncmp-service/src/main')
3 files changed, 41 insertions, 41 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java index aae2f209a..d9aeaf258 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServicePropertyHandler.java @@ -23,10 +23,6 @@ package org.onap.cps.ncmp.api.impl; import static org.onap.cps.ncmp.api.impl.NetworkCmProxyDataServicePropertyHandler.PropertyType.DMI_PROPERTY; import static org.onap.cps.ncmp.api.impl.NetworkCmProxyDataServicePropertyHandler.PropertyType.PUBLIC_PROPERTY; -import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NCMP_DATASPACE_NAME; -import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NCMP_DMI_REGISTRY_ANCHOR; -import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NCMP_DMI_REGISTRY_PARENT; -import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NO_TIMESTAMP; import com.google.common.collect.ImmutableMap; import java.util.ArrayList; @@ -39,11 +35,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.onap.cps.api.CpsDataService; +import org.onap.cps.ncmp.api.inventory.InventoryPersistence; import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse; import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationError; import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; -import org.onap.cps.spi.FetchDescendantsOption; import org.onap.cps.spi.exceptions.DataNodeNotFoundException; import org.onap.cps.spi.exceptions.DataValidationException; import org.onap.cps.spi.model.DataNode; @@ -58,9 +53,7 @@ import org.springframework.stereotype.Service; @SuppressWarnings("squid:S5852") public class NetworkCmProxyDataServicePropertyHandler { - private static final String CM_HANDLE_XPATH_TEMPLATE = NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='%s']"; - - private final CpsDataService cpsDataService; + private final InventoryPersistence inventoryPersistence; /** * Iterates over incoming ncmpServiceCmHandles and update the dataNodes based on the updated attributes. @@ -72,31 +65,28 @@ public class NetworkCmProxyDataServicePropertyHandler { final Collection<NcmpServiceCmHandle> ncmpServiceCmHandles) { final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses = new ArrayList<>(); for (final NcmpServiceCmHandle ncmpServiceCmHandle : ncmpServiceCmHandles) { - final String cmHandle = ncmpServiceCmHandle.getCmHandleId(); + final String cmHandleId = ncmpServiceCmHandle.getCmHandleId(); try { - CpsValidator.validateNameCharacters(cmHandle); - final String cmHandleXpath = String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandle); - final DataNode existingCmHandleDataNode = - cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, cmHandleXpath, - FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); + CpsValidator.validateNameCharacters(cmHandleId); + final DataNode existingCmHandleDataNode = inventoryPersistence.getCmHandleDataNode(cmHandleId); processUpdates(existingCmHandleDataNode, ncmpServiceCmHandle); - cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandle)); + cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)); } catch (final DataNodeNotFoundException e) { log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}", - cmHandle, e.getMessage()); + cmHandleId, e.getMessage()); cmHandleRegistrationResponses.add(CmHandleRegistrationResponse - .createFailureResponse(cmHandle, RegistrationError.CM_HANDLE_DOES_NOT_EXIST)); + .createFailureResponse(cmHandleId, RegistrationError.CM_HANDLE_DOES_NOT_EXIST)); } catch (final DataValidationException e) { log.error("Unable to update cm handle : {}, caused by : {}", - cmHandle, e.getMessage()); + cmHandleId, e.getMessage()); cmHandleRegistrationResponses.add( - CmHandleRegistrationResponse.createFailureResponse(cmHandle, + CmHandleRegistrationResponse.createFailureResponse(cmHandleId, RegistrationError.CM_HANDLE_INVALID_ID)); } catch (final Exception exception) { log.error("Unable to update cmHandle : {} , caused by : {}", - cmHandle, exception.getMessage()); + cmHandleId, exception.getMessage()); cmHandleRegistrationResponses.add( - CmHandleRegistrationResponse.createFailureResponse(cmHandle, exception)); + CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception)); } } return cmHandleRegistrationResponses; @@ -120,8 +110,7 @@ public class NetworkCmProxyDataServicePropertyHandler { if (replacementPropertyDataNodes.isEmpty()) { removeAllProperties(existingCmHandleDataNode, propertyType); } else { - cpsDataService.replaceListContent(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - existingCmHandleDataNode.getXpath(), replacementPropertyDataNodes, NO_TIMESTAMP); + inventoryPersistence.replaceListContent(existingCmHandleDataNode.getXpath(), replacementPropertyDataNodes); } } @@ -130,8 +119,7 @@ public class NetworkCmProxyDataServicePropertyHandler { final Matcher matcher = propertyType.propertyXpathPattern.matcher(dataNode.getXpath()); if (matcher.find()) { log.info("Deleting dataNode with xpath : [{}]", dataNode.getXpath()); - cpsDataService.deleteDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, dataNode.getXpath(), - NO_TIMESTAMP); + inventoryPersistence.deleteDataNode(dataNode.getXpath()); } }); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/constants/DmiRegistryConstants.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/constants/DmiRegistryConstants.java index c29c725d7..a133cfb80 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/constants/DmiRegistryConstants.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/constants/DmiRegistryConstants.java @@ -32,11 +32,5 @@ public final class DmiRegistryConstants { public static final String NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME = "NFP-Operational"; - public static final String NCMP_DATASPACE_NAME = "NCMP-Admin"; - - public static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry"; - - public static final String NCMP_DMI_REGISTRY_PARENT = "/dmi-registry"; - public static final OffsetDateTime NO_TIMESTAMP = null; } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java index 19cf22598..af01fb439 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java @@ -58,7 +58,7 @@ public class InventoryPersistence { private static final String NCMP_DMI_REGISTRY_PARENT = "/dmi-registry"; - private String xpathCmHandle = "/dmi-registry/cm-handles[@id='" + "%s" + "']"; + private static final String CM_HANDLE_XPATH_TEMPLATE = "/dmi-registry/cm-handles[@id='" + "%s" + "']"; private static final String ANCESTOR_CM_HANDLES = "\"]/ancestor::cm-handles"; @@ -80,7 +80,7 @@ public class InventoryPersistence { */ public CompositeState getCmHandleState(final String cmHandleId) { final DataNode stateAsDataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - String.format(xpathCmHandle, cmHandleId) + "/state", + String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId) + "/state", FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); return new CompositeStateBuilder().fromDataNode(stateAsDataNode).build(); } @@ -95,7 +95,7 @@ public class InventoryPersistence { final String cmHandleJsonData = String.format("{\"state\":%s}", jsonObjectMapper.asJsonString(compositeState)); cpsDataService.replaceNodeTree(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - String.format(xpathCmHandle, cmHandleId), + String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId), cmHandleJsonData, OffsetDateTime.now()); } @@ -241,14 +241,11 @@ public class InventoryPersistence { /** * Get data node of given cm handle. * - * @param cmHandle cm handle + * @param cmHandleId cmHandle ID * @return data node */ - private DataNode getCmHandleDataNode(final String cmHandle) { - return cpsDataService.getDataNode(NCMP_DATASPACE_NAME, - NCMP_DMI_REGISTRY_ANCHOR, - String.format(xpathCmHandle, cmHandle), - FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); + public DataNode getCmHandleDataNode(final String cmHandleId) { + return this.getDataNode(String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId)); } /** @@ -269,4 +266,25 @@ public class InventoryPersistence { public Collection<Anchor> getAnchors() { return cpsAdminPersistenceService.getAnchors(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME); } + + /** + * Replaces list content by removing all existing elements and inserting the given new elements as data nodes. + * + * @param parentNodeXpath parent node xpath + * @param dataNodes datanodes representing the updated data + */ + public void replaceListContent(final String parentNodeXpath, final Collection<DataNode> dataNodes) { + cpsDataService.replaceListContent(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, + parentNodeXpath, dataNodes, NO_TIMESTAMP); + } + + /** + * Deletes data node for given anchor and dataspace. + * + * @param dataNodeXpath data node xpath + */ + public void deleteDataNode(final String dataNodeXpath) { + cpsDataService.deleteDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, dataNodeXpath, + NO_TIMESTAMP); + } }
\ No newline at end of file |