summaryrefslogtreecommitdiffstats
path: root/cps-service
diff options
context:
space:
mode:
authorLuke Gleeson <luke.gleeson@est.tech>2023-02-20 09:57:05 +0000
committerGerrit Code Review <gerrit@onap.org>2023-02-20 09:57:05 +0000
commit33001d5b81f6f10b3b68987b13033bd1a232bbe2 (patch)
treea03256e1a204422160c70a3604a5c9c00596c58f /cps-service
parentfbb79a0a112da3b05989fdc3a8e88c5865f3cc9a (diff)
parent0bd192ca12ac2f768e44d0d3482785c79a881904 (diff)
Merge "CPS-1401 Implement V2 of GET Data Node API"
Diffstat (limited to 'cps-service')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsDataService.java38
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsDataServiceImpl.java20
-rw-r--r--cps-service/src/main/java/org/onap/cps/notification/CpsDataUpdatedEventFactory.java5
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java35
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy28
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/notification/CpsDataUpdateEventFactorySpec.groovy5
6 files changed, 77 insertions, 54 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 07da5773d8..39fa45ac1a 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
@@ -4,6 +4,7 @@
* Modifications Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2021-2022 Bell Canada
* Modifications Copyright (C) 2022 Deutsche Telekom AG
+ * Modifications Copyright (C) 2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -110,30 +111,31 @@ public interface CpsDataService {
Collection<String> jsonDataList, OffsetDateTime observedTimestamp);
/**
- * Retrieves datanode by XPath for given dataspace and anchor.
+ * Retrieves all the datanodes by XPath for given dataspace and anchor.
*
- * @param dataspaceName dataspace name
- * @param anchorName anchor name
- * @param xpath xpath
- * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
- * (recursively) as well
- * @return data node object
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param xpath xpath
+ * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
+ * (recursively) as well
+ * @return collection of data node objects
*/
- DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
- FetchDescendantsOption fetchDescendantsOption);
+ Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, String xpath,
+ FetchDescendantsOption fetchDescendantsOption);
/**
- * Retrieves datanodes by XPath for given dataspace and anchor.
+ * Retrieves all the datanodes for multiple XPaths for given dataspace and anchor.
*
- * @param dataspaceName dataspace name
- * @param anchorName anchor name
- * @param xpaths collection of xpath
- * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
- * (recursively) as well
- * @return data node object
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param xpaths collection of xpaths
+ * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
+ * (recursively) as well
+ * @return collection of data node objects
*/
- Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, Collection<String> xpaths,
- FetchDescendantsOption fetchDescendantsOption);
+ Collection<DataNode> getDataNodesForMultipleXpaths(String dataspaceName, String anchorName,
+ Collection<String> xpaths,
+ FetchDescendantsOption fetchDescendantsOption);
/**
* Updates data node for given dataspace and anchor using xpath to parent node.
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 59de411397..721d4a9fbb 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
@@ -3,7 +3,7 @@
* Copyright (C) 2021-2023 Nordix Foundation
* Modifications Copyright (C) 2020-2022 Bell Canada.
* Modifications Copyright (C) 2021 Pantheon.tech
- * Modifications Copyright (C) 2022 TechMahindra Ltd.
+ * Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
* Modifications Copyright (C) 2022 Deutsche Telekom AG
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -134,21 +134,23 @@ public class CpsDataServiceImpl implements CpsDataService {
@Override
@Timed(value = "cps.data.service.datanode.get",
- description = "Time taken to get a data node")
- public DataNode getDataNode(final String dataspaceName, final String anchorName, final String xpath,
- final FetchDescendantsOption fetchDescendantsOption) {
+ description = "Time taken to get data nodes for an xpath")
+ public Collection<DataNode> getDataNodes(final String dataspaceName, final String anchorName,
+ final String xpath,
+ final FetchDescendantsOption fetchDescendantsOption) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- return cpsDataPersistenceService.getDataNode(dataspaceName, anchorName, xpath, fetchDescendantsOption);
+ return cpsDataPersistenceService.getDataNodes(dataspaceName, anchorName, xpath, fetchDescendantsOption);
}
@Override
@Timed(value = "cps.data.service.datanode.batch.get",
description = "Time taken to get a batch of data nodes")
- public Collection<DataNode> getDataNodes(final String dataspaceName, final String anchorName,
- final Collection<String> xpaths,
- final FetchDescendantsOption fetchDescendantsOption) {
+ public Collection<DataNode> getDataNodesForMultipleXpaths(final String dataspaceName, final String anchorName,
+ final Collection<String> xpaths,
+ final FetchDescendantsOption fetchDescendantsOption) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- return cpsDataPersistenceService.getDataNodes(dataspaceName, anchorName, xpaths, fetchDescendantsOption);
+ return cpsDataPersistenceService.getDataNodesForMultipleXpaths(dataspaceName, anchorName, xpaths,
+ fetchDescendantsOption);
}
@Override
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 f0cdaee8d6..38f8988279 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
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (c) 2021-2022 Bell Canada.
* Modifications Copyright (c) 2022 Nordix Foundation
+ * Modifications Copyright (C) 2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -76,8 +77,8 @@ public class CpsDataUpdatedEventFactory {
public CpsDataUpdatedEvent createCpsDataUpdatedEvent(final Anchor anchor,
final OffsetDateTime observedTimestamp, final Operation operation) {
final var dataNode = (operation == Operation.DELETE) ? null :
- cpsDataService.getDataNode(anchor.getDataspaceName(), anchor.getName(),
- "/", FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
+ cpsDataService.getDataNodes(anchor.getDataspaceName(), anchor.getName(),
+ "/", FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS).iterator().next();
return toCpsDataUpdatedEvent(anchor, dataNode, observedTimestamp, operation);
}
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 fe9cf2f698..90e6ec761d 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
@@ -3,7 +3,7 @@
* Copyright (C) 2020-2023 Nordix Foundation.
* Modifications Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2022 Bell Canada
- * Modifications Copyright (C) 2022 TechMahindra Ltd.
+ * Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -99,30 +99,33 @@ public interface CpsDataPersistenceService {
Collection<Collection<DataNode>> newLists);
/**
- * Retrieves datanode by XPath for given dataspace and anchor.
+ * Retrieves multiple datanodes for a single XPath for given dataspace and anchor.
+ * Multiple data nodes are returned when xPath is set to root '/', otherwise single data node
+ * is returned when a specific xpath is used (Example: /bookstore).
*
* @param dataspaceName dataspace name
* @param anchorName anchor name
- * @param xpath xpath
+ * @param xpath one xpath
* @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
* (recursively) as well
- * @return data node object
+ * @return collection of data node object
*/
- DataNode getDataNode(String dataspaceName, String anchorName, String xpath,
- FetchDescendantsOption fetchDescendantsOption);
+ Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, String xpath,
+ FetchDescendantsOption fetchDescendantsOption);
/**
- * Retrieves datanode by XPath for given dataspace and anchor.
+ * Retrieves multiple datanodes for multiple XPaths, given a dataspace and anchor.
*
- * @param dataspaceName dataspace name
- * @param anchorName anchor name
- * @param xpaths collection of xpaths
- * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
- * (recursively) as well
- * @return data node object
- */
- Collection<DataNode> getDataNodes(String dataspaceName, String anchorName, Collection<String> xpaths,
- FetchDescendantsOption fetchDescendantsOption);
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param xpaths collection of xpaths
+ * @param fetchDescendantsOption defines the scope of data to fetch: either single node or all the descendant nodes
+ * (recursively) as well
+ * @return collection of data node object
+ */
+ Collection<DataNode> getDataNodesForMultipleXpaths(String dataspaceName, String anchorName,
+ Collection<String> xpaths,
+ FetchDescendantsOption fetchDescendantsOption);
/**
* Updates leaves for existing data node.
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 69b0c94f45..e304d28d8a 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
@@ -3,7 +3,7 @@
* Copyright (C) 2021-2023 Nordix Foundation
* Modifications Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2021-2022 Bell Canada.
- * Modifications Copyright (C) 2022 TechMahindra Ltd.
+ * Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
* Modifications Copyright (C) 2022 Deutsche Telekom AG
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -184,13 +184,27 @@ class CpsDataServiceImplSpec extends Specification {
thrown(DataValidationException)
}
- def 'Get data node with option #fetchDescendantsOption.'() {
- def xpath = '/xpath'
- def dataNode = new DataNodeBuilder().withXpath(xpath).build()
+ def 'Get all data nodes #scenario.'() {
+ given: 'persistence service returns data for GET request'
+ mockCpsDataPersistenceService.getDataNodes(dataspaceName, anchorName, xpath, fetchDescendantsOption) >> dataNode
+ expect: 'service returns same data if using same parameters'
+ objectUnderTest.getDataNodes(dataspaceName, anchorName, xpath, fetchDescendantsOption) == dataNode
+ where: 'following parameters were used'
+ scenario | xpath | fetchDescendantsOption | dataNode
+ 'with root node xpath and descendants' | '/' | FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS | [new DataNodeBuilder().withXpath('/xpath-1').build(), new DataNodeBuilder().withXpath('/xpath-2').build()]
+ 'with root node xpath and no descendants' | '/' | FetchDescendantsOption.OMIT_DESCENDANTS | [new DataNodeBuilder().withXpath('/xpath-1').build(), new DataNodeBuilder().withXpath('/xpath-2').build()]
+ 'with valid xpath and descendants' | '/xpath'| FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS | [new DataNodeBuilder().withXpath('/xpath').build()]
+ 'with valid xpath and no descendants' | '/xpath'| FetchDescendantsOption.OMIT_DESCENDANTS | [new DataNodeBuilder().withXpath('/xpath').build()]
+ }
+
+ def 'Get all data nodes over multiple xpaths with option #fetchDescendantsOption.'() {
+ def xpath1 = '/xpath-1'
+ def xpath2 = '/xpath-2'
+ def dataNode = [new DataNodeBuilder().withXpath(xpath1).build(), new DataNodeBuilder().withXpath(xpath2).build()]
given: 'persistence service returns data for get data request'
- mockCpsDataPersistenceService.getDataNode(dataspaceName, anchorName, xpath, fetchDescendantsOption) >> dataNode
+ mockCpsDataPersistenceService.getDataNodesForMultipleXpaths(dataspaceName, anchorName, [xpath1, xpath2], fetchDescendantsOption) >> dataNode
expect: 'service returns same data if uses same parameters'
- objectUnderTest.getDataNode(dataspaceName, anchorName, xpath, fetchDescendantsOption) == dataNode
+ objectUnderTest.getDataNodesForMultipleXpaths(dataspaceName, anchorName, [xpath1, xpath2], fetchDescendantsOption) == dataNode
where: 'all fetch options are supported'
fetchDescendantsOption << [FetchDescendantsOption.OMIT_DESCENDANTS, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS]
}
@@ -417,4 +431,4 @@ class CpsDataServiceImplSpec extends Specification {
1 * mockCpsDataPersistenceService.lockAnchor('some-sessionId', 'some-dataspaceName',
'some-anchorName', 250L)
}
-}
+} \ No newline at end of file
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 6f9a148eb2..5dbc2bb04b 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
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (c) 2021-2022 Bell Canada.
* Modifications Copyright (c) 2022 Nordix Foundation
+ * Modifications Copyright (C) 2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,8 +51,8 @@ class CpsDataUpdateEventFactorySpec extends Specification {
and: 'cps data service returns the data node details'
def xpath = '/xpath'
def dataNode = new DataNodeBuilder().withXpath(xpath).withLeaves(['leafName': 'leafValue']).build()
- mockCpsDataService.getDataNode(
- 'my-dataspace', 'my-anchorname', '/', FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> dataNode
+ mockCpsDataService.getDataNodes(
+ 'my-dataspace', 'my-anchorname', '/', FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS) >> [dataNode]
when: 'CPS data updated event is created'
def cpsDataUpdatedEvent = objectUnderTest.createCpsDataUpdatedEvent(anchor,
DateTimeUtility.toOffsetDateTime(inputObservedTimestamp), Operation.CREATE)