use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException 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;
}
use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException in project syncope by apache.
the class ConfTest method issueSYNCOPE418.
@Test
public void issueSYNCOPE418() {
try {
PlainSchema failing = entityFactory.newEntity(PlainSchema.class);
failing.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
failing.setType(AttrSchemaType.String);
plainSchemaDAO.save(failing);
fail("This should not happen");
} catch (InvalidEntityException e) {
assertTrue(e.hasViolation(EntityViolationType.InvalidKey));
}
}
use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException in project syncope by apache.
the class RealmTest method saveNullParent.
@Test
public void saveNullParent() {
Realm realm = entityFactory.newEntity(Realm.class);
realm.setName("name");
realm.setParent(null);
try {
realmDAO.save(realm);
fail("This should not happen");
} catch (InvalidEntityException e) {
assertTrue(e.hasViolation(EntityViolationType.InvalidRealm));
}
}
use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException in project syncope by apache.
the class RealmTest method saveInvalidName.
@Test
public void saveInvalidName() {
Realm realm = entityFactory.newEntity(Realm.class);
realm.setName(" a name");
realm.setParent(realmDAO.getRoot());
try {
realmDAO.save(realm);
fail("This should not happen");
} catch (InvalidEntityException e) {
assertTrue(e.hasViolation(EntityViolationType.InvalidRealm));
}
}
use of org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException in project syncope by apache.
the class PlainAttrTest method validateAndSave.
@Test
public void validateAndSave() {
User user = userDAO.find("1417acbe-cbf6-4277-9372-e75e04f97000");
PlainSchema emailSchema = plainSchemaDAO.find("email");
assertNotNull(emailSchema);
PlainSchema fullnameSchema = plainSchemaDAO.find("fullname");
assertNotNull(fullnameSchema);
UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
attr.setOwner(user);
attr.setSchema(emailSchema);
UPlainAttrUniqueValue uauv = entityFactory.newEntity(UPlainAttrUniqueValue.class);
uauv.setAttr(attr);
uauv.setSchema(fullnameSchema);
uauv.setStringValue("a value");
attr.setUniqueValue(uauv);
user.add(attr);
InvalidEntityException iee = null;
try {
userDAO.save(user);
fail("This should not happen");
} catch (InvalidEntityException e) {
iee = e;
}
assertNotNull(iee);
// for attribute
assertTrue(iee.hasViolation(EntityViolationType.InvalidValueList));
// for uauv
assertTrue(iee.hasViolation(EntityViolationType.InvalidPlainAttr));
}
Aggregations