From 421f824800e51ddd4f70758f5be386e50bf8ea1e Mon Sep 17 00:00:00 2001 From: emaclee Date: Tue, 7 Jun 2022 18:32:29 +0100 Subject: Fix sonar code smells - Remove useless curly braces around statement (https://sonarcloud.io/project/issues?resolved=false&types=CODE_SMELL&id=onap_cps&open=AYD_5_HLFWip2-KRhcLs) - Define a constant (https://sonarcloud.io/project/issues?resolved=false&types=CODE_SMELL&id=onap_cps&open=AYEj9y6sq272EuFEMiu-) Issue-ID: CPS-475 Signed-off-by: emaclee Change-Id: Ib430fac481b29dba8725ed0dac4da3daa56a3984 --- .../org/onap/cps/ncmp/api/inventory/InventoryPersistence.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'cps-ncmp-service/src/main/java/org') diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java index 873a44913a..f95ac64b14 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/InventoryPersistence.java @@ -43,6 +43,8 @@ public class InventoryPersistence { private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry"; + private static final String XPATH_TO_CM_HANDLE = "/dmi-registry/cm-handles[@id='" + "%s" + "']"; + private final JsonObjectMapper jsonObjectMapper; private final CpsDataService cpsDataService; @@ -59,7 +61,7 @@ public class InventoryPersistence { */ public CompositeState getCmHandleState(final String cmHandleId) { final DataNode stateAsDataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - "/dmi-registry/cm-handles[@id='" + cmHandleId + "']/state", + String.format(XPATH_TO_CM_HANDLE, cmHandleId) + "/state", FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); return compositeStateBuilder.fromDataNode(stateAsDataNode).build(); } @@ -74,7 +76,7 @@ public class InventoryPersistence { final String cmHandleJsonData = String.format("{\"state\":%s}", jsonObjectMapper.asJsonString(compositeState)); cpsDataService.replaceNodeTree(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - "/dmi-registry/cm-handles[@id='" + cmHandleId + "']", + String.format(XPATH_TO_CM_HANDLE, cmHandleId), cmHandleJsonData, OffsetDateTime.now()); } @@ -111,10 +113,9 @@ public class InventoryPersistence { } private DataNode getCmHandleDataNode(final String cmHandle) { - final String xpathForDmiRegistryToFetchCmHandle = "/dmi-registry/cm-handles[@id='" + cmHandle + "']"; return cpsDataService.getDataNode(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - xpathForDmiRegistryToFetchCmHandle, + String.format(XPATH_TO_CM_HANDLE, cmHandle), FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS); } -- cgit 1.2.3-korg