Search in sources :

Example 11 with WorkflowHistoricTaskInstanceDto

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

the class DefaultWorkflowHistoricTaskInstanceService method getTaskByProcessId.

@Override
public WorkflowHistoricTaskInstanceDto getTaskByProcessId(String processId) {
    WorkflowFilterDto filter = new WorkflowFilterDto();
    filter.setProcessInstanceId(processId);
    List<WorkflowHistoricTaskInstanceDto> resources = (List<WorkflowHistoricTaskInstanceDto>) this.find(filter, PageRequest.of(0, 1)).getContent();
    return !resources.isEmpty() ? resources.get(0) : null;
}
Also used : WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) ArrayList(java.util.ArrayList) List(java.util.List) WorkflowHistoricTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto)

Example 12 with WorkflowHistoricTaskInstanceDto

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

the class DefaultWorkflowHistoricTaskInstanceService method toResource.

private WorkflowHistoricTaskInstanceDto toResource(HistoricTaskInstance task) {
    if (task == null) {
        return null;
    }
    WorkflowHistoricTaskInstanceDto dto = new WorkflowHistoricTaskInstanceDto();
    // TODO can be slow
    if (task.getTaskLocalVariables() != null) {
        if (task.getTaskLocalVariables().containsKey(WorkflowHistoricTaskInstanceService.TASK_COMPLETE_DECISION)) {
            dto.setCompleteTaskDecision((String) task.getTaskLocalVariables().get(WorkflowHistoricTaskInstanceService.TASK_COMPLETE_DECISION));
        }
        if (task.getTaskLocalVariables().containsKey(WorkflowHistoricTaskInstanceService.TASK_COMPLETE_MESSAGE)) {
            dto.setCompleteTaskMessage((String) task.getTaskLocalVariables().get(WorkflowHistoricTaskInstanceService.TASK_COMPLETE_MESSAGE));
        }
    }
    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.setDescription(task.getDescription());
    dto.setProcessInstanceId(task.getProcessInstanceId());
    dto.setDeleteReason(task.getDeleteReason());
    dto.setDurationInMillis(task.getDurationInMillis());
    dto.setEndTime(task.getEndTime());
    dto.setStartTime(task.getStartTime());
    dto.setCreateTime(task.getCreateTime());
    dto.setDueDate(task.getDueDate());
    dto.setFormKey(task.getFormKey());
    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((String) processVariables.get(WorkflowProcessInstanceService.APPLICANT_IDENTIFIER).toString());
    }
    dto.setVariables(processVariables);
    workflowTaskInstanceService.convertToDtoVariables(dto, taskVariables);
    // TODO: Prevent selection of the definition here (performance).
    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());
        }
    }
    // Search and add identity links to dto (It means all user
    // (assigned/candidates/group) for this task)
    List<HistoricIdentityLink> identityLinks = historyService.getHistoricIdentityLinksForTask(task.getId());
    if (identityLinks != null) {
        List<IdentityLinkDto> identityLinksDtos = new ArrayList<>(identityLinks.size());
        identityLinks.forEach((identityLink) -> {
            identityLinksDtos.add(this.convertHistoricIdentityLink(identityLink));
        });
        dto.getIdentityLinks().addAll(identityLinksDtos);
    }
    return dto;
}
Also used : HistoricIdentityLink(org.activiti.engine.history.HistoricIdentityLink) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) ArrayList(java.util.ArrayList) WorkflowProcessDefinitionDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto) WorkflowHistoricTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto)

Example 13 with WorkflowHistoricTaskInstanceDto

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

the class DefaultWorkflowHistoricTaskInstanceService method get.

@Override
public WorkflowHistoricTaskInstanceDto get(Serializable id, WorkflowFilterDto context, BasePermission... permission) {
    Assert.notNull(id, "Identifier is required.");
    if (context == null) {
        context = new WorkflowFilterDto();
    }
    context.setId(UUID.fromString(String.valueOf(id)));
    List<WorkflowHistoricTaskInstanceDto> resources = this.find(context, PageRequest.of(0, 1)).getContent();
    return !resources.isEmpty() ? resources.get(0) : null;
}
Also used : WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) WorkflowHistoricTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto)

Example 14 with WorkflowHistoricTaskInstanceDto

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

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

Aggregations

WorkflowHistoricTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto)16 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)10 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)7 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)7 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)4 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)4 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)2 IdentityLinkDto (eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto)2 WorkflowProcessDefinitionDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto)2 List (java.util.List)2 PageImpl (org.springframework.data.domain.PageImpl)2 PageRequest (org.springframework.data.domain.PageRequest)2 Pageable (org.springframework.data.domain.Pageable)2 Sort (org.springframework.data.domain.Sort)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1