Search in sources :

Example 11 with WorkflowTaskEntity

use of org.apache.inlong.manager.dao.entity.WorkflowTaskEntity in project incubator-inlong by apache.

the class WorkflowContextBuilderImpl method buildContextForTask.

@SneakyThrows
private WorkflowContext buildContextForTask(Integer taskId, WorkflowAction action, TaskForm taskForm, List<String> transferToUsers, String remark, String operator) {
    WorkflowTaskEntity taskEntity = taskEntityMapper.selectById(taskId);
    Preconditions.checkNotNull(taskEntity, "task not exist with id: " + taskId);
    WorkflowProcessEntity processEntity = processEntityMapper.selectById(taskEntity.getProcessId());
    WorkflowProcess process = definitionRepository.get(processEntity.getName()).clone();
    ProcessForm processForm = WorkflowFormParserUtils.parseProcessForm(processEntity.getFormData(), process);
    WorkflowTask task = process.getTaskByName(taskEntity.getName());
    return new WorkflowContext().setProcess(process).setApplicant(processEntity.getApplicant()).setProcessForm(processForm).setProcessEntity(processEntity).setCurrentElement(task).setActionContext(new WorkflowContext.ActionContext().setAction(action).setTaskEntity(taskEntity).setTask(task).setForm(taskForm).setTransferToUsers(transferToUsers).setOperator(operator).setRemark(remark));
}
Also used : ProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) WorkflowTask(org.apache.inlong.manager.workflow.definition.WorkflowTask) WorkflowTaskEntity(org.apache.inlong.manager.dao.entity.WorkflowTaskEntity) WorkflowProcessEntity(org.apache.inlong.manager.dao.entity.WorkflowProcessEntity) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess) SneakyThrows(lombok.SneakyThrows)

Example 12 with WorkflowTaskEntity

use of org.apache.inlong.manager.dao.entity.WorkflowTaskEntity in project incubator-inlong by apache.

the class WorkflowQueryServiceImpl method getTaskNameStatusMap.

private Map<String, TaskStatus> getTaskNameStatusMap(WorkflowProcessEntity processEntity) {
    TaskQuery request = TaskQuery.builder().processId(processEntity.getId()).build();
    List<WorkflowTaskEntity> allTasks = taskEntityMapper.selectByQuery(request).stream().sorted(Comparator.comparing(WorkflowTaskEntity::getId).thenComparing(Comparator.nullsLast(Comparator.comparing(WorkflowTaskEntity::getEndTime)))).collect(Collectors.toList());
    Map<String, TaskStatus> nameStatusMap = Maps.newHashMap();
    allTasks.forEach(task -> nameStatusMap.put(task.getName(), TaskStatus.valueOf(task.getStatus())));
    return nameStatusMap;
}
Also used : TaskQuery(org.apache.inlong.manager.common.pojo.workflow.TaskQuery) WorkflowTaskEntity(org.apache.inlong.manager.dao.entity.WorkflowTaskEntity) TaskStatus(org.apache.inlong.manager.common.enums.TaskStatus)

Example 13 with WorkflowTaskEntity

use of org.apache.inlong.manager.dao.entity.WorkflowTaskEntity in project incubator-inlong by apache.

the class WorkflowQueryServiceImpl method detail.

