Search in sources :

Example 6 with WorkflowProcessEntity

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

the class WorkflowServiceImplTest method testListTaskExecuteLogs.

@Test
public void testListTaskExecuteLogs() {
    // insert process instance
    String groupId = "test_group";
    WorkflowProcessEntity process = new WorkflowProcessEntity();
    process.setId(1);
    process.setInlongGroupId(groupId);
    process.setName("CREATE_GROUP_RESOURCE");
    process.setDisplayName("Group-Resource");
    process.setHidden(1);
    process.setStatus(ProcessStatus.COMPLETED.name());
    processEntityMapper.insert(process);
    // insert task instance
    WorkflowTaskEntity task = new WorkflowTaskEntity();
    task.setId(1);
    task.setType("ServiceTask");
    task.setProcessId(1);
    taskEntityMapper.insert(task);
    // query execute logs
    TaskExecuteLogQuery query = new TaskExecuteLogQuery();
    query.setInlongGroupId(groupId);
    query.setProcessNames(Collections.singletonList("CREATE_GROUP_RESOURCE"));
    PageInfo<WorkflowExecuteLog> logPageInfo = workflowService.listTaskExecuteLogs(query);
    Assert.assertEquals(1, logPageInfo.getTotal());
}
Also used : TaskExecuteLogQuery(org.apache.inlong.manager.common.pojo.workflow.TaskExecuteLogQuery) WorkflowProcessEntity(org.apache.inlong.manager.dao.entity.WorkflowProcessEntity) WorkflowTaskEntity(org.apache.inlong.manager.dao.entity.WorkflowTaskEntity) Test(org.junit.Test) ServiceBaseTest(org.apache.inlong.manager.service.ServiceBaseTest)

Example 7 with WorkflowProcessEntity

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

the class UserTaskProcessor method create.

@Override
public void create(UserTask userTask, WorkflowContext context) {
    List<String> approvers = userTask.getApproverAssign().assign(context);
    Preconditions.checkNotEmpty(approvers, "cannot assign approvers for task: " + userTask.getDisplayName() + ", as the approvers was empty");
    if (!userTask.isNeedAllApprove()) {
        approvers = Collections.singletonList(StringUtils.join(approvers, WorkflowTaskEntity.APPROVERS_DELIMITER));
    }
    WorkflowProcessEntity processEntity = context.getProcessEntity();
    approvers.stream().map(approver -> saveTaskEntity(userTask, processEntity, approver)).forEach(context.getNewTaskList()::add);
    taskEventNotifier.notify(TaskEvent.CREATE, context);
}
Also used : WorkflowTaskEntityMapper(org.apache.inlong.manager.dao.mapper.WorkflowTaskEntityMapper) Date(java.util.Date) ArrayUtils(org.apache.commons.lang3.ArrayUtils) StringUtils(org.apache.commons.lang3.StringUtils) Lists(com.google.common.collect.Lists) Preconditions(org.apache.inlong.manager.common.util.Preconditions) TaskEvent(org.apache.inlong.manager.workflow.event.task.TaskEvent) Map(java.util.Map) WorkflowTaskEntity(org.apache.inlong.manager.dao.entity.WorkflowTaskEntity) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) WorkflowProcessEntity(org.apache.inlong.manager.dao.entity.WorkflowProcessEntity) ImmutableSet(com.google.common.collect.ImmutableSet) TaskStatus(org.apache.inlong.manager.common.enums.TaskStatus) WorkflowException(org.apache.inlong.manager.common.exceptions.WorkflowException) Set(java.util.Set) Maps(com.google.common.collect.Maps) WorkflowEventNotifier(org.apache.inlong.manager.workflow.core.impl.WorkflowEventNotifier) List(java.util.List) TaskEventNotifier(org.apache.inlong.manager.workflow.event.task.TaskEventNotifier) UserTask(org.apache.inlong.manager.workflow.definition.UserTask) Element(org.apache.inlong.manager.workflow.definition.Element) WorkflowAction(org.apache.inlong.manager.workflow.WorkflowAction) Optional(java.util.Optional) JsonUtils(org.apache.inlong.manager.common.util.JsonUtils) Collections(java.util.Collections) WorkflowProcessEntity(org.apache.inlong.manager.dao.entity.WorkflowProcessEntity)

Example 8 with WorkflowProcessEntity

use of org.apache.inlong.manager.dao.entity.WorkflowProcessEntity 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 9 with WorkflowProcessEntity

use of org.apache.inlong.manager.dao.entity.WorkflowProcessEntity 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 10 with WorkflowProcessEntity

use of org.apache.inlong.manager.dao.entity.WorkflowProcessEntity 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)

Aggregations

WorkflowProcessEntity (org.apache.inlong.manager.dao.entity.WorkflowProcessEntity)14 WorkflowTaskEntity (org.apache.inlong.manager.dao.entity.WorkflowTaskEntity)7 Date (java.util.Date)6 WorkflowContext (org.apache.inlong.manager.workflow.WorkflowContext)4 WorkflowProcess (org.apache.inlong.manager.workflow.definition.WorkflowProcess)4 Page (com.github.pagehelper.Page)2 Map (java.util.Map)2 SneakyThrows (lombok.SneakyThrows)2 WorkflowException (org.apache.inlong.manager.common.exceptions.WorkflowException)2 ProcessQuery (org.apache.inlong.manager.common.pojo.workflow.ProcessQuery)2 TaskQuery (org.apache.inlong.manager.common.pojo.workflow.TaskQuery)2 TaskResponse (org.apache.inlong.manager.common.pojo.workflow.TaskResponse)2 ProcessForm (org.apache.inlong.manager.common.pojo.workflow.form.ProcessForm)2 Element (org.apache.inlong.manager.workflow.definition.Element)2 UserTask (org.apache.inlong.manager.workflow.definition.UserTask)2 WorkflowTask (org.apache.inlong.manager.workflow.definition.WorkflowTask)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Collections (java.util.Collections)1