Support Alternate-id for CPS-E05 module definition 46/138846/7
authorseanbeirne <sean.beirne@est.tech>
Mon, 26 Aug 2024 13:13:29 +0000 (14:13 +0100)
committerseanbeirne <sean.beirne@est.tech>
Mon, 2 Sep 2024 13:09:25 +0000 (14:09 +0100)
Issue-ID: CPS-2379
Change-Id: Idd180c5792575522ceaaa094b94c8f5b36790186
Signed-off-by: seanbeirne <sean.beirne@est.tech>
cps-ncmp-rest/docs/openapi/ncmp.yml
cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java
cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyControllerSpec.groovy
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/NetworkCmProxyInventoryFacade.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/NetworkCmProxyInventoryFacadeSpec.groovy

index 9a6c076..c12b1c4 100755 (executable)
@@ -289,7 +289,7 @@ getModuleDefinitions:
     description: Get module definitions (module name, revision, yang resource) with options to filter on module name and revision
     operationId: getModuleDefinitions
     parameters:
-      - $ref: 'components.yaml#/components/parameters/cmHandleInPath'
+      - $ref: 'components.yaml#/components/parameters/cmHandleReferenceInPath'
       - $ref: 'components.yaml#/components/parameters/moduleNameInQuery'
       - $ref: 'components.yaml#/components/parameters/revisionInQuery'
     responses:
index ca2907b..b98d8c3 100755 (executable)
@@ -334,21 +334,23 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
     /**
      * Return module definitions.
      *
-     * @param cmHandleId    cm-handle identifier
-     * @param moduleName    module name
-     * @param revision      the revision of the module
+     * @param cmHandleReference   cm handle or alternate id 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>> getModuleDefinitions(final String cmHandleId,
+    public ResponseEntity<List<RestModuleDefinition>> getModuleDefinitions(final String cmHandleReference,
                                                                            final String moduleName,
                                                                            final String revision) {
         final Collection<ModuleDefinition> moduleDefinitions;
         if (StringUtils.hasText(moduleName)) {
             moduleDefinitions =
-                networkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleAndModule(cmHandleId, moduleName, revision);
+                networkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleAndModule(cmHandleReference,
+                    moduleName, revision);
         } else {
-            moduleDefinitions = networkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleId(cmHandleId);
+            moduleDefinitions =
+                networkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleReference(cmHandleReference);
             if (StringUtils.hasText(revision)) {
                 log.warn("Ignoring revision filter as no module name is provided");
             }
index 80e74ca..ef4cdfa 100644 (file)
@@ -415,12 +415,12 @@ class NetworkCmProxyControllerSpec extends Specification {
     def 'Getting module definitions filtering on #scenario'() {
         when: 'get module definition request is performed'
             def response = mvc.perform(
-                get("$ncmpBasePathV1/ch/some-cmhandle/modules/definitions?module-name=" + moduleName + "&revision=" + revision))
+                get("$ncmpBasePathV1/ch/some-cmhandle-reference/modules/definitions?module-name=" + moduleName + "&revision=" + revision))
                 .andReturn().response
-        then: 'ncmp service method to get definitions by cm handle is invoked when needed'
-            numberOfCallsToByCmHandleId * mockNetworkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleId('some-cmhandle') >> []
+        then: 'ncmp service method to get definitions by cm handle reference is invoked when needed'
+            numberOfCallsToByCmHandleId * mockNetworkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleReference('some-cmhandle-reference') >> []
         and: 'ncmp service method to get definitions by module is invoked when needed'
-            numberOfCallsToByModule * mockNetworkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleAndModule('some-cmhandle', moduleName, revision) >> []
+            numberOfCallsToByModule * mockNetworkCmProxyInventoryFacade.getModuleDefinitionsByCmHandleAndModule('some-cmhandle-reference', moduleName, revision) >> []
         and: 'response returns an OK http code'
             response.status == HttpStatus.OK.value()
         and: 'the correct message is logged when needed'
index 785eb8f..cd3c00c 100644 (file)
@@ -113,24 +113,26 @@ public class NetworkCmProxyInventoryFacade {
     /**
      * Retrieve module definitions for the given cm handle.
      *
-     * @param cmHandleId cm handle identifier
+     * @param cmHandleReference cm handle or alternate id identifier
      * @return a collection of module definition (moduleName, revision and yang resource content)
      */
