Search in sources :

Example 21 with WorkflowProcess

use of org.apache.inlong.manager.workflow.definition.WorkflowProcess in project incubator-inlong by apache.

the class WorkflowContextBuilderImpl method buildContextForTask.

@SneakyThrows
@Override
public WorkflowContext buildContextForTask(Integer taskId, WorkflowAction action) {
    WorkflowTaskEntity taskEntity = taskEntityMapper.selectById(taskId);
    WorkflowProcess process = definitionRepository.get(taskEntity.getProcessName()).clone();
    TaskForm taskForm = WorkflowFormParserUtils.parseTaskForm(taskEntity, process);
    List<String> transferToUsers = getTransferToUsers(taskEntity.getExtParams());
    return buildContextForTask(taskId, action, taskForm, transferToUsers, taskEntity.getRemark(), taskEntity.getOperator());
}
Also used : TaskForm(org.apache.inlong.manager.common.pojo.workflow.form.TaskForm) WorkflowTaskEntity(org.apache.inlong.manager.dao.entity.WorkflowTaskEntity) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess) SneakyThrows(lombok.SneakyThrows)

Example 22 with WorkflowProcess

use of org.apache.inlong.manager.workflow.definition.WorkflowProcess in project incubator-inlong by apache.

the class WorkflowContextBuilderImpl method buildContextForProcess.

@SneakyThrows
@Override
public WorkflowContext buildContextForProcess(Integer processId) {
    WorkflowProcessEntity processEntity = processEntityMapper.selectById(processId);
    Preconditions.checkNotNull(processEntity, "process not exist with id: " + processId);
    WorkflowProcess process = definitionRepository.get(processEntity.getName()).clone();
    return new WorkflowContext().setApplicant(processEntity.getApplicant()).setProcess(process).setProcessForm(WorkflowFormParserUtils.parseProcessForm(processEntity.getFormData(), process)).setProcessEntity(processEntity);
}
Also used : WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) WorkflowProcessEntity(org.apache.inlong.manager.dao.entity.WorkflowProcessEntity) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess) SneakyThrows(lombok.SneakyThrows)

Example 23 with WorkflowProcess

use of org.apache.inlong.manager.workflow.definition.WorkflowProcess 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 24 with WorkflowProcess

use of org.apache.inlong.manager.workflow.definition.WorkflowProcess 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 25 with WorkflowProcess

use of org.apache.inlong.manager.workflow.definition.WorkflowProcess in project incubator-inlong by apache.

the class StartEventProcessor method create.

@Override
public void create(StartEvent startEvent, WorkflowContext context) {
    String applicant = context.getApplicant();
    WorkflowProcess process = context.getProcess();
    ProcessForm form = context.getProcessForm();
    if (process.getFormClass() != null) {
        Preconditions.checkNotNull(form, "form cannot be null");
        Preconditions.checkTrue(form.getClass().isAssignableFrom(process.getFormClass()), "form type not match, should be class " + process.getFormClass());
        form.validate();
    } else {
        Preconditions.checkNull(form, "no form required");
    }
    WorkflowProcessEntity processEntity = saveProcessEntity(applicant, process, form);
    context.setProcessEntity(processEntity);
    context.setActionContext(new WorkflowContext.ActionContext().setAction(WorkflowAction.START));
}
Also used : ProcessForm(org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm) WorkflowProcessEntity(org.apache.inlong.manager.dao.entity.WorkflowProcessEntity) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess)

Aggregations

WorkflowProcess (org.apache.inlong.manager.workflow.definition.WorkflowProcess)29 WorkflowContext (org.apache.inlong.manager.workflow.WorkflowContext)15 ServiceTask (org.apache.inlong.manager.workflow.definition.ServiceTask)14 WorkflowTask (org.apache.inlong.manager.workflow.definition.WorkflowTask)13 Test (org.junit.Test)10 ProcessResponse (org.apache.inlong.manager.common.pojo.workflow.ProcessResponse)9 WorkflowResult (org.apache.inlong.manager.common.pojo.workflow.WorkflowResult)9 StartEvent (org.apache.inlong.manager.workflow.definition.StartEvent)8 UpdateGroupProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.UpdateGroupProcessForm)7 EndEvent (org.apache.inlong.manager.workflow.definition.EndEvent)7 TaskEventListener (org.apache.inlong.manager.workflow.event.task.TaskEventListener)7 ServiceBaseTest (org.apache.inlong.manager.service.ServiceBaseTest)6 InlongGroupInfo (org.apache.inlong.manager.common.pojo.group.InlongGroupInfo)5 SneakyThrows (lombok.SneakyThrows)4 ProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm)4 WorkflowProcessEntity (org.apache.inlong.manager.dao.entity.WorkflowProcessEntity)4 MockPlugin (org.apache.inlong.manager.service.mocks.MockPlugin)4 WorkflowServiceImplTest (org.apache.inlong.manager.service.workflow.WorkflowServiceImplTest)4 GroupResourceProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.GroupResourceProcessForm)3 WorkflowApproverEntity (org.apache.inlong.manager.dao.entity.WorkflowApproverEntity)3