Search in sources :

Example 11 with DerSchema

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

the class DerSchemaTest method findByName.

@Test
public void findByName() {
    DerSchema attributeSchema = derSchemaDAO.find("cn");
    assertNotNull(attributeSchema);
}
Also used : DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 12 with DerSchema

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

the class DerSchemaTest method issueSYNCOPE418.

@Test
public void issueSYNCOPE418() {
    DerSchema schema = entityFactory.newEntity(DerSchema.class);
    schema.setKey("http://schemas.examples.org/security/authorization/organizationUnit");
    try {
        derSchemaDAO.save(schema);
        fail("This should not happen");
    } catch (InvalidEntityException e) {
        assertTrue(e.hasViolation(EntityViolationType.InvalidKey));
    }
}
Also used : DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 13 with DerSchema

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

the class NotificationManagerImpl method getRecipientEmail.

private String getRecipientEmail(final String recipientAttrName, final User user) {
    String email = null;
    IntAttrName intAttrName;
    try {
        intAttrName = intAttrNameParser.parse(recipientAttrName, AnyTypeKind.USER);
    } catch (ParseException e) {
        LOG.error("Invalid intAttrName '{}' specified as recipient, ignoring", recipientAttrName, e);
        return email;
    }
    if ("username".equals(intAttrName.getField())) {
        email = user.getUsername();
    } else if (intAttrName.getSchemaType() != null) {
        UMembership membership = null;
        if (intAttrName.getMembershipOfGroup() != null) {
            Group group = groupDAO.findByName(intAttrName.getMembershipOfGroup());
            if (group != null) {
                membership = user.getMembership(group.getKey()).orElse(null);
            }
        }
        switch(intAttrName.getSchemaType()) {
            case PLAIN:
                Optional<? extends UPlainAttr> attr = membership == null ? user.getPlainAttr(recipientAttrName) : user.getPlainAttr(recipientAttrName, membership);
                if (attr.isPresent()) {
                    email = attr.get().getValuesAsStrings().isEmpty() ? null : attr.get().getValuesAsStrings().get(0);
                }
                break;
            case DERIVED:
                DerSchema schema = derSchemaDAO.find(recipientAttrName);
                if (schema == null) {
                    LOG.warn("Ignoring non existing {} {}", DerSchema.class.getSimpleName(), recipientAttrName);
                } else {
                    email = membership == null ? derAttrHander.getValue(user, schema) : derAttrHander.getValue(user, membership, schema);
                }
                break;
            case VIRTUAL:
                VirSchema virSchema = virSchemaDAO.find(recipientAttrName);
                if (virSchema == null) {
                    LOG.warn("Ignoring non existing {} {}", VirSchema.class.getSimpleName(), recipientAttrName);
                } else {
                    List<String> virAttrValues = membership == null ? virAttrHander.getValues(user, virSchema) : virAttrHander.getValues(user, membership, virSchema);
                    email = virAttrValues.isEmpty() ? null : virAttrValues.get(0);
                }
                break;
            default:
        }
    }
    return email;
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) Optional(java.util.Optional) UMembership(org.apache.syncope.core.persistence.api.entity.user.UMembership) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) List(java.util.List) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) UPlainAttr(org.apache.syncope.core.persistence.api.entity.user.UPlainAttr) IntAttrName(org.apache.syncope.core.provisioning.api.IntAttrName)

Example 14 with DerSchema

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

the class AnyTypeClassDataBinderImpl method update.

@Override
public void update(final AnyTypeClass anyTypeClass, final AnyTypeClassTO anyTypeClassTO) {
    if (anyTypeClass.getKey() == null) {
        anyTypeClass.setKey(anyTypeClassTO.getKey());
    }
    plainSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach(schema -> {
        schema.setAnyTypeClass(null);
    });
    anyTypeClass.getPlainSchemas().clear();
    anyTypeClassTO.getPlainSchemas().forEach(schemaName -> {
        PlainSchema schema = plainSchemaDAO.find(schemaName);
        if (schema == null || schema.getAnyTypeClass() != null) {
            LOG.debug("Invalid or already in use" + PlainSchema.class.getSimpleName() + "{}, ignoring...", schemaName);
        } else {
            anyTypeClass.add(schema);
        }
    });
    derSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach((schema) -> {
        schema.setAnyTypeClass(null);
    });
    anyTypeClass.getDerSchemas().clear();
    anyTypeClassTO.getDerSchemas().forEach(schemaName -> {
        DerSchema schema = derSchemaDAO.find(schemaName);
        if (schema == null || schema.getAnyTypeClass() != null) {
            LOG.debug("Invalid or already in use" + DerSchema.class.getSimpleName() + "{}, ignoring...", schemaName);
        } else {
            anyTypeClass.add(schema);
        }
    });
    virSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass)).forEach(schema -> {
        schema.setAnyTypeClass(null);
    });
    anyTypeClass.getVirSchemas().clear();
    anyTypeClassTO.getVirSchemas().forEach(schemaName -> {
        VirSchema schema = virSchemaDAO.find(schemaName);
        if (schema == null || schema.getAnyTypeClass() != null) {
            LOG.debug("Invalid or already in use" + VirSchema.class.getSimpleName() + "{}, ignoring...", schemaName);
        } else {
            anyTypeClass.add(schema);
        }
    });
}
Also used : DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema)

Example 15 with DerSchema

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

the class DerAttrHandlerImpl method getValues.

private Map<DerSchema, String> getValues(final Any<?> any, final Set<DerSchema> schemas) {
    Map<DerSchema, String> result = new HashMap<>(schemas.size());
    for (DerSchema schema : schemas) {
        JexlContext jexlContext = new MapContext();
        JexlUtils.addPlainAttrsToContext(any.getPlainAttrs(), jexlContext);
        JexlUtils.addFieldsToContext(any, jexlContext);
        result.put(schema, JexlUtils.evaluate(schema.getExpression(), jexlContext));
    }
    return result;
}
Also used : DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) HashMap(java.util.HashMap) JexlContext(org.apache.commons.jexl3.JexlContext) MapContext(org.apache.commons.jexl3.MapContext)

Aggregations

DerSchema (org.apache.syncope.core.persistence.api.entity.DerSchema)22 VirSchema (org.apache.syncope.core.persistence.api.entity.VirSchema)10 PlainSchema (org.apache.syncope.core.persistence.api.entity.PlainSchema)8 Test (org.junit.jupiter.api.Test)6 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)5 ArrayList (java.util.ArrayList)4 AnyTypeClass (org.apache.syncope.core.persistence.api.entity.AnyTypeClass)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 List (java.util.List)3 DerSchemaTO (org.apache.syncope.common.lib.to.DerSchemaTO)3 PlainSchemaTO (org.apache.syncope.common.lib.to.PlainSchemaTO)3 VirSchemaTO (org.apache.syncope.common.lib.to.VirSchemaTO)3 User (org.apache.syncope.core.persistence.api.entity.user.User)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ParseException (java.text.ParseException)2 HashMap (java.util.HashMap)2 Optional (java.util.Optional)2 JexlContext (org.apache.commons.jexl3.JexlContext)2 MapContext (org.apache.commons.jexl3.MapContext)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2