Search in sources :

Example 6 with ProcessInstance

use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.

the class LightProcessRuntime method startProcessInstance.

public ProcessInstance startProcessInstance(String processInstanceId, String trigger, Object triggerData) {
    ProcessInstance processInstance = getProcessInstance(processInstanceId);
    ((io.automatiko.engine.workflow.base.instance.ProcessInstance) processInstance).configureSLA();
    getProcessEventSupport().fireBeforeProcessStarted(processInstance, this);
    ((io.automatiko.engine.workflow.base.instance.ProcessInstance) processInstance).setReferenceFromRoot(null);
    ((io.automatiko.engine.workflow.base.instance.ProcessInstance) processInstance).start(trigger, triggerData);
    getProcessEventSupport().fireAfterProcessStarted(processInstance, this);
    return processInstance;
}
Also used : ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance)

Example 7 with ProcessInstance

use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.

the class LightWorkItemManager method internalExecuteWorkItem.

public void internalExecuteWorkItem(WorkItem workItem) {
    ((WorkItemImpl) workItem).setId(UUID.randomUUID().toString());
    internalAddWorkItem(workItem);
    WorkItemHandler handler = this.workItemHandlers.get(workItem.getName());
    if (handler != null) {
        ProcessInstance processInstance = workItem.getProcessInstance();
        Transition<?> transition = new TransitionToActive();
        eventSupport.fireBeforeWorkItemTransition(processInstance, workItem, transition, null);
        handler.executeWorkItem(workItem, this);
        eventSupport.fireAfterWorkItemTransition(processInstance, workItem, transition, null);
    } else
        throw new WorkItemHandlerNotFoundException(workItem.getName());
}
Also used : WorkItemHandler(io.automatiko.engine.api.runtime.process.WorkItemHandler) WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl) WorkItemHandlerNotFoundException(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance)

Example 8 with ProcessInstance

use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.

the class LightWorkItemManager method abortWorkItem.

public void abortWorkItem(String id, Policy<?>... policies) {
    WorkItemImpl workItem = (WorkItemImpl) workItems.get(id);
    // work item may have been aborted
    if (workItem != null) {
        if (!workItem.enforce(policies)) {
            throw new NotAuthorizedException("Work item can be aborted as it does not fulfil policies (e.g. security)");
        }
        ProcessInstance processInstance = workItem.getProcessInstance();
        Transition<?> transition = new TransitionToAbort(Arrays.asList(policies));
        eventSupport.fireBeforeWorkItemTransition(processInstance, workItem, transition, null);
        workItem.setState(ABORTED);
        abortPhase.apply(workItem, transition);
        // process instance may have finished already
        if (processInstance != null) {
            processInstance.signalEvent("workItemAborted", workItem);
        }
        workItem.setPhaseId(ID);
        workItem.setPhaseStatus(STATUS);
        eventSupport.fireAfterWorkItemTransition(processInstance, workItem, transition, null);
        workItems.remove(id);
    }
}
Also used : WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) NotAuthorizedException(io.automatiko.engine.api.workflow.workitem.NotAuthorizedException)

Example 9 with ProcessInstance

use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.

the class ProcessEventSupport method fireAfterProcessSignaled.

public void fireAfterProcessSignaled(String signal, Object data, final ProcessInstance instance, ProcessRuntime runtime) {
    final Iterator<ProcessEventListener> iter = getEventListenersIterator();
    final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
    final ProcessSignaledEvent event = new ProcessSignaledEventImpl(signal, data, instance, runtime);
    if (iter.hasNext()) {
        do {
            ProcessEventListener listener = iter.next();
            if (listener instanceof DelayedExecution) {
                delayedListeners.add(listener);
            } else {
                listener.afterProcessSignaled(event);
            }
        } while (iter.hasNext());
    }
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, (e) -> {
        delayedListeners.forEach(l -> l.afterProcessSignaled(e));
    }));
}
Also used : ProcessEventListener(io.automatiko.engine.api.event.process.ProcessEventListener) ProcessVariableChangedEvent(io.automatiko.engine.api.event.process.ProcessVariableChangedEvent) UnitOfWorkManager(io.automatiko.engine.api.uow.UnitOfWorkManager) DelayedExecution(io.automatiko.engine.api.event.process.DelayedExecution) ProcessNodeTriggeredEvent(io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem) Iterator(java.util.Iterator) ProcessNodeLeftEvent(io.automatiko.engine.api.event.process.ProcessNodeLeftEvent) ProcessSignaledEvent(io.automatiko.engine.api.event.process.ProcessSignaledEvent) ProcessStartedEvent(io.automatiko.engine.api.event.process.ProcessStartedEvent) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) ProcessRuntime(io.automatiko.engine.api.runtime.process.ProcessRuntime) ArrayList(java.util.ArrayList) WorkUnit(io.automatiko.engine.api.uow.WorkUnit) List(java.util.List) ProcessNodeInstanceFailedEvent(io.automatiko.engine.api.event.process.ProcessNodeInstanceFailedEvent) ProcessCompletedEvent(io.automatiko.engine.api.event.process.ProcessCompletedEvent) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) Transition(io.automatiko.engine.api.workflow.workitem.Transition) SLAViolatedEvent(io.automatiko.engine.api.event.process.SLAViolatedEvent) ProcessWorkItemTransitionEvent(io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent) DelayedExecution(io.automatiko.engine.api.event.process.DelayedExecution) ProcessEventListener(io.automatiko.engine.api.event.process.ProcessEventListener) ArrayList(java.util.ArrayList) ProcessSignaledEvent(io.automatiko.engine.api.event.process.ProcessSignaledEvent)

