Merge "Update CmHandle in DMI-Registry for a DMI-Plugin Instance in NCMP as part...
[cps.git] / cps-service / src / main / java / org / onap / cps / api / impl / CpsDataServiceImpl.java
index c822c68..b45645b 100755 (executable)
@@ -1,15 +1,15 @@
 /*
- * ============LICENSE_START=======================================================
+ *  ============LICENSE_START=======================================================
  *  Copyright (C) 2021 Nordix Foundation
- *  Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ *  Modifications Copyright (C) 2020-2021 Bell Canada.
  *  Modifications Copyright (C) 2021 Pantheon.tech
- *  Modifications Copyright (C) 2021 Bell Canada.
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
  *  You may obtain a copy of the License at
  *
  *        http://www.apache.org/licenses/LICENSE-2.0
+ *
  *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -97,6 +97,18 @@ public class CpsDataServiceImpl implements CpsDataService {
         notificationService.processDataUpdatedEvent(dataspaceName, anchorName);
     }
 
+    @Override
+    public void updateNodeLeavesAndExistingDescendantLeaves(final String dataspaceName, final String anchorName,
+                                                            final String parentNodeXpath,
+                                                            final String dataNodeUpdatesAsJson) {
+        final Collection<DataNode> dataNodeUpdates =
+            buildDataNodeCollectionFromJson(dataspaceName, anchorName, parentNodeXpath, dataNodeUpdatesAsJson);
+        for (final DataNode dataNodeUpdate : dataNodeUpdates) {
+            processDataNodeUpdate(dataspaceName, anchorName, dataNodeUpdate);
+        }
+        notificationService.processDataUpdatedEvent(dataspaceName, anchorName);
+    }
+
     @Override
     public void replaceNodeTree(final String dataspaceName, final String anchorName, final String parentNodeXpath,
         final String jsonData) {
@@ -114,6 +126,13 @@ public class CpsDataServiceImpl implements CpsDataService {
         notificationService.processDataUpdatedEvent(dataspaceName, anchorName);
     }
 
+    @Override
+    public void deleteListNodeData(final String dataspaceName, final String anchorName, final String listNodeXpath) {
+        cpsDataPersistenceService.deleteListDataNodes(dataspaceName, anchorName, listNodeXpath);
+        notificationService.processDataUpdatedEvent(dataspaceName, anchorName);
+    }
+
+
     private DataNode buildDataNodeFromJson(final String dataspaceName, final String anchorName,
         final String parentNodeXpath, final String jsonData) {
 
@@ -153,4 +172,17 @@ public class CpsDataServiceImpl implements CpsDataService {
     private SchemaContext getSchemaContext(final String dataspaceName, final String schemaSetName) {
         return yangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName).getSchemaContext();
     }
-}
\ No newline at end of file
+
+    private void processDataNodeUpdate(final String dataspaceName, final String anchorName,
+                                       final DataNode dataNodeUpdate) {
+        if (dataNodeUpdate == null) {
+            return;
+        }
+        cpsDataPersistenceService.updateDataLeaves(dataspaceName, anchorName, dataNodeUpdate.getXpath(),
+            dataNodeUpdate.getLeaves());
+        final Collection<DataNode> childDataNodeUpdates = dataNodeUpdate.getChildDataNodes();
+        for (final DataNode childDataNodeUpdate : childDataNodeUpdates) {
+            processDataNodeUpdate(dataspaceName, anchorName, childDataNodeUpdate);
+        }
+    }
+}