Search in sources :

Example 81 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class IdentityRemoveRoleBulkAction method processDto.

@Override
protected OperationResult processDto(IdmIdentityDto identity) {
    List<IdmIdentityContractDto> contracts = new ArrayList<>();
    if (this.isPrimaryContract()) {
        IdmIdentityContractDto contract = identityContractService.getPrimeValidContract(identity.getId());
        if (contract != null) {
            contracts.add(contract);
        }
    } else {
        contracts.addAll(identityContractService.findAllByIdentity(identity.getId()));
    }
    // contract empty return not processed
    if (contracts.isEmpty()) {
        LOG.warn("For identity id: [{}] username: [{}] wasn't found contranct.", identity.getId(), identity.getUsername());
        return new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.BULK_ACTION_CONTRACT_NOT_FOUND, // 
        ImmutableMap.of("identity", identity.getId()))).build();
    }
    boolean approve = isApprove();
    List<IdmRoleDto> roles = getRoles();
    Set<UUID> rolesIds = roles.stream().map(IdmRoleDto::getId).collect(Collectors.toSet());
    // 
    List<IdmConceptRoleRequestDto> concepts = new ArrayList<>();
    for (IdmIdentityContractDto contract : contracts) {
        if (!checkPermissionForContract(contract)) {
            LOG.warn("Insufficient permissions for asign role for contract [{}]", contract.getId());
            // 
            logItemProcessed(contract, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.BULK_ACTION_NOT_AUTHORIZED_ASSING_ROLE_FOR_CONTRACT, ImmutableMap.of("contractId", contract.getId()))).build());
            // 
            continue;
        }
        // check if contract has role
        List<IdmIdentityRoleDto> allByContract = identityRoleService.findAllByContract(contract.getId());
        Set<UUID> roleIdsSet = allByContract.stream().map(IdmIdentityRoleDto::getRole).collect(Collectors.toSet());
        if (Collections.disjoint(roleIdsSet, rolesIds)) {
            // contract hasn't assigned the roles
            continue;
        }
        // 
        for (IdmRoleDto role : roles) {
            List<IdmIdentityRoleDto> identityRoles = allByContract.stream().filter(ir -> ir.getRole().equals(role.getId())).filter(// direct role
            ir -> ir.getDirectRole() == null).filter(// not automatic
            ir -> ir.getAutomaticRole() == null).collect(Collectors.toList());
            if (identityRoles.isEmpty()) {
                continue;
            }
            // 
            for (IdmIdentityRoleDto identityRole : identityRoles) {
                IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
                concept.setRole(role.getId());
                concept.setIdentityContract(contract.getId());
                concept.setIdentityRole(identityRole.getId());
                concept.setOperation(ConceptRoleRequestOperation.REMOVE);
                concepts.add(concept);
            }
        }
    }
    if (!concepts.isEmpty()) {
        IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
        roleRequest.setApplicant(identity.getId());
        roleRequest.setRequestedByType(RoleRequestedByType.MANUALLY);
        roleRequest.setLog("Request was created by bulk action.");
        // if set approve, dont execute immediately
        roleRequest.setExecuteImmediately(!approve);
        roleRequest = roleRequestService.save(roleRequest, IdmBasePermission.CREATE);
        // 
        for (IdmConceptRoleRequestDto concept : concepts) {
            concept.setRoleRequest(roleRequest.getId());
            concept = conceptRoleRequestService.save(concept, IdmBasePermission.CREATE);
        }
        // 
        Map<String, Serializable> properties = new HashMap<>();
        properties.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, Boolean.TRUE);
        RoleRequestEvent event = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest, properties);
        event.setPriority(PriorityType.HIGH);
        roleRequest = roleRequestService.startRequestInternal(event);
        // 
        if (roleRequest.getState() == RoleRequestState.EXECUTED) {
            return new OperationResult.Builder(OperationState.EXECUTED).build();
        } else {
            return new OperationResult.Builder(OperationState.CREATED).build();
        }
    }
    // 
    LOG.warn("For identity id: [{}] username: [{}] wasn't found roles to removal." + " Roles not found or cannot be removed (its automatic role, business role or for insufficient permissions).", identity.getId(), identity.getUsername());
    return new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.BULK_ACTION_IDENTITY_REMOVE_ROLE_FAILED, // 
    ImmutableMap.of("identity", identity.getId()))).build();
}
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) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) Map(java.util.Map) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) ImmutableMap(com.google.common.collect.ImmutableMap) AbstractBulkAction(eu.bcvsolutions.idm.core.api.bulk.action.AbstractBulkAction) Collection(java.util.Collection) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) PriorityType(eu.bcvsolutions.idm.core.api.domain.PriorityType) Serializable(java.io.Serializable) List(java.util.List) ContractBasePermission(eu.bcvsolutions.idm.core.security.api.domain.ContractBasePermission) PermissionUtils(eu.bcvsolutions.idm.core.security.api.utils.PermissionUtils) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) 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) 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) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) BaseFaceType(eu.bcvsolutions.idm.core.eav.api.domain.BaseFaceType) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Description(org.springframework.context.annotation.Description) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) Component(org.springframework.stereotype.Component) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) Collections(java.util.Collections) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) Serializable(java.io.Serializable) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) UUID(java.util.UUID) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)

