Search in sources :

Example 66 with WorkflowTaskInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.

the class RoleRequestByWfEvaluatorIntegrationTest method checkAndCompleteOneTask.

private void checkAndCompleteOneTask(WorkflowFilterDto taskFilter, String user, String decision, String userTaskId) {
    IdmIdentityDto identity = identityService.getByUsername(user);
    List<WorkflowTaskInstanceDto> tasks;
    tasks = (List<WorkflowTaskInstanceDto>) workflowTaskInstanceService.find(taskFilter, null).getContent();
    assertEquals(1, tasks.size());
    if (userTaskId != null) {
        assertEquals(userTaskId, tasks.get(0).getDefinition().getId());
    }
    assertEquals(identity.getId().toString(), tasks.get(0).getApplicant());
    workflowTaskInstanceService.completeTask(tasks.get(0).getId(), decision);
}
Also used : WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 67 with WorkflowTaskInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowTaskInstanceService method toResource.

private WorkflowTaskInstanceDto toResource(TaskInfo task, BasePermission[] permission) {
    if (task == null) {
        return null;
    }
    WorkflowTaskInstanceDto dto = new WorkflowTaskInstanceDto();
    dto.setId(task.getId());
    dto.setName(task.getName());
    dto.setProcessDefinitionId(task.getProcessDefinitionId());
    dto.setPriority(task.getPriority());
    dto.setAssignee(task.getAssignee());
    dto.setCreated(task.getCreateTime());
    dto.setFormKey(task.getFormKey());
    dto.setDescription(task.getDescription());
    dto.setProcessInstanceId(task.getProcessInstanceId());
    Map<String, Object> taskVariables = task.getTaskLocalVariables();
    Map<String, Object> processVariables = task.getProcessVariables();
    // Add applicant username to task dto (for easier work)
    if (processVariables != null && processVariables.containsKey(WorkflowProcessInstanceService.APPLICANT_IDENTIFIER)) {
        dto.setApplicant(processVariables.get(WorkflowProcessInstanceService.APPLICANT_IDENTIFIER).toString());
    }
    dto.setVariables(processVariables);
    convertToDtoVariables(dto, taskVariables);
    dto.setDefinition(workflowTaskDefinitionService.searchTaskDefinitionById(task.getProcessDefinitionId(), task.getTaskDefinitionKey()));
    if (!Strings.isNullOrEmpty(task.getProcessDefinitionId())) {
        WorkflowProcessDefinitionDto processDefinition = workflowProcessDefinitionService.get(task.getProcessDefinitionId());
        if (processDefinition != null) {
            dto.setProcessDefinitionKey(processDefinition.getKey());
        }
    }
    TaskFormData taskFormData = formService.getTaskFormData(task.getId());
    // Add form data (it means form properties and value from WF)
    List<FormProperty> formProperties = taskFormData.getFormProperties();
    // Search and add identity links to dto (It means all user
    // (assigned/candidates/group) for this task)
    List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(task.getId());
    if (identityLinks != null) {
        List<IdentityLinkDto> identityLinksDtos = new ArrayList<>(identityLinks.size());
        identityLinks.forEach((il) -> {
            identityLinksDtos.add(toResource(il));
        });
        dto.getIdentityLinks().addAll(identityLinksDtos);
    }
    // Check if the logged user can complete this task
    boolean canExecute = this.canExecute(dto, permission);
    if (formProperties != null && !formProperties.isEmpty()) {
        formProperties.forEach((property) -> {
            resovleFormProperty(property, dto, canExecute);
        });
    }
    return dto;
}
Also used : FormProperty(org.activiti.engine.form.FormProperty) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) ArrayList(java.util.ArrayList) TaskFormData(org.activiti.engine.form.TaskFormData) IdentityLink(org.activiti.engine.task.IdentityLink) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) WorkflowProcessDefinitionDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto)

Example 68 with WorkflowTaskInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowTaskInstanceService method resovleFormProperty.

/**
 * Convert form property and add to result dto
 *
 * @param property
 * @param dto
 * @param canExecute
 */
