aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java18
-rw-r--r--cps-service/src/main/java/org/onap/cps/impl/CpsQueryServiceImpl.java16
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java17
-rw-r--r--cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java14
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/impl/CpsQueryServiceImplSpec.groovy19
5 files changed, 72 insertions, 12 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..30c8bbbdf3 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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020-2024 Nordix Foundation
+ * Copyright (C) 2020-2025 Nordix Foundation
* Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,6 +32,8 @@ import org.onap.cps.api.parameters.PaginationOption;
*/
public interface CpsQueryService {
+ 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..a3884820c7 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) {
+ 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);
+ 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/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java
index ab7a095572..04b491692a 100644
--- a/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java
+++ b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java
@@ -33,6 +33,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import lombok.NoArgsConstructor;
@@ -77,7 +78,7 @@ public final class YangTextSchemaSourceSetBuilder {
* @return the YangTextSchemaSourceSet
*/
public YangTextSchemaSourceSet build() {
- final var schemaContext = generateSchemaContext(yangModelMap.build());
+ final SchemaContext schemaContext = generateSchemaContext(yangModelMap.build());
return new YangTextSchemaSourceSetImpl(schemaContext);
}
@@ -113,9 +114,7 @@ public final class YangTextSchemaSourceSetBuilder {
@Override
public List<ModuleReference> getModuleReferences() {
- return schemaContext.getModules().stream()
- .map(YangTextSchemaSourceSetImpl::toModuleReference)
- .collect(Collectors.toList());
+ return schemaContext.getModules().stream().map(YangTextSchemaSourceSetImpl::toModuleReference).toList();
}
private static ModuleReference toModuleReference(final Module module) {
@@ -164,12 +163,11 @@ public final class YangTextSchemaSourceSetBuilder {
private static List<YangTextSchemaSource> forResources(final Map<String, String> yangResourceNameToContent) {
return yangResourceNameToContent.entrySet().stream()
- .map(entry -> toYangTextSchemaSource(entry.getKey(), entry.getValue()))
- .collect(Collectors.toList());
+ .map(entry -> toYangTextSchemaSource(entry.getKey(), entry.getValue())).toList();
}
private static YangTextSchemaSource toYangTextSchemaSource(final String sourceName, final String source) {
- final var revisionSourceIdentifier =
+ final RevisionSourceIdentifier revisionSourceIdentifier =
createIdentifierFromSourceName(checkNotNull(sourceName));
return new YangTextSchemaSource(revisionSourceIdentifier) {
@@ -192,7 +190,7 @@ public final class YangTextSchemaSourceSetBuilder {
}
private static RevisionSourceIdentifier createIdentifierFromSourceName(final String sourceName) {
- final var matcher = RFC6020_RECOMMENDED_FILENAME_PATTERN.matcher(sourceName);
+ final Matcher matcher = RFC6020_RECOMMENDED_FILENAME_PATTERN.matcher(sourceName);
if (matcher.matches()) {
return RevisionSourceIdentifier.create(matcher.group(1), Revision.of(matcher.group(2)));
}
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'