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