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;
}
Aggregations