Search in sources :

Example 51 with IdmIdentityRoleFilter

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;
}
Also used : AbstractRemoveBulkAction(eu.bcvsolutions.idm.core.api.bulk.action.AbstractRemoveBulkAction) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) EntityEventProcessor(eu.bcvsolutions.idm.core.api.event.EntityEventProcessor) StringUtils(org.apache.commons.lang3.StringUtils) RoleEvent(eu.bcvsolutions.idm.core.model.event.RoleEvent) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) ArrayList(java.util.ArrayList) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) HashSet(java.util.HashSet) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) EntityStateManager(eu.bcvsolutions.idm.core.api.service.EntityStateManager) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) RoleEventType(eu.bcvsolutions.idm.core.model.event.RoleEvent.RoleEventType) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) Description(org.springframework.context.annotation.Description) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) ImmutableMap(com.google.common.collect.ImmutableMap) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) Set(java.util.Set) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) EventContext(eu.bcvsolutions.idm.core.api.event.EventContext) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap) List(java.util.List) Component(org.springframework.stereotype.Component) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) ExceptionUtils(eu.bcvsolutions.idm.core.api.utils.ExceptionUtils) Entry(java.util.Map.Entry) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) Collections(java.util.Collections) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) HashMap(java.util.HashMap) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) IdmConceptRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter) Entry(java.util.Map.Entry) UUID(java.util.UUID)

Example 52 with IdmIdentityRoleFilter

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;
}
Also used : IdmConceptRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmConceptRoleRequestService) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) Enabled(eu.bcvsolutions.idm.core.security.api.domain.Enabled) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) Map(java.util.Map) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) Sort(org.springframework.data.domain.Sort) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) AbstractBulkAction(eu.bcvsolutions.idm.core.api.bulk.action.AbstractBulkAction) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) Serializable(java.io.Serializable) Objects(java.util.Objects) List(java.util.List) PermissionUtils(eu.bcvsolutions.idm.core.security.api.utils.PermissionUtils) LocalDate(java.time.LocalDate) Entry(java.util.Map.Entry) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) RoleRequestEventType(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent.RoleRequestEventType) RoleRequestApprovalProcessor(eu.bcvsolutions.idm.core.model.event.processor.role.RoleRequestApprovalProcessor) IdmIdentityRole_(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole_) RoleRequestedByType(eu.bcvsolutions.idm.core.api.domain.RoleRequestedByType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) CoreModuleDescriptor(eu.bcvsolutions.idm.core.CoreModuleDescriptor) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) Direction(org.springframework.data.domain.Sort.Direction) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Description(org.springframework.context.annotation.Description) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) Iterator(java.util.Iterator) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) Component(org.springframework.stereotype.Component) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) ArrayList(java.util.ArrayList) Sort(org.springframework.data.domain.Sort) List(java.util.List) ArrayList(java.util.ArrayList) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) UUID(java.util.UUID)

Example 53 with IdmIdentityRoleFilter

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);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) ArrayList(java.util.ArrayList) IdmRequestIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestIdentityRoleDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) PageRequest(org.springframework.data.domain.PageRequest) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)

Example 54 with IdmIdentityRoleFilter

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);
}
Also used : IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 55 with IdmIdentityRoleFilter

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();
}
Also used : IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)

Aggregations

IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)116 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)85 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)84 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)81 Test (org.junit.Test)72 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)67 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)46 UUID (java.util.UUID)41 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)39 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)38 List (java.util.List)38 Autowired (org.springframework.beans.factory.annotation.Autowired)38 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)33 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)31 LocalDate (java.time.LocalDate)31 Assert (org.junit.Assert)28 IdmRoleService (eu.bcvsolutions.idm.core.api.service.IdmRoleService)27 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)25 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)25 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)25