Search in sources :

Example 1 with IdmDelegation_

use of eu.bcvsolutions.idm.core.model.entity.IdmDelegation_ in project CzechIdMng by bcvsolutions.

the class WorkflowTaskInstanceController method addDelegationToTask.

/**
 * Find and add definition of the delegation connected with this task.
 *
 * @param dto
 */
private void addDelegationToTask(WorkflowTaskInstanceDto dto, BasePermission... permission) {
    if (dto != null && dto.getId() != null) {
        // We need to create mock task, because DTO can be instance of historic task here.
        WorkflowTaskInstanceDto mockTask = new WorkflowTaskInstanceDto();
        mockTask.setId(dto.getId());
        UUID currentUserId = securityService.getCurrentId();
        boolean currentUserIsCandidate = dto.getIdentityLinks().stream().filter(identityLink -> IdentityLinkType.CANDIDATE.equals(identityLink.getType()) || IdentityLinkType.ASSIGNEE.equals(identityLink.getType())).anyMatch(identityLink -> currentUserId != null && UUID.fromString(identityLink.getUserId()).equals(currentUserId));
        boolean filterOnlyForCurrentUser = currentUserIsCandidate && !workflowTaskInstanceService.canReadAllTask(permission);
        List<IdmDelegationDto> delegations = delegationManager.findDelegationForOwner(mockTask, permission).stream().filter(delegation -> {
            // Filter only delegation where delegator or delegate is logged user (and user is not admin).
            if (!filterOnlyForCurrentUser) {
                return true;
            }
            IdmDelegationDefinitionDto definition = DtoUtils.getEmbedded(delegation, IdmDelegation_.definition.getName(), IdmDelegationDefinitionDto.class);
            return definition.getDelegate().equals(currentUserId) || definition.getDelegator().equals(currentUserId);
        }).sorted(Comparator.comparing(IdmDelegationDto::getCreated)).collect(Collectors.toList());
        // TODO: ONLY first delegation definition is sets to the task!
        if (!CollectionUtils.isEmpty(delegations)) {
            Collections.reverse(delegations);
            IdmDelegationDto delegation = delegations.get(0);
            IdmDelegationDefinitionDto definition = DtoUtils.getEmbedded(delegation, IdmDelegation_.definition.getName(), IdmDelegationDefinitionDto.class);
            dto.setDelegationDefinition(definition);
        }
    }
}
Also used : IdmDelegation_(eu.bcvsolutions.idm.core.model.entity.IdmDelegation_) FormDataWrapperDto(eu.bcvsolutions.idm.core.workflow.model.dto.FormDataWrapperDto) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiParam(io.swagger.annotations.ApiParam) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) Valid(javax.validation.Valid) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) ApiOperation(io.swagger.annotations.ApiOperation) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) Pageable(org.springframework.data.domain.Pageable) AuthorizationScope(io.swagger.annotations.AuthorizationScope) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) IdmDelegationDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto) WorkflowTaskInstanceAbstractDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceAbstractDto) MediaType(org.springframework.http.MediaType) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) List(java.util.List) AbstractReadDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadDtoController) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) DelegationManager(eu.bcvsolutions.idm.core.api.service.DelegationManager) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) BulkActionManager(eu.bcvsolutions.idm.core.api.bulk.action.BulkActionManager) IdentityLinkType(org.activiti.engine.task.IdentityLinkType) RequestBody(org.springframework.web.bind.annotation.RequestBody) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) SwaggerConfig(eu.bcvsolutions.idm.core.api.config.swagger.SwaggerConfig) CollectionUtils(org.apache.commons.collections.CollectionUtils) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) Api(io.swagger.annotations.Api) MultiValueMap(org.springframework.util.MultiValueMap) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) WorkflowHistoricTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) BaseController(eu.bcvsolutions.idm.core.api.rest.BaseController) BaseDtoController(eu.bcvsolutions.idm.core.api.rest.BaseDtoController) PageableDefault(org.springframework.data.web.PageableDefault) Resources(org.springframework.hateoas.Resources) ResponseEntity(org.springframework.http.ResponseEntity) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) Comparator(java.util.Comparator) Authorization(io.swagger.annotations.Authorization) Collections(java.util.Collections) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmDelegationDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto) UUID(java.util.UUID)

Aggregations

BulkActionManager (eu.bcvsolutions.idm.core.api.bulk.action.BulkActionManager)1 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)1 SwaggerConfig (eu.bcvsolutions.idm.core.api.config.swagger.SwaggerConfig)1 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1 IdmDelegationDefinitionDto (eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto)1 IdmDelegationDto (eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto)1 ResultModels (eu.bcvsolutions.idm.core.api.dto.ResultModels)1 EntityNotFoundException (eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 AbstractReadDtoController (eu.bcvsolutions.idm.core.api.rest.AbstractReadDtoController)1 BaseController (eu.bcvsolutions.idm.core.api.rest.BaseController)1 BaseDtoController (eu.bcvsolutions.idm.core.api.rest.BaseDtoController)1 DelegationManager (eu.bcvsolutions.idm.core.api.service.DelegationManager)1 DtoUtils (eu.bcvsolutions.idm.core.api.utils.DtoUtils)1 CoreGroupPermission (eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission)1 IdmDelegation_ (eu.bcvsolutions.idm.core.model.entity.IdmDelegation_)1 BasePermission (eu.bcvsolutions.idm.core.security.api.domain.BasePermission)1 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)1 SecurityService (eu.bcvsolutions.idm.core.security.api.service.SecurityService)1 FormDataWrapperDto (eu.bcvsolutions.idm.core.workflow.model.dto.FormDataWrapperDto)1