From: egernug Date: Wed, 8 Oct 2025 12:58:24 +0000 (+0100) Subject: Fix YangModelCmHandle SonarQube error X-Git-Tag: 3.7.2~12^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=55b391f05c2cd2da469c561c9aab844b3bc50b24;p=cps.git Fix YangModelCmHandle SonarQube error - 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 --- diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java index f6f751e051..e254f9bb95 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java @@ -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(), diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/models/YangModelCmHandle.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/models/YangModelCmHandle.java index 40009bd695..39a8ff40f7 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/models/YangModelCmHandle.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/models/YangModelCmHandle.java @@ -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)); diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/YangDataConverter.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/YangDataConverter.java index 12b223a2be..a79f2b1384 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/YangDataConverter.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/utils/YangDataConverter.java @@ -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"), diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/models/YangModelCmHandleSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/models/YangModelCmHandleSpec.groovy index c1fe4f6bd8..33b2b84b2c 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/models/YangModelCmHandleSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/models/YangModelCmHandleSpec.groovy @@ -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: diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncServiceSpec.groovy index af2c7b759d..c310cda778 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncServiceSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/sync/ModuleSyncServiceSpec.groovy @@ -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, '', '', '', '') } }