Search in sources :

Example 1 with WorkflowException

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()));
    }
}
Also used : WorkflowException(org.apache.inlong.manager.common.exceptions.WorkflowException) WorkflowTaskEntity(org.apache.inlong.manager.dao.entity.WorkflowTaskEntity)

Example 2 with WorkflowException

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));
}
Also used : SkipableElementProcessor(org.apache.inlong.manager.workflow.processor.SkipableElementProcessor) NextableElement(org.apache.inlong.manager.workflow.definition.NextableElement) WorkflowException(org.apache.inlong.manager.common.exceptions.WorkflowException) Element(org.apache.inlong.manager.workflow.definition.Element) NextableElement(org.apache.inlong.manager.workflow.definition.NextableElement) SkippableElement(org.apache.inlong.manager.workflow.definition.SkippableElement) SkippableElement(org.apache.inlong.manager.workflow.definition.SkippableElement) ElementProcessor(org.apache.inlong.manager.workflow.processor.ElementProcessor) SkipableElementProcessor(org.apache.inlong.manager.workflow.processor.SkipableElementProcessor)

Example 3 with WorkflowException

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

Example 4 with WorkflowException

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");
}
Also used : List(java.util.List) EndEvent(org.apache.inlong.manager.workflow.definition.EndEvent) Preconditions(org.apache.inlong.manager.common.util.Preconditions) WorkflowException(org.apache.inlong.manager.common.exceptions.WorkflowException) CollectionUtils(org.springframework.util.CollectionUtils) Element(org.apache.inlong.manager.workflow.definition.Element) NextableElement(org.apache.inlong.manager.workflow.definition.NextableElement) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) WorkflowContext(org.apache.inlong.manager.workflow.WorkflowContext) Element(org.apache.inlong.manager.workflow.definition.Element) NextableElement(org.apache.inlong.manager.workflow.definition.NextableElement) WorkflowException(org.apache.inlong.manager.common.exceptions.WorkflowException) EndEvent(org.apache.inlong.manager.workflow.definition.EndEvent)

Example 5 with WorkflowException

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());
}
Also used : ProcessEvent(org.apache.inlong.manager.workflow.event.process.ProcessEvent) WorkflowEventLogEntity(org.apache.inlong.manager.dao.entity.WorkflowEventLogEntity) WorkflowException(org.apache.inlong.manager.common.exceptions.WorkflowException) TaskEvent(org.apache.inlong.manager.workflow.event.task.TaskEvent)

Aggregations

WorkflowException (org.apache.inlong.manager.common.exceptions.WorkflowException)7 WorkflowTaskEntity (org.apache.inlong.manager.dao.entity.WorkflowTaskEntity)2 Element (org.apache.inlong.manager.workflow.definition.Element)2 NextableElement (org.apache.inlong.manager.workflow.definition.NextableElement)2 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ColumnInfoBean (org.apache.inlong.manager.common.pojo.query.ColumnInfoBean)1 HiveColumnQueryBean (org.apache.inlong.manager.common.pojo.query.hive.HiveColumnQueryBean)1 HiveTableQueryBean (org.apache.inlong.manager.common.pojo.query.hive.HiveTableQueryBean)1 HiveSinkDTO (org.apache.inlong.manager.common.pojo.sink.hive.HiveSinkDTO)1 ProcessDetailResponse (org.apache.inlong.manager.common.pojo.workflow.ProcessDetailResponse)1 TaskResponse (org.apache.inlong.manager.common.pojo.workflow.TaskResponse)1 WorkflowApproverQuery (org.apache.inlong.manager.common.pojo.workflow.WorkflowApproverQuery)1 Preconditions (org.apache.inlong.manager.common.util.Preconditions)1 WorkflowApproverEntity (org.apache.inlong.manager.dao.entity.WorkflowApproverEntity)1 WorkflowEventLogEntity (org.apache.inlong.manager.dao.entity.WorkflowEventLogEntity)1 WorkflowProcessEntity (org.apache.inlong.manager.dao.entity.WorkflowProcessEntity)1 WorkflowContext (org.apache.inlong.manager.workflow.WorkflowContext)1 EndEvent (org.apache.inlong.manager.workflow.definition.EndEvent)1