aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri')
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java32
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java9
2 files changed, 33 insertions, 8 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
index b115f9a3c7..1e42702ab5 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020-2023 Nordix Foundation
+ * Copyright (C) 2020-2024 Nordix Foundation
* Modifications Copyright (C) 2020-2022 Bell Canada.
* Modifications Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2022 TechMahindra Ltd.
@@ -32,6 +32,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -79,6 +80,8 @@ import org.springframework.stereotype.Component;
public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceService {
private static final String YANG_RESOURCE_CHECKSUM_CONSTRAINT_NAME = "yang_resource_checksum_key";
+ private static final String NO_MODULE_NAME_FILTER = null;
+ private static final String NO_MODULE_REVISION = null;
private static final Pattern CHECKSUM_EXCEPTION_PATTERN = Pattern.compile(".*\\(checksum\\)=\\((\\w+)\\).*");
private static final Pattern RFC6020_RECOMMENDED_FILENAME_PATTERN = Pattern
.compile("([\\w-]+)@(\\d{4}-\\d{2}-\\d{2})(?:\\.yang)?", Pattern.CASE_INSENSITIVE);
@@ -122,10 +125,29 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
public Collection<ModuleDefinition> getYangResourceDefinitions(final String dataspaceName,
final String anchorName) {
final Set<YangResourceEntity> yangResourceEntities =
- yangResourceRepository
- .findAllModuleDefinitionsByDataspaceAndAnchor(dataspaceName, anchorName);
- return yangResourceEntities.stream().map(CpsModulePersistenceServiceImpl::toModuleDefinition)
- .collect(Collectors.toList());
+ yangResourceRepository.findAllModuleDefinitionsByDataspaceAndAnchorAndModule(dataspaceName, anchorName,
+ NO_MODULE_NAME_FILTER, NO_MODULE_REVISION);
+ return convertYangResourceEntityToModuleDefinition(yangResourceEntities);
+ }
+
+ @Override
+ public Collection<ModuleDefinition> getYangResourceDefinitionsByAnchorAndModule(final String dataspaceName,
+ final String anchorName,
+ final String moduleName,
+ final String moduleRevision) {
+ final Set<YangResourceEntity> yangResourceEntities =
+ yangResourceRepository.findAllModuleDefinitionsByDataspaceAndAnchorAndModule(dataspaceName, anchorName,
+ moduleName, moduleRevision);
+ return convertYangResourceEntityToModuleDefinition(yangResourceEntities);
+ }
+
+ private List<ModuleDefinition> convertYangResourceEntityToModuleDefinition(final Set<YangResourceEntity>
+ yangResourceEntities) {
+ final List<ModuleDefinition> resultModuleDefinitions = new ArrayList<>(yangResourceEntities.size());
+ for (final YangResourceEntity yangResourceEntity: yangResourceEntities) {
+ resultModuleDefinitions.add(toModuleDefinition(yangResourceEntity));
+ }
+ return resultModuleDefinitions;
}
@Override
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java
index 3fec462b44..b37f6357c1 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/YangResourceRepository.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Pantheon.tech
- * Modifications Copyright (C) 2021-2023 Nordix Foundation
+ * Modifications Copyright (C) 2021-2024 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -84,9 +84,12 @@ public interface YangResourceRepository extends JpaRepository<YangResourceEntity
WHERE
dataspace.name = :dataspaceName
AND anchor.name = :anchorName
+ AND (:moduleName IS NULL OR yang_resource.module_name = :moduleName)
+ AND (:revision IS NULL OR yang_resource.revision = :revision)
""", nativeQuery = true)
- Set<YangResourceEntity> findAllModuleDefinitionsByDataspaceAndAnchor(
- @Param("dataspaceName") String dataspaceName, @Param("anchorName") String anchorName);
+ Set<YangResourceEntity> findAllModuleDefinitionsByDataspaceAndAnchorAndModule(
+ @Param("dataspaceName") String dataspaceName, @Param("anchorName") String anchorName,
+ @Param("moduleName") String moduleName, @Param("revision") String revision);
@Query(value = """
SELECT DISTINCT