summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src/main')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/YangDataConverter.java46
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java32
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java41
3 files changed, 27 insertions, 92 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/YangDataConverter.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/YangDataConverter.java
index f8e06593c5..7466308981 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/YangDataConverter.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/YangDataConverter.java
@@ -91,40 +91,6 @@ public class YangDataConverter {
}
/**
- * This method convert cm handle data node to yang model cm handle without using NcmpServiceCmHandle.
- *
- * @param cmHandleDataNode the datanode of the cm handle
- * @param cmHandleId the id of the cm handle
- * @return yang model cm handle
- */
- public static YangModelCmHandle convertCmHandleToYangModelWithoutNcmpServiceCmHandle(
- final DataNode cmHandleDataNode,
- final String cmHandleId) {
- final Map<String, String> dmiProperties = new LinkedHashMap<>();
- final Map<String, String> publicProperties = new LinkedHashMap<>();
- final CompositeStateBuilder compositeStateBuilder = new CompositeStateBuilder();
- CompositeState compositeState = compositeStateBuilder.build();
- for (final DataNode childDataNode : cmHandleDataNode.getChildDataNodes()) {
- if (childDataNode.getXpath().contains("/additional-properties[@name=")) {
- addProperty(childDataNode, dmiProperties);
- } else if (childDataNode.getXpath().contains("/public-properties[@name=")) {
- addProperty(childDataNode, publicProperties);
- } else if (childDataNode.getXpath().endsWith("/state")) {
- compositeState = compositeStateBuilder.fromDataNode(childDataNode).build();
- }
- }
- return YangModelCmHandle.toYangModelCmHandleWithoutNcmpServiceHandle(
- (String) cmHandleDataNode.getLeaves().get("dmi-service-name"),
- (String) cmHandleDataNode.getLeaves().get("dmi-data-service-name"),
- (String) cmHandleDataNode.getLeaves().get("dmi-model-service-name"),
- cmHandleId,
- dmiProperties,
- publicProperties,
- compositeState
- );
- }
-
- /**
* This method convert cm handle data nodes to yang model cm handles.
* @param cmHandleDataNodes the datanode of the cm handle
* @return yang model cm handles
@@ -134,21 +100,15 @@ public class YangDataConverter {
final Collection<YangModelCmHandle> yangModelCmHandles = new ArrayList<>(cmHandleDataNodes.size());
cmHandleDataNodes.forEach(dataNode -> {
final String cmHandleId = extractCmHandleIdFromXpath(dataNode.getXpath());
- if (cmHandleId != null) {
- yangModelCmHandles.add(convertCmHandleToYangModelWithoutNcmpServiceCmHandle(dataNode, cmHandleId));
- }
+ yangModelCmHandles.add(convertCmHandleToYangModel(dataNode, cmHandleId));
});
return yangModelCmHandles;
}
private static String extractCmHandleIdFromXpath(final String xpath) {
final Matcher matcher = cmHandleIdInXpathPattern.matcher(xpath);
- if (matcher.find()) {
- return matcher.group(1);
- } else {
- log.error("Unexpected xpath {}", xpath);
- }
- return null;
+ matcher.find();
+ return matcher.group(1);
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java
index 5f98f14995..a6f953aa86 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/yangmodels/YangModelCmHandle.java
@@ -115,38 +115,6 @@ public class YangModelCmHandle {
return yangModelCmHandle;
}
-
- /**
- * Create a yangModelCmHandle without the use of NcmpServiceHandle.
- *
- * @param dmiServiceName dmi service name
- * @param dmiDataServiceName dmi data service name
- * @param dmiModelServiceName dmi model service name
- * @param cmHandleId the cm handle id
- * @param dmiProperties dmiProperties
- * @param publicProperties publicProperties
- * @param compositeState compositeState
- * @return instance of yangModelCmHandle
- */
- public static YangModelCmHandle toYangModelCmHandleWithoutNcmpServiceHandle(final String dmiServiceName,
- final String dmiDataServiceName,
- final String dmiModelServiceName,
- final String cmHandleId,
- final Map<String, String> dmiProperties,
- final Map<String, String> publicProperties,
- final CompositeState compositeState) {
- final YangModelCmHandle yangModelCmHandle = new YangModelCmHandle();
- yangModelCmHandle.setId(cmHandleId);
- yangModelCmHandle.setDmiServiceName(dmiServiceName);
- yangModelCmHandle.setDmiDataServiceName(dmiDataServiceName);
- yangModelCmHandle.setDmiModelServiceName(dmiModelServiceName);
- yangModelCmHandle.setDmiProperties(asYangModelCmHandleProperties(dmiProperties));
- yangModelCmHandle.setPublicProperties(asYangModelCmHandleProperties(publicProperties));
- yangModelCmHandle.setCompositeState(compositeState);
- return yangModelCmHandle;
- }
-
-
/**
* Resolve a dmi service name.
*
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java
index c2578ccbf7..4d1202b065 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistenceImpl.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation
+ * Copyright (C) 2022-2023 Nordix Foundation
* Modifications Copyright (C) 2022 Bell Canada
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,7 +33,6 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsAdminService;
@@ -62,8 +61,6 @@ public class InventoryPersistenceImpl implements InventoryPersistence {
private static final String NCMP_DMI_REGISTRY_PARENT = "/dmi-registry";
- private static final String CM_HANDLE_XPATH_TEMPLATE = "/dmi-registry/cm-handles[@id='" + "%s" + "']";
-
private final JsonObjectMapper jsonObjectMapper;
private final CpsDataService cpsDataService;
@@ -77,7 +74,7 @@ public class InventoryPersistenceImpl implements InventoryPersistence {
@Override
public CompositeState getCmHandleState(final String cmHandleId) {
final DataNode stateAsDataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId) + "/state",
+ createCmHandleXPath(cmHandleId) + "/state",
FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
cpsValidator.validateNameCharacters(cmHandleId);
return new CompositeStateBuilder().fromDataNode(stateAsDataNode).build();
@@ -85,10 +82,9 @@ public class InventoryPersistenceImpl implements InventoryPersistence {
@Override
public void saveCmHandleState(final String cmHandleId, final CompositeState compositeState) {
- final String cmHandleJsonData = String.format("{\"state\":%s}",
- jsonObjectMapper.asJsonString(compositeState));
+ final String cmHandleJsonData = createStateJsonData(jsonObjectMapper.asJsonString(compositeState));
cpsDataService.updateDataNodeAndDescendants(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId),
+ createCmHandleXPath(cmHandleId),
cmHandleJsonData, OffsetDateTime.now());
}
@@ -96,8 +92,8 @@ public class InventoryPersistenceImpl implements InventoryPersistence {
public void saveCmHandleStateBatch(final Map<String, CompositeState> cmHandleStatePerCmHandleId) {
final Map<String, String> cmHandlesJsonDataMap = new HashMap<>();
cmHandleStatePerCmHandleId.forEach((cmHandleId, compositeState) -> cmHandlesJsonDataMap.put(
- String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId),
- String.format("{\"state\":%s}", jsonObjectMapper.asJsonString(compositeState))));
+ createCmHandleXPath(cmHandleId),
+ createStateJsonData(jsonObjectMapper.asJsonString(compositeState))));
cpsDataService.updateDataNodesAndDescendants(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
cmHandlesJsonDataMap, OffsetDateTime.now());
}
@@ -110,7 +106,7 @@ public class InventoryPersistenceImpl implements InventoryPersistence {
@Override
public Collection<YangModelCmHandle> getYangModelCmHandles(final Collection<String> cmHandleIds) {
- final Collection<String> validCmHandleIds = new ArrayList<>();
+ final Collection<String> validCmHandleIds = new ArrayList<>(cmHandleIds.size());
cmHandleIds.forEach(cmHandleId -> {
try {
cpsValidator.validateNameCharacters(cmHandleId);
@@ -137,7 +133,7 @@ public class InventoryPersistenceImpl implements InventoryPersistence {
@Override
public void saveCmHandle(final YangModelCmHandle yangModelCmHandle) {
final String cmHandleJsonData =
- String.format("{\"cm-handles\":[%s]}", jsonObjectMapper.asJsonString(yangModelCmHandle));
+ createCmHandleJsonData(jsonObjectMapper.asJsonString(yangModelCmHandle));
cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, NCMP_DMI_REGISTRY_PARENT,
cmHandleJsonData, NO_TIMESTAMP);
}
@@ -146,7 +142,7 @@ public class InventoryPersistenceImpl implements InventoryPersistence {
public void saveCmHandleBatch(final Collection<YangModelCmHandle> yangModelCmHandles) {
final List<String> cmHandlesJsonData = new ArrayList<>();
yangModelCmHandles.forEach(yangModelCmHandle -> cmHandlesJsonData.add(
- String.format("{\"cm-handles\":[%s]}", jsonObjectMapper.asJsonString(yangModelCmHandle))));
+ createCmHandleJsonData(jsonObjectMapper.asJsonString(yangModelCmHandle))));
cpsDataService.saveListElementsBatch(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
NCMP_DMI_REGISTRY_PARENT, cmHandlesJsonData, NO_TIMESTAMP);
}
@@ -199,14 +195,13 @@ public class InventoryPersistenceImpl implements InventoryPersistence {
@Override
public DataNode getCmHandleDataNode(final String cmHandleId) {
- return this.getDataNode(String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId));
+ return this.getDataNode(createCmHandleXPath(cmHandleId));
}
@Override
public Collection<DataNode> getCmHandleDataNodes(final Collection<String> cmHandleIds) {
- final Collection<String> xpaths = cmHandleIds.stream().map(cmHandleId ->
- String.format(CM_HANDLE_XPATH_TEMPLATE, cmHandleId))
- .collect(Collectors.toList());
+ final Collection<String> xpaths = new ArrayList<>(cmHandleIds.size());
+ cmHandleIds.forEach(cmHandleId -> xpaths.add(createCmHandleXPath(cmHandleId)));
return this.getDataNodes(xpaths);
}
@@ -230,4 +225,16 @@ public class InventoryPersistenceImpl implements InventoryPersistence {
public void deleteDataNodes(final Collection<String> dataNodeXpaths) {
cpsDataService.deleteDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, dataNodeXpaths, NO_TIMESTAMP);
}
+
+ private static String createCmHandleXPath(final String cmHandleId) {
+ return "/dmi-registry/cm-handles[@id='" + cmHandleId + "']";
+ }
+
+ private static String createStateJsonData(final String state) {
+ return "{\"state\":" + state + "}";
+ }
+
+ private static String createCmHandleJsonData(final String cmHandleId) {
+ return "{\"cm-handles\":[" + cmHandleId + "]}";
+ }
} \ No newline at end of file