Search in sources :

Example 6 with DerSchema

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

the class SchemaLogic method resolveReference.

@Override
protected SchemaTO resolveReference(final Method method, final Object... args) throws UnresolvedReferenceException {
    String key = null;
    if (ArrayUtils.isNotEmpty(args)) {
        for (int i = 0; key == null && i < args.length; i++) {
            if (args[i] instanceof String) {
                key = (String) args[i];
            } else if (args[i] instanceof SchemaTO) {
                key = ((SchemaTO) args[i]).getKey();
            }
        }
    }
    if (key != null) {
        try {
            SchemaTO result = null;
            PlainSchema plainSchema = plainSchemaDAO.find(key);
            if (plainSchema == null) {
                DerSchema derSchema = derSchemaDAO.find(key);
                if (derSchema == null) {
                    VirSchema virSchema = virSchemaDAO.find(key);
                    if (virSchema != null) {
                        result = binder.getVirSchemaTO(virSchema);
                    }
                } else {
                    result = binder.getDerSchemaTO(derSchema);
                }
            } else {
                result = binder.getPlainSchemaTO(plainSchema);
            }
            return result;
        } catch (Throwable ignore) {
            LOG.debug("Unresolved reference", ignore);
            throw new UnresolvedReferenceException(ignore);
        }
    }
    throw new UnresolvedReferenceException();
}
Also used : DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) SchemaTO(org.apache.syncope.common.lib.to.SchemaTO) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema)

Example 7 with DerSchema

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

the class SchemaLogic method update.

@PreAuthorize("hasRole('" + StandardEntitlement.SCHEMA_UPDATE + "')")
public <T extends SchemaTO> void update(final SchemaType schemaType, final T schemaTO) {
    if (!doesSchemaExist(schemaType, schemaTO.getKey())) {
        throw new NotFoundException(schemaType + "/" + schemaTO.getKey());
    }
    switch(schemaType) {
        case VIRTUAL:
            VirSchema virSchema = virSchemaDAO.find(schemaTO.getKey());
            if (virSchema == null) {
                throw new NotFoundException("Virtual Schema '" + schemaTO.getKey() + "'");
            }
            virSchemaDAO.save(binder.update((VirSchemaTO) schemaTO, virSchema));
            break;
        case DERIVED:
            DerSchema derSchema = derSchemaDAO.find(schemaTO.getKey());
            if (derSchema == null) {
                throw new NotFoundException("Derived schema '" + schemaTO.getKey() + "'");
            }
            derSchemaDAO.save(binder.update((DerSchemaTO) schemaTO, derSchema));
            break;
        case PLAIN:
        default:
            PlainSchema plainSchema = plainSchemaDAO.find(schemaTO.getKey());
            if (plainSchema == null) {
                throw new NotFoundException("Schema '" + schemaTO.getKey() + "'");
            }
            plainSchemaDAO.save(binder.update((PlainSchemaTO) schemaTO, plainSchema));
    }
}
Also used : PlainSchemaTO(org.apache.syncope.common.lib.to.PlainSchemaTO) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) VirSchemaTO(org.apache.syncope.common.lib.to.VirSchemaTO) DerSchemaTO(org.apache.syncope.common.lib.to.DerSchemaTO) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 8 with DerSchema

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

the class SchemaLogic method read.

@PreAuthorize("isAuthenticated()")
@SuppressWarnings("unchecked")
public <T extends SchemaTO> T read(final SchemaType schemaType, final String schemaKey) {
    T read;
    switch(schemaType) {
        case VIRTUAL:
            VirSchema virSchema = virSchemaDAO.find(schemaKey);
            if (virSchema == null) {
                throw new NotFoundException("Virtual Schema '" + schemaKey + "'");
            }
            read = (T) binder.getVirSchemaTO(virSchema);
            break;
        case DERIVED:
            DerSchema derSchema = derSchemaDAO.find(schemaKey);
            if (derSchema == null) {
                throw new NotFoundException("Derived schema '" + schemaKey + "'");
            }
            read = (T) binder.getDerSchemaTO(derSchema);
            break;
        case PLAIN:
        default:
            PlainSchema schema = plainSchemaDAO.find(schemaKey);
            if (schema == null) {
                throw new NotFoundException("Schema '" + schemaKey + "'");
            }
            read = (T) binder.getPlainSchemaTO(schema);
    }
    return read;
}
Also used : DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 9 with DerSchema

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

the class UserTest method issueSYNCOPE800.

/**
 * Search by derived attribute.
 */
@Test
public void issueSYNCOPE800() {
    // create derived attribute (literal as prefix)
    DerSchema prefix = entityFactory.newEntity(DerSchema.class);
    prefix.setKey("kprefix");
    prefix.setExpression("'k' + firstname");
    derSchemaDAO.save(prefix);
    derSchemaDAO.flush();
    // create derived attribute (literal as suffix)
    DerSchema suffix = entityFactory.newEntity(DerSchema.class);
    suffix.setKey("ksuffix");
    suffix.setExpression("firstname + 'k'");
    derSchemaDAO.save(suffix);
    derSchemaDAO.flush();
    // add derived attributes to user
    User owner = userDAO.findByUsername("vivaldi");
    assertNotNull(owner);
    String firstname = owner.getPlainAttr("firstname").get().getValuesAsStrings().iterator().next();
    assertNotNull(firstname);
    // search by ksuffix derived attribute
    List<User> list = userDAO.findByDerAttrValue("ksuffix", firstname + "k");
    assertEquals(1, list.size());
    // search by kprefix derived attribute
    list = userDAO.findByDerAttrValue("kprefix", "k" + firstname);
    assertEquals(1, list.size());
}
Also used : DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) User(org.apache.syncope.core.persistence.api.entity.user.User) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 10 with DerSchema

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

the class DerSchemaTest method save.

@Test
public void save() {
    DerSchema derivedAttributeSchema = entityFactory.newEntity(DerSchema.class);
    derivedAttributeSchema.setKey("cn2");
    derivedAttributeSchema.setExpression("firstname surname");
    derSchemaDAO.save(derivedAttributeSchema);
    DerSchema actual = derSchemaDAO.find("cn2");
    assertNotNull(actual);
    assertEquals(derivedAttributeSchema, actual);
}
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)

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