summaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/DefaultExceptionMapper.java40
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapper.java38
2 files changed, 23 insertions, 55 deletions
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 9fe70fc5e5..0546180575 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
@@ -13,23 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdcrests.errors;
+import com.fasterxml.jackson.databind.JsonMappingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
-
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
-
import org.apache.commons.collections4.CollectionUtils;
-import com.fasterxml.jackson.databind.JsonMappingException;
import org.hibernate.validator.internal.engine.path.PathImpl;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.core.utilities.json.JsonUtil;
@@ -47,9 +44,8 @@ public class DefaultExceptionMapper implements ExceptionMapper<Exception> {
private static final String ERROR_CODES_TO_RESPONSE_STATUS_MAPPING_FILE = "errorCodesToResponseStatusMapping.json";
@SuppressWarnings("unchecked")
- private static final Map<String, String> ERROR_CODE_TO_RESPONSE_STATUS = FileUtils.readViaInputStream(
- ERROR_CODES_TO_RESPONSE_STATUS_MAPPING_FILE, stream -> JsonUtil.json2Object(stream, Map.class));
-
+ private static final Map<String, String> ERROR_CODE_TO_RESPONSE_STATUS = FileUtils
+ .readViaInputStream(ERROR_CODES_TO_RESPONSE_STATUS_MAPPING_FILE, stream -> JsonUtil.json2Object(stream, Map.class));
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionMapper.class);
@Override
@@ -59,14 +55,11 @@ public class DefaultExceptionMapper implements ExceptionMapper<Exception> {
response = transform(CoreException.class.cast(exception));
} else if (exception instanceof ConstraintViolationException) {
response = transform(ConstraintViolationException.class.cast(exception));
-
} else if (exception instanceof JsonMappingException) {
response = transform(JsonMappingException.class.cast(exception));
-
} else {
response = transform(exception);
}
-
List<Object> contentTypes = new ArrayList<>();
contentTypes.add(MediaType.APPLICATION_JSON);
response.getMetadata().put("Content-Type", contentTypes);
@@ -77,32 +70,23 @@ public class DefaultExceptionMapper implements ExceptionMapper<Exception> {
Response response;
ErrorCode code = coreException.code();
LOGGER.error(code.message(), coreException);
-
if (coreException.code().category().equals(ErrorCategory.APPLICATION)) {
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();
+ response = Response.status(Response.Status.NOT_FOUND).entity(toEntity(Response.Status.NOT_FOUND, code)).build();
} else if (Response.Status.BAD_REQUEST.name().equals(ERROR_CODE_TO_RESPONSE_STATUS.get(code.id()))) {
- response =
- Response.status(Response.Status.BAD_REQUEST).entity(toEntity(Response.Status.BAD_REQUEST, code))
- .build();
+ response = Response.status(Response.Status.BAD_REQUEST).entity(toEntity(Response.Status.BAD_REQUEST, code)).build();
} else {
- response = Response.status(Response.Status.EXPECTATION_FAILED)
- .entity(toEntity(Response.Status.EXPECTATION_FAILED, code)).build();
+ response = Response.status(Response.Status.EXPECTATION_FAILED).entity(toEntity(Response.Status.EXPECTATION_FAILED, code)).build();
}
} else {
- response = Response.status(Response.Status.INTERNAL_SERVER_ERROR)
- .entity(toEntity(Response.Status.INTERNAL_SERVER_ERROR, code)).build();
+ response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(toEntity(Response.Status.INTERNAL_SERVER_ERROR, code)).build();
}
-
-
return response;
}
private Response transform(ConstraintViolationException validationException) {
Set<ConstraintViolation<?>> constraintViolationSet = validationException.getConstraintViolations();
String message;
-
String fieldName = null;
if (CollectionUtils.isEmpty(constraintViolationSet)) {
message = validationException.getMessage();
@@ -111,28 +95,24 @@ public class DefaultExceptionMapper implements ExceptionMapper<Exception> {
ConstraintViolation<?> constraintViolation = constraintViolationSet.iterator().next();
message = constraintViolation.getMessage();
fieldName = getFieldName(constraintViolation.getPropertyPath());
-
}
-
ErrorCode validationErrorCode = new ValidationErrorBuilder(message, fieldName).build();
-
LOGGER.error(validationErrorCode.message(), validationException);
return Response.status(Response.Status.EXPECTATION_FAILED) //error 417
- .entity(toEntity(Response.Status.EXPECTATION_FAILED, validationErrorCode)).build();
+ .entity(toEntity(Response.Status.EXPECTATION_FAILED, validationErrorCode)).build();
}
private Response transform(JsonMappingException jsonMappingException) {
ErrorCode jsonMappingErrorCode = new JsonMappingErrorBuilder().build();
LOGGER.error(jsonMappingErrorCode.message(), jsonMappingException);
return Response.status(Response.Status.EXPECTATION_FAILED) //error 417
- .entity(toEntity(Response.Status.EXPECTATION_FAILED, jsonMappingErrorCode)).build();
+ .entity(toEntity(Response.Status.EXPECTATION_FAILED, jsonMappingErrorCode)).build();
}
private Response transform(Exception exception) {
ErrorCode errorCode = new GeneralErrorBuilder().build();
LOGGER.error(errorCode.message(), exception);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
- .entity(toEntity(Response.Status.INTERNAL_SERVER_ERROR, errorCode)).build();
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(toEntity(Response.Status.INTERNAL_SERVER_ERROR, errorCode)).build();
}
private String getFieldName(Path propertyPath) {
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapper.java b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapper.java
index abf6024701..497d3cfeb7 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapper.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/openecomp-sdc-common-rest/src/main/java/org/openecomp/sdcrests/errors/ZusammenExceptionMapper.java
@@ -13,16 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdcrests.errors;
import com.amdocs.zusammen.datatypes.response.Module;
-
import java.util.stream.Stream;
-
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
-
import org.openecomp.sdc.common.errors.ErrorCode;
import org.openecomp.sdc.common.errors.ErrorCodeAndMessage;
import org.openecomp.sdc.common.errors.GeneralErrorBuilder;
@@ -32,19 +28,16 @@ import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
public class ZusammenExceptionMapper implements ExceptionMapper<SdcRuntimeException> {
+
private static final String ZUSAMMEN_DB_PREFIX = Module.ZDB + "-";
static final String VLM_VSP_VERSION_ID_DOES_NOT_EXISTS =
- ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_VERSION_NOT_EXIST;
+ ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_VERSION_NOT_EXIST;
static final String VLM_VSP_ITEM_ID_DOES_NOT_EXISTS =
- ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_DOES_NOT_EXIST;
- static final String SUB_ENTITY_ID_DOES_NOT_EXISTS =
- ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ELEMENT_GET_INFO;
- static final String FAILED_TO_SYNC =
- ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_VERSION_SYNC;
+ ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_DOES_NOT_EXIST;
+ static final String SUB_ENTITY_ID_DOES_NOT_EXISTS = ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ELEMENT_GET_INFO;
+ static final String FAILED_TO_SYNC = ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_VERSION_SYNC;
static final String FAILED_TO_PUBLISH_OUT_OF_SYNC =
- ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode
- .ZU_ITEM_VERSION_PUBLISH_NOT_ALLOWED;
-
+ ZUSAMMEN_DB_PREFIX + com.amdocs.zusammen.datatypes.response.ErrorCode.ZU_ITEM_VERSION_PUBLISH_NOT_ALLOWED;
private static final Logger LOGGER = LoggerFactory.getLogger(ZusammenExceptionMapper.class);
@Override
@@ -53,29 +46,24 @@ public class ZusammenExceptionMapper implements ExceptionMapper<SdcRuntimeExcept
}
private Response transform(SdcRuntimeException exception) {
- if (Stream.of(VLM_VSP_ITEM_ID_DOES_NOT_EXISTS, VLM_VSP_VERSION_ID_DOES_NOT_EXISTS)
- .anyMatch(exception.getMessage()::contains)) {
+ if (Stream.of(VLM_VSP_ITEM_ID_DOES_NOT_EXISTS, VLM_VSP_VERSION_ID_DOES_NOT_EXISTS).anyMatch(exception.getMessage()::contains)) {
return generateSdcErrorResponse(Messages.ENTITY_NOT_FOUND, Response.Status.NOT_FOUND,
- new SdcRuntimeException(Messages.ENTITY_NOT_FOUND.getErrorMessage(), exception));
+ new SdcRuntimeException(Messages.ENTITY_NOT_FOUND.getErrorMessage(), exception));
} else if (exception.getMessage().contains(SUB_ENTITY_ID_DOES_NOT_EXISTS)) {
return generateSdcErrorResponse(Messages.SUB_ENTITY_NOT_FOUND, Response.Status.NOT_FOUND,
- new SdcRuntimeException(Messages.SUB_ENTITY_NOT_FOUND.getErrorMessage(), exception));
+ new SdcRuntimeException(Messages.SUB_ENTITY_NOT_FOUND.getErrorMessage(), exception));
} else if (exception.getMessage().contains(FAILED_TO_SYNC)) {
return generateSdcErrorResponse(Messages.FAILED_TO_SYNC, Response.Status.EXPECTATION_FAILED,
- new SdcRuntimeException(Messages.FAILED_TO_SYNC.getErrorMessage(), exception));
+ new SdcRuntimeException(Messages.FAILED_TO_SYNC.getErrorMessage(), exception));
} else if (exception.getMessage().contains(FAILED_TO_PUBLISH_OUT_OF_SYNC)) {
return generateSdcErrorResponse(Messages.FAILED_TO_PUBLISH_OUT_OF_SYNC, Response.Status.EXPECTATION_FAILED,
- new SdcRuntimeException(Messages.FAILED_TO_PUBLISH_OUT_OF_SYNC.getErrorMessage(), exception));
+ new SdcRuntimeException(Messages.FAILED_TO_PUBLISH_OUT_OF_SYNC.getErrorMessage(), exception));
}
-
return genericError(exception);
}
private Response generateSdcErrorResponse(Messages messages, Response.Status status, Exception exception) {
- ErrorCode errorCode = new ErrorCode.ErrorCodeBuilder()
- .withId(messages.name())
- .withMessage(exception.getMessage()).build();
-
+ ErrorCode errorCode = new ErrorCode.ErrorCodeBuilder().withId(messages.name()).withMessage(exception.getMessage()).build();
LOGGER.error(errorCode.message(), exception);
return Response.status(status).entity(new ErrorCodeAndMessage(status, errorCode)).build();
}
@@ -84,6 +72,6 @@ public class ZusammenExceptionMapper implements ExceptionMapper<SdcRuntimeExcept
ErrorCode errorCode = new GeneralErrorBuilder().build();
LOGGER.error(errorCode.message(), exception);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
- .entity(new ErrorCodeAndMessage(Response.Status.INTERNAL_SERVER_ERROR, errorCode)).build();
+ .entity(new ErrorCodeAndMessage(Response.Status.INTERNAL_SERVER_ERROR, errorCode)).build();
}
}