summaryrefslogtreecommitdiffstats
path: root/cps-service/src/main/java
diff options
context:
space:
mode:
authorDylanB95EST <dylan.byrne@est.tech>2021-10-29 17:33:06 +0100
committerDylanB95EST <dylan.byrne@est.tech>2021-11-02 11:59:14 +0000
commita79c9f1bdf335843c29a425da53c15b5e353e5a3 (patch)
tree4299454209e6187220728440160c7934db31c825 /cps-service/src/main/java
parent717215a36dde7bedb4257e693650c8728056b9d6 (diff)
Clean Up Code around List Nodes
Make sure code refers clearly to List (whole) nodes or List elements incl. method names, parameter names, test descriptions etc. Issue-ID: CPS-756 Change-Id: Ic9dae6565c0e84c1ba4c2d6e891d3ea307f589da Signed-off-by: DylanB95EST <dylan.byrne@est.tech>
Diffstat (limited to 'cps-service/src/main/java')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsDataService.java34
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java47
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java41
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/spi/exceptions/DataNodeNotFoundException.java15
-rw-r--r--cps-service/src/main/java/org/onap/cps/utils/DataMapUtils.java6
5 files changed, 86 insertions, 57 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
index 31a7517340..e6cb65fa78 100644
--- a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
@@ -56,17 +56,18 @@ public interface CpsDataService {
@NonNull String jsonData, OffsetDateTime observedTimestamp);
/**
- * Persists child data fragment representing list-node (with one or more elements) under existing data node for the
+ * Persists child data fragment representing one or more list elements under existing data node for the
* given anchor and dataspace.
*
- * @param dataspaceName dataspace name
- * @param anchorName anchor name
- * @param parentNodeXpath parent node xpath
- * @param jsonData json data representing list element
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param parentNodeXpath parent node xpath
+ * @param jsonData json data representing list element(s)
* @param observedTimestamp observedTimestamp
*/
- void saveListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
- @NonNull String jsonData, OffsetDateTime observedTimestamp);
+ void saveListElements(@NonNull String dataspaceName, @NonNull String anchorName,
+ @NonNull String parentNodeXpath,
+ @NonNull String jsonData, OffsetDateTime observedTimestamp);
/**
* Retrieves datanode by XPath for given dataspace and anchor.
@@ -106,29 +107,28 @@ public interface CpsDataService {
@NonNull String jsonData, OffsetDateTime observedTimestamp);
/**
- * Replaces (if exists) child data fragment representing list-node (with one or more elements) under existing data
- * node for the given anchor and dataspace.
+ * Replaces list content by removing all existing elements and inserting the given new elements as json
+ * under given parent, anchor and dataspace.
*
* @param dataspaceName dataspace name
* @param anchorName anchor name
* @param parentNodeXpath parent node xpath
- * @param jsonData json data representing list element
+ * @param jsonData json data representing the new list elements
* @param observedTimestamp observedTimestamp
*/
- void replaceListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
- @NonNull String jsonData, OffsetDateTime observedTimestamp);
+ void replaceListContent(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
+ @NonNull String jsonData, OffsetDateTime observedTimestamp);
/**
- * Deletes (if exists) child data fragment representing list-node (with one or more elements) under existing data
- * node for the given anchor and dataspace.
+ * Deletes a list or a list-element under given anchor and dataspace.
*
* @param dataspaceName dataspace name
* @param anchorName anchor name
- * @param listNodeXpath list node xpath
+ * @param listElementXpath list element xpath
* @param observedTimestamp observedTimestamp
*/
- void deleteListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String listNodeXpath,
- OffsetDateTime observedTimestamp);
+ void deleteListOrListElement(@NonNull String dataspaceName, @NonNull String anchorName,
+ @NonNull String listElementXpath, OffsetDateTime observedTimestamp);
/**
* Updates leaves of DataNode for given dataspace and anchor using xpath, along with the leaves of each Child Data
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
index 7b3567ed3c..44a17f89dd 100755
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java
@@ -64,7 +64,7 @@ public class CpsDataServiceImpl implements CpsDataService {
@Override
public void saveData(final String dataspaceName, final String anchorName, final String jsonData,
final OffsetDateTime observedTimestamp) {
- final var dataNode = buildDataNodeFromJson(dataspaceName, anchorName, ROOT_NODE_XPATH, jsonData);
+ final var dataNode = buildDataNode(dataspaceName, anchorName, ROOT_NODE_XPATH, jsonData);
cpsDataPersistenceService.storeDataNode(dataspaceName, anchorName, dataNode);
processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp);
}
@@ -72,17 +72,18 @@ public class CpsDataServiceImpl implements CpsDataService {
@Override
public void saveData(final String dataspaceName, final String anchorName, final String parentNodeXpath,
final String jsonData, final OffsetDateTime observedTimestamp) {
- final var dataNode = buildDataNodeFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
+ final var dataNode = buildDataNode(dataspaceName, anchorName, parentNodeXpath, jsonData);
cpsDataPersistenceService.addChildDataNode(dataspaceName, anchorName, parentNodeXpath, dataNode);
processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp);
}
@Override
- public void saveListNodeData(final String dataspaceName, final String anchorName,
+ public void saveListElements(final String dataspaceName, final String anchorName,
final String parentNodeXpath, final String jsonData, final OffsetDateTime observedTimestamp) {
- final Collection<DataNode> dataNodesCollection =
- buildDataNodeCollectionFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
- cpsDataPersistenceService.addListDataNodes(dataspaceName, anchorName, parentNodeXpath, dataNodesCollection);
+ final Collection<DataNode> listElementDataNodeCollection =
+ buildDataNodes(dataspaceName, anchorName, parentNodeXpath, jsonData);
+ cpsDataPersistenceService.addListElements(dataspaceName, anchorName, parentNodeXpath,
+ listElementDataNodeCollection);
processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp);
}
@@ -95,7 +96,7 @@ public class CpsDataServiceImpl implements CpsDataService {
@Override
public void updateNodeLeaves(final String dataspaceName, final String anchorName, final String parentNodeXpath,
final String jsonData, final OffsetDateTime observedTimestamp) {
- final var dataNode = buildDataNodeFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
+ final var dataNode = buildDataNode(dataspaceName, anchorName, parentNodeXpath, jsonData);
cpsDataPersistenceService
.updateDataLeaves(dataspaceName, anchorName, dataNode.getXpath(), dataNode.getLeaves());
processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp);
@@ -107,7 +108,8 @@ public class CpsDataServiceImpl implements CpsDataService {
final String dataNodeUpdatesAsJson,
final OffsetDateTime observedTimestamp) {
final Collection<DataNode> dataNodeUpdates =
- buildDataNodeCollectionFromJson(dataspaceName, anchorName, parentNodeXpath, dataNodeUpdatesAsJson);
+ buildDataNodes(dataspaceName, anchorName,
+ parentNodeXpath, dataNodeUpdatesAsJson);
for (final DataNode dataNodeUpdate : dataNodeUpdates) {
processDataNodeUpdate(dataspaceName, anchorName, dataNodeUpdate);
}
@@ -117,30 +119,29 @@ public class CpsDataServiceImpl implements CpsDataService {
@Override
public void replaceNodeTree(final String dataspaceName, final String anchorName, final String parentNodeXpath,
final String jsonData, final OffsetDateTime observedTimestamp) {
- final var dataNode = buildDataNodeFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
+ final var dataNode = buildDataNode(dataspaceName, anchorName, parentNodeXpath, jsonData);
cpsDataPersistenceService.replaceDataNodeTree(dataspaceName, anchorName, dataNode);
processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp);
}
@Override
- public void replaceListNodeData(final String dataspaceName, final String anchorName, final String parentNodeXpath,
- final String jsonData, final OffsetDateTime observedTimestamp) {
- final Collection<DataNode> dataNodes =
- buildDataNodeCollectionFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
- cpsDataPersistenceService.replaceListDataNodes(dataspaceName, anchorName, parentNodeXpath, dataNodes);
+ public void replaceListContent(final String dataspaceName, final String anchorName, final String parentNodeXpath,
+ final String jsonData, final OffsetDateTime observedTimestamp) {
+ final Collection<DataNode> newListElements =
+ buildDataNodes(dataspaceName, anchorName, parentNodeXpath, jsonData);
+ cpsDataPersistenceService.replaceListContent(dataspaceName, anchorName, parentNodeXpath, newListElements);
processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp);
}
@Override
- public void deleteListNodeData(final String dataspaceName, final String anchorName, final String listNodeXpath,
+ public void deleteListOrListElement(final String dataspaceName, final String anchorName, final String listNodeXpath,
final OffsetDateTime observedTimestamp) {
- cpsDataPersistenceService.deleteListDataNodes(dataspaceName, anchorName, listNodeXpath);
+ cpsDataPersistenceService.deleteListDataNode(dataspaceName, anchorName, listNodeXpath);
processDataUpdatedEventAsync(dataspaceName, anchorName, observedTimestamp);
}
-
- private DataNode buildDataNodeFromJson(final String dataspaceName, final String anchorName,
- final String parentNodeXpath, final String jsonData) {
+ private DataNode buildDataNode(final String dataspaceName, final String anchorName,
+ final String parentNodeXpath, final String jsonData) {
final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
final var schemaContext = getSchemaContext(dataspaceName, anchor.getSchemaSetName());
@@ -157,8 +158,10 @@ public class CpsDataServiceImpl implements CpsDataService {
.build();
}
- private Collection<DataNode> buildDataNodeCollectionFromJson(final String dataspaceName, final String anchorName,
- final String parentNodeXpath, final String jsonData) {
+ private Collection<DataNode> buildDataNodes(final String dataspaceName,
+ final String anchorName,
+ final String parentNodeXpath,
+ final String jsonData) {
final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
final var schemaContext = getSchemaContext(dataspaceName, anchor.getSchemaSetName());
@@ -169,7 +172,7 @@ public class CpsDataServiceImpl implements CpsDataService {
.withNormalizedNodeTree(normalizedNode)
.buildCollection();
if (dataNodes.isEmpty()) {
- throw new DataValidationException("Invalid list data.", "List node is empty.");
+ throw new DataValidationException("Invalid data.", "No data nodes provided");
}
return dataNodes;
diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
index bf8dd1a073..b8c472f277 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
@@ -55,16 +55,16 @@ public interface CpsDataPersistenceService {
@NonNull DataNode dataNode);
/**
- * Adds list node child elements to a Fragment.
+ * Adds list child elements to a Fragment.
*
- * @param dataspaceName dataspace name
- * @param anchorName anchor name
- * @param parentNodeXpath parent node xpath
- * @param dataNodes collection of data nodes representing list node elements
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param parentNodeXpath parent node xpath
+ * @param listElementsCollection collection of data nodes representing list elements
*/
- void addListDataNodes(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
- @NonNull Collection<DataNode> dataNodes);
+ void addListElements(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String parentNodeXpath,
+ @NonNull Collection<DataNode> listElementsCollection);
/**
* Retrieves datanode by XPath for given dataspace and anchor.
@@ -101,25 +101,36 @@ public interface CpsDataPersistenceService {
void replaceDataNodeTree(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull DataNode dataNode);
/**
- * Replaces existing list data node content including descendants.
+ * Replaces list content by removing all existing elements and inserting the given new elements
+ * under given parent, anchor and dataspace.
*
* @param dataspaceName dataspace name
* @param anchorName anchor name
* @param parentNodeXpath parent node xpath
- * @param dataNodes collection of data nodes representing list node elements
+ * @param newListElements collection of data nodes representing the new list content
+ */
+ void replaceListContent(@NonNull String dataspaceName, @NonNull String anchorName,
+ @NonNull String parentNodeXpath, @NonNull Collection<DataNode> newListElements);
+
+ /**
+ * Deletes any dataNode, yang container or yang list or yang list element.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param targetXpath xpath to list or list element (include [@key=value] to delete a single list element)
*/
- void replaceListDataNodes(@NonNull String dataspaceName, @NonNull String anchorName,
- @NonNull String parentNodeXpath, @NonNull Collection<DataNode> dataNodes);
+ void deleteDataNode(@NonNull String dataspaceName, @NonNull String anchorName,
+ @NonNull String targetXpath);
/**
- * Deletes existing list data node content including descendants.
+ * Deletes existing a single list element or the whole list.
*
* @param dataspaceName dataspace name
* @param anchorName anchor name
- * @param listNodeXpath list node xpath
+ * @param targetXpath xpath to list or list element (include [@key=value] to delete a single list element)
*/
- void deleteListDataNodes(@NonNull String dataspaceName, @NonNull String anchorName,
- @NonNull String listNodeXpath);
+ void deleteListDataNode(@NonNull String dataspaceName, @NonNull String anchorName,
+ @NonNull String targetXpath);
/**
* Get a datanode by cps path.
diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataNodeNotFoundException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataNodeNotFoundException.java
index 848d5692c1..b717a2b183 100755
--- a/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataNodeNotFoundException.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/DataNodeNotFoundException.java
@@ -31,6 +31,21 @@ public class DataNodeNotFoundException extends DataValidationException {
/**
* Constructor.
*
+ * @param dataspaceName the name of the dataspace
+ * @param anchorName the anchor name
+ * @param xpath datanode xpath
+ * @param additionalInformation additional information
+ */
+ public DataNodeNotFoundException(final String dataspaceName, final String anchorName, final String xpath,
+ final String additionalInformation) {
+ super("DataNode not found", String
+ .format("DataNode with xpath %s was not found for anchor %s and dataspace %s, %s.", xpath,
+ anchorName, dataspaceName, additionalInformation));
+ }
+
+ /**
+ * Constructor.
+ *
* @param dataspaceName the name of the dataspace
* @param anchorName the anchor name
* @param xpath datanode xpath
diff --git a/cps-service/src/main/java/org/onap/cps/utils/DataMapUtils.java b/cps-service/src/main/java/org/onap/cps/utils/DataMapUtils.java
index 3ee6afb719..71a95f1ca0 100644
--- a/cps-service/src/main/java/org/onap/cps/utils/DataMapUtils.java
+++ b/cps-service/src/main/java/org/onap/cps/utils/DataMapUtils.java
@@ -58,7 +58,7 @@ public class DataMapUtils {
return ImmutableMap.<String, Object>builder()
.putAll(
dataNodes.stream()
- .filter(dataNode -> isListNode(dataNode.getXpath()))
+ .filter(dataNode -> isListElement(dataNode.getXpath()))
.collect(groupingBy(
dataNode -> getNodeIdentifier(dataNode.getXpath()),
mapping(DataMapUtils::toDataMap, toUnmodifiableList())
@@ -86,10 +86,10 @@ public class DataMapUtils {
}
private static boolean isContainerNode(final String xpath) {
- return !isListNode(xpath);
+ return !isListElement(xpath);
}
- private static boolean isListNode(final String xpath) {
+ private static boolean isListElement(final String xpath) {
return xpath.endsWith("]");
}
}