Search in sources :

Example 1 with UserTask

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

the class NewGroupWorkflowDefinition method defineProcess.

@Override
public WorkflowProcess defineProcess() {
    // Configuration process
    WorkflowProcess process = new WorkflowProcess();
    process.setType(getProcessName().getDisplayName());
    process.setName(getProcessName().name());
    process.setDisplayName(getProcessName().getDisplayName());
    process.setFormClass(NewGroupProcessForm.class);
    process.setVersion(1);
    // Set up the listener
    process.addListener(groupCancelProcessListener);
    process.addListener(approveRejectProcessListener);
    // Initiate the process of creating inlong group resources, and set the inlong group status
    // to [Configuration Successful]/[Configuration Failed] according to its completion
    process.addListener(startCreateGroupProcessListener);
    // Start node
    StartEvent startEvent = new StartEvent();
    process.setStartEvent(startEvent);
    // End node
    EndEvent endEvent = new EndEvent();
    process.setEndEvent(endEvent);
    // System administrator approval
    UserTask adminUserTask = new UserTask();
    adminUserTask.setName("ut_admin");
    adminUserTask.setDisplayName("System Administrator");
    adminUserTask.setFormClass(InlongGroupApproveForm.class);
    adminUserTask.setApproverAssign(context -> getTaskApprovers(adminUserTask.getName()));
    adminUserTask.addListener(groupPassTaskListener);
    process.addTask(adminUserTask);
    // Configuration order relationship
    startEvent.addNext(adminUserTask);
    // If you need another approval process, you can add it here
    adminUserTask.addNext(endEvent);
    return process;
}
Also used : StartEvent(org.apache.inlong.manager.workflow.definition.StartEvent) UserTask(org.apache.inlong.manager.workflow.definition.UserTask) EndEvent(org.apache.inlong.manager.workflow.definition.EndEvent) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess)

Example 2 with UserTask

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

the class UserTaskProcessor method saveTaskEntity.

private WorkflowTaskEntity saveTaskEntity(UserTask task, WorkflowProcessEntity processEntity, String approvers) {
    WorkflowTaskEntity taskEntity = new WorkflowTaskEntity();
    taskEntity.setType(UserTask.class.getSimpleName());
    taskEntity.setProcessId(processEntity.getId());
    taskEntity.setProcessName(processEntity.getName());
    taskEntity.setProcessDisplayName(processEntity.getDisplayName());
    taskEntity.setApplicant(processEntity.getApplicant());
    taskEntity.setName(task.getName());
    taskEntity.setDisplayName(task.getDisplayName());
    taskEntity.setApprovers(approvers);
    taskEntity.setStatus(TaskStatus.PENDING.name());
    taskEntity.setStartTime(new Date());
    taskEntityMapper.insert(taskEntity);
    Preconditions.checkNotNull(taskEntity.getId(), "task saved failed");
    return taskEntity;
}
Also used : UserTask(org.apache.inlong.manager.workflow.definition.UserTask) WorkflowTaskEntity(org.apache.inlong.manager.dao.entity.WorkflowTaskEntity) Date(java.util.Date)

Example 3 with UserTask

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

the class WorkflowFormParserUtils method parseTaskForm.

/**
 * Parse the task form in JSON string format into a WorkflowTask instance
 */
