+ final String jsonData, final OffsetDateTime observedTimestamp) {
+ cpsValidator.validateNameCharacters(dataspaceName, anchorName);
+ final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final Collection<DataNode> dataNodesInPatch = buildDataNodes(anchor, parentNodeXpath, jsonData,
+ ContentType.JSON);
+ final Map<String, Map<String, Serializable>> xpathToUpdatedLeaves = dataNodesInPatch.stream()
+ .collect(Collectors.toMap(DataNode::getXpath, DataNode::getLeaves));
+ cpsDataPersistenceService.batchUpdateDataLeaves(dataspaceName, anchorName, xpathToUpdatedLeaves);
+ processDataUpdatedEventAsync(anchor, parentNodeXpath, UPDATE, observedTimestamp);
+ }
+
+ @Override
+ @Timed(value = "cps.data.service.datanode.leaves.descendants.leaves.update",
+ description = "Time taken to update data node leaves and existing descendants leaves")
+ public void updateNodeLeavesAndExistingDescendantLeaves(final String dataspaceName, final String anchorName,
+ final String parentNodeXpath,
+ final String dataNodeUpdatesAsJson,
+ final OffsetDateTime observedTimestamp) {
+ cpsValidator.validateNameCharacters(dataspaceName, anchorName);
+ final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final Collection<DataNode> dataNodeUpdates =
+ buildDataNodes(anchor, parentNodeXpath, dataNodeUpdatesAsJson, ContentType.JSON);
+ for (final DataNode dataNodeUpdate : dataNodeUpdates) {
+ processDataNodeUpdate(anchor, dataNodeUpdate);
+ }
+ processDataUpdatedEventAsync(anchor, parentNodeXpath, UPDATE, observedTimestamp);
+ }
+
+ @Override
+ public String startSession() {
+ return cpsDataPersistenceService.startSession();
+ }
+
+ @Override
+ public void closeSession(final String sessionId) {
+ cpsDataPersistenceService.closeSession(sessionId);
+ }
+
+ @Override
+ public void lockAnchor(final String sessionID, final String dataspaceName, final String anchorName) {
+ lockAnchor(sessionID, dataspaceName, anchorName, DEFAULT_LOCK_TIMEOUT_IN_MILLISECONDS);
+ }
+
+ @Override
+ public void lockAnchor(final String sessionID, final String dataspaceName,
+ final String anchorName, final Long timeoutInMilliseconds) {
+ cpsDataPersistenceService.lockAnchor(sessionID, dataspaceName, anchorName, timeoutInMilliseconds);
+ }
+
+ @Override
+ @Timed(value = "cps.data.service.datanode.descendants.update",
+ description = "Time taken to update a data node and descendants")
+ public void updateDataNodeAndDescendants(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<DataNode> dataNodes = buildDataNodes(anchor, parentNodeXpath, jsonData, ContentType.JSON);
+ cpsDataPersistenceService.updateDataNodesAndDescendants(dataspaceName, anchorName, dataNodes);
+ processDataUpdatedEventAsync(anchor, parentNodeXpath, UPDATE, observedTimestamp);
+ }
+
+ @Override
+ @Timed(value = "cps.data.service.datanode.descendants.batch.update",
+ description = "Time taken to update a batch of data nodes and descendants")
+ public void updateDataNodesAndDescendants(final String dataspaceName, final String anchorName,
+ final Map<String, String> nodesJsonData,
+ final OffsetDateTime observedTimestamp) {
+ cpsValidator.validateNameCharacters(dataspaceName, anchorName);
+ final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ final Collection<DataNode> dataNodes = buildDataNodes(anchor, nodesJsonData);
+ cpsDataPersistenceService.updateDataNodesAndDescendants(dataspaceName, anchorName, dataNodes);
+ nodesJsonData.keySet().forEach(nodeXpath ->
+ processDataUpdatedEventAsync(anchor, nodeXpath, UPDATE, observedTimestamp));
+ }
+
+ @Override
+ @Timed(value = "cps.data.service.list.update",
+ description = "Time taken to update a list")
+ public void replaceListContent(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<DataNode> newListElements =
+ buildDataNodes(anchor, parentNodeXpath, jsonData, ContentType.JSON);
+ replaceListContent(dataspaceName, anchorName, parentNodeXpath, newListElements, observedTimestamp);
+ }
+
+ @Override
+ @Timed(value = "cps.data.service.list.batch.update",
+ description = "Time taken to update a batch of lists")
+ public void replaceListContent(final String dataspaceName, final String anchorName, final String parentNodeXpath,
+ final Collection<DataNode> dataNodes, final OffsetDateTime observedTimestamp) {
+ cpsValidator.validateNameCharacters(dataspaceName, anchorName);
+ final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ cpsDataPersistenceService.replaceListContent(dataspaceName, anchorName, parentNodeXpath, dataNodes);
+ processDataUpdatedEventAsync(anchor, parentNodeXpath, UPDATE, observedTimestamp);
+ }
+
+ @Override
+ @Timed(value = "cps.data.service.datanode.delete",
+ description = "Time taken to delete a datanode")
+ public void deleteDataNode(final String dataspaceName, final String anchorName, final String dataNodeXpath,
+ final OffsetDateTime observedTimestamp) {
+ cpsValidator.validateNameCharacters(dataspaceName, anchorName);
+ final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+ cpsDataPersistenceService.deleteDataNode(dataspaceName, anchorName, dataNodeXpath);
+ processDataUpdatedEventAsync(anchor, dataNodeXpath, DELETE, observedTimestamp);