Search in sources :

Example 11 with Any

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

the class JEXLItemTransformerImpl method beforePropagation.

@Override
public List<PlainAttrValue> beforePropagation(final Item item, final Entity entity, final List<PlainAttrValue> values) {
    if (StringUtils.isNotBlank(propagationJEXL) && values != null) {
        values.forEach(value -> {
            JexlContext jexlContext = new MapContext();
            if (entity != null) {
                JexlUtils.addFieldsToContext(entity, jexlContext);
                if (entity instanceof Any) {
                    JexlUtils.addPlainAttrsToContext(((Any<?>) entity).getPlainAttrs(), jexlContext);
                    JexlUtils.addDerAttrsToContext(((Any<?>) entity), jexlContext);
                }
            }
            jexlContext.set("value", value.getValueAsString());
            value.setStringValue(JexlUtils.evaluate(propagationJEXL, jexlContext));
        });
        return values;
    }
    return values;
}
Also used : JexlContext(org.apache.commons.jexl3.JexlContext) MapContext(org.apache.commons.jexl3.MapContext) Any(org.apache.syncope.core.persistence.api.entity.Any)

Example 12 with Any

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

the class AbstractAnyDataBinder method fill.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void fill(final Any any, final AnyTO anyTO, final AnyUtils anyUtils, final SyncopeClientCompositeException scce) {
    // 0. aux classes
    any.getAuxClasses().clear();
    anyTO.getAuxClasses().stream().map(className -> anyTypeClassDAO.find(className)).forEachOrdered(auxClass -> {
        if (auxClass == null) {
            LOG.debug("Invalid " + AnyTypeClass.class.getSimpleName() + " {}, ignoring...", auxClass);
        } else {
            any.add(auxClass);
        }
    });
    // 1. attributes
    SyncopeClientException invalidValues = SyncopeClientException.build(ClientExceptionType.InvalidValues);
    anyTO.getPlainAttrs().stream().filter(attrTO -> !attrTO.getValues().isEmpty()).forEach(attrTO -> {
        PlainSchema schema = getPlainSchema(attrTO.getSchema());
        if (schema != null) {
            PlainAttr<?> attr = (PlainAttr<?>) any.getPlainAttr(schema.getKey()).orElse(null);
            if (attr == null) {
                attr = anyUtils.newPlainAttr();
                ((PlainAttr) attr).setOwner(any);
                attr.setSchema(schema);
            }
            fillAttr(attrTO.getValues(), anyUtils, schema, attr, invalidValues);
            if (attr.getValuesAsStrings().isEmpty()) {
                attr.setOwner(null);
            } else {
                any.add(attr);
            }
        }
    });
    if (!invalidValues.isEmpty()) {
        scce.addException(invalidValues);
    }
    SyncopeClientException requiredValuesMissing = checkMandatory(any, anyUtils);
    if (!requiredValuesMissing.isEmpty()) {
        scce.addException(requiredValuesMissing);
    }
    // 2. resources
    anyTO.getResources().forEach(resourceKey -> {
        ExternalResource resource = resourceDAO.find(resourceKey);
        if (resource == null) {
            LOG.debug("Invalid " + ExternalResource.class.getSimpleName() + " {}, ignoring...", resourceKey);
        } else {
            any.add(resource);
        }
    });
    requiredValuesMissing = checkMandatoryOnResources(any, anyUtils.getAllResources(any));
    if (!requiredValuesMissing.isEmpty()) {
        scce.addException(requiredValuesMissing);
    }
}
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) 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) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)

Aggregations

Any (org.apache.syncope.core.persistence.api.entity.Any)12 List (java.util.List)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 Set (java.util.Set)8 StringUtils (org.apache.commons.lang3.StringUtils)8 GroupDAO (org.apache.syncope.core.persistence.api.dao.GroupDAO)8 UserDAO (org.apache.syncope.core.persistence.api.dao.UserDAO)8 ArrayList (java.util.ArrayList)7 Collections (java.util.Collections)7 Optional (java.util.Optional)7 Collectors (java.util.stream.Collectors)7 AnyObjectDAO (org.apache.syncope.core.persistence.api.dao.AnyObjectDAO)7 Realm (org.apache.syncope.core.persistence.api.entity.Realm)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 AnyUtils (org.apache.syncope.core.persistence.api.entity.AnyUtils)6 VirSchema (org.apache.syncope.core.persistence.api.entity.VirSchema)6 Provision (org.apache.syncope.core.persistence.api.entity.resource.Provision)6 MappingManager (org.apache.syncope.core.provisioning.api.MappingManager)6 MappingUtils (org.apache.syncope.core.provisioning.java.utils.MappingUtils)6