From f4cd6a4850b5fade38ff6ef13c448f3ac7407882 Mon Sep 17 00:00:00 2001 From: lukegleeson Date: Mon, 6 Sep 2021 10:03:00 +0100 Subject: Fix Sonar Qube Violations Issue-ID: CPS-475 Signed-off-by: lukegleeson Change-Id: I7d4242f49212fb7b973450a841f0251e2fb36b08 --- .../ncmp/dmi/rest/controller/DmiRestController.java | 2 +- .../onap/cps/ncmp/dmi/service/DmiServiceImpl.java | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java index 1d7abf24..4a18b067 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java @@ -58,7 +58,7 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi { @Override public ResponseEntity getModulesForCmHandle(final String cmHandle) { final var moduleSet = dmiService.getModulesForCmHandle(cmHandle); - return new ResponseEntity(moduleSet, HttpStatus.OK); + return new ResponseEntity<>(moduleSet, HttpStatus.OK); } @Override diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java index 87936bb7..e9ecc592 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java @@ -62,6 +62,10 @@ public class DmiServiceImpl implements DmiService { private DmiPluginProperties dmiPluginProperties; private static final String CONTENT_QUERY_PASSTHROUGH_OPERATIONAL = "content=all"; private static final String CONTENT_QUERY_PASSTHROUGH_RUNNING = "content=config"; + private static final String RESPONSE_CODE = "response code : "; + private static final String MESSAGE = " message : "; + private static final String IETF_NETCONF_MONITORING_OUTPUT = "ietf-netconf-monitoring:output"; + /** * Constructor. @@ -91,7 +95,7 @@ public class DmiServiceImpl implements DmiService { return createModuleSchema(responseBody); } else { throw new DmiException("SDNC is not able to process request.", - "response code : " + responseEntity.getStatusCode() + " message : " + responseEntity.getBody()); + RESPONSE_CODE + responseEntity.getStatusCode() + MESSAGE + responseEntity.getBody()); } } @@ -100,7 +104,7 @@ public class DmiServiceImpl implements DmiService { final var getModuleResponses = new JSONArray(); for (final var moduleReference : moduleReferences) { final var moduleRequest = createModuleRequest(moduleReference); - final ResponseEntity responseEntity = sdncOperations.getModuleResource(cmHandle, moduleRequest); + final ResponseEntity responseEntity = sdncOperations.getModuleResource(cmHandle, moduleRequest); if (responseEntity.getStatusCode() == HttpStatus.OK) { getModuleResponses.add(toJsonObject(moduleReference, responseEntity)); } else if (responseEntity.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -110,7 +114,7 @@ public class DmiServiceImpl implements DmiService { } else { log.error("Error occurred when getting module resources from SDNC for the given cmHandle {}", cmHandle); throw new DmiException(cmHandle, - "response code : " + responseEntity.getStatusCode() + " message : " + responseEntity.getBody()); + RESPONSE_CODE + responseEntity.getStatusCode() + MESSAGE + responseEntity.getBody()); } } return getModuleResponses.toJSONString(); @@ -214,7 +218,7 @@ public class DmiServiceImpl implements DmiService { return responseEntity.getBody(); } else { throw new DmiException(cmHandle, - "response code : " + responseEntity.getStatusCode() + " message : " + responseEntity.getBody()); + RESPONSE_CODE + responseEntity.getStatusCode() + MESSAGE + responseEntity.getBody()); } } @@ -223,7 +227,7 @@ public class DmiServiceImpl implements DmiService { return responseEntity.getBody(); } else { throw new ResourceDataNotFound(cmHandle, - "response code : " + responseEntity.getStatusCode() + " message : " + responseEntity.getBody()); + RESPONSE_CODE + responseEntity.getStatusCode() + MESSAGE + responseEntity.getBody()); } } @@ -255,14 +259,14 @@ public class DmiServiceImpl implements DmiService { private String extractYangSourceFromBody(final ResponseEntity responseEntity) { final var responseBodyAsJsonObject = new Gson().fromJson(responseEntity.getBody(), JsonObject.class); - if (responseBodyAsJsonObject.getAsJsonObject("ietf-netconf-monitoring:output") == null - || responseBodyAsJsonObject.getAsJsonObject("ietf-netconf-monitoring:output") + if (responseBodyAsJsonObject.getAsJsonObject(IETF_NETCONF_MONITORING_OUTPUT) == null + || responseBodyAsJsonObject.getAsJsonObject(IETF_NETCONF_MONITORING_OUTPUT) .getAsJsonPrimitive("data") == null) { log.error("Error occurred when trying to parse the response body from sdnc {}", responseEntity.getBody()); throw new ModuleResourceNotFoundException(responseEntity.getBody(), "Error occurred when trying to parse the response body from sdnc."); } - return responseBodyAsJsonObject.getAsJsonObject("ietf-netconf-monitoring:output").getAsJsonPrimitive("data") + return responseBodyAsJsonObject.getAsJsonObject(IETF_NETCONF_MONITORING_OUTPUT).getAsJsonPrimitive("data") .toString(); } } \ No newline at end of file -- cgit 1.2.3-korg