summaryrefslogtreecommitdiffstats
path: root/cps-service/src
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service/src')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsDataService.java13
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java25
-rw-r--r--cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java9
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy16
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/notification/CpsDataUpdateEventFactorySpec.groovy3
-rw-r--r--cps-service/src/test/resources/dmi-registry.yang42
6 files changed, 100 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 6036f92225..2583e9905b 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
@@ -118,4 +118,17 @@ public interface CpsDataService {
* @param listNodeXpath list node xpath
*/
void deleteListNodeData(@NonNull String dataspaceName, @NonNull String anchorName, @NonNull String listNodeXpath);
+
+ /**
+ * Updates leaves of DataNode for given dataspace and anchor using xpath,
+ * along with the leaves of each Child Data Node which already exists.
+ * This method will throw an exception if data node update or any descendant update does not exist.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param parentNodeXpath xpath
+ * @param dataNodeUpdatesAsJson json data representing data node updates
+ */
+ void updateNodeLeavesAndExistingDescendantLeaves(String dataspaceName, String anchorName, String parentNodeXpath,
+ String dataNodeUpdatesAsJson);
}
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 a512f67baf..8989dc80ef 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
@@ -100,6 +100,18 @@ public class CpsDataServiceImpl implements CpsDataService {
}
@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) {
final var dataNode = buildDataNodeFromJson(dataspaceName, anchorName, parentNodeXpath, jsonData);
@@ -170,4 +182,17 @@ public class CpsDataServiceImpl implements CpsDataService {
private SchemaContext getSchemaContext(final String dataspaceName, final String schemaSetName) {
return yangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName).getSchemaContext();
}
+
+ 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);
+ }
+ }
}
diff --git a/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java b/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java
index 6b7f5a89be..e0c8fe7055 100644
--- a/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java
+++ b/cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java
@@ -29,7 +29,6 @@ import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.event.model.Content;
import org.onap.cps.event.model.CpsDataUpdatedEvent;
-import org.onap.cps.event.model.CpsDataUpdatedEvent.Schema;
import org.onap.cps.event.model.Data;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.Anchor;
@@ -40,6 +39,7 @@ import org.springframework.stereotype.Component;
@Component
public class CpsDataUpdatedEventFactory {
+ private static final URI EVENT_SCHEMA;
private static final URI EVENT_SOURCE;
private static final String EVENT_TYPE = "org.onap.cps.data-updated-event";
private static final DateTimeFormatter dateTimeFormatter =
@@ -47,6 +47,7 @@ public class CpsDataUpdatedEventFactory {
static {
try {
+ EVENT_SCHEMA = new URI("urn:cps:org.onap.cps:data-updated-event-schema:v1");
EVENT_SOURCE = new URI("urn:cps:org.onap.cps");
} catch (final URISyntaxException e) {
// As it is fixed string, I don't expect to see this error
@@ -54,8 +55,8 @@ public class CpsDataUpdatedEventFactory {
}
}
- private CpsDataService cpsDataService;
- private CpsAdminService cpsAdminService;
+ private final CpsDataService cpsDataService;
+ private final CpsAdminService cpsAdminService;
public CpsDataUpdatedEventFactory(final CpsDataService cpsDataService, final CpsAdminService cpsAdminService) {
this.cpsDataService = cpsDataService;
@@ -80,7 +81,7 @@ public class CpsDataUpdatedEventFactory {
final var cpsDataUpdatedEvent = new CpsDataUpdatedEvent();
cpsDataUpdatedEvent.withContent(createContent(anchor, dataNode));
cpsDataUpdatedEvent.withId(UUID.randomUUID().toString());
- cpsDataUpdatedEvent.withSchema(Schema.URN_CPS_ORG_ONAP_CPS_DATA_UPDATED_EVENT_SCHEMA_1_1_0_SNAPSHOT);
+ cpsDataUpdatedEvent.withSchema(EVENT_SCHEMA);
cpsDataUpdatedEvent.withSource(EVENT_SOURCE);
cpsDataUpdatedEvent.withType(EVENT_TYPE);
return cpsDataUpdatedEvent;
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
index 122039728a..97eac5aaa9 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
@@ -28,7 +28,6 @@ import org.onap.cps.api.CpsModuleService
import org.onap.cps.notification.NotificationService
import org.onap.cps.spi.CpsDataPersistenceService
import org.onap.cps.spi.FetchDescendantsOption
-import org.onap.cps.spi.exceptions.CpsPathException
import org.onap.cps.spi.exceptions.DataValidationException
import org.onap.cps.spi.model.Anchor
import org.onap.cps.spi.model.DataNodeBuilder
@@ -148,10 +147,23 @@ class CpsDataServiceImplSpec extends Specification {
thrown(DataValidationException)
where: 'following parameters were used'
scenario | jsonData
- 'multiple leaves' | '{"code": "01","name": "some-name"}'
+ 'multiple expectedLeaves' | '{"code": "01","name": "some-name"}'
'one leaf' | '{"name": "some-name"}'
}
+ def 'Update cm-handle properties' () {
+ given: 'a dmi registry model'
+ setupSchemaSetMocks('dmi-registry.yang')
+ and: 'the expected json string'
+ def jsonData = '{"cm-handles":[{"id":"cmHandle001", "additional-properties":[{"name":"P1"}]}]}'
+ when: 'update data method is invoked with json data and parent node xpath'
+ objectUnderTest.updateNodeLeavesAndExistingDescendantLeaves(dataspaceName, anchorName, '/dmi-registry', jsonData)
+ then: 'the persistence service method is invoked with correct parameters'
+ 1 * mockCpsDataPersistenceService.updateDataLeaves(dataspaceName, anchorName, "/dmi-registry/cm-handles[@id='cmHandle001']", ['id': 'cmHandle001'])
+ and: 'the data updated event is sent to the notification service'
+ 1 * mockNotificationService.processDataUpdatedEvent(dataspaceName, anchorName)
+ }
+
def 'Replace data node: #scenario.'() {
given: 'schema set for given anchor and dataspace references test-tree model'
setupSchemaSetMocks('test-tree.yang')
diff --git a/cps-service/src/test/groovy/org/onap/cps/notification/CpsDataUpdateEventFactorySpec.groovy b/cps-service/src/test/groovy/org/onap/cps/notification/CpsDataUpdateEventFactorySpec.groovy
index aecc3f7ee0..2ce77bd1a8 100644
--- a/cps-service/src/test/groovy/org/onap/cps/notification/CpsDataUpdateEventFactorySpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/notification/CpsDataUpdateEventFactorySpec.groovy
@@ -21,7 +21,6 @@ package org.onap.cps.notification
import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsDataService
-import org.onap.cps.event.model.CpsDataUpdatedEvent
import org.onap.cps.event.model.Data
import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.spi.model.Anchor
@@ -61,7 +60,7 @@ class CpsDataUpdateEventFactorySpec extends Specification {
with(cpsDataUpdatedEvent) {
type == 'org.onap.cps.data-updated-event'
source == new URI('urn:cps:org.onap.cps')
- schema == CpsDataUpdatedEvent.Schema.URN_CPS_ORG_ONAP_CPS_DATA_UPDATED_EVENT_SCHEMA_1_1_0_SNAPSHOT
+ schema == new URI('urn:cps:org.onap.cps:data-updated-event-schema:v1')
StringUtils.hasText(id)
content != null
}
diff --git a/cps-service/src/test/resources/dmi-registry.yang b/cps-service/src/test/resources/dmi-registry.yang
new file mode 100644
index 0000000000..3c2d893b2a
--- /dev/null
+++ b/cps-service/src/test/resources/dmi-registry.yang
@@ -0,0 +1,42 @@
+module dmi-registry {
+
+ yang-version 1.1;
+
+ namespace "org:onap:cps:ncmp";
+
+ prefix dmi-reg;
+
+ revision "2021-05-20" {
+ description
+ "Initial Version";
+ }
+
+ container dmi-registry {
+
+ list cm-handles {
+
+ key "id";
+
+ leaf id {
+ type string;
+ }
+
+ leaf dmi-service-name {
+ type string;
+ }
+
+ list additional-properties {
+
+ key "name";
+
+ leaf name {
+ type string;
+ }
+
+ leaf value {
+ type string;
+ }
+ }
+ }
+ }
+} \ No newline at end of file