From b701e3090b90b4bb3aef93c9f89a6d642e6e084a Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Wed, 5 Mar 2025 17:28:07 +0000 Subject: 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 Change-Id: Ieb922ac1acc91dbfd67fb5ade7856213a2f93ce8 --- .../src/main/java/org/onap/cps/api/CpsQueryService.java | 13 +++++++++++++ .../main/java/org/onap/cps/impl/CpsQueryServiceImpl.java | 9 ++++++++- .../java/org/onap/cps/spi/CpsDataPersistenceService.java | 4 +++- .../groovy/org/onap/cps/impl/CpsQueryServiceImplSpec.groovy | 8 ++++---- 4 files changed, 28 insertions(+), 6 deletions(-) (limited to 'cps-service/src') 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 @@ -73,6 +73,19 @@ public interface CpsQueryService { */ Set queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, Class 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 + */ + Set queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, int queryResultLimit, + Class targetClass); + /** * Get data nodes for the given dataspace across all anchors by cps path. * 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 Set queryDataLeaf(final String dataspaceName, final String anchorName, final String cpsPath, final Class targetClass) { + return queryDataLeaf(dataspaceName, anchorName, cpsPath, NO_LIMIT, targetClass); + } + + @Override + public Set queryDataLeaf(final String dataspaceName, final String anchorName, final String cpsPath, + final int queryResultLimit, final Class 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 */ - Set queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, Class targetClass); + Set queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, int queryResultLimit, + Class 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) } } -- cgit