Support alternate id for CPS-E05 GetCmHandleDetailsById 93/138893/1
authormpriyank <priyank.maheshwari@est.tech>
Tue, 3 Sep 2024 16:00:17 +0000 (17:00 +0100)
committermpriyank <priyank.maheshwari@est.tech>
Tue, 3 Sep 2024 16:00:26 +0000 (17:00 +0100)
- added support for alternate id when retreiving cmhandle details by id
- Note : The performance for alternate id fetching will be taken care as
  part of a separate story.

Issue-ID: CPS-2385
Change-Id: I019b85d128e4b0a1f1d61623c92e1a2381c406c0
Signed-off-by: mpriyank <priyank.maheshwari@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..446b17c 100755 (executable)
@@ -354,7 +354,7 @@ retrieveCmHandleDetailsById:
     summary: Retrieve CM handle details
     operationId: retrieveCmHandleDetailsById
     parameters:
-      - $ref: 'components.yaml#/components/parameters/cmHandleInPath'
+      - $ref: 'components.yaml#/components/parameters/cmHandleReferenceInPath'
     responses:
       200:
         description: OK
index ca2907b..6657a3a 100755 (executable)
@@ -286,13 +286,13 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
     /**
      * Search for Cm Handle and Properties by Name.
      *
-     * @param cmHandleId cm-handle identifier
+     * @param cmHandleReference cm-handle or alternate identifier
      * @return cm handle and its properties
      */
     @Override
-    public ResponseEntity<RestOutputCmHandle> retrieveCmHandleDetailsById(final String cmHandleId) {
+    public ResponseEntity<RestOutputCmHandle> retrieveCmHandleDetailsById(final String cmHandleReference) {
         final NcmpServiceCmHandle ncmpServiceCmHandle
-            = networkCmProxyInventoryFacade.getNcmpServiceCmHandle(cmHandleId);
+            = networkCmProxyInventoryFacade.getNcmpServiceCmHandle(cmHandleReference);
         final RestOutputCmHandle restOutputCmHandle = toRestOutputCmHandle(ncmpServiceCmHandle);
         return ResponseEntity.ok(restOutputCmHandle);
     }
index 80e74ca..361167e 100644 (file)
@@ -284,17 +284,18 @@ class NetworkCmProxyControllerSpec extends Specification {
             assert response.contentAsString == '[{"cmHandle":"ch-1","publicCmHandleProperties":[{"color":"yellow"}],"state":null,"trustLevel":"NONE","moduleSetTag":null,"alternateId":null,"dataProducerIdentifier":null},{"cmHandle":"ch-2","publicCmHandleProperties":[{"color":"green"}],"state":null,"trustLevel":null,"moduleSetTag":"someModuleSetTag","alternateId":"someAlternateId","dataProducerIdentifier":"someDataProducerIdentifier"}]'
     }
 
-    def 'Get complete Cm Handle details by Cm Handle id.'() {
-        given: 'an endpoint and a cm handle'
-            def cmHandleDetailsEndpoint = "$ncmpBasePathV1/ch/some-cm-handle"
+    def 'Get complete Cm Handle details by Cm Handle Reference.'() {
+        given: 'an endpoint and a cm handle reference'
+            def cmHandleDetailsEndpoint = "$ncmpBasePathV1/ch/some-cm-handle-reference"
         and: 'an existing ncmp service cm handle'
             def cmHandleId = 'some-cm-handle'
+            def alternateId = 'some-alternate-id'
             def dmiProperties = [prop: 'some DMI property']
             def publicProperties = ["public prop": 'some public property']
             def compositeState = compositeStateTestObject()
-            def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, dmiProperties: dmiProperties, publicProperties: publicProperties, compositeState: compositeState, currentTrustLevel: TrustLevel.COMPLETE)
-        and: 'the service method is invoked with the cm handle id'
-            1 * mockNetworkCmProxyInventoryFacade.getNcmpServiceCmHandle('some-cm-handle') >> ncmpServiceCmHandle
+            def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, alternateId: alternateId, dmiProperties: dmiProperties, publicProperties: publicProperties, compositeState: compositeState, currentTrustLevel: TrustLevel.COMPLETE)
+        and: 'the service method is invoked with the cm handle reference'
+            1 * mockNetworkCmProxyInventoryFacade.getNcmpServiceCmHandle('some-cm-handle-reference') >> ncmpServiceCmHandle
         when: 'the cm handle details api is invoked'
             def response = mvc.perform(
                     get(cmHandleDetailsEndpoint)).andReturn().response
index 785eb8f..07c1a8b 100644 (file)
@@ -180,12 +180,13 @@ public class NetworkCmProxyInventoryFacade {
     }
 
     /**
-     * Retrieve cm handle details for a given cm handle.
+     * Retrieve cm handle details for a given cm handle reference.
      *
-     * @param cmHandleId cm handle identifier
+     * @param cmHandleReference cm handle or alternate identifier
      * @return cm handle details
      */
-    public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleId) {
+    public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleReference) {
+        final String cmHandleId = alternateIdMatcher.getCmHandleId(cmHandleReference);
         final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId);
         return toNcmpServiceCmHandleWithTrustLevel(yangModelCmHandle);
     }