public static <T extends TaskForm> T parseTaskForm(WorkflowTaskEntity workflowTaskEntity, WorkflowProcess process) throws FormParseException {
    Preconditions.checkNotNull(workflowTaskEntity, "workflowTaskEntity cannot be null");
    Preconditions.checkNotNull(process, "process cannot be null");
    if (StringUtils.isEmpty(workflowTaskEntity.getFormData())) {
        return null;
    }
    WorkflowTask task = process.getTaskByName(workflowTaskEntity.getName());
    Preconditions.checkNotNull(task, "user task not exist " + workflowTaskEntity.getName());
    Preconditions.checkTrue(task instanceof UserTask, "task should be userTask " + workflowTaskEntity.getName());
    UserTask userTask = (UserTask) task;
    try {
        JavaType javaType = JsonUtils.MAPPER.constructType(userTask.getFormClass());
        return JsonUtils.parse(workflowTaskEntity.getFormData(), javaType);
    } catch (Exception e) {
        log.error("task form parse failed, form is: {}", workflowTaskEntity.getFormData(), e);
        throw new FormParseException("task form parse failed");
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) FormParseException(org.apache.inlong.manager.common.exceptions.FormParseException) UserTask(org.apache.inlong.manager.workflow.definition.UserTask) WorkflowTask(org.apache.inlong.manager.workflow.definition.WorkflowTask) FormParseException(org.apache.inlong.manager.common.exceptions.FormParseException)

Example 4 with UserTask

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

the class NewConsumptionWorkflowDefinition method defineProcess.

@Override
public WorkflowProcess defineProcess() {
    // Define process information
    WorkflowProcess process = new WorkflowProcess();
    process.setType("Data Consumption Resource Creation");
    process.setName(getProcessName().name());
    process.setDisplayName(getProcessName().getDisplayName());
    process.setFormClass(NewConsumptionProcessForm.class);
    process.setVersion(1);
    process.setProcessDetailHandler(newConsumptionProcessDetailHandler);
    // Start node
    StartEvent startEvent = new StartEvent();
    process.setStartEvent(startEvent);
    // End node
    EndEvent endEvent = new EndEvent();
    process.setEndEvent(endEvent);
    // Group approval tasks
    UserTask groupOwnerUserTask = new UserTask();
    groupOwnerUserTask.setName(UT_GROUP_OWNER_NAME);
    groupOwnerUserTask.setDisplayName("Group Approval");
    groupOwnerUserTask.setApproverAssign(this::bizOwnerUserTaskApprover);
    process.addTask(groupOwnerUserTask);
    // System administrator approval
    UserTask adminUserTask = new UserTask();
    adminUserTask.setName(UT_ADMINT_NAME);
    adminUserTask.setDisplayName("System Administrator");
    adminUserTask.setFormClass(ConsumptionApproveForm.class);
    adminUserTask.setApproverAssign(this::adminUserTaskApprover);
    adminUserTask.addListener(consumptionPassTaskListener);
    process.addTask(adminUserTask);
    // Set order relationship
    startEvent.addNext(groupOwnerUserTask);
    groupOwnerUserTask.addNext(adminUserTask);
    adminUserTask.addNext(endEvent);
    // Set up the listener
    process.addListener(consumptionCompleteProcessListener);
    process.addListener(consumptionRejectProcessListener);
    process.addListener(consumptionCancelProcessListener);
    return process;
}
Also used : StartEvent(org.apache.inlong.manager.workflow.definition.StartEvent) UserTask(org.apache.inlong.manager.workflow.definition.UserTask) EndEvent(org.apache.inlong.manager.workflow.definition.EndEvent) WorkflowProcess(org.apache.inlong.manager.workflow.definition.WorkflowProcess)

Example 5 with UserTask

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

the class UserTaskProcessor method completeTaskInstance.

private void completeTaskInstance(WorkflowContext.ActionContext actionContext) {
    WorkflowTaskEntity taskEntity = actionContext.getTaskEntity();
    TaskStatus taskStatus = toTaskState(actionContext.getAction());
    taskEntity.setStatus(taskStatus.name());
    taskEntity.setOperator(actionContext.getOperator());
    taskEntity.setRemark(actionContext.getRemark());
    UserTask userTask = (UserTask) actionContext.getTask();
    if (needForm(userTask, actionContext.getAction())) {
        Preconditions.checkNotNull(actionContext.getForm(), "form cannot be null");
        Preconditions.checkTrue(actionContext.getForm().getClass().isAssignableFrom(userTask.getFormClass()), "form type not match, should be class " + userTask.getFormClass());
        actionContext.getForm().validate();
        taskEntity.setFormData(JsonUtils.toJson(actionContext.getForm()));
    } else {
        Preconditions.checkNull(actionContext.getForm(), "no form required");
    }
    taskEntity.setEndTime(new Date());
    taskEntity.setExtParams(handlerExt(actionContext, taskEntity.getExtParams()));
    taskEntityMapper.update(taskEntity);
}
Also used : UserTask(org.apache.inlong.manager.workflow.definition.UserTask) WorkflowTaskEntity(org.apache.inlong.manager.dao.entity.WorkflowTaskEntity) TaskStatus(org.apache.inlong.manager.common.enums.TaskStatus) Date(java.util.Date)

Aggregations

UserTask (org.apache.inlong.manager.workflow.definition.UserTask)8 Date (java.util.Date)4 WorkflowTaskEntity (org.apache.inlong.manager.dao.entity.WorkflowTaskEntity)3 WorkflowProcess (org.apache.inlong.manager.workflow.definition.WorkflowProcess)3 TaskStatus (org.apache.inlong.manager.common.enums.TaskStatus)2 Element (org.apache.inlong.manager.workflow.definition.Element)2 EndEvent (org.apache.inlong.manager.workflow.definition.EndEvent)2 StartEvent (org.apache.inlong.manager.workflow.definition.StartEvent)2 WorkflowTask (org.apache.inlong.manager.workflow.definition.WorkflowTask)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 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 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ArrayUtils (org.apache.commons.lang3.ArrayUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1