summaryrefslogtreecommitdiffstats
path: root/cps-service/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service/src/main/java/org')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsDataService.java18
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java29
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java13
3 files changed, 52 insertions, 8 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 cde25a9f98..decf67d24e 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
@@ -24,6 +24,7 @@ package org.onap.cps.api;
import java.time.OffsetDateTime;
import java.util.Collection;
+import java.util.Map;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.DataNode;
@@ -93,7 +94,7 @@ public interface CpsDataService {
OffsetDateTime observedTimestamp);
/**
- * Replaces existing data node content including descendants.
+ * Replaces an existing data node's content including descendants.
*
* @param dataspaceName dataspace name
* @param anchorName anchor name
@@ -101,8 +102,19 @@ public interface CpsDataService {
* @param jsonData json data
* @param observedTimestamp observedTimestamp
*/
- void replaceNodeTree(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
- OffsetDateTime observedTimestamp);
+ void updateDataNodeAndDescendants(String dataspaceName, String anchorName, String parentNodeXpath, String jsonData,
+ OffsetDateTime observedTimestamp);
+
+ /**
+ * Replaces multiple existing data nodes' content including descendants in a batch operation.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param nodesJsonData map of xpath and node JSON data
+ * @param observedTimestamp observedTimestamp
+ */
+ void updateDataNodesAndDescendants(String dataspaceName, String anchorName, Map<String, String> nodesJsonData,
+ OffsetDateTime observedTimestamp);
/**
* Replaces list content by removing all existing elements and inserting the given new elements as json
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 7bdc2c166a..092fd31fcf 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
@@ -28,6 +28,9 @@ import static org.onap.cps.notification.Operation.UPDATE;
import java.time.OffsetDateTime;
import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsAdminService;
@@ -142,15 +145,28 @@ public class CpsDataServiceImpl implements CpsDataService {
}
@Override
- public void replaceNodeTree(final String dataspaceName, final String anchorName, final String parentNodeXpath,
- final String jsonData, final OffsetDateTime observedTimestamp) {
+ public void updateDataNodeAndDescendants(final String dataspaceName, final String anchorName,
+ final String parentNodeXpath, final String jsonData,
+ final OffsetDateTime observedTimestamp) {
CpsValidator.validateNameCharacters(dataspaceName, anchorName);
final DataNode dataNode = buildDataNode(dataspaceName, anchorName, parentNodeXpath, jsonData);
- cpsDataPersistenceService.replaceDataNodeTree(dataspaceName, anchorName, dataNode);
+ cpsDataPersistenceService.updateDataNodeAndDescendants(dataspaceName, anchorName, dataNode);
processDataUpdatedEventAsync(dataspaceName, anchorName, parentNodeXpath, UPDATE, observedTimestamp);
}
@Override
+ public void updateDataNodesAndDescendants(final String dataspaceName, final String anchorName,
+ final Map<String, String> nodesJsonData,
+ final OffsetDateTime observedTimestamp) {
+ CpsValidator.validateNameCharacters(dataspaceName, anchorName);
+ final List<DataNode> dataNodes = buildDataNodes(dataspaceName, anchorName, nodesJsonData);
+ cpsDataPersistenceService.updateDataNodesAndDescendants(dataspaceName, anchorName, dataNodes);
+ nodesJsonData.keySet().forEach(nodeXpath ->
+ processDataUpdatedEventAsync(dataspaceName, anchorName, nodeXpath,
+ UPDATE, observedTimestamp));
+ }
+
+ @Override
public void replaceListContent(final String dataspaceName, final String anchorName, final String parentNodeXpath,
final String jsonData, final OffsetDateTime observedTimestamp) {
CpsValidator.validateNameCharacters(dataspaceName, anchorName);
@@ -209,6 +225,13 @@ public class CpsDataServiceImpl implements CpsDataService {
.build();
}
+ private List<DataNode> buildDataNodes(final String dataspaceName, final String anchorName,
+ final Map<String, String> nodesJsonData) {
+ return nodesJsonData.entrySet().stream().map(nodeJsonData ->
+ buildDataNode(dataspaceName, anchorName, nodeJsonData.getKey(),
+ nodeJsonData.getValue())).collect(Collectors.toList());
+ }
+
private Collection<DataNode> buildDataNodes(final String dataspaceName,
final String anchorName,
final String parentNodeXpath,
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 b27a2976d0..686f0f3fee 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
@@ -90,13 +90,22 @@ public interface CpsDataPersistenceService {
void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Object> leaves);
/**
- * Replaces existing data node content including descendants.
+ * Replaces an existing data node's content including descendants.
*
* @param dataspaceName dataspace name
* @param anchorName anchor name
* @param dataNode data node
*/
- void replaceDataNodeTree(String dataspaceName, String anchorName, DataNode dataNode);
+ void updateDataNodeAndDescendants(String dataspaceName, String anchorName, DataNode dataNode);
+
+ /**
+ * Replaces multiple existing data nodes' content including descendants in a batch operation.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param dataNodes data nodes
+ */
+ void updateDataNodesAndDescendants(String dataspaceName, String anchorName, final List<DataNode> dataNodes);
/**
* Replaces list content by removing all existing elements and inserting the given new elements