index 9d51fff..1657046 100644 (file)
@@ -97,7 +97,7 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification {
             1 * mockInventoryPersistence.getYangResourcesModuleReferences('some-cm-handle')
     }
 
-    def 'Get a cm handle.'() {
+    def 'Get a cm handle details using #scenario'() {
         given: 'the system returns a yang modelled cm handle'
             def dmiServiceName = 'some service name'
             def compositeState = new CompositeState(cmHandleState: CmHandleState.ADVISED,
@@ -109,17 +109,18 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification {
             def publicProperties = [new YangModelCmHandle.Property('Public Book', 'Public Romance Novel')]
             def moduleSetTag = 'some-module-set-tag'
             def alternateId = 'some-alternate-id'
-            def yangModelCmHandle = new YangModelCmHandle(id: 'ch-1', dmiServiceName: dmiServiceName, dmiProperties: dmiProperties,
+            def yangModelCmHandle = new YangModelCmHandle(id: 'some-cm-handle', dmiServiceName: dmiServiceName, dmiProperties: dmiProperties,
                  publicProperties: publicProperties, compositeState: compositeState, moduleSetTag: moduleSetTag, alternateId: alternateId)
-            1 * mockInventoryPersistence.getYangModelCmHandle('ch-1') >> yangModelCmHandle
+            mockAlternateIdMatcher.getCmHandleId(cmHandleRef) >> 'some-cm-handle'
+            1 * mockInventoryPersistence.getYangModelCmHandle('some-cm-handle') >> yangModelCmHandle
         and: 'a trust level for the cm handle in the cache'
             mockTrustLevelManager.getEffectiveTrustLevel(*_) >> TrustLevel.COMPLETE
         when: 'getting cm handle details for a given cm handle id from ncmp service'
-            def result = objectUnderTest.getNcmpServiceCmHandle('ch-1')
+            def result = objectUnderTest.getNcmpServiceCmHandle(cmHandleRef)
         then: 'the result is a ncmpServiceCmHandle'
             assert result.class == NcmpServiceCmHandle.class
         and: 'the cm handle contains the cm handle id'
-            assert result.cmHandleId == 'ch-1'
+            assert result.cmHandleId == 'some-cm-handle'
         and: 'the cm handle contains the alternate id'
             assert result.alternateId == 'some-alternate-id'
         and: 'the cm handle contains the module-set-tag'
@@ -132,6 +133,10 @@ class NetworkCmProxyInventoryFacadeSpec extends Specification {
             assert result.compositeState == compositeState
         and: 'the cm handle contains the trust level from the cache'
             assert result.currentTrustLevel == TrustLevel.COMPLETE
+        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 'Get cm handle public properties using #scenario'() {