Example 82 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class IdentityRemoveContractGuaranteeBulkAction method prevalidate.

/**
 * If no guarantee for selected identities exists,
 * return the info in the result model.
 */
@Override
public ResultModels prevalidate() {
    ResultModels result = new ResultModels();
    IdmBulkActionDto action = getAction();
    try {
        List<UUID> guarantees = getContractGuaranteeIdentities(action);
        if (guarantees.isEmpty()) {
            result.addInfo(new DefaultResultModel(CoreResultCode.BULK_ACTION_NO_CONTRACT_GUARANTEE_EXISTS));
        }
        if (guarantees.size() > 45) {
            // this is because during autocomplete all IDs are put into the URL
            // which has a max length of 2048
            // the user will be shown all identities without the added filtering
            result.addInfo(new DefaultResultModel(CoreResultCode.BULK_ACTION_TOO_MANY_CONTRACT_GUARANTEE_EXIST));
        }
    } catch (FilterSizeExceededException e) {
        result.addInfo(new DefaultResultModel(CoreResultCode.BULK_ACTION_TOO_MANY_USERS_SELECTED, Map.of("maximum", e.getMaximum())));
    }
    return result;
}
Also used : FilterSizeExceededException(eu.bcvsolutions.idm.core.api.exception.FilterSizeExceededException) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) UUID(java.util.UUID) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels)

Example 83 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class FormValueDeleteBulkAction method prevalidate.

@Override
public ResultModels prevalidate() {
    IdmBulkActionDto action = getAction();
    List<IdmFormValueDto> values = getValues(action, null);
    ResultModels result = new ResultModels();
    Map<UUID, IdmFormAttributeDto> attributes = new HashMap<>();
    Map<UUID, Long> requiredAttributes = new HashMap<>();
    values.forEach(value -> {
        IdmFormAttributeDto attribute;
        UUID attributeId = value.getFormAttribute();
        if (attributes.containsKey(attributeId)) {
            attribute = attributes.get(attributeId);
        } else {
            attribute = getAttribute(value);
            // prevent to load attributes repetitively, if is not given in dto embedded
            attributes.put(attribute.getId(), attribute);
        }
        if (attribute.isRequired()) {
            Long count;
            if (requiredAttributes.containsKey(attributeId)) {
                count = requiredAttributes.get(attributeId) + 1;
            } else {
                count = 1L;
            }
            requiredAttributes.put(attributeId, count);
        }
    });
    // Sort by count
    // 
    requiredAttributes.entrySet().stream().sorted(// 
    Collections.reverseOrder(Map.Entry.comparingByValue())).forEach(entry -> {
        IdmFormAttributeDto attribute = attributes.get(entry.getKey());
        ResultModel model = new DefaultResultModel(CoreResultCode.FORM_VALUE_DELETE_FAILED_IS_REQUIRED, ImmutableMap.of("count", entry.getValue(), "attribute", attribute.getCode()));
        // 
        result.addInfo(model);
    });
    // 
    return result;
}
Also used : IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) HashMap(java.util.HashMap) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) UUID(java.util.UUID) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels)

Example 84 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class ManualWorkflowTaskDelegationBulkAction method prevalidate.

@Override
public ResultModels prevalidate() {
    ResultModels result = new ResultModels();
    IdmIdentityDto delegator = this.findDelegator();
    if (delegator == null) {
        result.addInfo(new DefaultResultModel(CoreResultCode.MANUAL_TASK_DELEGATION_DELEGATOR_MISSING));
    }
    return result;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels)

Example 85 with DefaultResultModel

use of eu.bcvsolutions.idm.core.api.dto.DefaultResultModel in project CzechIdMng by bcvsolutions.

the class RoleCatalogueDeleteBulkAction 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(roleCatalogueId -> {
        IdmRoleCatalogueFilter filter = new IdmRoleCatalogueFilter();
        filter.setParent(roleCatalogueId);
        filter.setRecursively(true);
        IdmRoleCatalogueDto roleCatalogue = getService().get(roleCatalogueId);
        long count = roleCatalogueService.count(filter);
        if (count > 0) {
            if (securityService.hasAnyAuthority(CoreGroupPermission.ROLECATALOGUE_ADMIN)) {
                models.put(new DefaultResultModel(CoreResultCode.ROLE_CATALOGUE_FORCE_DELETE_HAS_CHILDREN, ImmutableMap.of("roleCatalogue", roleCatalogue.getCode(), "count", count)), count);
            } else {
                models.put(new DefaultResultModel(CoreResultCode.ROLE_CATALOGUE_DELETE_FAILED_HAS_CHILDREN, ImmutableMap.of("roleCatalogue", roleCatalogue.getCode(), "count", count)), count);
            }
        }
    });
    // 
    // 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());
    });
    // 
    return result;
}
Also used : 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) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) Entry(java.util.Map.Entry) IdmRoleCatalogueFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleCatalogueFilter) UUID(java.util.UUID)

Aggregations

DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)104 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)52 UUID (java.util.UUID)48 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)40 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)35 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)25 IdmEntityStateDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityStateDto)24 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)21 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)19 HashMap (java.util.HashMap)19 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)18 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)16 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)16 Autowired (org.springframework.beans.factory.annotation.Autowired)16 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)15 List (java.util.List)15 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)14 Set (java.util.Set)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)13