Search in sources :

Example 1 with AnyTypeClass

use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass in project syncope by apache.

the class JPAVirSchemaDAO method findByAnyTypeClasses.

@Override
public List<VirSchema> findByAnyTypeClasses(final Collection<AnyTypeClass> anyTypeClasses) {
    StringBuilder queryString = new StringBuilder("SELECT e FROM ").append(JPAVirSchema.class.getSimpleName()).append(" e WHERE ");
    for (AnyTypeClass anyTypeClass : anyTypeClasses) {
        queryString.append("e.anyTypeClass.id='").append(anyTypeClass.getKey()).append("' OR ");
    }
    TypedQuery<VirSchema> query = entityManager().createQuery(queryString.substring(0, queryString.length() - 4), VirSchema.class);
    return query.getResultList();
}
Also used : JPAVirSchema(org.apache.syncope.core.persistence.jpa.entity.JPAVirSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) JPAAnyTypeClass(org.apache.syncope.core.persistence.jpa.entity.JPAAnyTypeClass)

Example 2 with AnyTypeClass

use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass in project syncope by apache.

the class JPAPlainSchemaDAO method findByAnyTypeClasses.

@Override
public List<PlainSchema> findByAnyTypeClasses(final Collection<AnyTypeClass> anyTypeClasses) {
    StringBuilder queryString = new StringBuilder("SELECT e FROM ").append(JPAPlainSchema.class.getSimpleName()).append(" e WHERE ");
    for (AnyTypeClass anyTypeClass : anyTypeClasses) {
        queryString.append("e.anyTypeClass.id='").append(anyTypeClass.getKey()).append("' OR ");
    }
    TypedQuery<PlainSchema> query = entityManager().createQuery(queryString.substring(0, queryString.length() - 4), PlainSchema.class);
    return query.getResultList();
}
Also used : JPAPlainSchema(org.apache.syncope.core.persistence.jpa.entity.JPAPlainSchema) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass)

Example 3 with AnyTypeClass

use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass in project syncope by apache.

the class AbstractAnyDataBinder method fill.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected PropagationByResource fill(final Any any, final AnyPatch anyPatch, final AnyUtils anyUtils, final SyncopeClientCompositeException scce) {
    PropagationByResource propByRes = new PropagationByResource();
    // 1. anyTypeClasses
    for (StringPatchItem patch : anyPatch.getAuxClasses()) {
        AnyTypeClass auxClass = anyTypeClassDAO.find(patch.getValue());
        if (auxClass == null) {
            LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + " {}, ignoring...", patch.getValue());
        } else {
            switch(patch.getOperation()) {
                case ADD_REPLACE:
                    any.add(auxClass);
                    break;
                case DELETE:
                default:
                    any.getAuxClasses().remove(auxClass);
            }
        }
    }
    // 2. resources
    for (StringPatchItem patch : anyPatch.getResources()) {
        ExternalResource resource = resourceDAO.find(patch.getValue());
        if (resource == null) {
            LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", patch.getValue());
        } else {
            switch(patch.getOperation()) {
                case ADD_REPLACE:
                    propByRes.add(ResourceOperation.CREATE, resource.getKey());
                    any.add(resource);
                    break;
                case DELETE:
                default:
                    propByRes.add(ResourceOperation.DELETE, resource.getKey());
                    any.getResources().remove(resource);
            }
        }
    }
    Set<ExternalResource> resources = anyUtils.getAllResources(any);
    SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
    // 3. plain attributes
    anyPatch.getPlainAttrs().stream().filter(patch -> patch.getAttrTO() != null).forEach(patch -> {
        PlainSchema schema = getPlainSchema(patch.getAttrTO().getSchema());
        if (schema == null) {
            LOG.debug("Invalid " + PlainSchema.class.getSimpleName() + " {}, ignoring...", patch.getAttrTO().getSchema());
        } else {
            PlainAttr<?> attr = (PlainAttr<?>) any.getPlainAttr(schema.getKey()).orElse(null);
            if (attr == null) {
                LOG.debug("No plain attribute found for schema {}", schema);
                if (patch.getOperation() == PatchOperation.ADD_REPLACE) {
                    attr = anyUtils.newPlainAttr();
                    ((PlainAttr) attr).setOwner(any);
                    attr.setSchema(schema);
                    any.add(attr);
                }
            }
            if (attr != null) {
                processAttrPatch(any, patch, schema, attr, anyUtils, resources, propByRes, invalidValues);
            }
        }
    });
    if (!invalidValues.isEmpty()) {
        scce.addException(invalidValues);
    }
    SyncopeClientException requiredValuesMissing = checkMandatory(any, anyUtils);
    if (!requiredValuesMissing.isEmpty()) {
        scce.addException(requiredValuesMissing);
    }
    requiredValuesMissing = checkMandatoryOnResources(any, resources);
    if (!requiredValuesMissing.isEmpty()) {
        scce.addException(requiredValuesMissing);
    }
    return propByRes;
}
Also used : StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) Realm(org.apache.syncope.core.persistence.api.entity.Realm) PlainAttr(org.apache.syncope.core.persistence.api.entity.PlainAttr) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) InvalidPlainAttrValueException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidPlainAttrValueException) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) AllowedSchemas(org.apache.syncope.core.persistence.api.dao.AllowedSchemas) JexlUtils(org.apache.syncope.core.provisioning.java.jexl.JexlUtils) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Map(java.util.Map) SchemaDataBinder(org.apache.syncope.core.provisioning.api.data.SchemaDataBinder) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) ParseException(java.text.ParseException) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) AnyPatch(org.apache.syncope.common.lib.patch.AnyPatch) RelationshipTypeDAO(org.apache.syncope.core.persistence.api.dao.RelationshipTypeDAO) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) Collection(java.util.Collection) DerAttrHandler(org.apache.syncope.core.provisioning.api.DerAttrHandler) Set(java.util.Set) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) MappingItem(org.apache.syncope.core.persistence.api.entity.resource.MappingItem) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) List(java.util.List) Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) AttrPatch(org.apache.syncope.common.lib.patch.AttrPatch) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) Optional(java.util.Optional) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName) AttrTO(org.apache.syncope.common.lib.to.AttrTO) AnyUtilsFactory(org.apache.syncope.core.persistence.api.entity.AnyUtilsFactory) GroupableRelatable(org.apache.syncope.core.persistence.api.entity.GroupableRelatable) AnyTO(org.apache.syncope.common.lib.to.AnyTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) MappingManager(org.apache.syncope.core.provisioning.api.MappingManager) SyncopeClientCompositeException(org.apache.syncope.common.lib.SyncopeClientCompositeException) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) MembershipTO(org.apache.syncope.common.lib.to.MembershipTO) Logger(org.slf4j.Logger) PlainSchemaDAO(org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO) VirAttrHandler(org.apache.syncope.core.provisioning.api.VirAttrHandler) Membership(org.apache.syncope.core.persistence.api.entity.Membership) PlainAttrValueDAO(org.apache.syncope.core.persistence.api.dao.PlainAttrValueDAO) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) MappingUtils(org.apache.syncope.core.provisioning.java.utils.MappingUtils) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) RelationshipTO(org.apache.syncope.common.lib.to.RelationshipTO) PatchOperation(org.apache.syncope.common.lib.types.PatchOperation) IntAttrNameParser(org.apache.syncope.core.provisioning.java.IntAttrNameParser) AnyUtils(org.apache.syncope.core.persistence.api.entity.AnyUtils) Collections(java.util.Collections) AnyTypeClassDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO) Any(org.apache.syncope.core.persistence.api.entity.Any) PlainAttrDAO(org.apache.syncope.core.persistence.api.dao.PlainAttrDAO) GroupablePlainAttr(org.apache.syncope.core.persistence.api.entity.GroupablePlainAttr) PlainAttr(org.apache.syncope.core.persistence.api.entity.PlainAttr) GroupablePlainAttr(org.apache.syncope.core.persistence.api.entity.GroupablePlainAttr) StringPatchItem(org.apache.syncope.common.lib.patch.StringPatchItem) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)

