use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass in project syncope by apache.
the class AnyTypeClassTest method create.
@Test
public void create() {
PlainSchema newSchema = entityFactory.newEntity(PlainSchema.class);
newSchema.setKey("new_plain_schema");
newSchema.setType(AttrSchemaType.String);
plainSchemaDAO.save(newSchema);
plainSchemaDAO.flush();
newSchema = plainSchemaDAO.find(newSchema.getKey());
assertNotNull(newSchema);
AnyTypeClass newClass = entityFactory.newEntity(AnyTypeClass.class);
newClass.setKey("new class");
newClass.add(newSchema);
anyTypeClassDAO.save(newClass);
anyTypeClassDAO.flush();
newClass = anyTypeClassDAO.find(newClass.getKey());
assertNotNull(newClass);
assertEquals(1, newClass.getPlainSchemas().size());
assertEquals(newSchema, newClass.getPlainSchemas().get(0));
assertEquals(newClass, newClass.getPlainSchemas().get(0).getAnyTypeClass());
newSchema = plainSchemaDAO.find(newSchema.getKey());
assertNotNull(newSchema.getAnyTypeClass());
}
use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass in project syncope by apache.
the class AnyTypeDataBinderImpl method update.
@Override
public void update(final AnyType anyType, final AnyTypeTO anyTypeTO) {
if (anyType.getKey() == null) {
anyType.setKey(anyTypeTO.getKey());
}
if (anyType.getKind() == null) {
anyType.setKind(anyTypeTO.getKind());
}
if (anyType.getKind() != anyTypeTO.getKind()) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidAnyType);
sce.getElements().add(AnyTypeKind.class.getSimpleName() + " cannot be changed");
throw sce;
}
anyType.getClasses().clear();
anyTypeTO.getClasses().forEach(anyTypeClassName -> {
AnyTypeClass anyTypeClass = anyTypeClassDAO.find(anyTypeClassName);
if (anyTypeClass == null) {
LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + " {}, ignoring...", anyTypeClassName);
} else {
anyType.add(anyTypeClass);
}
});
}
use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass in project syncope by apache.
the class GroupDataBinderImpl method update.
@Override
public PropagationByResource update(final Group toBeUpdated, final GroupPatch groupPatch) {
// Re-merge any pending change from workflow tasks
Group group = groupDAO.save(toBeUpdated);
PropagationByResource propByRes = new PropagationByResource();
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
AnyUtils anyUtils = anyUtilsFactory.getInstance(AnyTypeKind.GROUP);
// fetch connObjectKeys before update
Map<String, String> oldConnObjectKeys = getConnObjectKeys(group, anyUtils);
// realm
setRealm(group, groupPatch);
// name
if (groupPatch.getName() != null && StringUtils.isNotBlank(groupPatch.getName().getValue())) {
propByRes.addAll(ResourceOperation.UPDATE, groupDAO.findAllResourceKeys(group.getKey()));
group.setName(groupPatch.getName().getValue());
}
// owner
if (groupPatch.getUserOwner() != null) {
group.setUserOwner(groupPatch.getUserOwner().getValue() == null ? null : userDAO.find(groupPatch.getUserOwner().getValue()));
}
if (groupPatch.getGroupOwner() != null) {
group.setGroupOwner(groupPatch.getGroupOwner().getValue() == null ? null : groupDAO.find(groupPatch.getGroupOwner().getValue()));
}
// attributes and resources
propByRes.merge(fill(group, groupPatch, anyUtils, scce));
// check if some connObjectKey was changed by the update above
Map<String, String> newConnObjectKeys = getConnObjectKeys(group, anyUtils);
oldConnObjectKeys.entrySet().stream().filter(entry -> newConnObjectKeys.containsKey(entry.getKey()) && !entry.getValue().equals(newConnObjectKeys.get(entry.getKey()))).forEach(entry -> {
propByRes.addOldConnObjectKey(entry.getKey(), entry.getValue());
propByRes.add(ResourceOperation.UPDATE, entry.getKey());
});
group = groupDAO.save(group);
// dynamic membership
if (groupPatch.getUDynMembershipCond() == null) {
if (group.getUDynMembership() != null) {
group.getUDynMembership().setGroup(null);
group.setUDynMembership(null);
groupDAO.clearUDynMembers(group);
}
} else {
setDynMembership(group, anyTypeDAO.findUser(), groupPatch.getUDynMembershipCond());
}
for (Iterator<? extends ADynGroupMembership> itor = group.getADynMemberships().iterator(); itor.hasNext(); ) {
ADynGroupMembership memb = itor.next();
memb.setGroup(null);
itor.remove();
}
groupDAO.clearADynMembers(group);
for (Map.Entry<String, String> entry : groupPatch.getADynMembershipConds().entrySet()) {
AnyType anyType = anyTypeDAO.find(entry.getKey());
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), entry.getKey());
} else {
setDynMembership(group, anyType, entry.getValue());
}
}
// type extensions
for (TypeExtensionTO typeExtTO : groupPatch.getTypeExtensions()) {
AnyType anyType = anyTypeDAO.find(typeExtTO.getAnyType());
if (anyType == null) {
LOG.warn("Ignoring invalid {}: {}", AnyType.class.getSimpleName(), typeExtTO.getAnyType());
} else {
TypeExtension typeExt = group.getTypeExtension(anyType).orElse(null);
if (typeExt == null) {
typeExt = entityFactory.newEntity(TypeExtension.class);
typeExt.setAnyType(anyType);
typeExt.setGroup(group);
group.add(typeExt);
}
// add all classes contained in the TO
for (String name : typeExtTO.getAuxClasses()) {
AnyTypeClass anyTypeClass = anyTypeClassDAO.find(name);
if (anyTypeClass == null) {
LOG.warn("Ignoring invalid {}: {}", AnyTypeClass.class.getSimpleName(), name);
} else {
typeExt.add(anyTypeClass);
}
}
// remove all classes not contained in the TO
typeExt.getAuxClasses().removeIf(anyTypeClass -> !typeExtTO.getAuxClasses().contains(anyTypeClass.getKey()));
// only consider non-empty type extensions
if (typeExt.getAuxClasses().isEmpty()) {
group.getTypeExtensions().remove(typeExt);
typeExt.setGroup(null);
}
}
}
// remove all type extensions not contained in the TO
group.getTypeExtensions().removeIf(typeExt -> !groupPatch.getTypeExtension(typeExt.getAnyType().getKey()).isPresent());
// Throw composite exception if there is at least one element set in the composing exceptions
if (scce.hasExceptions()) {
throw scce;
}
return propByRes;
}
use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass in project syncope by apache.
the class AnyTypeClassDataBinderImpl method create.
@Override
public AnyTypeClass create(final AnyTypeClassTO anyTypeClassTO) {
AnyTypeClass anyTypeClass = entityFactory.newEntity(AnyTypeClass.class);
update(anyTypeClass, anyTypeClassTO);
return anyTypeClass;
}
use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass in project syncope by apache.
the class SchemaDataBinderImpl method fill.
// --------------- DERIVED -----------------
private DerSchema fill(final DerSchema schema, final DerSchemaTO schemaTO) {
SyncopeClientCompositeException scce = SyncopeClientException.buildComposite();
if (StringUtils.isBlank(schemaTO.getExpression())) {
SyncopeClientException requiredValuesMissing = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing);
requiredValuesMissing.getElements().add("expression");
scce.addException(requiredValuesMissing);
} else if (!JexlUtils.isExpressionValid(schemaTO.getExpression())) {
SyncopeClientException e = SyncopeClientException.build(ClientExceptionType.InvalidValues);
e.getElements().add(schemaTO.getExpression());
scce.addException(e);
}
if (scce.hasExceptions()) {
throw scce;
}
BeanUtils.copyProperties(schemaTO, schema, IGNORE_PROPERTIES);
DerSchema merged = derSchemaDAO.save(schema);
if (schemaTO.getAnyTypeClass() != null && (merged.getAnyTypeClass() == null || !schemaTO.getAnyTypeClass().equals(merged.getAnyTypeClass().getKey()))) {
AnyTypeClass anyTypeClass = anyTypeClassDAO.find(schemaTO.getAnyTypeClass());
if (anyTypeClass == null) {
LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + "{}, ignoring...", schemaTO.getAnyTypeClass());
} else {
anyTypeClass.add(merged);
merged.setAnyTypeClass(anyTypeClass);
}
} else if (schemaTO.getAnyTypeClass() == null && merged.getAnyTypeClass() != null) {
merged.getAnyTypeClass().getDerSchemas().remove(merged);
merged.setAnyTypeClass(null);
}
return merged;
}
Aggregations