Fix YangModelCmHandle SonarQube error 46/142246/2
authoregernug <gerard.nugent@est.tech>
Wed, 8 Oct 2025 12:58:24 +0000 (13:58 +0100)
committeregernug <gerard.nugent@est.tech>
Wed, 8 Oct 2025 13:48:26 +0000 (14:48 +0100)
- Changed YangModelCmHandle.toYangModelCmHandle to use DmiPluginRegistration object instead of 3 inputs
- Changed tests and YangDataConverter to reflect change

Issue-ID: CPS-3002

Change-Id: I8aab2ff8593d88b8b1655ea85dc509e062996392
Signed-off-by: egernug <gerard.nugent@est.tech>
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/models/YangModelCmHandle.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/YangDataConverter.java
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/models/YangModelCmHandleSpec.groovy
cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncServiceSpec.groovy

index f6f751e..e254f9b 100644 (file)
@@ -401,9 +401,7 @@ public class CmHandleRegistrationService {
     private YangModelCmHandle getYangModelCmHandle(final DmiPluginRegistration dmiPluginRegistration,
                                                    final NcmpServiceCmHandle ncmpServiceCmHandle) {
         return YangModelCmHandle.toYangModelCmHandle(
-            dmiPluginRegistration.getDmiPlugin(),
-            dmiPluginRegistration.getDmiDataPlugin(),
-            dmiPluginRegistration.getDmiModelPlugin(),
+                dmiPluginRegistration,
             ncmpServiceCmHandle,
             ncmpServiceCmHandle.getModuleSetTag(),
             ncmpServiceCmHandle.getAlternateId(),
index 40009bd..39a8ff4 100644 (file)
@@ -32,6 +32,7 @@ import lombok.NoArgsConstructor;
 import lombok.Setter;
 import org.apache.commons.lang3.StringUtils;
 import org.onap.cps.ncmp.api.inventory.models.CompositeState;
+import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration;
 import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle;
 import org.onap.cps.ncmp.impl.dmi.DmiServiceNameResolver;
 import org.onap.cps.ncmp.impl.models.RequiredDmiService;
@@ -112,9 +113,7 @@ public class YangModelCmHandle {
     /**
      * Create a yangModelCmHandle.
      *
-     * @param dmiServiceName      dmi service name
-     * @param dmiDataServiceName  dmi data service name
-     * @param dmiModelServiceName dmi model service name
+     * @param dmiPluginRegistration dmi service name, dmi data service name, dmi model service name
      * @param ncmpServiceCmHandle the cm handle
      * @param moduleSetTag moduleSetTag
      * @param alternateId alternateId
@@ -123,9 +122,7 @@ public class YangModelCmHandle {
      * @param dmiProperties dmi properties
      * @return instance of yangModelCmHandle
      */
-    public static YangModelCmHandle toYangModelCmHandle(final String dmiServiceName,
-                                                        final String dmiDataServiceName,
-                                                        final String dmiModelServiceName,
+    public static YangModelCmHandle toYangModelCmHandle(final DmiPluginRegistration dmiPluginRegistration,
                                                         final NcmpServiceCmHandle ncmpServiceCmHandle,
                                                         final String moduleSetTag,
                                                         final String alternateId,
@@ -134,9 +131,9 @@ public class YangModelCmHandle {
                                                         final String dmiProperties) {
         final YangModelCmHandle yangModelCmHandle = new YangModelCmHandle();
         yangModelCmHandle.setId(ncmpServiceCmHandle.getCmHandleId());
-        yangModelCmHandle.setDmiServiceName(dmiServiceName);
-        yangModelCmHandle.setDmiDataServiceName(dmiDataServiceName);
-        yangModelCmHandle.setDmiModelServiceName(dmiModelServiceName);
+        yangModelCmHandle.setDmiServiceName(dmiPluginRegistration.getDmiPlugin());
+        yangModelCmHandle.setDmiDataServiceName(dmiPluginRegistration.getDmiDataPlugin());
+        yangModelCmHandle.setDmiModelServiceName(dmiPluginRegistration.getDmiModelPlugin());
         yangModelCmHandle.setModuleSetTag(StringUtils.trimToEmpty(moduleSetTag));
         yangModelCmHandle.setAlternateId(StringUtils.trimToEmpty(alternateId));
         yangModelCmHandle.setDataProducerIdentifier(StringUtils.trimToEmpty(dataProducerIdentifier));
index 12b223a..a79f2b1 100644 (file)
@@ -33,6 +33,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.onap.cps.api.model.DataNode;
 import org.onap.cps.ncmp.api.inventory.models.CompositeState;
 import org.onap.cps.ncmp.api.inventory.models.CompositeStateBuilder;
+import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration;
 import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle;
 import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle;
 
@@ -90,10 +91,12 @@ public class YangDataConverter {
         final String cmHandleId = cmHandleDataNode.getLeaves().get("id").toString();
         ncmpServiceCmHandle.setCmHandleId(cmHandleId);
         populateCmHandleDetails(cmHandleDataNode, ncmpServiceCmHandle);
+        final DmiPluginRegistration dmiPluginRegistration = new DmiPluginRegistration();
+        dmiPluginRegistration.setDmiPlugin(safeGetLeafValue(cmHandleDataNode, "dmi-service-name"));
+        dmiPluginRegistration.setDmiDataPlugin(safeGetLeafValue(cmHandleDataNode, "dmi-data-service-name"));
+        dmiPluginRegistration.setDmiModelPlugin(safeGetLeafValue(cmHandleDataNode, "dmi-model-service-name"));
         return YangModelCmHandle.toYangModelCmHandle(
-                safeGetLeafValue(cmHandleDataNode, "dmi-service-name"),
-                safeGetLeafValue(cmHandleDataNode, "dmi-data-service-name"),
-                safeGetLeafValue(cmHandleDataNode, "dmi-model-service-name"),
+                dmiPluginRegistration,
                 ncmpServiceCmHandle,
                 safeGetLeafValue(cmHandleDataNode, "module-set-tag"),
                 safeGetLeafValue(cmHandleDataNode, "alternate-id"),
index c1fe4f6..33b2b84 100644 (file)
@@ -23,6 +23,7 @@ package org.onap.cps.ncmp.impl.inventory.models
 import org.onap.cps.ncmp.api.inventory.models.CmHandleState
 import org.onap.cps.ncmp.api.inventory.models.CompositeState
 import org.onap.cps.ncmp.api.inventory.models.CompositeStateBuilder
+import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration
 import org.onap.cps.ncmp.api.inventory.models.LockReasonCategory
 import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle
 import org.onap.cps.ncmp.api.inventory.DataStoreSyncState
@@ -48,7 +49,7 @@ class YangModelCmHandleSpec extends Specification {
                 .withOperationalDataStores(DataStoreSyncState.SYNCHRONIZED, 'some-sync-time').build()
             ncmpServiceCmHandle.setCompositeState(compositeState)
         when: 'it is converted to a yang model cm handle'
-            def objectUnderTest = YangModelCmHandle.toYangModelCmHandle('', '', '', ncmpServiceCmHandle,'my-module-set-tag', 'my-alternate-id', 'my-data-producer-identifier', 'ADVISED', 'my-dmi-property')
+            def objectUnderTest = YangModelCmHandle.toYangModelCmHandle(new DmiPluginRegistration(), ncmpServiceCmHandle,'my-module-set-tag', 'my-alternate-id', 'my-data-producer-identifier', 'ADVISED', 'my-dmi-property')
         then: 'the result has the right size'
             assert objectUnderTest.additionalProperties.size() == 1
         and: 'the result has the correct values for module set tag, alternate ID, and data producer identifier'
@@ -72,8 +73,12 @@ class YangModelCmHandleSpec extends Specification {
 
     def 'Resolve DMI service name: #scenario and #requiredService service require.'() {
         given: 'a yang model cm handle'
-            def objectUnderTest = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, dmiDataServiceName,
-                    dmiModelServiceName, new NcmpServiceCmHandle(cmHandleId: 'cm-handle-id-1'),'', '', '', '', '')
+            def dmiPluginRegistration = new DmiPluginRegistration(
+                    dmiPlugin: dmiServiceName,
+                    dmiDataPlugin: dmiDataServiceName,
+                    dmiModelPlugin: dmiModelServiceName
+            )
+            def objectUnderTest = YangModelCmHandle.toYangModelCmHandle(dmiPluginRegistration, new NcmpServiceCmHandle(cmHandleId: 'cm-handle-id-1'),'', '', '', '', '')
         expect:
             assert objectUnderTest.resolveDmiServiceName(requiredService) == expectedService
         where:
index af2c7b7..c310cda 100644 (file)
@@ -27,6 +27,7 @@ import org.onap.cps.api.exceptions.AlreadyDefinedException
 import org.onap.cps.api.exceptions.DuplicatedYangResourceException
 import org.onap.cps.api.model.ModuleReference
 import org.onap.cps.ncmp.api.inventory.models.CompositeStateBuilder
+import org.onap.cps.ncmp.api.inventory.models.DmiPluginRegistration
 import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle
 import org.onap.cps.ncmp.impl.inventory.CmHandleQueryService
 import org.onap.cps.ncmp.api.inventory.models.CmHandleState
@@ -139,7 +140,8 @@ class ModuleSyncServiceSpec extends Specification {
             ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder().withLockReason(MODULE_UPGRADE, '').build())
             def dmiServiceName = 'some service name'
             ncmpServiceCmHandle.cmHandleId = 'upgraded-ch'
-            def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(dmiServiceName, '', '', ncmpServiceCmHandle,'', '', '', '', '')
+        def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: dmiServiceName)
+            def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(dmiPluginRegistration, ncmpServiceCmHandle,'', '', '', '', '')
         and: 'DMI operations returns some module references for upgraded cm handle'
             def moduleReferences =  [ new ModuleReference('module1','1') ]
             mockDmiModelOperations.getModuleReferences(yangModelCmHandle, NO_MODULE_SET_TAG) >> moduleReferences
@@ -159,7 +161,8 @@ class ModuleSyncServiceSpec extends Specification {
             def ncmpServiceCmHandle = new NcmpServiceCmHandle()
             ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder().withLockReason(MODULE_UPGRADE, 'Upgrade to ModuleSetTag: ' + tagTo).build())
             ncmpServiceCmHandle.setCmHandleId('cmHandleId-1')
-            def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle('some service name', '', '', ncmpServiceCmHandle, tagFrom, '', '', '', '')
+        def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'some service name')
+            def yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(dmiPluginRegistration, ncmpServiceCmHandle, tagFrom, '', '', '', '')
             mockCmHandleQueries.cmHandleHasState('cmHandleId-1', CmHandleState.READY) >> true
         and: 'the module tag (schemaset) exists is #schemaExists'
             mockCpsModuleService.schemaSetExists(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, tagTo) >> schemaExists
@@ -186,7 +189,8 @@ class ModuleSyncServiceSpec extends Specification {
         def ncmpServiceCmHandle = new NcmpServiceCmHandle()
         ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder().withCmHandleState(CmHandleState.ADVISED).build())
         ncmpServiceCmHandle.cmHandleId = 'ch-1'
-        return YangModelCmHandle.toYangModelCmHandle('some service name', '', '', ncmpServiceCmHandle, moduleSetTag, '', '', '', '')
+        def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'some service name')
+        return YangModelCmHandle.toYangModelCmHandle(dmiPluginRegistration, ncmpServiceCmHandle, moduleSetTag, '', '', '', '')
     }
 
 }