From 386af7e65bbc73f50f0c78b3a745c8c81ecad288 Mon Sep 17 00:00:00 2001 From: shrikantawachar Date: Thu, 4 Jan 2018 19:57:04 +0530 Subject: Fixing sonar qube issues Refactored the code as per review comment in DefaultExceptionMapper.java file. Change-Id: I23c43e52e444cbd26b9c6bcf1c060f0f8b8f8204 Issue-ID: SDC-343 Signed-off-by: shrikantawachar --- .../sdcrests/errors/DefaultExceptionMapper.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp') diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java index 2f6d298f01..28917b9fb7 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java @@ -50,11 +50,12 @@ public class DefaultExceptionMapper implements ExceptionMapper { private static final String ERROR_CODES_TO_RESPONSE_STATUS_MAPPING_FILE = "errorCodesToResponseStatusMapping.json"; @SuppressWarnings("unchecked") - private static Map errorCodeToResponseStatus = + private static final Map ERROR_CODE_TO_RESPONSE_STATUS = FileUtils.readViaInputStream(ERROR_CODES_TO_RESPONSE_STATUS_MAPPING_FILE, - stream -> JsonUtil.json2Object(stream, Map.class)); + stream -> JsonUtil.json2Object(stream, Map.class)); - private static Logger logger = (Logger) LoggerFactory.getLogger(DefaultExceptionMapper.class); + private static final Logger LOGGER = (Logger) LoggerFactory.getLogger(DefaultExceptionMapper + .class); @Override public Response toResponse(Exception exception) { @@ -80,16 +81,16 @@ public class DefaultExceptionMapper implements ExceptionMapper { private Response transform(CoreException coreException) { Response response; ErrorCode code = coreException.code(); - logger.error(code.message(), coreException); + LOGGER.error(code.message(), coreException); if (coreException.code().category().equals(ErrorCategory.APPLICATION)) { - if (Response.Status.NOT_FOUND.name().equals(errorCodeToResponseStatus.get(code.id()))) { + if (Response.Status.NOT_FOUND.name().equals(ERROR_CODE_TO_RESPONSE_STATUS.get(code.id()))) { response = Response .status(Response.Status.NOT_FOUND) .entity(toEntity(Response.Status.NOT_FOUND, code)) .build(); } else if (Response.Status.BAD_REQUEST.name() - .equals(errorCodeToResponseStatus.get(code.id()))) { + .equals(ERROR_CODE_TO_RESPONSE_STATUS.get(code.id()))) { response = Response .status(Response.Status.BAD_REQUEST) .entity(toEntity(Response.Status.BAD_REQUEST, code)) @@ -129,7 +130,7 @@ public class DefaultExceptionMapper implements ExceptionMapper { ErrorCode validationErrorCode = new ValidationErrorBuilder(message, fieldName).build(); - logger.error(validationErrorCode.message(), validationException); + LOGGER.error(validationErrorCode.message(), validationException); return Response .status(Response.Status.EXPECTATION_FAILED) //error 417 .entity(toEntity(Response.Status.EXPECTATION_FAILED, validationErrorCode)) @@ -138,7 +139,7 @@ public class DefaultExceptionMapper implements ExceptionMapper { private Response transform(JsonMappingException jsonMappingException) { ErrorCode jsonMappingErrorCode = new JsonMappingErrorBuilder().build(); - logger.error(jsonMappingErrorCode.message(), jsonMappingException); + LOGGER.error(jsonMappingErrorCode.message(), jsonMappingException); return Response .status(Response.Status.EXPECTATION_FAILED) //error 417 .entity(toEntity(Response.Status.EXPECTATION_FAILED, jsonMappingErrorCode)) @@ -147,7 +148,7 @@ public class DefaultExceptionMapper implements ExceptionMapper { private Response transform(Exception exception) { ErrorCode generalErrorCode = new GeneralErrorBuilder(exception.getMessage()).build(); - logger.error(generalErrorCode.message(), exception); + LOGGER.error(generalErrorCode.message(), exception); return Response .status(Response.Status.INTERNAL_SERVER_ERROR) .entity(toEntity(Response.Status.INTERNAL_SERVER_ERROR, generalErrorCode)) -- cgit 1.2.3-korg