Updating get module schema request body 03/124703/3
authorniamhcore <niamh.core@est.tech>
Wed, 6 Oct 2021 08:49:12 +0000 (09:49 +0100)
committerniamhcore <niamh.core@est.tech>
Thu, 7 Oct 2021 10:51:40 +0000 (11:51 +0100)
Issue-ID: CPS-706
Signed-off-by: niamhcore <niamh.core@est.tech>
Change-Id: I92d241c4ccde77aaaf8aa5a3903437016edf65d0

docs/openapi/components.yml
docs/openapi/openapi.yml
src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java
src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
src/test/resources/GetModules.json

index a03cb1f..30e5987 100644 (file)
@@ -19,14 +19,15 @@ components:
           items:
             type: string
 
-    DmiModuleReadRequestBody:
+    ModuleReferencesRequest:
+      type: object
+      properties:
+        cmHandleProperties:
+          $ref: '#/components/schemas/cmHandleProperties'
+
+    ModuleResourcesReadRequest:
       type: object
       properties:
-        operation:
-          type: string
-          enum: [read]
-        dataType:
-          type: string
         data:
           type: object
           properties:
@@ -36,9 +37,9 @@ components:
                 type: object
                 properties:
                   name:
-                    type: string
+                    $ref: '#/components/schemas/name'
                   revision:
-                    type: string
+                    $ref: '#/components/schemas/revision'
         cmHandleProperties:
           $ref: '#/components/schemas/cmHandleProperties'
 
@@ -53,7 +54,7 @@ components:
               moduleName:
                 type: string
               revision:
-                type: string
+                $ref: '#/components/schemas/revision'
               namespace:
                 type: string
 
@@ -70,7 +71,7 @@ components:
         moduleName:
           type: string
         revision:
-          type: string
+          $ref: '#/components/schemas/revision'
 
     DataAccessReadRequest:
       type: object
@@ -100,6 +101,14 @@ components:
         type: string
         example: {"prop1":"value1","prop2":"value2"}
 
+    name:
+      type: string
+      example: someName
+
+    revision:
+      type: string
+      example: someRevision
+
   responses:
     NotFound:
       description: The specified resource was not found
index 66f2e6b..83c05ab 100644 (file)
@@ -37,7 +37,7 @@ paths:
         - dmi-plugin
       summary: Get all modules for cm handle
       description: Get all modules for given cm handle
-      operationId: getModulesForCmHandle
+      operationId: getModuleReferences
       parameters:
         - name: cmHandle
           in: path
@@ -50,7 +50,7 @@ paths:
         content:
           application/json:
             schema:
-              $ref: 'components.yml#/components/schemas/DataAccessReadRequest'
+              $ref: 'components.yml#/components/schemas/ModuleReferencesRequest'
       responses:
         '200':
           description: OK
@@ -113,7 +113,7 @@ paths:
         content:
           application/json:
             schema:
-              $ref: 'components.yml#/components/schemas/DmiModuleReadRequestBody'
+              $ref: 'components.yml#/components/schemas/ModuleResourcesReadRequest'
       responses:
         '200':
           description: OK
index 908ccbe..b17280a 100644 (file)
@@ -20,8 +20,6 @@
 
 package org.onap.cps.ncmp.dmi.rest.controller;
 
-import static org.onap.cps.ncmp.dmi.model.DmiModuleReadRequestBody.OperationEnum.READ;
-
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import java.util.List;
@@ -30,7 +28,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.onap.cps.ncmp.dmi.model.CmHandles;
 import org.onap.cps.ncmp.dmi.model.DataAccessReadRequest;
 import org.onap.cps.ncmp.dmi.model.DataAccessWriteRequest;
-import org.onap.cps.ncmp.dmi.model.DmiModuleReadRequestBody;
+import org.onap.cps.ncmp.dmi.model.ModuleReferencesRequest;
+import org.onap.cps.ncmp.dmi.model.ModuleResourcesReadRequest;
 import org.onap.cps.ncmp.dmi.model.ModuleSet;
 import org.onap.cps.ncmp.dmi.model.YangResources;
 import org.onap.cps.ncmp.dmi.rest.api.DmiPluginApi;
@@ -58,8 +57,8 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
     }
 
     @Override
