use of org.apache.syncope.core.persistence.api.dao.DuplicateException in project syncope by apache.
the class RestServiceExceptionMapper method toResponse.
@Override
public Response toResponse(final Exception ex) {
LOG.error("Exception thrown", ex);
ResponseBuilder builder;
if (ex instanceof AccessDeniedException) {
// leaves the default exception processing to Spring Security
builder = null;
} else if (ex instanceof SyncopeClientException) {
SyncopeClientException sce = (SyncopeClientException) ex;
builder = sce.isComposite() ? getSyncopeClientCompositeExceptionResponse(sce.asComposite()) : getSyncopeClientExceptionResponse(sce);
} else if (ex instanceof DelegatedAdministrationException || ExceptionUtils.getRootCause(ex) instanceof DelegatedAdministrationException) {
builder = builder(ClientExceptionType.DelegatedAdministration, ExceptionUtils.getRootCauseMessage(ex));
} else if (ex instanceof EntityExistsException || ex instanceof DuplicateException || ex instanceof PersistenceException && ex.getCause() instanceof EntityExistsException) {
builder = builder(ClientExceptionType.EntityExists, getJPAMessage(ex instanceof PersistenceException ? ex.getCause() : ex));
} else if (ex instanceof DataIntegrityViolationException || ex instanceof JpaSystemException) {
builder = builder(ClientExceptionType.DataIntegrityViolation, getJPAMessage(ex));
} else if (ex instanceof ConnectorException) {
builder = builder(ClientExceptionType.ConnectorException, ExceptionUtils.getRootCauseMessage(ex));
} else if (ex instanceof NotFoundException) {
builder = builder(ClientExceptionType.NotFound, ExceptionUtils.getRootCauseMessage(ex));
} else {
builder = processInvalidEntityExceptions(ex);
if (builder == null) {
builder = processBadRequestExceptions(ex);
}
// process JAX-RS validation errors
if (builder == null && ex instanceof ValidationException) {
builder = builder(validationEM.toResponse((ValidationException) ex)).header(RESTHeaders.ERROR_CODE, ClientExceptionType.RESTValidation.name()).header(RESTHeaders.ERROR_INFO, ClientExceptionType.RESTValidation.getInfoHeaderValue(ExceptionUtils.getRootCauseMessage(ex)));
ErrorTO error = new ErrorTO();
error.setStatus(ClientExceptionType.RESTValidation.getResponseStatus().getStatusCode());
error.setType(ClientExceptionType.RESTValidation);
error.getElements().add(ExceptionUtils.getRootCauseMessage(ex));
builder.entity(error);
}
// ...or just report as InternalServerError
if (builder == null) {
builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR).header(RESTHeaders.ERROR_INFO, ClientExceptionType.Unknown.getInfoHeaderValue(ExceptionUtils.getRootCauseMessage(ex)));
ErrorTO error = new ErrorTO();
error.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
error.setType(ClientExceptionType.Unknown);
error.getElements().add(ExceptionUtils.getRootCauseMessage(ex));
builder.entity(error);
}
}
return builder == null ? null : builder.build();
}
use of org.apache.syncope.core.persistence.api.dao.DuplicateException in project syncope by apache.
the class ReportTemplateLogic method create.
@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_TEMPLATE_CREATE + "')")
public ReportTemplateTO create(final String key) {
if (reportTemplateDAO.find(key) != null) {
throw new DuplicateException(key);
}
ReportTemplate reportTemplate = entityFactory.newEntity(ReportTemplate.class);
reportTemplate.setKey(key);
reportTemplateDAO.save(reportTemplate);
return getReportTemplateTO(key);
}
use of org.apache.syncope.core.persistence.api.dao.DuplicateException in project syncope by apache.
the class AnyTypeClassLogic method create.
@PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPECLASS_CREATE + "')")
public AnyTypeClassTO create(final AnyTypeClassTO anyTypeClassTO) {
if (StringUtils.isBlank(anyTypeClassTO.getKey())) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
sce.getElements().add(AnyTypeClass.class.getSimpleName() + " name");
throw sce;
}
if (anyTypeClassDAO.find(anyTypeClassTO.getKey()) != null) {
throw new DuplicateException(anyTypeClassTO.getKey());
}
return binder.getAnyTypeClassTO(anyTypeClassDAO.save(binder.create(anyTypeClassTO)));
}
use of org.apache.syncope.core.persistence.api.dao.DuplicateException in project syncope by apache.
the class AnyTypeLogic method create.
@PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPE_CREATE + "')")
public AnyTypeTO create(final AnyTypeTO anyTypeTO) {
if (StringUtils.isBlank(anyTypeTO.getKey())) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
sce.getElements().add(AnyType.class.getSimpleName() + " key");
throw sce;
}
if (anyTypeDAO.find(anyTypeTO.getKey()) != null) {
throw new DuplicateException(anyTypeTO.getKey());
}
return binder.getAnyTypeTO(anyTypeDAO.save(binder.create(anyTypeTO)));
}
use of org.apache.syncope.core.persistence.api.dao.DuplicateException in project syncope by apache.
the class SCIMExceptionMapper method toResponse.
@Override
public Response toResponse(final Exception ex) {
LOG.error("Exception thrown", ex);
ResponseBuilder builder;
if (ex instanceof AccessDeniedException || ex instanceof ForbiddenException || ex instanceof NotAuthorizedException) {
// leaves the default exception processing
builder = null;
} else if (ex instanceof NotFoundException) {
return Response.status(Response.Status.NOT_FOUND).entity(new SCIMError(null, Response.Status.NOT_FOUND.getStatusCode(), ExceptionUtils.getRootCauseMessage(ex))).build();
} else if (ex instanceof SyncopeClientException) {
SyncopeClientException sce = (SyncopeClientException) ex;
builder = builder(sce.getType(), ExceptionUtils.getRootCauseMessage(ex));
} else if (ex instanceof DelegatedAdministrationException || ExceptionUtils.getRootCause(ex) instanceof DelegatedAdministrationException) {
builder = builder(ClientExceptionType.DelegatedAdministration, ExceptionUtils.getRootCauseMessage(ex));
} else if (ENTITYEXISTS_EXCLASS.isAssignableFrom(ex.getClass()) || ex instanceof DuplicateException || PERSISTENCE_EXCLASS.isAssignableFrom(ex.getClass()) && ENTITYEXISTS_EXCLASS.isAssignableFrom(ex.getCause().getClass())) {
builder = builder(ClientExceptionType.EntityExists, ExceptionUtils.getRootCauseMessage(ex));
} else if (ex instanceof DataIntegrityViolationException || JPASYSTEM_EXCLASS.isAssignableFrom(ex.getClass())) {
builder = builder(ClientExceptionType.DataIntegrityViolation, ExceptionUtils.getRootCauseMessage(ex));
} else if (CONNECTOR_EXCLASS.isAssignableFrom(ex.getClass())) {
builder = builder(ClientExceptionType.ConnectorException, ExceptionUtils.getRootCauseMessage(ex));
} else {
builder = processInvalidEntityExceptions(ex);
if (builder == null) {
builder = processBadRequestExceptions(ex);
}
// process JAX-RS validation errors
if (builder == null && ex instanceof ValidationException) {
builder = builder(ClientExceptionType.RESTValidation, ExceptionUtils.getRootCauseMessage(ex));
}
// ...or just report as InternalServerError
if (builder == null) {
builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ExceptionUtils.getRootCauseMessage(ex));
}
}
return builder == null ? null : builder.build();
}
Aggregations