aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2025-03-05 17:28:07 +0000
committerdanielhanrahan <daniel.hanrahan@est.tech>2025-03-11 09:33:56 +0000
commitb701e3090b90b4bb3aef93c9f89a6d642e6e084a (patch)
tree46c3ba9a98d6e7a45832b2514b837545190321af /cps-service/src
parent025b21992b7b88d03f630beb8299bf2be28286a9 (diff)
Allow limiting results in queryDataLeaf
This exposes queryResultLimit parameter in queryDataLeaf, same as was implemented for queryDataNodes API. Issue-ID: CPS-2680 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: Ieb922ac1acc91dbfd67fb5ade7856213a2f93ce8
Diffstat (limited to 'cps-service/src')
-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
4 files changed, 28 insertions, 6 deletions
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)
}
}