Search in sources :

Example 6 with IdmRoleGuarantee

use of eu.bcvsolutions.idm.core.model.entity.IdmRoleGuarantee 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);
    // quick
    if (StringUtils.isNotEmpty(filter.getText())) {
        predicates.add(builder.or(builder.like(builder.lower(root.get(IdmRole_.name)), "%" + filter.getText().toLowerCase() + "%"), builder.like(builder.lower(root.get(IdmRole_.description)), "%" + filter.getText().toLowerCase() + "%")));
    }
    // role type
    if (filter.getRoleType() != null) {
        predicates.add(builder.equal(root.get(IdmRole_.roleType), filter.getRoleType()));
    }
    // property
    if (StringUtils.equals(IdmRole_.name.getName(), filter.getProperty())) {
        predicates.add(builder.equal(root.get(IdmRole_.name), filter.getValue()));
    }
    // guarantee
    if (filter.getGuaranteeId() != null) {
        Subquery<IdmRoleGuarantee> subquery = query.subquery(IdmRoleGuarantee.class);
        Root<IdmRoleGuarantee> subRoot = subquery.from(IdmRoleGuarantee.class);
        subquery.select(subRoot);
        subquery.where(builder.and(// correlation attr
        builder.equal(subRoot.get(IdmRoleGuarantee_.role), root), builder.equal(subRoot.get(IdmRoleGuarantee_.guarantee).get(IdmIdentity_.id), filter.getGuaranteeId())));
        predicates.add(builder.exists(subquery));
    }
    // role catalogue by forest index
    if (filter.getRoleCatalogueId() != null) {
        // TODO: use subquery - see DefaultIdmIdentityService#toPredicates
        IdmRoleCatalogue roleCatalogue = roleCatalogueRepository.findOne(filter.getRoleCatalogueId());
        Subquery<IdmRoleCatalogueRole> subquery = query.subquery(IdmRoleCatalogueRole.class);
        Root<IdmRoleCatalogueRole> subRoot = subquery.from(IdmRoleCatalogueRole.class);
        subquery.select(subRoot);
        subquery.where(builder.and(// correlation attr
        builder.equal(subRoot.get(IdmRoleCatalogueRole_.role), root), builder.between(subRoot.get(IdmRoleCatalogueRole_.roleCatalogue).get(IdmRoleCatalogue_.forestIndex).get(IdmForestIndexEntity_.lft), roleCatalogue.getLft(), roleCatalogue.getRgt())));
        predicates.add(builder.exists(subquery));
    }
    // 
    return predicates;
}
Also used : IdmRoleGuarantee(eu.bcvsolutions.idm.core.model.entity.IdmRoleGuarantee) IdmRoleCatalogue(eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogue) IdmRoleCatalogueRole(eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogueRole) Predicate(javax.persistence.criteria.Predicate)

Aggregations

IdmRoleGuarantee (eu.bcvsolutions.idm.core.model.entity.IdmRoleGuarantee)6 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)4 Test (org.junit.Test)4 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)2 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)2 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)2 AbstractVerifiableUnitTest (eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest)2 ArrayList (java.util.ArrayList)2 IdmRoleCatalogue (eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogue)1 IdmRoleCatalogueRole (eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogueRole)1 AbstractAuthentication (eu.bcvsolutions.idm.core.security.api.domain.AbstractAuthentication)1 UUID (java.util.UUID)1 Predicate (javax.persistence.criteria.Predicate)1