X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=inline;f=cps-service%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fcps%2Fapi%2Fimpl%2FCpsDataServiceImpl.java;h=0a7afc8f648e7eaf06a22b37694feec02c2c5e3a;hb=e79415f72acce2d9508737fae552b989db1d473f;hp=51e31f08c82c6d4d2c39b8ead31cebdadba2187e;hpb=2b4c48824947478f12c7b2e7b962aeb6b46ae4fc;p=cps.git 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 51e31f08c..0a7afc8f6 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 @@ -29,14 +29,17 @@ import static org.onap.cps.notification.Operation.DELETE; import static org.onap.cps.notification.Operation.UPDATE; import io.micrometer.core.annotation.Timed; +import java.io.Serializable; import java.time.OffsetDateTime; import java.util.Collection; +import java.util.Collections; import java.util.Map; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.onap.cps.api.CpsAdminService; import org.onap.cps.api.CpsDataService; +import org.onap.cps.cpspath.parser.CpsPathUtil; import org.onap.cps.notification.NotificationService; import org.onap.cps.notification.Operation; import org.onap.cps.spi.CpsDataPersistenceService; @@ -155,20 +158,16 @@ public class CpsDataServiceImpl implements CpsDataService { @Override @Timed(value = "cps.data.service.datanode.leaves.update", - description = "Time taken to get a batch of data nodes") + description = "Time taken to update a batch of leaf data nodes") public void updateNodeLeaves(final String dataspaceName, final String anchorName, final String parentNodeXpath, final String jsonData, final OffsetDateTime observedTimestamp) { cpsValidator.validateNameCharacters(dataspaceName, anchorName); final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName); final Collection dataNodesInPatch = buildDataNodes(anchor, parentNodeXpath, jsonData, ContentType.JSON); - if (dataNodesInPatch.size() > 1) { - throw new DataValidationException("Operation is not supported for multiple data nodes", - "Number of data nodes present: " + dataNodesInPatch.size()); - } - cpsDataPersistenceService.updateDataLeaves(dataspaceName, anchorName, - dataNodesInPatch.iterator().next().getXpath(), - dataNodesInPatch.iterator().next().getLeaves()); + final Map> xpathToUpdatedLeaves = dataNodesInPatch.stream() + .collect(Collectors.toMap(DataNode::getXpath, DataNode::getLeaves)); + cpsDataPersistenceService.batchUpdateDataLeaves(dataspaceName, anchorName, xpathToUpdatedLeaves); processDataUpdatedEventAsync(anchor, parentNodeXpath, UPDATE, observedTimestamp); } @@ -356,10 +355,11 @@ public class CpsDataServiceImpl implements CpsDataService { } return dataNodes; } + final String normalizedParentNodeXpath = CpsPathUtil.getNormalizedXpath(parentNodeXpath); final ContainerNode containerNode = - timedYangParser.parseData(contentType, nodeData, schemaContext, parentNodeXpath); + timedYangParser.parseData(contentType, nodeData, schemaContext, normalizedParentNodeXpath); final Collection dataNodes = new DataNodeBuilder() - .withParentNodeXpath(parentNodeXpath) + .withParentNodeXpath(normalizedParentNodeXpath) .withContainerNode(containerNode) .buildCollection(); if (dataNodes.isEmpty()) { @@ -395,8 +395,8 @@ public class CpsDataServiceImpl implements CpsDataService { if (dataNodeUpdate == null) { return; } - cpsDataPersistenceService.updateDataLeaves(anchor.getDataspaceName(), anchor.getName(), - dataNodeUpdate.getXpath(), dataNodeUpdate.getLeaves()); + cpsDataPersistenceService.batchUpdateDataLeaves(anchor.getDataspaceName(), anchor.getName(), + Collections.singletonMap(dataNodeUpdate.getXpath(), dataNodeUpdate.getLeaves())); final Collection childDataNodeUpdates = dataNodeUpdate.getChildDataNodes(); for (final DataNode childDataNodeUpdate : childDataNodeUpdates) { processDataNodeUpdate(anchor, childDataNodeUpdate);