-    public ResponseEntity<ModuleSet> getModulesForCmHandle(final String cmHandle,
-                                                           final @Valid DataAccessReadRequest body) {
+    public ResponseEntity<ModuleSet> getModuleReferences(final String cmHandle,
+                                                           final @Valid ModuleReferencesRequest body) {
         // For onap-dmi-plugin we don't need cmHandleProperties, so DataAccessReadRequest is not used.
         final var moduleSet = dmiService.getModulesForCmHandle(cmHandle);
         return ResponseEntity.ok(moduleSet);
@@ -67,14 +66,11 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
 
     @Override
     public ResponseEntity<YangResources> retrieveModuleResources(
-            final @Valid DmiModuleReadRequestBody dmiModuleReadRequestBody,
-            final String cmHandle) {
-        if (READ.equals(dmiModuleReadRequestBody.getOperation())) {
-            final var moduleReferenceList = convertRestObjectToJavaApiObject(dmiModuleReadRequestBody);
-            final var response = dmiService.getModuleResources(cmHandle, moduleReferenceList);
-            return new ResponseEntity<>(response, HttpStatus.OK);
-        }
-        return new ResponseEntity<>(HttpStatus.CONFLICT);
+        final @Valid ModuleResourcesReadRequest moduleResourcesReadRequest,
+        final String cmHandle) {
+        final List<ModuleReference> moduleReferences = convertRestObjectToJavaApiObject(moduleResourcesReadRequest);
+        final YangResources yangResources = dmiService.getModuleResources(cmHandle, moduleReferences);
+        return new ResponseEntity<>(yangResources, HttpStatus.OK);
     }
 
     /**
@@ -162,9 +158,9 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi {
     }
 
     private List<ModuleReference> convertRestObjectToJavaApiObject(
-            final DmiModuleReadRequestBody dmiModuleSchemaReadRequestBody) {
+            final ModuleResourcesReadRequest moduleResourcesReadRequest) {
         return objectMapper
-            .convertValue(dmiModuleSchemaReadRequestBody.getData().getModules(),
+            .convertValue(moduleResourcesReadRequest.getData().getModules(),
                           new TypeReference<List<ModuleReference>>() {});
     }
 }
index 3bc1f3b..ac78928 100644 (file)
@@ -65,7 +65,7 @@ class DmiRestControllerSpec extends Specification {
         given: 'REST endpoint for getting all modules'
             def getModuleUrl = "$basePathV1/ch/node1/modules"
         and: 'get modules for cm-handle returns a json'
-            def json = '{"operation" : "read", "cmHandleProperties" : {}}'
+            def json = '{"cmHandleProperties" : {}}'
             def moduleSetSchema = new ModuleSetSchemas(namespace:'some-namespace',
                                                         moduleName:'some-moduleName',
                                                         revision:'some-revision')
@@ -101,7 +101,7 @@ class DmiRestControllerSpec extends Specification {
         given: 'REST endpoint for getting all modules'
             def getModuleUrl = "$basePathV1/ch/node1/modules"
         and: 'given request body and get modules for cm-handle throws #exceptionClass'
-            def json = '{"operation" : "read", "cmHandleProperties" : {}}'
+            def json = '{"cmHandleProperties" : {}}'
             mockDmiService.getModulesForCmHandle('node1') >> { throw Mock(exceptionClass) }
         when: 'post is invoked'
             def response = mvc.perform( post(getModuleUrl)
@@ -150,7 +150,7 @@ class DmiRestControllerSpec extends Specification {
     def 'Retrieve module resources.'() {
         given: 'an endpoint and json data'
             def getModulesEndpoint = "$basePathV1/ch/some-cm-handle/moduleResources"
-            String jsonData = getJsonDataForGetModules('read')
+            String jsonData = TestUtils.getResourceFileContent('GetModules.json')
         and: 'the DMI service returns the yang resources'
             ModuleReference moduleReference1 = new ModuleReference(name: 'ietf-yang-library', revision: '2016-06-21')
             ModuleReference moduleReference2 = new ModuleReference(name: 'nc-notifications', revision: '2008-07-14')
@@ -169,22 +169,10 @@ class DmiRestControllerSpec extends Specification {
             response.getContentAsString() == '[{"yangSource":"\\"some-data\\"","moduleName":"NAME","revision":"REVISION"}]'
     }
 
-    def 'Retrieve module resources with invalid operation.'() {
-        given: 'an endpoint and json data with invalid operation value'
-            def getModulesEndpoint = "$basePathV1/ch/some-cm-handle/moduleResources"
-            def jsonData = getJsonDataForGetModules('invalid operation')
-        when: 'get module resource api is invoked'
-            def response = mvc.perform(post(getModulesEndpoint)
-                .contentType(MediaType.APPLICATION_JSON)
-                .content(jsonData)).andReturn().response
-        then: 'a conflict status is returned'
-            response.status == HttpStatus.CONFLICT.value()
-    }
-
     def 'Retrieve module resources with exception handling.'() {
         given: 'an endpoint and json data'
             def getModulesEndpoint = "$basePathV1/ch/some-cm-handle/moduleResources"
-            String jsonData = getJsonDataForGetModules('read')
+            String jsonData = TestUtils.getResourceFileContent('GetModules.json')
         and: 'the service method is invoked to get module resources and throws an exception'
             mockDmiService.getModuleResources('some-cm-handle', _) >> { throw Mock(ModuleResourceNotFoundException.class) }
         when: 'get module resource api is invoked'
@@ -267,10 +255,4 @@ class DmiRestControllerSpec extends Specification {
             '? needs to be encoded as %3F' | 'idWith%3F'
 
     }
-
-    def getJsonDataForGetModules(operation) {
-        def jsonData = TestUtils.getResourceFileContent('GetModules.json')
-        return jsonData.replace('${operation-for-test}', operation)
-    }
-
 }
index 98e4167..57f5aef 100644 (file)
@@ -1,5 +1,4 @@
 {
-  "operation": "${operation-for-test}",
   "data": {
     "modules": [
       {