summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java/org
diff options
context:
space:
mode:
authorNiamh Core <niamh.core@est.tech>2021-09-21 13:04:11 +0000
committerGerrit Code Review <gerrit@onap.org>2021-09-21 13:04:11 +0000
commit2ee46351129de73cf2cf2f0579e73b1ef8abdafc (patch)
tree6cf888ce1a659588a2846d76984a44af63188219 /cps-ncmp-service/src/main/java/org
parentcf2482c1fa1b7b9d9638e7c658807e8ab35069b4 (diff)
parent4f736db2a0ab0df49b5cae6599da8e655c5ea8cd (diff)
Merge "Address Sonar Qube issues"
Diffstat (limited to 'cps-ncmp-service/src/main/java/org')
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java75
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 ff9502d501..dc5dc77334 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);