use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.
the class AnyTypeTest method saveInvalidName.
@Test
public void saveInvalidName() {
assertThrows(InvalidEntityException.class, () -> {
AnyType newType = entityFactory.newEntity(AnyType.class);
newType.setKey("group");
newType.setKind(AnyTypeKind.ANY_OBJECT);
anyTypeDAO.save(newType);
});
}
use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.
the class AnyTypeTest method delete.
@Test
public void delete() {
AnyType otherType = anyTypeDAO.find("PRINTER");
assertNotNull(otherType);
anyTypeDAO.delete(otherType.getKey());
assertNull(anyTypeDAO.find("PRINTER"));
}
use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.
the class AnyTypeTest method saveInvalidKind.
@Test
public void saveInvalidKind() {
assertThrows(InvalidEntityException.class, () -> {
AnyType newType = entityFactory.newEntity(AnyType.class);
newType.setKey("new type");
newType.setKind(AnyTypeKind.USER);
anyTypeDAO.save(newType);
});
}
use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.
the class AnyTypeTest method save.
@Test
public void save() {
AnyType newType = entityFactory.newEntity(AnyType.class);
newType.setKey("new type");
newType.setKind(AnyTypeKind.ANY_OBJECT);
newType.add(anyTypeClassDAO.find("generic membership"));
newType.add(anyTypeClassDAO.find("csv"));
newType = anyTypeDAO.save(newType);
assertNotNull(newType);
assertFalse(newType.getClasses().isEmpty());
}
use of org.apache.syncope.core.persistence.api.entity.AnyType in project syncope by apache.
the class GroupValidator method isValid.
@Override
public boolean isValid(final Group group, final ConstraintValidatorContext context) {
context.disableDefaultConstraintViolation();
boolean isValid = true;
if (group.getUserOwner() != null && group.getGroupOwner() != null) {
isValid = false;
context.buildConstraintViolationWithTemplate(getTemplate(EntityViolationType.InvalidGroupOwner, "A group must either be owned by an user or a group, not both")).addPropertyNode("owner").addConstraintViolation();
}
if (isValid && (group.getName() == null || !KEY_PATTERN.matcher(group.getName()).matches())) {
isValid = false;
context.buildConstraintViolationWithTemplate(getTemplate(EntityViolationType.InvalidName, "Invalid group name")).addPropertyNode("name").addConstraintViolation();
}
if (isValid) {
Set<AnyType> anyTypes = new HashSet<>();
for (ADynGroupMembership memb : group.getADynMemberships()) {
anyTypes.add(memb.getAnyType());
if (memb.getAnyType().getKind() != AnyTypeKind.ANY_OBJECT) {
isValid = false;
context.buildConstraintViolationWithTemplate(getTemplate(EntityViolationType.InvalidADynMemberships, "No user or group dynamic membership condition are allowed here")).addPropertyNode("aDynMemberships").addConstraintViolation();
}
}
if (isValid && anyTypes.size() < group.getADynMemberships().size()) {
context.buildConstraintViolationWithTemplate(getTemplate(EntityViolationType.InvalidADynMemberships, "Each dynamic membership condition requires a different " + AnyType.class.getSimpleName())).addPropertyNode("aDynMemberships").addConstraintViolation();
return false;
}
}
return isValid;
}
Aggregations