Search in sources :

Example 1 with IdmRoleComposition

use of eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleService method toPredicates.

@Override
protected List<Predicate> toPredicates(Root<IdmRole> root, CriteriaQuery<?> query, CriteriaBuilder builder, IdmRoleFilter filter) {
    List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
    // 
    // role type
    RoleType roleType = filter.getRoleType();
    if (roleType != null) {
        predicates.add(builder.equal(root.get(IdmRole_.roleType), roleType));
    }
    // role catalogue by forest index
    UUID roleCatalogueId = filter.getRoleCatalogueId();
    if (roleCatalogueId != null) {
        Subquery<IdmRoleCatalogueRole> subquery = query.subquery(IdmRoleCatalogueRole.class);
        Root<IdmRoleCatalogueRole> subRoot = subquery.from(IdmRoleCatalogueRole.class);
        subquery.select(subRoot);
        Subquery<IdmRoleCatalogue> subqueryCatalogue = query.subquery(IdmRoleCatalogue.class);
        Root<IdmRoleCatalogue> subRootCatalogue = subqueryCatalogue.from(IdmRoleCatalogue.class);
        subqueryCatalogue.select(subRootCatalogue);
        subqueryCatalogue.where(builder.and(builder.equal(subRootCatalogue.get(IdmRoleCatalogue_.id), roleCatalogueId), builder.between(subRoot.get(IdmRoleCatalogueRole_.roleCatalogue).get(IdmRoleCatalogue_.forestIndex).get(IdmForestIndexEntity_.lft), subRootCatalogue.get(IdmRoleCatalogue_.forestIndex).get(IdmForestIndexEntity_.lft), subRootCatalogue.get(IdmRoleCatalogue_.forestIndex).get(IdmForestIndexEntity_.rgt))));
        subquery.where(builder.and(// correlation attr
        builder.equal(subRoot.get(IdmRoleCatalogueRole_.role), root), builder.exists(subqueryCatalogue)));
        predicates.add(builder.exists(subquery));
    }
    // environment
    List<String> environments = filter.getEnvironments();
    if (!CollectionUtils.isEmpty(environments)) {
        predicates.add(root.get(IdmRole_.environment).in(environments));
    }
    // baseCode
    String baseCode = filter.getBaseCode();
    if (StringUtils.isNotEmpty(baseCode)) {
        predicates.add(builder.equal(root.get(IdmRole_.baseCode), baseCode));
    }
    UUID parent = filter.getParent();
    if (parent != null) {
        Subquery<IdmRoleComposition> subquery = query.subquery(IdmRoleComposition.class);
        Root<IdmRoleComposition> subRoot = subquery.from(IdmRoleComposition.class);
        subquery.select(subRoot);
        subquery.where(builder.and(// correlation attr
        builder.equal(subRoot.get(IdmRoleComposition_.sub), root), builder.equal(subRoot.get(IdmRoleComposition_.superior).get(IdmRole_.id), parent)));
        // 
        predicates.add(builder.exists(subquery));
    }
    // form definition for role attributes
    UUID definitionId = filter.getAttributeFormDefinitionId();
    if (definitionId != null) {
        predicates.add(builder.equal(root.get(IdmRole_.identityRoleAttributeDefinition).get(IdmFormDefinition_.id), definitionId));
    }
    // without role catalogue
    Boolean withoutCatalogue = filter.getWithoutCatalogue();
    if (withoutCatalogue != null) {
        Subquery<IdmRoleCatalogueRole> subquery = query.subquery(IdmRoleCatalogueRole.class);
        Root<IdmRoleCatalogueRole> subRoot = subquery.from(IdmRoleCatalogueRole.class);
        subquery.select(subRoot);
        subquery.where(builder.equal(subRoot.get(IdmRoleCatalogueRole_.role), root));
        // 
        if (withoutCatalogue) {
            // without
            predicates.add(builder.not(builder.exists(subquery)));
        } else {
            // with some
            predicates.add(builder.exists(subquery));
        }
    }
    // 
    return predicates;
}
Also used : IdmRoleComposition(eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition) RoleType(eu.bcvsolutions.idm.core.api.domain.RoleType) IdmRoleCatalogue(eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogue) IdmRoleCatalogueRole(eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogueRole) Predicate(javax.persistence.criteria.Predicate) UUID(java.util.UUID)

Aggregations

RoleType (eu.bcvsolutions.idm.core.api.domain.RoleType)1 IdmRoleCatalogue (eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogue)1 IdmRoleCatalogueRole (eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogueRole)1 IdmRoleComposition (eu.bcvsolutions.idm.core.model.entity.IdmRoleComposition)1 UUID (java.util.UUID)1 Predicate (javax.persistence.criteria.Predicate)1