-    public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
+    public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleReference(final String cmHandleReference) {
+        final String cmHandleId = alternateIdMatcher.getCmHandleId(cmHandleReference);
         return inventoryPersistence.getModuleDefinitionsByCmHandleId(cmHandleId);
     }
 
     /**
      * Get module definitions for the given parameters.
      *
-     * @param cmHandleId        cm-handle identifier
-     * @param moduleName        module name
-     * @param moduleRevision    the revision of the module
+     * @param cmHandleReference  cm handle or alternate id identifier
+     * @param moduleName         module name
+     * @param moduleRevision     the revision of the module
      * @return list of module definitions (module name, revision, yang resource content)
      */
-    public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleAndModule(final String cmHandleId,
+    public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleAndModule(final String cmHandleReference,
                                                                                 final String moduleName,
                                                                                 final String moduleRevision) {
+        final String cmHandleId = alternateIdMatcher.getCmHandleId(cmHandleReference);
         return inventoryPersistence.getModuleDefinitionsByCmHandleAndModule(cmHandleId, moduleName, moduleRevision);
     }
 
index 9d51fff..3352c26 100644 (file)
@@ -198,18 +198,30 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification {
             assert result == ['cm-handle-id-1']
     }
 
-    def 'Getting module definitions by module'() {
-        when: 'get module definitions is performed with module name'
-            objectUnderTest.getModuleDefinitionsByCmHandleAndModule('some-cm-handle', 'some-module', '2021-08-04')
-        then: 'ncmp inventory persistence service is invoked once with correct parameters'
+    def 'Getting module definitions by module for a given #scenario'() {
+        when: 'get module definitions is performed with module name and cm handle reference'
+            objectUnderTest.getModuleDefinitionsByCmHandleAndModule(cmHandleRef, 'some-module', '2021-08-04')
+        then: 'alternate id matcher returns some cm handle id for a given cm handle reference'
+            mockAlternateIdMatcher.getCmHandleId(cmHandleRef) >> 'some-cm-handle'
+        and: 'ncmp inventory persistence service is invoked once with correct parameters'
             1 * mockInventoryPersistence.getModuleDefinitionsByCmHandleAndModule('some-cm-handle', 'some-module', '2021-08-04')
+        where: 'following cm handle reference is used'
+            scenario                              | cmHandleRef
+            'Cm Handle Reference as cm handle-id' | 'some-cm-handle'
+            'Cm Handle Reference as alternate-id' | 'some-alternate-id'
     }
 
-    def 'Getting module definitions by cm handle id'() {
-        when: 'get module definitions is performed with cm handle id'
-            objectUnderTest.getModuleDefinitionsByCmHandleId('some-cm-handle')
+    def 'Getting module definitions for a given #scenario'() {
+        when: 'get module definitions is performed with cm handle reference'
+            objectUnderTest.getModuleDefinitionsByCmHandleReference(cmHandleRef)
+        then: 'alternate id matcher returns some cm handle id for a given cm handle reference'
+            mockAlternateIdMatcher.getCmHandleId(cmHandleRef) >> 'some-cm-handle'
         then: 'ncmp inventory persistence service is invoked once with correct parameter'
             1 * mockInventoryPersistence.getModuleDefinitionsByCmHandleId('some-cm-handle')
+        where: 'following cm handle reference is used'
+            scenario                              | cmHandleRef
+            'Cm Handle Reference as cm handle-id' | 'some-cm-handle'
+            'Cm Handle Reference as alternate-id' | 'some-alternate-id'
     }
 
     def 'Execute cm handle search'() {