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