aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service/src/main/java')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsDataService.java4
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java21
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsQueryService.java16
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/model/DataNode.java7
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/model/DeltaReport.java7
-rw-r--r--cps-service/src/main/java/org/onap/cps/impl/CpsAnchorServiceImpl.java2
-rw-r--r--cps-service/src/main/java/org/onap/cps/impl/CpsDataServiceImpl.java27
-rw-r--r--cps-service/src/main/java/org/onap/cps/impl/CpsDataspaceServiceImpl.java2
-rw-r--r--cps-service/src/main/java/org/onap/cps/impl/CpsDeltaServiceImpl.java1
-rw-r--r--cps-service/src/main/java/org/onap/cps/impl/CpsModuleServiceImpl.java28
-rw-r--r--cps-service/src/main/java/org/onap/cps/impl/CpsQueryServiceImpl.java24
-rw-r--r--cps-service/src/main/java/org/onap/cps/impl/DataNodeBuilder.java (renamed from cps-service/src/main/java/org/onap/cps/api/model/DataNodeBuilder.java)3
-rw-r--r--cps-service/src/main/java/org/onap/cps/impl/DeltaReportBuilder.java (renamed from cps-service/src/main/java/org/onap/cps/api/model/DeltaReportBuilder.java)3
-rw-r--r--cps-service/src/main/java/org/onap/cps/impl/YangTextSchemaSourceSetCache.java2
-rw-r--r--cps-service/src/main/java/org/onap/cps/init/AbstractModelLoader.java4
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java31
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java41
-rw-r--r--cps-service/src/main/java/org/onap/cps/utils/CpsValidator.java (renamed from cps-service/src/main/java/org/onap/cps/impl/utils/CpsValidator.java)2
-rw-r--r--cps-service/src/main/java/org/onap/cps/utils/YangParser.java16
-rw-r--r--cps-service/src/main/java/org/onap/cps/yang/TimedYangTextSchemaSourceSetBuilder.java4
20 files changed, 155 insertions, 90 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
index 345bc8825b..41713746b7 100644
--- a/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpsDataService.java
@@ -314,13 +314,13 @@ public interface CpsDataService {
* @param dataspaceName source dataspace name
* @param sourceAnchorName source anchor name
* @param xpath xpath
- * @param yangResourcesNameToContentMap YANG resources (files) map where key is a name and value is content
+ * @param yangResourceContentPerName YANG resources (files) map where key is a name and value is content
* @param targetData target data to be compared in JSON string format
* @param fetchDescendantsOption defines the scope of data to fetch: defaulted to INCLUDE_ALL_DESCENDANTS
* @return list containing {@link DeltaReport} objects
*/
List<DeltaReport> getDeltaByDataspaceAnchorAndPayload(String dataspaceName, String sourceAnchorName, String xpath,
- Map<String, String> yangResourcesNameToContentMap,
+ Map<String, String> yangResourceContentPerName,
String targetData,
FetchDescendantsOption fetchDescendantsOption);
diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java
index 81b6439efc..2494be4021 100644
--- a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java
@@ -40,21 +40,21 @@ public interface CpsModuleService {
*
* @param dataspaceName dataspace name
* @param schemaSetName schema set name
- * @param yangResourcesNameToContentMap yang resources (files) as a mep where key is resource name
+ * @param yangResourceContentPerName yang resources (files) as a mep where key is resource name
* and value is content
*/
void createSchemaSet(String dataspaceName, String schemaSetName,
- Map<String, String> yangResourcesNameToContentMap);
+ Map<String, String> yangResourceContentPerName);
/**
* Create or upgrade a schema set from new modules and existing modules or only existing modules.
- * @param dataspaceName Dataspace name
- * @param schemaSetName schema set name
- * @param newModuleNameToContentMap YANG resources map where key is a module name and value is content
- * @param allModuleReferences All YANG resource module references
+ * @param dataspaceName Dataspace name
+ * @param schemaSetName schema set name
+ * @param yangResourceContentPerName YANG resources map where key is a name and value is content
+ * @param allModuleReferences All YANG resource module references
*/
void createSchemaSetFromModules(String dataspaceName, String schemaSetName,
- Map<String, String> newModuleNameToContentMap,
+ Map<String, String> yangResourceContentPerName,
Collection<ModuleReference> allModuleReferences);
/**
@@ -164,8 +164,11 @@ public interface CpsModuleService {
Collection<ModuleReference> identifyNewModuleReferences(Collection<ModuleReference> moduleReferencesToCheck);
/**
- * Remove any Yang Resource Modules and Schema Sets from the DB that are no longer referenced by any anchor.
+ * Remove any Yang Resource Modules and Schema Sets from the given dataspace that are no longer referenced
+ * by any anchor.
+ *
+ * @param dataspaceName dataspace name
*/
- void deleteAllUnusedYangModuleData();
+ void deleteAllUnusedYangModuleData(String dataspaceName);
}
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/api/model/DataNode.java b/cps-service/src/main/java/org/onap/cps/api/model/DataNode.java
index be80b636ad..6597aa3908 100644
--- a/cps-service/src/main/java/org/onap/cps/api/model/DataNode.java
+++ b/cps-service/src/main/java/org/onap/cps/api/model/DataNode.java
@@ -26,20 +26,19 @@ import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
-import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
-@Setter(AccessLevel.PROTECTED)
+@Setter
@Getter
@EqualsAndHashCode
+@NoArgsConstructor
public class DataNode implements Serializable {
private static final long serialVersionUID = 1482619410918597467L;
- DataNode() {}
-
private String dataspace;
private String schemaSetName;
private String anchorName;
diff --git a/cps-service/src/main/java/org/onap/cps/api/model/DeltaReport.java b/cps-service/src/main/java/org/onap/cps/api/model/DeltaReport.java
index df642628d0..761c6ad01d 100644
--- a/cps-service/src/main/java/org/onap/cps/api/model/DeltaReport.java
+++ b/cps-service/src/main/java/org/onap/cps/api/model/DeltaReport.java
@@ -23,21 +23,20 @@ package org.onap.cps.api.model;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
import java.util.Map;
-import lombok.AccessLevel;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import lombok.Setter;
-@Setter(AccessLevel.PROTECTED)
+@Setter
@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
+@NoArgsConstructor
public class DeltaReport {
public static final String CREATE_ACTION = "create";
public static final String REMOVE_ACTION = "remove";
public static final String REPLACE_ACTION = "replace";
- DeltaReport() {}
-
private String action;
private String xpath;
private Map<String, Serializable> sourceData;
diff --git a/cps-service/src/main/java/org/onap/cps/impl/CpsAnchorServiceImpl.java b/cps-service/src/main/java/org/onap/cps/impl/CpsAnchorServiceImpl.java
index fb22311128..f18ae74c73 100644
--- a/cps-service/src/main/java/org/onap/cps/impl/CpsAnchorServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/impl/CpsAnchorServiceImpl.java
@@ -24,9 +24,9 @@ import java.util.Collection;
import lombok.RequiredArgsConstructor;
import org.onap.cps.api.CpsAnchorService;
import org.onap.cps.api.model.Anchor;
-import org.onap.cps.impl.utils.CpsValidator;
import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.CpsDataPersistenceService;
+import org.onap.cps.utils.CpsValidator;
import org.springframework.stereotype.Service;
@Service
diff --git a/cps-service/src/main/java/org/onap/cps/impl/CpsDataServiceImpl.java b/cps-service/src/main/java/org/onap/cps/impl/CpsDataServiceImpl.java
index f2513173a6..9f70ac9132 100644
--- a/cps-service/src/main/java/org/onap/cps/impl/CpsDataServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/impl/CpsDataServiceImpl.java
@@ -42,15 +42,14 @@ import org.onap.cps.api.CpsDeltaService;
import org.onap.cps.api.exceptions.DataValidationException;
import org.onap.cps.api.model.Anchor;
import org.onap.cps.api.model.DataNode;
-import org.onap.cps.api.model.DataNodeBuilder;
import org.onap.cps.api.model.DeltaReport;
import org.onap.cps.api.parameters.FetchDescendantsOption;
import org.onap.cps.cpspath.parser.CpsPathUtil;
import org.onap.cps.events.CpsDataUpdateEventsService;
import org.onap.cps.events.model.Data.Operation;
-import org.onap.cps.impl.utils.CpsValidator;
import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.utils.ContentType;
+import org.onap.cps.utils.CpsValidator;
import org.onap.cps.utils.DataMapUtils;
import org.onap.cps.utils.JsonObjectMapper;
import org.onap.cps.utils.PrefixResolver;
@@ -231,7 +230,7 @@ public class CpsDataServiceImpl implements CpsDataService {
@Override
public List<DeltaReport> getDeltaByDataspaceAnchorAndPayload(final String dataspaceName,
final String sourceAnchorName, final String xpath,
- final Map<String, String> yangResourcesNameToContentMap,
+ final Map<String, String> yangResourceContentPerName,
final String targetData,
final FetchDescendantsOption fetchDescendantsOption) {
@@ -244,7 +243,7 @@ public class CpsDataServiceImpl implements CpsDataService {
new ArrayList<>(rebuildSourceDataNodes(xpath, sourceAnchor, sourceDataNodes));
final Collection<DataNode> targetDataNodes =
- new ArrayList<>(buildTargetDataNodes(sourceAnchor, xpath, yangResourcesNameToContentMap, targetData));
+ new ArrayList<>(buildTargetDataNodes(sourceAnchor, xpath, yangResourceContentPerName, targetData));
return cpsDeltaService.getDeltaReports(sourceDataNodesRebuilt, targetDataNodes);
}
@@ -381,12 +380,12 @@ public class CpsDataServiceImpl implements CpsDataService {
}
private Collection<DataNode> buildTargetDataNodes(final Anchor sourceAnchor, final String xpath,
- final Map<String, String> yangResourcesNameToContentMap,
+ final Map<String, String> yangResourceContentPerName,
final String targetData) {
- if (yangResourcesNameToContentMap.isEmpty()) {
+ if (yangResourceContentPerName.isEmpty()) {
return buildDataNodesWithAnchorAndXpath(sourceAnchor, xpath, targetData, ContentType.JSON);
} else {
- return buildDataNodesWithYangResourceAndXpath(yangResourcesNameToContentMap, xpath,
+ return buildDataNodesWithYangResourceAndXpath(yangResourceContentPerName, xpath,
targetData, ContentType.JSON);
}
}
@@ -455,12 +454,12 @@ public class CpsDataServiceImpl implements CpsDataService {
}
private Collection<DataNode> buildDataNodesWithParentNodeXpath(
- final Map<String, String> yangResourcesNameToContentMap, final String xpath,
+ final Map<String, String> yangResourceContentPerName, final String xpath,
final String nodeData, final ContentType contentType) {
if (isRootNodeXpath(xpath)) {
final ContainerNode containerNode = yangParser.parseData(contentType, nodeData,
- yangResourcesNameToContentMap, PARENT_NODE_XPATH_FOR_ROOT_NODE_XPATH);
+ yangResourceContentPerName, PARENT_NODE_XPATH_FOR_ROOT_NODE_XPATH);
final Collection<DataNode> dataNodes = new DataNodeBuilder()
.withContainerNode(containerNode)
.buildCollection();
@@ -471,7 +470,7 @@ public class CpsDataServiceImpl implements CpsDataService {
}
final String normalizedParentNodeXpath = CpsPathUtil.getNormalizedXpath(xpath);
final ContainerNode containerNode =
- yangParser.parseData(contentType, nodeData, yangResourcesNameToContentMap, normalizedParentNodeXpath);
+ yangParser.parseData(contentType, nodeData, yangResourceContentPerName, normalizedParentNodeXpath);
final Collection<DataNode> dataNodes = new DataNodeBuilder()
.withParentNodeXpath(normalizedParentNodeXpath)
.withContainerNode(containerNode)
@@ -497,18 +496,18 @@ public class CpsDataServiceImpl implements CpsDataService {
}
private Collection<DataNode> buildDataNodesWithYangResourceAndXpath(
- final Map<String, String> yangResourcesNameToContentMap, final String xpath,
+ final Map<String, String> yangResourceContentPerName, final String xpath,
final String nodeData, final ContentType contentType) {
if (!isRootNodeXpath(xpath)) {
final String parentNodeXpath = CpsPathUtil.getNormalizedParentXpath(xpath);
if (parentNodeXpath.isEmpty()) {
- return buildDataNodesWithParentNodeXpath(yangResourcesNameToContentMap, ROOT_NODE_XPATH,
+ return buildDataNodesWithParentNodeXpath(yangResourceContentPerName, ROOT_NODE_XPATH,
nodeData, contentType);
}
- return buildDataNodesWithParentNodeXpath(yangResourcesNameToContentMap, parentNodeXpath,
+ return buildDataNodesWithParentNodeXpath(yangResourceContentPerName, parentNodeXpath,
nodeData, contentType);
}
- return buildDataNodesWithParentNodeXpath(yangResourcesNameToContentMap, xpath, nodeData, contentType);
+ return buildDataNodesWithParentNodeXpath(yangResourceContentPerName, xpath, nodeData, contentType);
}
private static boolean isRootNodeXpath(final String xpath) {
diff --git a/cps-service/src/main/java/org/onap/cps/impl/CpsDataspaceServiceImpl.java b/cps-service/src/main/java/org/onap/cps/impl/CpsDataspaceServiceImpl.java
index 15caa2276d..1a85147b64 100644
--- a/cps-service/src/main/java/org/onap/cps/impl/CpsDataspaceServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/impl/CpsDataspaceServiceImpl.java
@@ -27,8 +27,8 @@ import java.util.Collection;
import lombok.RequiredArgsConstructor;
import org.onap.cps.api.CpsDataspaceService;
import org.onap.cps.api.model.Dataspace;
-import org.onap.cps.impl.utils.CpsValidator;
import org.onap.cps.spi.CpsAdminPersistenceService;
+import org.onap.cps.utils.CpsValidator;
import org.springframework.stereotype.Service;
@Service
diff --git a/cps-service/src/main/java/org/onap/cps/impl/CpsDeltaServiceImpl.java b/cps-service/src/main/java/org/onap/cps/impl/CpsDeltaServiceImpl.java
index 7a9d142506..d532001aec 100644
--- a/cps-service/src/main/java/org/onap/cps/impl/CpsDeltaServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/impl/CpsDeltaServiceImpl.java
@@ -32,7 +32,6 @@ import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsDeltaService;
import org.onap.cps.api.model.DataNode;
import org.onap.cps.api.model.DeltaReport;
-import org.onap.cps.api.model.DeltaReportBuilder;
import org.springframework.stereotype.Service;
@Slf4j
diff --git a/cps-service/src/main/java/org/onap/cps/impl/CpsModuleServiceImpl.java b/cps-service/src/main/java/org/onap/cps/impl/CpsModuleServiceImpl.java
index 7622ba5fe2..e50325c739 100644
--- a/cps-service/src/main/java/org/onap/cps/impl/CpsModuleServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/impl/CpsModuleServiceImpl.java
@@ -36,8 +36,8 @@ import org.onap.cps.api.model.ModuleDefinition;
import org.onap.cps.api.model.ModuleReference;
import org.onap.cps.api.model.SchemaSet;
import org.onap.cps.api.parameters.CascadeDeleteAllowed;
-import org.onap.cps.impl.utils.CpsValidator;
import org.onap.cps.spi.CpsModulePersistenceService;
+import org.onap.cps.utils.CpsValidator;
import org.onap.cps.yang.TimedYangTextSchemaSourceSetBuilder;
import org.onap.cps.yang.YangTextSchemaSourceSet;
import org.springframework.stereotype.Service;
@@ -57,21 +57,21 @@ public class CpsModuleServiceImpl implements CpsModuleService {
@Timed(value = "cps.module.service.schemaset.create",
description = "Time taken to create (and store) a schemaset")
public void createSchemaSet(final String dataspaceName, final String schemaSetName,
- final Map<String, String> yangResourcesNameToContentMap) {
+ final Map<String, String> yangResourceContentPerName) {
cpsValidator.validateNameCharacters(dataspaceName);
- cpsModulePersistenceService.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap);
+ cpsModulePersistenceService.createSchemaSet(dataspaceName, schemaSetName, yangResourceContentPerName);
final YangTextSchemaSourceSet yangTextSchemaSourceSet =
- timedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourcesNameToContentMap);
+ timedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourceContentPerName);
yangTextSchemaSourceSetCache.updateCache(dataspaceName, schemaSetName, yangTextSchemaSourceSet);
}
@Override
public void createSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
- final Map<String, String> newModuleNameToContentMap,
+ final Map<String, String> yangResourceContentPerName,
final Collection<ModuleReference> allModuleReferences) {
cpsValidator.validateNameCharacters(dataspaceName);
- cpsModulePersistenceService.storeSchemaSetFromModules(dataspaceName, schemaSetName,
- newModuleNameToContentMap, allModuleReferences);
+ cpsModulePersistenceService.createSchemaSetFromNewAndExistingModules(dataspaceName, schemaSetName,
+ yangResourceContentPerName, allModuleReferences);
}
@Override
@@ -83,7 +83,7 @@ public class CpsModuleServiceImpl implements CpsModuleService {
@Override
public SchemaSet getSchemaSet(final String dataspaceName, final String schemaSetName) {
cpsValidator.validateNameCharacters(dataspaceName);
- final var yangTextSchemaSourceSet = yangTextSchemaSourceSetCache
+ final YangTextSchemaSourceSet yangTextSchemaSourceSet = yangTextSchemaSourceSetCache
.get(dataspaceName, schemaSetName);
return SchemaSet.builder().name(schemaSetName).dataspaceName(dataspaceName)
.moduleReferences(yangTextSchemaSourceSet.getModuleReferences()).build();
@@ -130,15 +130,14 @@ public class CpsModuleServiceImpl implements CpsModuleService {
@Override
public void upgradeSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
- final Map<String, String> newModuleNameToContentMap,
+ final Map<String, String> newYangResourceContentPerModule,
final Collection<ModuleReference> allModuleReferences) {
cpsValidator.validateNameCharacters(dataspaceName);
- cpsModulePersistenceService.updateSchemaSetFromModules(dataspaceName, schemaSetName,
- newModuleNameToContentMap, allModuleReferences);
+ cpsModulePersistenceService.updateSchemaSetFromNewAndExistingModules(dataspaceName, schemaSetName,
+ newYangResourceContentPerModule, allModuleReferences);
yangTextSchemaSourceSetCache.removeFromCache(dataspaceName, schemaSetName);
}
-
@Override
public Collection<ModuleReference> getYangResourceModuleReferences(final String dataspaceName) {
cpsValidator.validateNameCharacters(dataspaceName);
@@ -175,8 +174,9 @@ public class CpsModuleServiceImpl implements CpsModuleService {
}
@Override
- public void deleteAllUnusedYangModuleData() {
- cpsModulePersistenceService.deleteAllUnusedYangModuleData();
+ public void deleteAllUnusedYangModuleData(final String dataspaceName) {
+ cpsValidator.validateNameCharacters(dataspaceName);
+ cpsModulePersistenceService.deleteAllUnusedYangModuleData(dataspaceName);
}
private boolean isCascadeDeleteProhibited(final CascadeDeleteAllowed cascadeDeleteAllowed) {
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 e534e0aea1..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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2024 Nordix Foundation
+ * Copyright (C) 2021-2025 Nordix Foundation
* Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,8 +29,8 @@ import org.onap.cps.api.CpsQueryService;
import org.onap.cps.api.model.DataNode;
import org.onap.cps.api.parameters.FetchDescendantsOption;
import org.onap.cps.api.parameters.PaginationOption;
-import org.onap.cps.impl.utils.CpsValidator;
import org.onap.cps.spi.CpsDataPersistenceService;
+import org.onap.cps.utils.CpsValidator;
import org.springframework.stereotype.Service;
@Service
@@ -46,15 +46,29 @@ 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
public <T> Set<T> queryDataLeaf(final String dataspaceName, final String anchorName, final String cpsPath,
final Class<T> targetClass) {
cpsValidator.validateNameCharacters(dataspaceName, anchorName);
- throw new UnsupportedOperationException("Query by attribute-axis not implemented yet!");
+ return cpsDataPersistenceService.queryDataLeaf(dataspaceName, anchorName, cpsPath, targetClass);
}
@Override
diff --git a/cps-service/src/main/java/org/onap/cps/api/model/DataNodeBuilder.java b/cps-service/src/main/java/org/onap/cps/impl/DataNodeBuilder.java
index d509f53525..a78f3d9826 100644
--- a/cps-service/src/main/java/org/onap/cps/api/model/DataNodeBuilder.java
+++ b/cps-service/src/main/java/org/onap/cps/impl/DataNodeBuilder.java
@@ -20,7 +20,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.api.model;
+package org.onap.cps.impl;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
@@ -33,6 +33,7 @@ import java.util.Set;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.exceptions.DataValidationException;
+import org.onap.cps.api.model.DataNode;
import org.onap.cps.utils.YangUtils;
import org.opendaylight.yangtools.yang.common.Ordering;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
diff --git a/cps-service/src/main/java/org/onap/cps/api/model/DeltaReportBuilder.java b/cps-service/src/main/java/org/onap/cps/impl/DeltaReportBuilder.java
index a8e922f3df..fdc2e939d6 100644
--- a/cps-service/src/main/java/org/onap/cps/api/model/DeltaReportBuilder.java
+++ b/cps-service/src/main/java/org/onap/cps/impl/DeltaReportBuilder.java
@@ -18,11 +18,12 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.api.model;
+package org.onap.cps.impl;
import java.io.Serializable;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.api.model.DeltaReport;
@Slf4j
public class DeltaReportBuilder {
diff --git a/cps-service/src/main/java/org/onap/cps/impl/YangTextSchemaSourceSetCache.java b/cps-service/src/main/java/org/onap/cps/impl/YangTextSchemaSourceSetCache.java
index 688669c941..e7e7b1c5ce 100644
--- a/cps-service/src/main/java/org/onap/cps/impl/YangTextSchemaSourceSetCache.java
+++ b/cps-service/src/main/java/org/onap/cps/impl/YangTextSchemaSourceSetCache.java
@@ -27,8 +27,8 @@ import io.micrometer.core.instrument.Metrics;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import lombok.RequiredArgsConstructor;
-import org.onap.cps.impl.utils.CpsValidator;
import org.onap.cps.spi.CpsModulePersistenceService;
+import org.onap.cps.utils.CpsValidator;
import org.onap.cps.yang.YangTextSchemaSourceSet;
import org.onap.cps.yang.YangTextSchemaSourceSetBuilder;
import org.springframework.cache.annotation.CacheConfig;
diff --git a/cps-service/src/main/java/org/onap/cps/init/AbstractModelLoader.java b/cps-service/src/main/java/org/onap/cps/init/AbstractModelLoader.java
index e864633f25..a80239039a 100644
--- a/cps-service/src/main/java/org/onap/cps/init/AbstractModelLoader.java
+++ b/cps-service/src/main/java/org/onap/cps/init/AbstractModelLoader.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2023-2024 Nordix Foundation
+ * Copyright (C) 2023-2025 Nordix Foundation
* Modifications Copyright (C) 2024 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -77,7 +77,7 @@ public abstract class AbstractModelLoader implements ModelLoader {
} catch (final AlreadyDefinedException alreadyDefinedException) {
log.warn("Creating new schema set failed as schema set already exists");
} catch (final Exception exception) {
- log.error("Creating schema set failed: {} ", exception.getMessage());
+ log.error("Creating schema set {} failed: {} ", schemaSetName, exception.getMessage());
throw new ModelOnboardingException("Creating schema set failed", exception.getMessage());
}
}
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 5be5b1e2e0..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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020-2024 Nordix Foundation.
+ * Copyright (C) 2020-2025 Nordix Foundation.
* Modifications Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2022 Bell Canada
* Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
@@ -27,6 +27,7 @@ import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.onap.cps.api.model.DataNode;
import org.onap.cps.api.parameters.FetchDescendantsOption;
import org.onap.cps.api.parameters.PaginationOption;
@@ -185,6 +186,34 @@ 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
+ * @param anchorName anchor name
+ * @param cpsPath cps path
+ * @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);
+
+ /**
* Get a datanode by dataspace name and cps path across all anchors.
*
* @param dataspaceName dataspace name
diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java
index b1f8aad88f..02e1b6c754 100755
--- a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java
@@ -36,34 +36,37 @@ public interface CpsModulePersistenceService {
/**
* Stores Schema Set.
*
- * @param dataspaceName dataspace name
- * @param schemaSetName schema set name
- * @param yangResourcesNameToContentMap YANG resources (files) map where key is a name and value is content
+ * @param dataspaceName dataspace name
+ * @param schemaSetName schema set name
+ * @param yangResourceContentPerName a map of YANG resources map where key is a name and value is content
*/
- void storeSchemaSet(String dataspaceName, String schemaSetName, Map<String, String> yangResourcesNameToContentMap);
+ void createSchemaSet(String dataspaceName, String schemaSetName, Map<String, String> yangResourceContentPerName);
/**
* Stores a new schema set from new modules and existing modules.
*
- * @param dataspaceName Dataspace name
- * @param schemaSetName Schema set name
- * @param newModuleNameToContentMap YANG resources map where key is a module name and value is content
- * @param allModuleReferences All YANG resources module references
+ * @param dataspaceName dataspace name
+ * @param schemaSetName Schema set name
+ * @param newYangResourceContentPerName a map of only the new YANG resources
+ * the key is a name and value is its content
+ * @param allModuleReferences all YANG resources module references
*/
- void storeSchemaSetFromModules(String dataspaceName, String schemaSetName,
- Map<String, String> newModuleNameToContentMap, Collection<ModuleReference> allModuleReferences);
+ void createSchemaSetFromNewAndExistingModules(String dataspaceName, String schemaSetName,
+ Map<String, String> newYangResourceContentPerName,
+ Collection<ModuleReference> allModuleReferences);
/**
* Update an existing schema set from new modules and existing modules.
*
- * @param dataspaceName Dataspace name
+ * @param dataspaceName dataspace name
* @param schemaSetName Schema set name
- * @param newModuleNameToContentMap YANG resources map where key is a module name and value is content
- * @param allModuleReferences All YANG resources module references
+ * @param newYangResourcesPerName a map of only the new YANG resources
+ * the key is a module name and value is its content
+ * @param allModuleReferences all YANG resources module references
*/
- void updateSchemaSetFromModules(final String dataspaceName, final String schemaSetName,
- final Map<String, String> newModuleNameToContentMap,
- final Collection<ModuleReference> allModuleReferences);
+ void updateSchemaSetFromNewAndExistingModules(String dataspaceName, String schemaSetName,
+ Map<String, String> newYangResourcesPerName,
+ Collection<ModuleReference> allModuleReferences);
/**
* Checks whether a schema set exists in the specified dataspace.
@@ -146,9 +149,11 @@ public interface CpsModulePersistenceService {
String moduleName, String moduleRevision);
/**
- * Remove any unused Yang Resource Modules and Schema Sets.
+ * Remove any unused Yang Resource Modules and Schema Sets from the given dataspace.
+ *
+ * @param dataspaceName dataspace name
*/
- void deleteAllUnusedYangModuleData();
+ void deleteAllUnusedYangModuleData(String dataspaceName);
/**
* Identify new module references from those returned by a node compared to what is in CPS already.
diff --git a/cps-service/src/main/java/org/onap/cps/impl/utils/CpsValidator.java b/cps-service/src/main/java/org/onap/cps/utils/CpsValidator.java
index 75bcf126a4..93f51ee58d 100644
--- a/cps-service/src/main/java/org/onap/cps/impl/utils/CpsValidator.java
+++ b/cps-service/src/main/java/org/onap/cps/utils/CpsValidator.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.impl.utils;
+package org.onap.cps.utils;
import org.onap.cps.api.parameters.PaginationOption;
diff --git a/cps-service/src/main/java/org/onap/cps/utils/YangParser.java b/cps-service/src/main/java/org/onap/cps/utils/YangParser.java
index 08f450e2f1..5dfeb2fb3f 100644
--- a/cps-service/src/main/java/org/onap/cps/utils/YangParser.java
+++ b/cps-service/src/main/java/org/onap/cps/utils/YangParser.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2024 Nordix Foundation.
+ * Copyright (C) 2024-2025 Nordix Foundation.
* Modifications Copyright (C) 2024 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -71,17 +71,17 @@ public class YangParser {
/**
* Parses data into (normalized) ContainerNode according to schema context for the given yang resource.
*
- * @param nodeData data string
- * @param yangResourcesNameToContentMap yang resource to content map
- * @return the NormalizedNode object
+ * @param nodeData data string
+ * @param yangResourceContentPerName yang resource content per name
+ * @return the NormalizedNode object
*/
@Timed(value = "cps.utils.yangparser.nodedata.with.parent.with.yangResourceMap.parse",
description = "Time taken to parse node data with a parent")
public ContainerNode parseData(final ContentType contentType,
final String nodeData,
- final Map<String, String> yangResourcesNameToContentMap,
+ final Map<String, String> yangResourceContentPerName,
final String parentNodeXpath) {
- final SchemaContext schemaContext = getSchemaContext(yangResourcesNameToContentMap);
+ final SchemaContext schemaContext = getSchemaContext(yangResourceContentPerName);
return yangParserHelper.parseData(contentType, nodeData, schemaContext, parentNodeXpath, VALIDATE_AND_PARSE);
}
@@ -114,8 +114,8 @@ public class YangParser {
anchor.getSchemaSetName()).getSchemaContext();
}
- private SchemaContext getSchemaContext(final Map<String, String> yangResourcesNameToContentMap) {
- return timedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourcesNameToContentMap)
+ private SchemaContext getSchemaContext(final Map<String, String> yangResourceContentPerName) {
+ return timedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourceContentPerName)
.getSchemaContext();
}
diff --git a/cps-service/src/main/java/org/onap/cps/yang/TimedYangTextSchemaSourceSetBuilder.java b/cps-service/src/main/java/org/onap/cps/yang/TimedYangTextSchemaSourceSetBuilder.java
index 013faff0c8..9b2ac944dc 100644
--- a/cps-service/src/main/java/org/onap/cps/yang/TimedYangTextSchemaSourceSetBuilder.java
+++ b/cps-service/src/main/java/org/onap/cps/yang/TimedYangTextSchemaSourceSetBuilder.java
@@ -30,8 +30,8 @@ public class TimedYangTextSchemaSourceSetBuilder {
@Timed(value = "cps.yangtextschemasourceset.build",
description = "Time taken to build a yang text schema source set")
public YangTextSchemaSourceSet getYangTextSchemaSourceSet(
- final Map<String, String> yangResourcesNameToContentMap) {
- return YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap);
+ final Map<String, String> yangResourceContentPerName) {
+ return YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName);
}
}