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/main/java | |
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/main/java')
3 files changed, 49 insertions, 2 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 |