Example 4 with AnyTypeClass

use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass in project syncope by apache.

the class SchemaDataBinderImpl method fill.

// --------------- VIRTUAL -----------------
private VirSchema fill(final VirSchema schema, final VirSchemaTO schemaTO) {
    BeanUtils.copyProperties(schemaTO, schema, IGNORE_PROPERTIES);
    if (schemaTO.getAnyTypeClass() != null && (schema.getAnyTypeClass() == null || !schemaTO.getAnyTypeClass().equals(schema.getAnyTypeClass().getKey()))) {
        AnyTypeClass anyTypeClass = anyTypeClassDAO.find(schemaTO.getAnyTypeClass());
        if (anyTypeClass == null) {
            LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + "{}, ignoring...", schemaTO.getAnyTypeClass());
        } else {
            anyTypeClass.add(schema);
            schema.setAnyTypeClass(anyTypeClass);
        }
    } else if (schemaTO.getAnyTypeClass() == null && schema.getAnyTypeClass() != null) {
        schema.getAnyTypeClass().getVirSchemas().remove(schema);
        schema.setAnyTypeClass(null);
    }
    ExternalResource resource = resourceDAO.find(schemaTO.getResource());
    if (resource == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSchemaDefinition);
        sce.getElements().add("Resource " + schemaTO.getResource() + " not found");
        throw sce;
    }
    AnyType anyType = anyTypeDAO.find(schemaTO.getAnyType());
    if (anyType == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSchemaDefinition);
        sce.getElements().add("AnyType " + schemaTO.getAnyType() + " not found");
        throw sce;
    }
    Provision provision = resource.getProvision(anyType).orElse(null);
    if (provision == null) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSchemaDefinition);
        sce.getElements().add("Provision for AnyType" + schemaTO.getAnyType() + " not found in " + schemaTO.getResource());
        throw sce;
    }
    schema.setProvision(provision);
    return virSchemaDAO.save(schema);
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType)

Example 5 with AnyTypeClass

use of org.apache.syncope.core.persistence.api.entity.AnyTypeClass in project syncope by apache.

the class SchemaDataBinderImpl method fill.

// --------------- PLAIN -----------------
private PlainSchema fill(final PlainSchema schema, final PlainSchemaTO schemaTO) {
    if (!JexlUtils.isExpressionValid(schemaTO.getMandatoryCondition())) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidValues);
        sce.getElements().add(schemaTO.getMandatoryCondition());
        throw sce;
    }
    BeanUtils.copyProperties(schemaTO, schema, IGNORE_PROPERTIES);
    if (schemaTO.getValidator() == null) {
        schema.setValidator(null);
    } else {
        Implementation validator = implementationDAO.find(schemaTO.getValidator());
        if (validator == null) {
            LOG.debug("Invalid " + Implementation.class.getSimpleName() + " {}, ignoring...", schemaTO.getValidator());
        } else {
            schema.setValidator(validator);
        }
    }
    PlainSchema merged = plainSchemaDAO.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().getPlainSchemas().remove(merged);
        merged.setAnyTypeClass(null);
    }
    return merged;
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation)

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