Search in sources :

Example 16 with AnyTypeClass

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

the class SchemaLogic method search.

@PreAuthorize("isAuthenticated()")
@Transactional(readOnly = true)
public <T extends SchemaTO> List<T> search(final SchemaType schemaType, final List<String> anyTypeClasses, final String keyword) {
    List<AnyTypeClass> classes = new ArrayList<>(anyTypeClasses == null ? 0 : anyTypeClasses.size());
    if (anyTypeClasses != null) {
        anyTypeClasses.remove(AnyTypeKind.USER.name());
        anyTypeClasses.remove(AnyTypeKind.GROUP.name());
        anyTypeClasses.forEach(anyTypeClass -> {
            AnyTypeClass clazz = anyTypeClassDAO.find(anyTypeClass);
            if (clazz == null) {
                LOG.warn("Ignoring invalid {}: {}", AnyTypeClass.class.getSimpleName(), anyTypeClass);
            } else {
                classes.add(clazz);
            }
        });
    }
    List<T> result;
    switch(schemaType) {
        case VIRTUAL:
            result = (classes.isEmpty() ? keyword == null ? virSchemaDAO.findAll() : virSchemaDAO.findByKeyword(keyword) : virSchemaDAO.findByAnyTypeClasses(classes)).stream().map(new Function<VirSchema, T>() {

                @Override
                public T apply(final VirSchema schema) {
                    return (T) binder.getVirSchemaTO(schema);
                }
            }).collect(Collectors.toList());
            break;
        case DERIVED:
            result = (classes.isEmpty() ? keyword == null ? derSchemaDAO.findAll() : derSchemaDAO.findByKeyword(keyword) : derSchemaDAO.findByAnyTypeClasses(classes)).stream().map(new Function<DerSchema, T>() {

                @Override
                public T apply(final DerSchema schema) {
                    return (T) binder.getDerSchemaTO(schema);
                }
            }).collect(Collectors.toList());
            break;
        case PLAIN:
        default:
            result = (classes.isEmpty() ? keyword == null ? plainSchemaDAO.findAll() : plainSchemaDAO.findByKeyword(keyword) : plainSchemaDAO.findByAnyTypeClasses(classes)).stream().map(new Function<PlainSchema, T>() {

                @Override
                public T apply(final PlainSchema schema) {
                    return (T) binder.getPlainSchemaTO(schema);
                }
            }).collect(Collectors.toList());
    }
    return result;
}
Also used : DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) ArrayList(java.util.ArrayList) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with AnyTypeClass

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

the class AnyTypeClassLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.ANYTYPECLASS_DELETE + "')")
public AnyTypeClassTO delete(final String key) {
    AnyTypeClass anyTypeClass = anyTypeClassDAO.find(key);
    if (anyTypeClass == null) {
        LOG.error("Could not find anyTypeClass '" + key + "'");
        throw new NotFoundException(key);
    }
    AnyTypeClassTO deleted = binder.getAnyTypeClassTO(anyTypeClass);
    anyTypeClassDAO.delete(key);
    return deleted;
}
Also used : NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) AnyTypeClassTO(org.apache.syncope.common.lib.to.AnyTypeClassTO) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 18 with AnyTypeClass

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

the class JPAAnyTypeClassDAO method delete.

@Override
public void delete(final String key) {
    AnyTypeClass anyTypeClass = find(key);
    if (anyTypeClass == null) {
        return;
    }
    for (PlainSchema schema : plainSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) {
        schema.setAnyTypeClass(null);
    }
    for (DerSchema schema : derSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) {
        schema.setAnyTypeClass(null);
    }
    for (VirSchema schema : virSchemaDAO.findByAnyTypeClasses(Collections.singletonList(anyTypeClass))) {
        schema.setAnyTypeClass(null);
    }
    for (AnyType type : anyTypeDAO.findByTypeClass(anyTypeClass)) {
        type.getClasses().remove(anyTypeClass);
    }
    for (TypeExtension typeExt : groupDAO.findTypeExtensions(anyTypeClass)) {
        typeExt.getAuxClasses().remove(anyTypeClass);
        if (typeExt.getAuxClasses().isEmpty()) {
            typeExt.getGroup().getTypeExtensions().remove(typeExt);
            typeExt.setGroup(null);
        }
    }
    for (Provision provision : resourceDAO.findProvisionsByAuxClass(anyTypeClass)) {
        provision.getAuxClasses().remove(anyTypeClass);
    }
    entityManager().remove(anyTypeClass);
}
Also used : Provision(org.apache.syncope.core.persistence.api.entity.resource.Provision) DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) VirSchema(org.apache.syncope.core.persistence.api.entity.VirSchema) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) JPAAnyTypeClass(org.apache.syncope.core.persistence.jpa.entity.JPAAnyTypeClass) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType)

Example 19 with AnyTypeClass

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

the class JPADerSchemaDAO method findByAnyTypeClasses.

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

Example 20 with AnyTypeClass

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

the class AnyTypeClassTest method find.

@Test
public void find() {
    AnyTypeClass minimalGroup = anyTypeClassDAO.find("minimal group");
    assertNotNull(minimalGroup);
    assertFalse(minimalGroup.getPlainSchemas().isEmpty());
    assertFalse(minimalGroup.getDerSchemas().isEmpty());
    assertFalse(minimalGroup.getVirSchemas().isEmpty());
}
Also used : AnyTypeClass(org.apache.syncope.core.persistence.api.entity.AnyTypeClass) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

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