aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToine Siebelink <toine.siebelink@est.tech>2025-03-12 17:21:28 +0000
committerGerrit Code Review <gerrit@onap.org>2025-03-12 17:21:28 +0000
commit36027000ecc2d0bbffc7cd45fe3941db77e1d178 (patch)
tree2c933735724c22ef1767d01e74d418d03581d839
parent2cbb4d5940a099c4626bc4bf99090538d8311971 (diff)
parentb701e3090b90b4bb3aef93c9f89a6d642e6e084a (diff)
Merge "Allow limiting results in queryDataLeaf"
-rw-r--r--cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java4
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java13
-rw-r--r--cps-service/src/main/java/org/onap/cps/impl/CpsQueryServiceImpl.java9
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java4
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/impl/CpsQueryServiceImplSpec.groovy8
-rw-r--r--integration-test/src/test/groovy/org/onap/cps/integration/functional/cps/QueryServiceIntegrationSpec.groovy17
6 files changed, 45 insertions, 10 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java
index e102765a64..a510d308d6 100644
--- a/cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java
@@ -242,7 +242,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
@Override
public <T> Set<T> queryDataLeaf(final String dataspaceName, final String anchorName, final String cpsPath,
- final Class<T> targetClass) {
+ final int queryResultLimit, final Class<T> targetClass) {
final CpsPathQuery cpsPathQuery = getCpsPathQuery(cpsPath);
if (!cpsPathQuery.hasAttributeAxis()) {
throw new IllegalArgumentException(
@@ -251,7 +251,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
final String attributeName = cpsPathQuery.getAttributeAxisAttributeName();
final List<DataNode> dataNodes = queryDataNodes(dataspaceName, anchorName, cpsPath,
- FetchDescendantsOption.OMIT_DESCENDANTS);
+ FetchDescendantsOption.OMIT_DESCENDANTS, queryResultLimit);
return dataNodes.stream()
.map(dataNode -> {
final Object attributeValue = dataNode.getLeaves().get(attributeName);
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java b/cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java
index 30c8bbbdf3..d6c1f7fc60 100644
--- a/cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java
@@ -74,6 +74,19 @@ public interface CpsQueryService {
<T> Set<T> queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, Class<T> targetClass);
/**
+ * Get data leaf for the given dataspace and anchor by cps path.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @param cpsPath cps path
+ * @param queryResultLimit the maximum number of data nodes to return; if less than 1, returns all matching nodes
+ * @param targetClass class of the expected data type
+ * @return a collection of data objects of expected type
+ */
+ <T> Set<T> queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, int queryResultLimit,
+ Class<T> targetClass);
+
+ /**
* Get data nodes for the given dataspace across all anchors by cps path.
*
* @param dataspaceName dataspace name
diff --git a/cps-service/src/main/java/org/onap/cps/impl/CpsQueryServiceImpl.java b/cps-service/src/main/java/org/onap/cps/impl/CpsQueryServiceImpl.java
index a3884820c7..5abdd0fe2b 100644
--- a/cps-service/src/main/java/org/onap/cps/impl/CpsQueryServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/impl/CpsQueryServiceImpl.java
@@ -67,8 +67,15 @@ public class CpsQueryServiceImpl implements CpsQueryService {
@Override
public <T> Set<T> queryDataLeaf(final String dataspaceName, final String anchorName, final String cpsPath,
final Class<T> targetClass) {
+ return queryDataLeaf(dataspaceName, anchorName, cpsPath, NO_LIMIT, targetClass);
+ }
+
+ @Override
+ public <T> Set<T> queryDataLeaf(final String dataspaceName, final String anchorName, final String cpsPath,
+ final int queryResultLimit, final Class<T> targetClass) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- return cpsDataPersistenceService.queryDataLeaf(dataspaceName, anchorName, cpsPath, targetClass);
+ return cpsDataPersistenceService.queryDataLeaf(dataspaceName, anchorName, cpsPath, queryResultLimit,
+ targetClass);
}
@Override
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 5be5fb0481..b319929e47 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
@@ -208,10 +208,12 @@ public interface CpsDataPersistenceService {
* @param dataspaceName dataspace name
* @param anchorName anchor name
* @param cpsPath cps path
+ * @param queryResultLimit limits the number of returned entities (if less than 1 returns all)
* @param targetClass class of the expected data type
* @return a collection of data objects of expected type
*/
- <T> Set<T> queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, Class<T> targetClass);
+ <T> Set<T> queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, int queryResultLimit,
+ Class<T> targetClass);
/**
* Get a datanode by dataspace name and cps path across all anchors.
diff --git a/cps-service/src/test/groovy/org/onap/cps/impl/CpsQueryServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/impl/CpsQueryServiceImplSpec.groovy
index 9db4aa4c3e..d581727e40 100644
--- a/cps-service/src/test/groovy/org/onap/cps/impl/CpsQueryServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/impl/CpsQueryServiceImplSpec.groovy
@@ -77,8 +77,8 @@ class CpsQueryServiceImplSpec extends Specification {
and: 'the CpsValidator is called on the dataspaceName, schemaSetName and anchorName'
1 * mockCpsValidator.validateNameCharacters(dataspaceName)
where: 'all fetch descendants options are supported'
- fetchDescendantsOption << [FetchDescendantsOption.OMIT_DESCENDANTS, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS,
- FetchDescendantsOption.DIRECT_CHILDREN_ONLY, new FetchDescendantsOption(10)]
+ fetchDescendantsOption << [FetchDescendantsOption.OMIT_DESCENDANTS, FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS,
+ FetchDescendantsOption.DIRECT_CHILDREN_ONLY, new FetchDescendantsOption(10)]
}
def 'Query total anchors for dataspace and cps path.'() {
@@ -91,7 +91,7 @@ class CpsQueryServiceImplSpec extends Specification {
def 'Query data leaf.'() {
when: 'a query for a specific leaf is executed'
objectUnderTest.queryDataLeaf('some-dataspace', 'some-anchor', '/cps-path/@id', Object.class)
- then: 'solution is not implemented yet'
- 1 * mockCpsDataPersistenceService.queryDataLeaf('some-dataspace', 'some-anchor', '/cps-path/@id', Object.class)
+ then: 'the persistence service is called once with the correct parameters'
+ 1 * mockCpsDataPersistenceService.queryDataLeaf('some-dataspace', 'some-anchor', '/cps-path/@id', 0, Object.class)
}
}
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/cps/QueryServiceIntegrationSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/cps/QueryServiceIntegrationSpec.groovy
index 42fb964d52..6ae14dd11b 100644
--- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/cps/QueryServiceIntegrationSpec.groovy
+++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/cps/QueryServiceIntegrationSpec.groovy
@@ -458,8 +458,8 @@ class QueryServiceIntegrationSpec extends FunctionalSpecBase {
assert result.anchorName.toSet() == [BOOKSTORE_ANCHOR_1, BOOKSTORE_ANCHOR_2].toSet()
}
- def 'Query with a limit of #limit.' () {
- when:
+ def 'Query data nodes with a limit of #limit.' () {
+ when: 'a query for data nodes is executed with a result limit'
def result = objectUnderTest.queryDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories', OMIT_DESCENDANTS, limit)
then: 'the expected number of nodes is returned'
assert countDataNodesInTree(result) == expectedNumberOfResults
@@ -470,4 +470,17 @@ class QueryServiceIntegrationSpec extends FunctionalSpecBase {
0 || 5
-1 || 5
}
+
+ def 'Query data leaf with a limit of #limit.' () {
+ when: 'a query for data leaf is executed with a result limit'
+ def result = objectUnderTest.queryDataLeaf(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories/@name', limit, String)
+ then: 'the expected number of leaf values is returned'
+ assert result.size() == expectedNumberOfResults
+ where: 'the following parameters are used'
+ limit || expectedNumberOfResults
+ 1 || 1
+ 2 || 2
+ 0 || 5
+ -1 || 5
+ }
}