use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class RoleDeleteBulkAction method prevalidate.
@Override
public ResultModels prevalidate() {
IdmBulkActionDto action = getAction();
List<UUID> entities = getEntities(action, new StringBuilder());
ResultModels result = new ResultModels();
Map<ResultModel, Long> models = new HashMap<>();
entities.forEach(roleId -> {
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setRoleId(roleId);
IdmRoleDto role = getService().get(roleId);
long count = identityRoleService.count(identityRoleFilter);
if (count > 0) {
if (securityService.hasAnyAuthority(CoreGroupPermission.ROLE_ADMIN)) {
models.put(new DefaultResultModel(CoreResultCode.ROLE_FORCE_DELETE_BULK_ACTION_NUMBER_OF_IDENTITIES, ImmutableMap.of("role", role.getCode(), "count", count)), count);
} else {
models.put(new DefaultResultModel(CoreResultCode.ROLE_DELETE_BULK_ACTION_NUMBER_OF_IDENTITIES, ImmutableMap.of("role", role.getCode(), "count", count)), count);
}
}
});
long conceptsToModify = //
entities.stream().map(roleId -> {
IdmConceptRoleRequestFilter roleRequestFilter = new IdmConceptRoleRequestFilter();
roleRequestFilter.setRoleId(roleId);
return conceptRoleRequestService.count(roleRequestFilter);
}).reduce(0L, Long::sum);
ResultModel conceptCountResult = null;
if (conceptsToModify > 0) {
conceptCountResult = new DefaultResultModel(CoreResultCode.ROLE_DELETE_BULK_ACTION_CONCEPTS_TO_MODIFY, ImmutableMap.of("conceptCount", conceptsToModify));
}
// Sort by count
List<Entry<ResultModel, Long>> collect = //
models.entrySet().stream().sorted(//
Collections.reverseOrder(Map.Entry.comparingByValue())).limit(//
5).collect(//
Collectors.toList());
collect.forEach(entry -> {
result.addInfo(entry.getKey());
});
if (conceptCountResult != null) {
result.addInfo(conceptCountResult);
}
return result;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class IdentityRoleByIdentityDeduplicationBulkAction method getDuplicatesIdentityRoleForContract.
/**
* Method return duplicities for {@link IdmIdentityContractDto}
* @param contract
* @return
*/
public List<IdmIdentityRoleDto> getDuplicatesIdentityRoleForContract(IdmIdentityContractDto contract) {
boolean checkSubdefinition = isCheckSubdefinition();
// Get all identity roles
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(contract.getIdentity());
identityRoleFilter.setIdentityContractId(contract.getId());
// Identity roles must be sorted by create, for duplicities with manually will be removed always the newer.
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, PageRequest.of(0, Integer.MAX_VALUE, new Sort(Direction.DESC, IdmIdentityRole_.created.getName())), PermissionUtils.toPermissions(getAuthoritiesForIdentityRole()).toArray(new BasePermission[] {})).getContent();
// load eav instance, if eav values has to be checked
if (checkSubdefinition) {
identityRoles.forEach(identityRole -> {
identityRole.setEavs(Lists.newArrayList(identityRoleService.getRoleAttributeValues(identityRole)));
});
}
// Get map of duplicity roles (roleId, assignedRoles).
Map<UUID, List<IdmIdentityRoleDto>> duplicateRoles = identityRoles.stream().collect(// Group identity roles by role.
Collectors.groupingBy(//
IdmIdentityRoleDto::getRole)).entrySet().stream().filter(// Filter only by values where is more than one record (possible duplicates).
entry -> entry.getValue().size() > 1).collect(//
Collectors.toMap(// Collect as map where key is UUID of role.
k -> k.getKey(), // And value is list of identity roles for this role.
v -> v.getValue()));
//
//
List<IdmIdentityRoleDto> resolvedDuplicities = new ArrayList<>();
// Iterate over duplicated roles. In Key is ID of role that has more finding for the contract.
for (Entry<UUID, List<IdmIdentityRoleDto>> entry : duplicateRoles.entrySet()) {
List<IdmIdentityRoleDto> assignedRoles = entry.getValue();
List<IdmIdentityRoleDto> rolesToCheck = // ~ manually assigned direct roles can be removed only
assignedRoles.stream().filter(idenityRole -> {
// not automatic
return idenityRole.getAutomaticRole() == null;
}).filter(idenityRole -> {
// not sub role
return idenityRole.getDirectRole() == null;
}).collect(Collectors.toList());
if (rolesToCheck.isEmpty()) {
continue;
}
//
for (IdmIdentityRoleDto checkRoleOne : rolesToCheck) {
// skip already processed assigned role
if (resolvedDuplicities.contains(checkRoleOne)) {
continue;
}
//
while (true) {
IdmIdentityRoleDto duplicate = null;
for (Iterator<IdmIdentityRoleDto> i = assignedRoles.iterator(); i.hasNext(); ) {
IdmIdentityRoleDto checkRoleTwo = i.next();
if (Objects.equals(checkRoleOne.getId(), checkRoleTwo.getId())) {
// the same assigned role is not duplicate
continue;
}
//
duplicate = identityRoleService.getDuplicated(checkRoleOne, checkRoleTwo, !checkSubdefinition);
//
if (duplicate != null) {
// add duplicate
if (!resolvedDuplicities.contains(duplicate)) {
resolvedDuplicities.add(duplicate);
}
assignedRoles.remove(duplicate);
// ~ run again, until no duplicate is found
break;
} else {
continue;
}
}
// end => no duplicates was found finally, or duplicate is controlled role itself
if (duplicate == null || duplicate.getId().equals(checkRoleOne.getId())) {
break;
}
}
}
}
//
return resolvedDuplicities;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmRequestIdentityRoleService method find.
@Override
public Page<IdmRequestIdentityRoleDto> find(IdmRequestIdentityRoleFilter filter, Pageable pageable, BasePermission... permission) {
LOG.debug(MessageFormat.format("Find idm-request-identity-roles by filter [{0}] ", filter));
Assert.notNull(filter, "Filter is required.");
if (pageable == null) {
// Page is null, so we set page to max value
pageable = PageRequest.of(0, Integer.MAX_VALUE);
}
// If is true, then we want to return only concepts (not assigned roles)
boolean returnOnlyChanges = filter.isOnlyChanges();
List<IdmRequestIdentityRoleDto> results = new ArrayList<>();
long total = 0;
int countConcepts = 0;
if (filter.getRoleRequestId() != null) {
if (!returnOnlyChanges) {
// We want to load only new added roles
filter.setOperation(ConceptRoleRequestOperation.ADD);
// We don`t want load ADD concepts with filled identityRoleId (such concepts were already executed )
filter.setIdentityRoleIsNull(true);
}
Page<IdmConceptRoleRequestDto> conceptsPage = conceptRoleService.find(filter, pageable, permission);
results.addAll(this.conceptsToRequestIdentityRoles(conceptsPage.getContent(), filter));
total = conceptsPage.getTotalElements();
countConcepts = results.size();
}
int pageSizeForAssignedRoles = pageable.getPageSize() - countConcepts;
long numberOfPagesWithConcepts = total / pageable.getPageSize();
int pageNumberForAssignedRoles = pageable.getPageNumber() - ((int) numberOfPagesWithConcepts);
if (!returnOnlyChanges && filter.getIdentityId() != null && pageSizeForAssignedRoles > 0 && pageNumberForAssignedRoles >= 0) {
IdmIdentityRoleFilter identityRoleFilter = toIdentityRoleFilter(filter);
PageRequest pageableForAssignedRoles = PageRequest.of(pageNumberForAssignedRoles, pageable.getPageSize(), pageable.getSort());
// TODO: On a task detail approver must have permission to read identity-roles. If don't have it, then no concept are show.
// Maybe identity-roles should be load without permission here (permission by request).
Page<IdmIdentityRoleDto> identityRolesPage = identityRoleService.find(identityRoleFilter, pageableForAssignedRoles, permission);
List<IdmIdentityRoleDto> identityRoles = identityRolesPage.getContent();
// Transform identity-roles to request-identity-roles
results.addAll(this.identityRolesToRequestIdentityRoles(identityRoles, filter));
total = total + identityRolesPage.getTotalElements();
if (filter.getRoleRequestId() != null && !identityRoles.isEmpty()) {
compileIdentityRolesWithConcepts(results, identityRoles, filter, permission);
}
}
PageRequest pageableRequest = PageRequest.of(pageable.getPageNumber(), Math.max(results.size(), pageable.getPageSize()), pageable.getSort());
return new PageImpl<>(results, pageableRequest, total);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityRoleService method findValidRoles.
@Override
@Transactional(readOnly = true)
public Page<IdmIdentityRoleDto> findValidRoles(UUID identityId, Pageable pageable) {
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setValid(Boolean.TRUE);
identityRoleFilter.setIdentityId(identityId);
//
return this.find(identityRoleFilter, pageable);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityRoleService method findAllByContractPosition.
@Override
public List<IdmIdentityRoleDto> findAllByContractPosition(UUID contractPositionId) {
Assert.notNull(contractPositionId, "contract position identifier is required.");
//
IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
filter.setContractPositionId(contractPositionId);
//
return find(filter, null).getContent();
}
Aggregations