use of org.apache.inlong.manager.common.exceptions.WorkflowException in project incubator-inlong by apache.
the class UserTaskProcessor method checkOperator.
private void checkOperator(WorkflowContext.ActionContext actionContext) {
WorkflowTaskEntity workflowTaskEntity = actionContext.getTaskEntity();
if (!SHOULD_CHECK_OPERATOR_ACTIONS.contains(actionContext.getAction())) {
return;
}
boolean operatorIsApprover = ArrayUtils.contains(workflowTaskEntity.getApprovers().split(WorkflowTaskEntity.APPROVERS_DELIMITER), actionContext.getOperator());
if (!operatorIsApprover) {
throw new WorkflowException(String.format("current operator %s not in approvers list: %s", actionContext.getOperator(), workflowTaskEntity.getApprovers()));
}
}
use of org.apache.inlong.manager.common.exceptions.WorkflowException in project incubator-inlong by apache.
the class ProcessorExecutorImpl method executeSkipAndNext.
private void executeSkipAndNext(Element element, WorkflowContext context) {
if (!(element instanceof SkippableElement)) {
throw new WorkflowException("element not instance of skip element " + element.getDisplayName());
}
if (!(element instanceof NextableElement)) {
throw new WorkflowException("element not instance of nextable element " + element.getDisplayName());
}
ElementProcessor processor = this.getProcessor(element.getClass());
if (!(processor instanceof SkipableElementProcessor)) {
throw new WorkflowException("element processor not instance of skip processor " + element.getDisplayName());
}
// Execute skip logic
SkipableElementProcessor skipableProcessor = (SkipableElementProcessor) processor;
skipableProcessor.skip(element, context);
// Execute next
context.getActionContext().setAction(((NextableElement) element).defaultNextAction());
List<Element> nextElements = processor.next(element, context);
nextElements.forEach(next -> executeStart(next, context));
}
use of org.apache.inlong.manager.common.exceptions.WorkflowException 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.common.exceptions.WorkflowException in project incubator-inlong by apache.
the class AbstractNextableElementProcessor method next.
@Override
public List<Element> next(T element, WorkflowContext context) {
WorkflowContext.ActionContext actionContext = context.getActionContext();
List<Element> nextElements = element.getNextList(actionContext.getAction(), context);
Preconditions.checkNotEmpty(nextElements, "not found next element ");
Element endEvent = nextElements.stream().filter(EndEvent.class::isInstance).findFirst().orElse(null);
if (endEvent == null) {
return nextElements;
}
List<Element> notEndEventElements = nextElements.stream().filter(ele -> !(ele instanceof EndEvent)).collect(Collectors.toList());
if (CollectionUtils.isEmpty(notEndEventElements)) {
return Collections.singletonList(endEvent);
}
throw new WorkflowException("process definition error, find endEvent and not endEvent at the same time");
}
use of org.apache.inlong.manager.common.exceptions.WorkflowException in project incubator-inlong by apache.
the class EventListenerServiceImpl method executeEventListener.
@Override
public void executeEventListener(Integer eventLogId) {
WorkflowEventLogEntity eventLogEntity = eventLogMapper.selectById(eventLogId);
Preconditions.checkNotNull(eventLogEntity, "event log not exist with id: " + eventLogId);
if (ProcessEvent.class.getSimpleName().equals(eventLogEntity.getEventType())) {
this.executeProcessEventListener(eventLogEntity.getProcessId(), eventLogEntity.getListener());
return;
}
if (TaskEvent.class.getSimpleName().equals(eventLogEntity.getEventType())) {
this.executeTaskEventListener(eventLogEntity.getTaskId(), eventLogEntity.getListener());
return;
}
throw new WorkflowException("unknown event type: " + eventLogEntity.getEventType());
}
Aggregations