use of org.apache.syncope.common.lib.types.EntityViolationType in project syncope by apache.
the class SCIMExceptionMapper method processInvalidEntityExceptions.
private ResponseBuilder processInvalidEntityExceptions(final Exception ex) {
InvalidEntityException iee = null;
if (ex instanceof InvalidEntityException) {
iee = (InvalidEntityException) ex;
}
if (ex instanceof TransactionSystemException && ROLLBACK_EXCLASS.isAssignableFrom(ex.getCause().getClass()) && ex.getCause().getCause() instanceof InvalidEntityException) {
iee = (InvalidEntityException) ex.getCause().getCause();
}
if (iee != null) {
ClientExceptionType exType;
if (iee.getEntityClassSimpleName().endsWith("Policy")) {
exType = ClientExceptionType.InvalidPolicy;
} else if (iee.getEntityClassSimpleName().equals(PlainAttr.class.getSimpleName())) {
exType = ClientExceptionType.InvalidValues;
} else {
try {
exType = ClientExceptionType.valueOf("Invalid" + iee.getEntityClassSimpleName());
} catch (IllegalArgumentException e) {
// ignore
exType = ClientExceptionType.InvalidEntity;
}
}
StringBuilder msg = new StringBuilder();
for (Map.Entry<Class<?>, Set<EntityViolationType>> violation : iee.getViolations().entrySet()) {
for (EntityViolationType violationType : violation.getValue()) {
msg.append(violationType.name()).append(": ").append(violationType.getMessage()).append('\n');
}
}
return builder(exType, msg.toString());
}
return null;
}
use of org.apache.syncope.common.lib.types.EntityViolationType in project syncope by apache.
the class RestServiceExceptionMapper method processInvalidEntityExceptions.
private ResponseBuilder processInvalidEntityExceptions(final Exception ex) {
InvalidEntityException iee = null;
if (ex instanceof InvalidEntityException) {
iee = (InvalidEntityException) ex;
}
if (ex instanceof TransactionSystemException && ex.getCause() instanceof RollbackException && ex.getCause().getCause() instanceof InvalidEntityException) {
iee = (InvalidEntityException) ex.getCause().getCause();
}
if (iee != null) {
ClientExceptionType exType;
if (iee.getEntityClassSimpleName().endsWith("Policy")) {
exType = ClientExceptionType.InvalidPolicy;
} else if (iee.getEntityClassSimpleName().equals(PlainAttr.class.getSimpleName())) {
exType = ClientExceptionType.InvalidValues;
} else {
try {
exType = ClientExceptionType.valueOf("Invalid" + iee.getEntityClassSimpleName());
} catch (IllegalArgumentException e) {
// ignore
exType = ClientExceptionType.InvalidEntity;
}
}
ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
builder.header(RESTHeaders.ERROR_CODE, exType.name());
ErrorTO error = new ErrorTO();
error.setStatus(exType.getResponseStatus().getStatusCode());
error.setType(exType);
for (Map.Entry<Class<?>, Set<EntityViolationType>> violation : iee.getViolations().entrySet()) {
for (EntityViolationType violationType : violation.getValue()) {
builder.header(RESTHeaders.ERROR_INFO, exType.getInfoHeaderValue(violationType.name() + ": " + violationType.getMessage()));
error.getElements().add(violationType.name() + ": " + violationType.getMessage());
}
}
return builder;
}
return null;
}
Aggregations