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;
}
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;
}
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");
}
}
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;
}
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);
}
Aggregations