Search in sources :

Example 1 with EntityViolationType

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;
}
Also used : Set(java.util.Set) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) TransactionSystemException(org.springframework.transaction.TransactionSystemException) Map(java.util.Map) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) EntityViolationType(org.apache.syncope.common.lib.types.EntityViolationType)

Example 2 with EntityViolationType

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;
}
Also used : ErrorTO(org.apache.syncope.common.lib.to.ErrorTO) Set(java.util.Set) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) TransactionSystemException(org.springframework.transaction.TransactionSystemException) RollbackException(javax.persistence.RollbackException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) HashMap(java.util.HashMap) Map(java.util.Map) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) EntityViolationType(org.apache.syncope.common.lib.types.EntityViolationType)

Aggregations

Map (java.util.Map)2 Set (java.util.Set)2 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)2 EntityViolationType (org.apache.syncope.common.lib.types.EntityViolationType)2 InvalidEntityException (org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException)2 TransactionSystemException (org.springframework.transaction.TransactionSystemException)2 HashMap (java.util.HashMap)1 RollbackException (javax.persistence.RollbackException)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 ErrorTO (org.apache.syncope.common.lib.to.ErrorTO)1