summaryrefslogtreecommitdiffstats
path: root/cps-ri/src
diff options
context:
space:
mode:
authorhalil.cakal <halil.cakal@est.tech>2024-01-23 10:05:36 +0000
committerhalil.cakal <halil.cakal@est.tech>2024-02-01 16:41:39 +0000
commit04280e2f93bbf30e8654c411bb1e107d275c22bb (patch)
treefaf4ac9ae4d80617f6b11cb0d78174e0c12452db /cps-ri/src
parent0f6a966b363e5347de2d44b1527d19b4cf2825a6 (diff)
Extend API: Get Module Definitions
- add query parameters: module-name and revision to OpenAPI - extend the controller method to hande the new parameters - add the new method stack to the service layer - extend the SQL query to support the new parameters - add unit and integration testwares Issue-ID: CPS-1135 Change-Id: I089ad2ad71effb58ac0ba809e9f441d6cdb59c4f Signed-off-by: halil.cakal <halil.cakal@est.tech>
Diffstat (limited to 'cps-ri/src')
-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