diff options
author | ToineSiebelink <toine.siebelink@est.tech> | 2021-09-20 13:29:09 +0100 |
---|---|---|
committer | ToineSiebelink <toine.siebelink@est.tech> | 2021-09-21 10:29:52 +0100 |
commit | 4f736db2a0ab0df49b5cae6599da8e655c5ea8cd (patch) | |
tree | 5f9bc85212bcd9c4cae11b2d4705a4569714180b /cps-ncmp-service/src/main/java/org | |
parent | e896016a3bde25d1a83e7bc368dbf267f1b1ac57 (diff) |
Address Sonar Qube issues
- Add some basic test for missed coverage
- Refactored NetworkCmProxyDataServiceImpl to addres duplcaied code and code coverage
- Increased Coverage treshold where possible
Issue-ID: CPS-475
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
Change-Id: Id05f41ac242aeaf57606748009c0e370199e054f
Diffstat (limited to 'cps-ncmp-service/src/main/java/org')
-rwxr-xr-x | cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java | 75 |
1 files changed, 37 insertions, 38 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java index a28b73c427..719508b6c5 100755 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java @@ -149,14 +149,18 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService @Override public void updateDmiRegistrationAndSyncModule(final DmiPluginRegistration dmiPluginRegistration) { - if (dmiPluginRegistration.getCreatedCmHandles() != null) { - parseAndCreateCmHandlesInDmiRegistrationAndSyncModule(dmiPluginRegistration); - } - if (dmiPluginRegistration.getUpdatedCmHandles() != null) { - parseAndUpdateCmHandlesInDmiRegistration(dmiPluginRegistration); - } - if (dmiPluginRegistration.getRemovedCmHandles() != null) { - parseAndRemoveCmHandlesInDmiRegistration(dmiPluginRegistration); + try { + if (dmiPluginRegistration.getCreatedCmHandles() != null) { + parseAndCreateCmHandlesInDmiRegistrationAndSyncModule(dmiPluginRegistration); + } + if (dmiPluginRegistration.getUpdatedCmHandles() != null) { + parseAndUpdateCmHandlesInDmiRegistration(dmiPluginRegistration); + } + if (dmiPluginRegistration.getRemovedCmHandles() != null) { + parseAndRemoveCmHandlesInDmiRegistration(dmiPluginRegistration); + } + } catch (final JsonProcessingException e) { + handleJsonProcessingException(dmiPluginRegistration, e); } } @@ -286,38 +290,32 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService return prepareOperationBody(requestBodyObject); } - private void parseAndUpdateCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) { - try { - final PersistenceCmHandlesList persistenceCmHandlesList = new PersistenceCmHandlesList(); - - for (final CmHandle cmHandle : dmiPluginRegistration.getUpdatedCmHandles()) { - final PersistenceCmHandle persistenceCmHandle = - toPersistenceCmHandle(dmiPluginRegistration.getDmiPlugin(), cmHandle); - persistenceCmHandlesList.add(persistenceCmHandle); - } - final String cmHandlesJsonData = objectMapper.writeValueAsString(persistenceCmHandlesList); - cpsDataService.updateNodeLeavesAndExistingDescendantLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, - "/dmi-registry", cmHandlesJsonData, NO_TIMESTAMP); - } catch (final JsonProcessingException e) { - handleJsonProcessingException(dmiPluginRegistration, e); - } + private void parseAndUpdateCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) + throws JsonProcessingException { + final PersistenceCmHandlesList updatedPersistenceCmHandlesList = toPersistenceCmHandlesList( + dmiPluginRegistration.getDmiPlugin(), + dmiPluginRegistration.getUpdatedCmHandles()); + final String cmHandlesAsJson = objectMapper.writeValueAsString(updatedPersistenceCmHandlesList); + cpsDataService.updateNodeLeavesAndExistingDescendantLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, + "/dmi-registry", cmHandlesAsJson, NO_TIMESTAMP); } private void parseAndCreateCmHandlesInDmiRegistrationAndSyncModule( - final DmiPluginRegistration dmiPluginRegistration) { - try { - final var persistenceCmHandlesList = new PersistenceCmHandlesList(); - for (final CmHandle cmHandle : dmiPluginRegistration.getCreatedCmHandles()) { - final PersistenceCmHandle persistenceCmHandle = - toPersistenceCmHandle(dmiPluginRegistration.getDmiPlugin(), cmHandle); - persistenceCmHandlesList.add(persistenceCmHandle); - } - final String cmHandleJsonData = objectMapper.writeValueAsString(persistenceCmHandlesList); + final DmiPluginRegistration dmiPluginRegistration) throws JsonProcessingException { + final PersistenceCmHandlesList createdPersistenceCmHandlesList = toPersistenceCmHandlesList( + dmiPluginRegistration.getDmiPlugin(), + dmiPluginRegistration.getCreatedCmHandles()); + registerAndSyncNewCmHandles(createdPersistenceCmHandlesList); + } - registerAndSyncNode(persistenceCmHandlesList, cmHandleJsonData); - } catch (final JsonProcessingException e) { - handleJsonProcessingException(dmiPluginRegistration, e); + private static PersistenceCmHandlesList toPersistenceCmHandlesList(final String dmiPlugin, + final Collection<CmHandle> cmHandles) { + final PersistenceCmHandlesList persistenceCmHandlesList = new PersistenceCmHandlesList(); + for (final CmHandle cmHandle : cmHandles) { + final PersistenceCmHandle persistenceCmHandle = toPersistenceCmHandle(dmiPlugin, cmHandle); + persistenceCmHandlesList.add(persistenceCmHandle); } + return persistenceCmHandlesList; } private static void handleJsonProcessingException(final DmiPluginRegistration dmiPluginRegistration, @@ -328,8 +326,9 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService throw new DataValidationException(message, e.getMessage(), e); } - private void registerAndSyncNode(final PersistenceCmHandlesList persistenceCmHandlesList, - final String cmHandleJsonData) { + private void registerAndSyncNewCmHandles(final PersistenceCmHandlesList persistenceCmHandlesList) + throws JsonProcessingException { + final String cmHandleJsonData = objectMapper.writeValueAsString(persistenceCmHandlesList); cpsDataService.saveListNodeData(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, "/dmi-registry", cmHandleJsonData, NO_TIMESTAMP); @@ -435,7 +434,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService private static YangResource toYangResource(final JsonObject yangResourceAsJson) { final YangResource yangResource = new YangResource(); yangResource.setModuleName(yangResourceAsJson.get("moduleName").getAsString()); - yangResource.setRevision(yangResourceAsJson.get("revision").getAsString()); + yangResource.setRevision(yangResourceAsJson.get(REVISION).getAsString()); final String yangSourceJson = yangResourceAsJson.get("yangSource").getAsString(); String yangSource = JsonUtils.removeWrappingTokens(yangSourceJson); |