diff options
author | sourabh_sourabh <sourabh.sourabh@est.tech> | 2024-01-04 17:01:27 +0000 |
---|---|---|
committer | sourabh_sourabh <sourabh.sourabh@est.tech> | 2024-01-11 11:22:34 +0000 |
commit | 02d8bf8c8a3469f75ef841c9d8c72349c51f3330 (patch) | |
tree | c2334148ec039389f70eb626609a742356114a66 /dmi-plugin-demo-and-csit-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java | |
parent | 8092359e5a03ebfd1fe5afaee3e6e64fdba082d3 (diff) |
Improve dmi plugin csit stub
- Modified dmi plugin stub to return diff. modules based on cm handle
id
Issue-ID: CPS-2006
Change-Id: I61a0fd11b8f41ceb69dac296ad3570b91137cdcd
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Diffstat (limited to 'dmi-plugin-demo-and-csit-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java')
-rw-r--r-- | dmi-plugin-demo-and-csit-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/DmiRestStubController.java | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/dmi-plugin-demo-and-csit-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/DmiRestStubController.java b/dmi-plugin-demo-and-csit-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/DmiRestStubController.java index 5c724290db..a4f7111324 100644 --- a/dmi-plugin-demo-and-csit-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/DmiRestStubController.java +++ b/dmi-plugin-demo-and-csit-stub/dmi-plugin-demo-and-csit-stub-service/src/main/java/org/onap/cps/ncmp/dmi/rest/stub/controller/DmiRestStubController.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation + * Copyright (C) 2023-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. @@ -44,6 +44,7 @@ import org.onap.cps.ncmp.events.async1_0_0.DataOperationEvent; import org.onap.cps.ncmp.events.async1_0_0.Response; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; +import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -73,37 +74,35 @@ public class DmiRestStubController { /** * Get all modules for given cm handle. * - * @param cmHandle The identifier for a network function, network element, subnetwork, + * @param cmHandleId The identifier for a network function, network element, subnetwork, * or any other cm object by managed Network CM Proxy * @param moduleReferencesRequest module references request body * @return ResponseEntity response entity having module response as json string. */ - @PostMapping("/v1/ch/{cmHandle}/modules") - public ResponseEntity<String> getModuleReferences(@PathVariable final String cmHandle, + @PostMapping("/v1/ch/{cmHandleId}/modules") + public ResponseEntity<String> getModuleReferences(@PathVariable final String cmHandleId, @RequestBody final Object moduleReferencesRequest) { - final String moduleResponseContent = ResourceFileReaderUtil - .getResourceFileContent(applicationContext.getResource( - ResourceLoader.CLASSPATH_URL_PREFIX + "module/moduleResponse.json")); - log.info("cm handle: {} requested for modules", cmHandle); + final String moduleResponseContent = getModuleResourceResponse(cmHandleId, + "ModuleResponse.json"); + log.info("cm handle: {} requested for modules", cmHandleId); return ResponseEntity.ok(moduleResponseContent); } /** - * Get all module resources for given cm handle. + * Retrieves module resources for a given cmHandleId. * - * @param cmHandle The identifier for a network function, network element, subnetwork, + * @param cmHandleId The identifier for a network function, network element, subnetwork, * or any other cm object by managed Network CM Proxy * @param moduleResourcesReadRequest module resources read request body * @return ResponseEntity response entity having module resources response as json string. */ - @PostMapping("/v1/ch/{cmHandle}/moduleResources") + @PostMapping("/v1/ch/{cmHandleId}/moduleResources") public ResponseEntity<String> retrieveModuleResources( - @PathVariable final String cmHandle, + @PathVariable final String cmHandleId, @RequestBody final Object moduleResourcesReadRequest) { - final String moduleResourcesResponseContent = ResourceFileReaderUtil - .getResourceFileContent(applicationContext.getResource( - ResourceLoader.CLASSPATH_URL_PREFIX + "module/moduleResourcesResponse.json")); - log.info("cm handle: {} requested for module resources", cmHandle); + final String moduleResourcesResponseContent = getModuleResourceResponse(cmHandleId, + "ModuleResourcesResponse.json"); + log.info("cm handle: {} requested for modules resources", cmHandleId); return ResponseEntity.ok(moduleResourcesResponseContent); } @@ -186,4 +185,18 @@ public class DmiRestStubController { dataOperationEvent.setData(data); return dataOperationEvent; } + + private String getModuleResourceResponse(final String cmHandleId, final String moduleResponseType) { + final String nodeType = cmHandleId.split("-")[0]; + final String moduleResponseFilePath = String.format("module/%s%s", nodeType, moduleResponseType); + final Resource moduleResponseResource = applicationContext.getResource( + ResourceLoader.CLASSPATH_URL_PREFIX + moduleResponseFilePath); + if (moduleResponseResource.exists()) { + log.info("Using requested node type: {}", nodeType); + return ResourceFileReaderUtil.getResourceFileContent(moduleResponseResource); + } + log.info("Using default node type: ietfYang"); + return ResourceFileReaderUtil.getResourceFileContent(applicationContext.getResource( + ResourceLoader.CLASSPATH_URL_PREFIX + "module/ietfYang" + moduleResponseType)); + } } |