@Override
public ProcessDetailResponse detail(Integer processId, Integer taskId, String operator) {
    WorkflowProcessEntity processEntity = this.getProcessEntity(processId);
    if (processEntity == null) {
        return null;
    }
    WorkflowTaskEntity taskEntity = null;
    if (taskId == null) {
        if (!operator.equals(processEntity.getApplicant())) {
            throw new WorkflowException("current user is not the applicant of the process");
        }
    } else {
        taskEntity = this.getTaskEntity(taskId);
        List<String> taskApprovers = Arrays.asList(taskEntity.getApprovers().split(","));
        if (!taskApprovers.contains(operator)) {
            WorkflowApproverQuery query = new WorkflowApproverQuery();
            query.setProcessName(processEntity.getName());
            List<WorkflowApproverEntity> approverList = approverMapper.selectByQuery(query);
            boolean match = approverList.stream().anyMatch(approverEntity -> {
                String[] approverArr = approverEntity.getApprovers().split(",");
                for (String approver : approverArr) {
                    if (Objects.equals(approver, operator)) {
                        return true;
                    }
                }
                return false;
            });
            if (!match) {
                throw new WorkflowException("current user is not the approver of the process");
            }
        }
    }
    WorkflowProcess process = definitionRepository.get(processEntity.getName());
    TaskResponse currentTask = null;
    if (taskEntity != null) {
        currentTask = WorkflowBeanUtils.fromTaskEntity(taskEntity);
        if (process != null && TaskStatus.PENDING.equals(currentTask.getStatus())) {
            WorkflowTask task = process.getTaskByName(currentTask.getName());
            currentTask.setFormData(this.getEmptyTaskForm(task));
        }
        if (!processId.equals(currentTask.getProcessId())) {
            throw new WorkflowException("task [" + taskId + "] not belongs to process [" + processId + "]");
        }
    }
    ProcessDetailResponse detailResponse = this.getProcessDetail(processId, processEntity);
    detailResponse.setCurrentTask(currentTask);
    if (process == null || process.getProcessDetailHandler() == null) {
        return detailResponse;
    }
    return process.getProcessDetailHandler().handle(detailResponse);
}
Also used : WorkflowException(org.apache.inlong.manager.common.exceptions.WorkflowException) WorkflowTask(org.apache.inlong.manager.workflow.definition.WorkflowTask) WorkflowTaskEntity(org.apache.inlong.manager.dao.entity.WorkflowTaskEntity) WorkflowApproverEntity(org.apache.inlong.manager.dao.entity.WorkflowApproverEntity) WorkflowApproverQuery(org.apache.inlong.manager.common.pojo.workflow.WorkflowApproverQuery) ProcessDetailResponse(org.apache.inlong.manager.common.pojo.workflow.ProcessDetailResponse) WorkflowProcessEntity(org.apache.inlong.manager.dao.entity.WorkflowProcessEntity) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess) TaskResponse(org.apache.inlong.manager.common.pojo.workflow.TaskResponse)

Example 14 with WorkflowTaskEntity

use of org.apache.inlong.manager.dao.entity.WorkflowTaskEntity in project incubator-inlong by apache.

the class AbstractTaskProcessor method skip.

@Override
public void skip(T task, WorkflowContext context) {
    WorkflowProcessEntity workflowProcessEntity = context.getProcessEntity();
    Date now = new Date();
    String operators = Joiner.on(WorkflowTaskEntity.APPROVERS_DELIMITER).join(ApproverAssign.DEFAULT_SKIP_APPROVER.assign(context));
    WorkflowTaskEntity taskEntity = new WorkflowTaskEntity();
    taskEntity.setType(task.getClass().getSimpleName());
    taskEntity.setProcessId(workflowProcessEntity.getId());
    taskEntity.setProcessName(workflowProcessEntity.getName());
    taskEntity.setProcessDisplayName(workflowProcessEntity.getDisplayName());
    taskEntity.setApplicant(workflowProcessEntity.getApplicant());
    taskEntity.setApprovers(operators);
    taskEntity.setOperator(operators);
    taskEntity.setName(task.getName());
    taskEntity.setDisplayName(task.getDisplayName());
    taskEntity.setStatus(TaskStatus.SKIPPED.name());
    taskEntity.setRemark("auto skipped");
    taskEntity.setStartTime(now);
    taskEntity.setEndTime(now);
    taskEntityMapper.insert(taskEntity);
    Preconditions.checkNotNull(taskEntity.getId(), "task saved failed");
}
Also used : WorkflowProcessEntity(org.apache.inlong.manager.dao.entity.WorkflowProcessEntity) WorkflowTaskEntity(org.apache.inlong.manager.dao.entity.WorkflowTaskEntity) Date(java.util.Date)