@SuppressWarnings("unchecked")
private void resovleFormProperty(FormProperty property, WorkflowTaskInstanceDto dto, boolean canExecute) {
    FormType formType = property.getType();
    if (formType instanceof DecisionFormType) {
        // task
        if (!canExecute) {
            return;
        }
        DecisionFormTypeDto decisionDto = (DecisionFormTypeDto) ((DecisionFormType) formType).convertFormValueToModelValue(property.getValue());
        if (decisionDto != null) {
            decisionDto.setId(property.getId());
            setDecisionReasonRequired(decisionDto);
            dto.getDecisions().add(decisionDto);
        }
    } else if (formType instanceof TaskHistoryFormType) {
        WorkflowFilterDto filterDto = new WorkflowFilterDto();
        filterDto.setProcessInstanceId(dto.getProcessInstanceId());
        List<WorkflowHistoricTaskInstanceDto> tasks = historicTaskInstanceService.find(filterDto, PageRequest.of(0, 50)).getContent();
        List<WorkflowHistoricTaskInstanceDto> history = tasks.stream().filter(workflowHistoricTaskInstanceDto -> workflowHistoricTaskInstanceDto.getEndTime() != null).sorted((o1, o2) -> {
            if (o1.getEndTime().before(o2.getEndTime())) {
                return -1;
            } else if (o1.getEndTime().after(o2.getEndTime())) {
                return 1;
            }
            return 0;
        }).collect(Collectors.toList());
        dto.getFormData().add(historyToResource(property, history));
    } else if (formType instanceof AbstractFormType) {
        // To rest will be add only component form type marked as "exportable to rest".
        if (formType instanceof AbstractComponentFormType && !((AbstractComponentFormType) formType).isExportableToRest()) {
            return;
        }
        Object values = formType.getInformation("values");
        if (values instanceof Map<?, ?>) {
            dto.getFormData().add(toResource(property, (Map<String, String>) values));
        } else {
            dto.getFormData().add(toResource(property, null));
        }
    }
}
Also used : DecisionFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.DecisionFormType) Date(java.util.Date) FormDataDto(eu.bcvsolutions.idm.core.workflow.model.dto.FormDataDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) AbstractComponentFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.AbstractComponentFormType) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) AbstractBaseDtoService(eu.bcvsolutions.idm.core.rest.AbstractBaseDtoService) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) Pageable(org.springframework.data.domain.Pageable) TaskQuery(org.activiti.engine.task.TaskQuery) IdentityLink(org.activiti.engine.task.IdentityLink) ImmutableMap(com.google.common.collect.ImmutableMap) FormType(org.activiti.engine.form.FormType) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) TaskHistoryFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.TaskHistoryFormType) UUID(java.util.UUID) TaskInfo(org.activiti.engine.task.TaskInfo) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) AbstractFormType(org.activiti.engine.form.AbstractFormType) List(java.util.List) PageImpl(org.springframework.data.domain.PageImpl) WorkflowProcessDefinitionService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessDefinitionService) TaskService(org.activiti.engine.TaskService) HashMap(java.util.HashMap) IdentityLinkType(org.activiti.engine.task.IdentityLinkType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Service(org.springframework.stereotype.Service) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) TaskFormData(org.activiti.engine.form.TaskFormData) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) WorkflowHistoricTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowHistoricTaskInstanceService) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) Task(org.activiti.engine.task.Task) FormService(org.activiti.engine.FormService) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) FormProperty(org.activiti.engine.form.FormProperty) WorkflowTaskDefinitionService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskDefinitionService) WorkflowHistoricTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) WorkflowProcessDefinitionDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto) DecisionFormTypeDto(eu.bcvsolutions.idm.core.workflow.model.dto.DecisionFormTypeDto) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) Assert(org.springframework.util.Assert) AbstractComponentFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.AbstractComponentFormType) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) TaskHistoryFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.TaskHistoryFormType) DecisionFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.DecisionFormType) AbstractComponentFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.AbstractComponentFormType) FormType(org.activiti.engine.form.FormType) TaskHistoryFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.TaskHistoryFormType) AbstractFormType(org.activiti.engine.form.AbstractFormType) DecisionFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.DecisionFormType) List(java.util.List) ArrayList(java.util.ArrayList) AbstractFormType(org.activiti.engine.form.AbstractFormType) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) DecisionFormTypeDto(eu.bcvsolutions.idm.core.workflow.model.dto.DecisionFormTypeDto)

Example 69 with WorkflowTaskInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.

the class WorkflowTaskInstanceController method getDto.

@Override
public // need call direct service with Permission.READ!
WorkflowTaskInstanceDto getDto(Serializable backendId) {
    WorkflowTaskInstanceDto dto = getService().get(backendId, IdmBasePermission.READ);
    // on FE will said that task was resolved. For prevent this, I try to find task instance if user has permission to the process.
    if (dto == null || dto instanceof WorkflowHistoricTaskInstanceDto) {
        WorkflowFilterDto filter = new WorkflowFilterDto();
        filter.setOnlyInvolved(Boolean.FALSE);
        if (dto == null) {
            // First load the task without check permission. We need ID of a process.
            WorkflowTaskInstanceDto task = workflowTaskInstanceService.get(backendId, filter);
            if (task == null) {
                return null;
            }
            dto = task;
        }
        boolean hasUsePermissionOnProcess = processInstanceService.canReadProcessOrHistoricProcess(dto.getProcessInstanceId());
        if (hasUsePermissionOnProcess) {
            // User has permission to read the process. We can set filter for find all tasks (check on the user has to be involved in tasks, will be skip).
            dto = getService().get(backendId, filter, IdmBasePermission.READ);
        }
    }
    // Add delegation to a task.
    addDelegationToTask(dto, IdmBasePermission.READ);
    return dto;
}
Also used : WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) WorkflowHistoricTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto)

Example 70 with WorkflowTaskInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto 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

WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)81 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)69 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)63 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)56 Test (org.junit.Test)56 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)55 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)54 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)49 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)48 ZonedDateTime (java.time.ZonedDateTime)43 List (java.util.List)39 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)28 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)28 UUID (java.util.UUID)17 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)12 IdentityLinkDto (eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto)12 WorkflowTaskInstanceService (eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService)12 Autowired (org.springframework.beans.factory.annotation.Autowired)12 IdentityLinkType (org.activiti.engine.task.IdentityLinkType)11 WorkflowHistoricTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto)9