summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest/src/main
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-ncmp-rest/src/main
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-ncmp-rest/src/main')
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java35
1 files changed, 26 insertions, 9 deletions
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
index be33c6a010..6ec24448d7 100755
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Pantheon.tech
- * Modifications Copyright (C) 2021-2023 Nordix Foundation
+ * Modifications Copyright (C) 2021-2024 Nordix Foundation
* Modifications Copyright (C) 2021 highstreet technologies GmbH
* Modifications Copyright (C) 2021-2022 Bell Canada
* ================================================================================
@@ -31,6 +31,7 @@ import static org.onap.cps.ncmp.api.impl.operations.OperationType.PATCH;
import static org.onap.cps.ncmp.api.impl.operations.OperationType.UPDATE;
import io.micrometer.core.annotation.Timed;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -59,9 +60,11 @@ import org.onap.cps.ncmp.rest.model.RestOutputCmHandle;
import org.onap.cps.ncmp.rest.model.RestOutputCmHandleCompositeState;
import org.onap.cps.ncmp.rest.model.RestOutputCmHandlePublicProperties;
import org.onap.cps.ncmp.rest.util.DeprecationHelper;
+import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
+import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -317,18 +320,32 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
}
/**
- * Return module definitions for a cm handle.
+ * Return module definitions.
*
- * @param cmHandleId cm-handle identifier
+ * @param cmHandleId cm-handle identifier
+ * @param moduleName module name
+ * @param revision the revision of the module
* @return list of module definitions (module name, revision, yang resource content)
*/
@Override
- public ResponseEntity<List<RestModuleDefinition>> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
- final List<RestModuleDefinition> restModuleDefinitions =
- networkCmProxyDataService.getModuleDefinitionsByCmHandleId(cmHandleId).stream()
- .map(ncmpRestInputMapper::toRestModuleDefinition)
- .collect(Collectors.toList());
- return new ResponseEntity<>(restModuleDefinitions, HttpStatus.OK);
+ public ResponseEntity<List<RestModuleDefinition>> getModuleDefinitions(final String cmHandleId,
+ final String moduleName,
+ final String revision) {
+ final Collection<ModuleDefinition> moduleDefinitions;
+ if (StringUtils.hasText(moduleName)) {
+ moduleDefinitions =
+ networkCmProxyDataService.getModuleDefinitionsByCmHandleAndModule(cmHandleId, moduleName, revision);
+ } else {
+ moduleDefinitions = networkCmProxyDataService.getModuleDefinitionsByCmHandleId(cmHandleId);
+ if (StringUtils.hasText(revision)) {
+ log.warn("Ignoring revision filter as no module name is provided");
+ }
+ }
+ final List<RestModuleDefinition> response = new ArrayList<>();
+ for (final ModuleDefinition moduleDefinition: moduleDefinitions) {
+ response.add(ncmpRestInputMapper.toRestModuleDefinition(moduleDefinition));
+ }
+ return new ResponseEntity<>(response, HttpStatus.OK);
}
/**