use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmConceptRoleRequestService method toPredicates.
@Override
protected List<Predicate> toPredicates(Root<IdmConceptRoleRequest> root, CriteriaQuery<?> query, CriteriaBuilder builder, IdmConceptRoleRequestFilter filter) {
List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
//
if (filter.getRoleRequestId() != null) {
predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.roleRequest).get(IdmRoleRequest_.id), filter.getRoleRequestId()));
}
if (filter.getIdentityRoleId() != null) {
predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.identityRole).get(IdmIdentityRole_.id), filter.getIdentityRoleId()));
}
if (filter.getRoleId() != null) {
predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.role).get(IdmRole_.id), filter.getRoleId()));
}
// by role text
String roleText = filter.getRoleText();
if (StringUtils.isNotEmpty(roleText)) {
IdmRoleFilter subFilter = new IdmRoleFilter();
subFilter.setText(roleText);
Subquery<IdmRole> subquery = query.subquery(IdmRole.class);
Root<IdmRole> subRoot = subquery.from(IdmRole.class);
subquery.select(subRoot);
Predicate rolePredicate = filterManager.getBuilder(IdmRole.class, IdmRoleFilter.PARAMETER_TEXT).getPredicate(subRoot, subquery, builder, subFilter);
subquery.where(builder.and(// correlation attr
builder.equal(root.get(IdmConceptRoleRequest_.role), subRoot), rolePredicate));
//
predicates.add(builder.exists(subquery));
}
if (filter.getIdentityContractId() != null) {
predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.identityContract).get(IdmIdentityContract_.id), filter.getIdentityContractId()));
}
if (filter.getAutomaticRole() != null) {
predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.automaticRole).get(IdmAutomaticRole_.id), filter.getAutomaticRole()));
}
if (filter.getOperation() != null) {
predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.operation), filter.getOperation()));
}
if (filter.getState() != null) {
predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.state), filter.getState()));
}
Set<UUID> ids = filter.getIdentityRoleIds();
if (ids != null && !ids.isEmpty()) {
predicates.add(root.get(IdmConceptRoleRequest_.identityRole).get(IdmIdentityRole_.id).in(ids));
}
if (filter.getRoleEnvironment() != null) {
predicates.add(builder.equal(root.get(IdmConceptRoleRequest_.role).get(IdmRole_.environment), filter.getRoleEnvironment()));
}
List<String> roleEnvironments = filter.getRoleEnvironments();
if (CollectionUtils.isNotEmpty(roleEnvironments)) {
predicates.add(root.get(IdmConceptRoleRequest_.role).get(IdmRole_.environment).in(roleEnvironments));
}
if (filter.isIdentityRoleIsNull()) {
predicates.add(builder.isNull(root.get(IdmConceptRoleRequest_.identityRole)));
}
//
return predicates;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityRoleService method toPredicates.
@Override
protected List<Predicate> toPredicates(Root<IdmIdentityRole> root, CriteriaQuery<?> query, CriteriaBuilder builder, IdmIdentityRoleFilter filter) {
List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
// quick - by identity's username
String text = filter.getText();
if (StringUtils.isNotEmpty(text)) {
text = text.toLowerCase();
predicates.add(builder.like(builder.lower(root.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.identity).get(IdmIdentity_.username)), "%" + text + "%"));
}
// by role text
String roleText = filter.getRoleText();
if (StringUtils.isNotEmpty(roleText)) {
IdmRoleFilter subFilter = new IdmRoleFilter();
subFilter.setText(roleText);
Subquery<IdmRole> subquery = query.subquery(IdmRole.class);
Root<IdmRole> subRoot = subquery.from(IdmRole.class);
subquery.select(subRoot);
//
Predicate rolePredicate = filterManager.getBuilder(IdmRole.class, IdmRoleFilter.PARAMETER_TEXT).getPredicate(subRoot, subquery, builder, subFilter);
//
subquery.where(builder.and(// correlation attr
builder.equal(root.get(IdmIdentityRole_.role), subRoot), rolePredicate));
//
predicates.add(builder.exists(subquery));
}
List<UUID> identities = filter.getIdentities();
if (!identities.isEmpty()) {
predicates.add(root.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.identity).get(IdmIdentity_.id).in(identities));
}
List<UUID> roles = filter.getRoles();
if (!roles.isEmpty()) {
predicates.add(root.get(IdmIdentityRole_.role).get(IdmRole_.id).in(roles));
}
List<String> roleEnvironments = filter.getRoleEnvironments();
if (CollectionUtils.isNotEmpty(roleEnvironments)) {
predicates.add(root.get(IdmIdentityRole_.role).get(IdmRole_.environment).in(roleEnvironments));
}
UUID roleCatalogueId = filter.getRoleCatalogueId();
if (roleCatalogueId != null) {
Subquery<IdmRoleCatalogueRole> roleCatalogueRoleSubquery = query.subquery(IdmRoleCatalogueRole.class);
Root<IdmRoleCatalogueRole> subRootRoleCatalogueRole = roleCatalogueRoleSubquery.from(IdmRoleCatalogueRole.class);
roleCatalogueRoleSubquery.select(subRootRoleCatalogueRole);
roleCatalogueRoleSubquery.where(builder.and(builder.equal(subRootRoleCatalogueRole.get(IdmRoleCatalogueRole_.role), root.get(IdmIdentityRole_.role)), builder.equal(subRootRoleCatalogueRole.get(IdmRoleCatalogueRole_.roleCatalogue).get(AbstractEntity_.id), roleCatalogueId)));
predicates.add(builder.exists(roleCatalogueRoleSubquery));
}
//
Boolean valid = filter.getValid();
if (valid != null) {
// Only valid identity-role include check on contract validity too
if (valid) {
final LocalDate today = LocalDate.now();
predicates.add(builder.and(RepositoryUtils.getValidPredicate(root, builder, today), RepositoryUtils.getValidPredicate(root.get(IdmIdentityRole_.identityContract), builder, today), builder.equal(root.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.disabled), Boolean.FALSE)));
}
// Only invalid identity-role
if (!valid) {
final LocalDate today = LocalDate.now();
predicates.add(builder.or(builder.not(RepositoryUtils.getValidPredicate(root, builder, today)), builder.not(RepositoryUtils.getValidPredicate(root.get(IdmIdentityRole_.identityContract), builder, today)), builder.equal(root.get(IdmIdentityRole_.identityContract).get(IdmIdentityContract_.disabled), Boolean.TRUE)));
}
}
//
// is automatic role
Boolean automaticRole = filter.getAutomaticRole();
if (automaticRole != null) {
if (automaticRole) {
predicates.add(builder.isNotNull(root.get(IdmIdentityRole_.automaticRole)));
} else {
predicates.add(builder.isNull(root.get(IdmIdentityRole_.automaticRole)));
}
}
//
UUID automaticRoleId = filter.getAutomaticRoleId();
if (automaticRoleId != null) {
predicates.add(builder.equal(root.get(IdmIdentityRole_.automaticRole).get(IdmAutomaticRole_.id), automaticRoleId));
}
//
UUID identityContractId = filter.getIdentityContractId();
if (identityContractId != null) {
predicates.add(builder.equal(root.get(IdmIdentityRole_.identityContract).get(AbstractEntity_.id), identityContractId));
}
//
UUID contractPositionId = filter.getContractPositionId();
if (contractPositionId != null) {
predicates.add(builder.equal(root.get(IdmIdentityRole_.contractPosition).get(AbstractEntity_.id), contractPositionId));
}
//
UUID directRoleId = filter.getDirectRoleId();
if (directRoleId != null) {
predicates.add(builder.equal(root.get(IdmIdentityRole_.directRole).get(IdmIdentityRole_.id), directRoleId));
}
//
UUID roleCompositionId = filter.getRoleCompositionId();
if (roleCompositionId != null) {
predicates.add(builder.equal(root.get(IdmIdentityRole_.roleComposition).get(IdmRoleComposition_.id), roleCompositionId));
}
//
// is direct role
Boolean directRole = filter.getDirectRole();
if (directRole != null) {
if (directRole) {
predicates.add(builder.isNull(root.get(IdmIdentityRole_.directRole)));
} else {
predicates.add(builder.isNotNull(root.get(IdmIdentityRole_.directRole)));
}
}
// Role-system
UUID roleSystemId = filter.getRoleSystemId();
if (roleSystemId != null) {
predicates.add(builder.equal(root.get(IdmIdentityRole_.roleSystem), roleSystemId));
}
return predicates;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.
the class RoleUniversalSearchType method createFilter.
protected IdmRoleFilter createFilter(String text) {
IdmRoleFilter filter = new IdmRoleFilter();
filter.setText(text);
return filter;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.
the class RoleByRoleCatalogueEvaluator method getPermissions.
@Override
public Set<String> getPermissions(IdmRole authorizable, AuthorizationPolicy policy) {
Set<String> permissions = super.getPermissions(authorizable, policy);
UUID roleCatalogueId = getUuid(policy);
if (roleCatalogueId == null) {
return permissions;
}
// we try found role by id and role catalogue
IdmRoleFilter filter = new IdmRoleFilter();
filter.setId(authorizable.getId());
filter.setRoleCatalogueId(roleCatalogueId);
long rolesCount = roleService.count(filter);
if (rolesCount > 0) {
permissions.addAll(policy.getPermissions());
}
return permissions;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter in project CzechIdMng by bcvsolutions.
the class RoleDuplicateBulkActionIntegrationTest method testDuplicateRoleOnlyOnTheDifferentEnvironment.
@Test
public void testDuplicateRoleOnlyOnTheDifferentEnvironment() {
IdmRoleDto role = createRole();
// create attributes, automatic roles etc.
createRoleFormAttribute(role, getHelper().createName(), getHelper().createName());
createAutomaticRole(role, getHelper().createTreeNode());
createAutomaticRole(role, getHelper().createName());
//
Assert.assertFalse(findAllSubRoles(role).isEmpty());
Assert.assertFalse(findAutomaticRolesByTree(role).isEmpty());
Assert.assertFalse(findRoleFormAttributes(role).isEmpty());
Assert.assertFalse(findAutomaticRolesByAttribute(role).isEmpty());
//
String roleBaseCode = role.getBaseCode();
//
String targetEnvironment = getHelper().createName();
IdmBulkActionDto bulkAction = findBulkAction(IdmRole.class, RoleDuplicateBulkAction.NAME);
bulkAction.setIdentifiers(Sets.newHashSet(role.getId()));
bulkAction.getProperties().put(RoleDuplicateBulkAction.PROPERTY_ENVIRONMENT, targetEnvironment);
bulkAction.getProperties().put(DuplicateRoleAutomaticByTreeProcessor.PARAMETER_INCLUDE_AUTOMATIC_ROLE, false);
bulkAction.getProperties().put(DuplicateRoleFormAttributeProcessor.PARAMETER_INCLUDE_ROLE_FORM_ATTRIBUTE, false);
bulkAction.getProperties().put(DuplicateRoleCompositionProcessor.PARAMETER_INCLUDE_ROLE_COMPOSITION, false);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
IdmRoleFilter filter = new IdmRoleFilter();
filter.setEnvironment(targetEnvironment);
List<IdmRoleDto> roles = roleService.find(filter, null).getContent();
//
Assert.assertEquals(1, roles.size());
IdmRoleDto duplicate = roles.get(0);
Assert.assertEquals(roleBaseCode, duplicate.getBaseCode());
Assert.assertEquals(role.getName(), duplicate.getName());
Assert.assertEquals(role.getDescription(), duplicate.getDescription());
//
Assert.assertTrue(findAllSubRoles(duplicate).isEmpty());
Assert.assertTrue(findAutomaticRolesByTree(duplicate).isEmpty());
Assert.assertTrue(findRoleFormAttributes(duplicate).isEmpty());
Assert.assertTrue(findAutomaticRolesByAttribute(duplicate).isEmpty());
//
role.setDescription(getHelper().createName());
role = roleService.save(role);
//
processAction = bulkActionManager.processAction(bulkAction);
//
checkResultLrt(processAction, 1l, null, null);
//
roles = roleService.find(filter, null).getContent();
Assert.assertEquals(1, roles.size());
duplicate = roles.get(0);
// on the different environment is updated the first duplicate
Assert.assertEquals(1, roles.size());
Assert.assertEquals(role.getDescription(), duplicate.getDescription());
}
Aggregations