Search in sources :

Example 11 with AnyTypeClass

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());
}
Also used : PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 12 with AnyTypeClass

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);
        }
    });
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass)

Example 13 with 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;
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) UDynGroupMembership(org.apache.syncope.core.persistence.api.entity.user.UDynGroupMembership) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Entity(org.apache.syncope.core.persistence.api.entity.Entity) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) GroupDataBinder(org.apache.syncope.core.provisioning.api.data.GroupDataBinder) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) Map(java.util.Map) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) SearchCondConverter(org.apache.syncope.core.persistence.api.search.SearchCondConverter) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) Iterator(java.util.Iterator) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) User(org.apache.syncope.core.persistence.api.entity.user.User) ADynGroupMembership(org.apache.syncope.core.persistence.api.entity.anyobject.ADynGroupMembership) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) DynGroupMembership(org.apache.syncope.core.persistence.api.entity.DynGroupMembership) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) List(java.util.List) Component(org.springframework.stereotype.Component) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) Group(org.apache.syncope.core.persistence.api.entity.group.Group) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) Any(org.apache.syncope.core.persistence.api.entity.Any) Transactional(org.springframework.transaction.annotation.Transactional) Group(org.apache.syncope.core.persistence.api.entity.group.Group) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) ADynGroupMembership(org.apache.syncope.core.persistence.api.entity.anyobject.ADynGroupMembership) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) HashMap(java.util.HashMap) Map(java.util.Map) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass)

Example 14 with AnyTypeClass

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;
}
Also used : AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass)

Example 15 with 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;
}
Also used : SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass)

Aggregations

AnyTypeClass (org.apache.syncope.core.persistence.api.entity.AnyTypeClass)22 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)8 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)7 AnyType (org.apache.syncope.core.persistence.api.entity.AnyType)6 VirSchema (org.apache.syncope.core.persistence.api.entity.VirSchema)6 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)6 Test (org.junit.jupiter.api.Test)6 SyncopeClientCompositeException (org.apache.syncope.common.lib.SyncopeClientCompositeException)5 DerSchema (org.apache.syncope.core.persistence.api.entity.DerSchema)5 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)4 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 StringUtils (org.apache.commons.lang3.StringUtils)2 AnyTypeClassTO (org.apache.syncope.common.lib.to.AnyTypeClassTO)2 ClientExceptionType (org.apache.syncope.common.lib.types.ClientExceptionType)2