diff options
author | 2025-02-06 15:26:11 +0100 | |
---|---|---|
committer | 2025-02-11 17:58:40 +0100 | |
commit | 56d550a3513681b1b20d612a21072b9955b12b82 (patch) | |
tree | af725f47679a81dac54eb5bf551dcef62feb2ca9 /cps-service/src | |
parent | 2489064ffa94f76a5e49fed8e06d1299ec9cc671 (diff) |
Query data nodes with limit
- added new methods to java interfaces
- added integration test
- removed unused methods
Issue-ID: CPS-2394
Change-Id: Iac4094a5daedbf593d17f55928136a80391c6d23
Signed-off-by: leventecsanyi <levente.csanyi@est.tech>
Diffstat (limited to 'cps-service/src')
4 files changed, 66 insertions, 4 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 d783b9ed0e..3044fe0a90 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 @@ -32,6 +32,8 @@ import org.onap.cps.api.parameters.PaginationOption; */ public interface CpsQueryService { + public static int NO_LIMIT = 0; + /** * Get data nodes for the given dataspace and anchor by cps path. * @@ -45,6 +47,20 @@ public interface CpsQueryService { Collection<DataNode> queryDataNodes(String dataspaceName, String anchorName, String cpsPath, FetchDescendantsOption fetchDescendantsOption); + /** + * Retrieves a collection of data nodes based on the specified CPS path query. + * + * @param dataspaceName the name of the dataspace (must not be null or empty) + * @param anchorName the name of the anchor (must not be null or empty) + * @param cpsPath the CPS path used for querying (must not be null or empty) + * @param fetchDescendantsOption specifies whether to include descendant nodes in the output + * @param queryResultLimit the maximum number of data nodes to return; if less than 1, returns all matching nodes + * + * @return a collection of matching {@link DataNode} instances (can be empty if no nodes are found) + */ + Collection<DataNode> queryDataNodes(String dataspaceName, String anchorName, + String cpsPath, FetchDescendantsOption fetchDescendantsOption, + int queryResultLimit); /** * Get data leaf for the given dataspace and anchor 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 508a1b2449..f27445f7c9 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 @@ -46,8 +46,22 @@ public class CpsQueryServiceImpl implements CpsQueryService { public Collection<DataNode> queryDataNodes(final String dataspaceName, final String anchorName, final String cpsPath, final FetchDescendantsOption fetchDescendantsOption) { - cpsValidator.validateNameCharacters(dataspaceName, anchorName); - return cpsDataPersistenceService.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption); + return queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption, NO_LIMIT); + } + + @Override + @Timed(value = "cps.data.service.datanode.query", + description = "Time taken to query data nodes with a limit on results") + public Collection<DataNode> queryDataNodes(final String dataSpaceName, final String anchorName, + final String cpsPath, + final FetchDescendantsOption fetchDescendantsOption, + final int queryResultLimit) { + cpsValidator.validateNameCharacters(dataSpaceName, anchorName); + return cpsDataPersistenceService.queryDataNodes(dataSpaceName, + anchorName, + cpsPath, + fetchDescendantsOption, + queryResultLimit); } @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 a4f05cdb53..5be5fb0481 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 @@ -186,6 +186,23 @@ public interface CpsDataPersistenceService { String cpsPath, FetchDescendantsOption fetchDescendantsOption); /** + * Get a datanode by cps path. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @param cpsPath cps path + * @param fetchDescendantsOption defines whether the descendants of the node(s) found by the query should be + * included in the output + * @param queryResultLimit limits the number of returned entities (if less than 1 returns all) + * + * @return the data nodes found i.e. 0 or more data nodes + */ + List<DataNode> queryDataNodes(String dataspaceName, + String anchorName, + String cpsPath, FetchDescendantsOption fetchDescendantsOption, + int queryResultLimit); + + /** * Get data leaf for the given dataspace and anchor by cps path. * * @param dataspaceName dataspace name 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 b15ee72370..9db4aa4c3e 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 @@ -21,7 +21,7 @@ package org.onap.cps.impl - +import org.onap.cps.api.CpsQueryService import org.onap.cps.utils.CpsValidator import org.onap.cps.spi.CpsDataPersistenceService import org.onap.cps.api.parameters.FetchDescendantsOption @@ -42,7 +42,7 @@ class CpsQueryServiceImplSpec extends Specification { when: 'queryDataNodes is invoked' objectUnderTest.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption) then: 'the persistence service is called once with the correct parameters' - 1 * mockCpsDataPersistenceService.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption) + 1 * mockCpsDataPersistenceService.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption, CpsQueryService.NO_LIMIT) and: 'the CpsValidator is called on the dataspaceName, schemaSetName and anchorName' 1 * mockCpsValidator.validateNameCharacters(dataspaceName, anchorName) where: 'all fetch descendants options are supported' @@ -50,6 +50,21 @@ class CpsQueryServiceImplSpec extends Specification { FetchDescendantsOption.DIRECT_CHILDREN_ONLY, new FetchDescendantsOption(10)] } + def 'Query data nodes by cps path with limit.'() { + given: 'a dataspace name, an anchor name and a cps path' + def dataspaceName = 'some-dataspace' + def anchorName = 'some-anchor' + def cpsPath = '/cps-path' + def fetchDescendantsOption = FetchDescendantsOption.OMIT_DESCENDANTS + def myLimit = 123 + when: 'queryDataNodes (with limit) is invoked' + objectUnderTest.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption, myLimit) + then: 'the persistence service is called once with the correct parameters' + 1 * mockCpsDataPersistenceService.queryDataNodes(dataspaceName, anchorName, cpsPath, fetchDescendantsOption, myLimit) + and: 'the CpsValidator is called on the dataspaceName, schemaSetName and anchorName' + 1 * mockCpsValidator.validateNameCharacters(dataspaceName, anchorName) + } + def 'Query data nodes across all anchors by cps path with #fetchDescendantsOption.'() { given: 'a dataspace name, an anchor name and a cps path' def dataspaceName = 'some-dataspace' |