Example 15 with WorkflowTaskEntity

use of org.apache.inlong.manager.dao.entity.WorkflowTaskEntity in project incubator-inlong by apache.

the class ServiceTaskProcessor method saveTaskEntity.

private WorkflowTaskEntity saveTaskEntity(ServiceTask serviceTask, WorkflowContext context) {
    WorkflowProcessEntity workflowProcessEntity = context.getProcessEntity();
    List<String> approvers = ApproverAssign.DEFAULT_SYSTEM_APPROVER.assign(context);
    WorkflowTaskEntity taskEntity = new WorkflowTaskEntity();
    taskEntity.setType(ServiceTask.class.getSimpleName());
    taskEntity.setProcessId(workflowProcessEntity.getId());
    taskEntity.setProcessName(context.getProcess().getName());
    taskEntity.setProcessDisplayName(context.getProcess().getDisplayName());
    taskEntity.setName(serviceTask.getName());
    taskEntity.setDisplayName(serviceTask.getDisplayName());
    taskEntity.setApplicant(workflowProcessEntity.getApplicant());
    taskEntity.setApprovers(StringUtils.join(approvers, WorkflowTaskEntity.APPROVERS_DELIMITER));
    taskEntity.setStatus(TaskStatus.PENDING.name());
    taskEntity.setStartTime(new Date());
    taskEntityMapper.insert(taskEntity);
    Preconditions.checkNotNull(taskEntity.getId(), "task saved failed");
    return taskEntity;
}
Also used : ServiceTask(org.apache.inlong.manager.workflow.definition.ServiceTask) WorkflowProcessEntity(org.apache.inlong.manager.dao.entity.WorkflowProcessEntity) WorkflowTaskEntity(org.apache.inlong.manager.dao.entity.WorkflowTaskEntity) Date(java.util.Date)

Aggregations

WorkflowTaskEntity (org.apache.inlong.manager.dao.entity.WorkflowTaskEntity)17 WorkflowProcessEntity (org.apache.inlong.manager.dao.entity.WorkflowProcessEntity)6 WorkflowContext (org.apache.inlong.manager.workflow.WorkflowContext)6 Date (java.util.Date)5 WorkflowProcess (org.apache.inlong.manager.workflow.definition.WorkflowProcess)3 WorkflowTask (org.apache.inlong.manager.workflow.definition.WorkflowTask)3 SneakyThrows (lombok.SneakyThrows)2 TaskStatus (org.apache.inlong.manager.common.enums.TaskStatus)2 WorkflowException (org.apache.inlong.manager.common.exceptions.WorkflowException)2 ProcessDetailResponse (org.apache.inlong.manager.common.pojo.workflow.ProcessDetailResponse)2 TaskResponse (org.apache.inlong.manager.common.pojo.workflow.TaskResponse)2 UserTask (org.apache.inlong.manager.workflow.definition.UserTask)2 TaskExecuteLogQuery (org.apache.inlong.manager.common.pojo.workflow.TaskExecuteLogQuery)1 TaskQuery (org.apache.inlong.manager.common.pojo.workflow.TaskQuery)1 WorkflowApproverQuery (org.apache.inlong.manager.common.pojo.workflow.WorkflowApproverQuery)1 WorkflowBriefDTO (org.apache.inlong.manager.common.pojo.workflow.WorkflowBriefDTO)1 ProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm)1 TaskForm (org.apache.inlong.manager.common.pojo.workflow.form.TaskForm)1 WorkflowApproverEntity (org.apache.inlong.manager.dao.entity.WorkflowApproverEntity)1 ServiceBaseTest (org.apache.inlong.manager.service.ServiceBaseTest)1