Example 10 with ProcessInstance

use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.

the class ProcessEventSupport method fireAfterProcessStarted.

public void fireAfterProcessStarted(final ProcessInstance instance, ProcessRuntime runtime) {
    final Iterator<ProcessEventListener> iter = getEventListenersIterator();
    final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
    final ProcessStartedEvent event = new ProcessStartedEventImpl(instance, runtime);
    if (iter.hasNext()) {
        do {
            ProcessEventListener listener = iter.next();
            if (listener instanceof DelayedExecution) {
                delayedListeners.add(listener);
            } else {
                listener.afterProcessStarted(event);
            }
        } while (iter.hasNext());
    }
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
        delayedListeners.forEach(l -> l.afterProcessStarted(e));
    }));
}
Also used : ProcessEventListener(io.automatiko.engine.api.event.process.ProcessEventListener) ProcessVariableChangedEvent(io.automatiko.engine.api.event.process.ProcessVariableChangedEvent) UnitOfWorkManager(io.automatiko.engine.api.uow.UnitOfWorkManager) DelayedExecution(io.automatiko.engine.api.event.process.DelayedExecution) ProcessNodeTriggeredEvent(io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem) Iterator(java.util.Iterator) ProcessNodeLeftEvent(io.automatiko.engine.api.event.process.ProcessNodeLeftEvent) ProcessSignaledEvent(io.automatiko.engine.api.event.process.ProcessSignaledEvent) ProcessStartedEvent(io.automatiko.engine.api.event.process.ProcessStartedEvent) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) ProcessRuntime(io.automatiko.engine.api.runtime.process.ProcessRuntime) ArrayList(java.util.ArrayList) WorkUnit(io.automatiko.engine.api.uow.WorkUnit) List(java.util.List) ProcessNodeInstanceFailedEvent(io.automatiko.engine.api.event.process.ProcessNodeInstanceFailedEvent) ProcessCompletedEvent(io.automatiko.engine.api.event.process.ProcessCompletedEvent) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) Transition(io.automatiko.engine.api.workflow.workitem.Transition) SLAViolatedEvent(io.automatiko.engine.api.event.process.SLAViolatedEvent) ProcessWorkItemTransitionEvent(io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent) DelayedExecution(io.automatiko.engine.api.event.process.DelayedExecution) ProcessEventListener(io.automatiko.engine.api.event.process.ProcessEventListener) ArrayList(java.util.ArrayList) ProcessStartedEvent(io.automatiko.engine.api.event.process.ProcessStartedEvent)

Aggregations

ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)56 ArrayList (java.util.ArrayList)25 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)19 List (java.util.List)18 WorkItem (io.automatiko.engine.api.runtime.process.WorkItem)17 ProcessCompletedEvent (io.automatiko.engine.api.event.process.ProcessCompletedEvent)16 ProcessEventListener (io.automatiko.engine.api.event.process.ProcessEventListener)16 ProcessNodeLeftEvent (io.automatiko.engine.api.event.process.ProcessNodeLeftEvent)16 ProcessNodeTriggeredEvent (io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent)16 ProcessStartedEvent (io.automatiko.engine.api.event.process.ProcessStartedEvent)16 ProcessVariableChangedEvent (io.automatiko.engine.api.event.process.ProcessVariableChangedEvent)16 ProcessRuntime (io.automatiko.engine.api.runtime.process.ProcessRuntime)16 DelayedExecution (io.automatiko.engine.api.event.process.DelayedExecution)15 ProcessNodeInstanceFailedEvent (io.automatiko.engine.api.event.process.ProcessNodeInstanceFailedEvent)15 ProcessSignaledEvent (io.automatiko.engine.api.event.process.ProcessSignaledEvent)15 ProcessWorkItemTransitionEvent (io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent)15 SLAViolatedEvent (io.automatiko.engine.api.event.process.SLAViolatedEvent)15 UnitOfWorkManager (io.automatiko.engine.api.uow.UnitOfWorkManager)15 WorkUnit (io.automatiko.engine.api.uow.WorkUnit)15 Transition (io.automatiko.engine.api.workflow.workitem.Transition)15