use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.
the class ProtobufProcessMarshaller method writeProcessInstances.
public void writeProcessInstances(MarshallerWriteContext context) throws IOException {
AutomatikoMessages.ProcessData.Builder _pdata = (AutomatikoMessages.ProcessData.Builder) context.parameterObject;
List<io.automatiko.engine.api.runtime.process.ProcessInstance> processInstances = new ArrayList<io.automatiko.engine.api.runtime.process.ProcessInstance>(context.getProcessRuntime().getProcessInstances());
Collections.sort(processInstances, new Comparator<io.automatiko.engine.api.runtime.process.ProcessInstance>() {
public int compare(io.automatiko.engine.api.runtime.process.ProcessInstance o1, io.automatiko.engine.api.runtime.process.ProcessInstance o2) {
return (int) (o1.getId().compareTo(o2.getId()));
}
});
for (io.automatiko.engine.api.runtime.process.ProcessInstance processInstance : processInstances) {
String processType = processInstance.getProcess().getType();
AutomatikoMessages.ProcessInstance _instance = (AutomatikoMessages.ProcessInstance) ProcessMarshallerRegistry.INSTANCE.getMarshaller(processType).writeProcessInstance(context, processInstance);
_pdata.addExtension(AutomatikoMessages.processInstance, _instance);
}
}
use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.
the class CompensationTest method runCompensationBoundaryEventGeneralTest.
public static void runCompensationBoundaryEventGeneralTest(InternalProcessRuntime ksession, ExecutableProcess process, String processId, String[] workItemNames, List<String> eventList, String compensationEvent) {
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
for (String workItem : workItemNames) {
ksession.getWorkItemManager().registerWorkItemHandler(workItem, workItemHandler);
}
ProcessInstance processInstance = ksession.startProcess(processId);
// general compensation should not cause anything to happen
ksession.signalEvent("Compensation", compensationEvent, processInstance.getId());
assertEquals(0, eventList.size(), "Compensation should not have fired yet.");
// complete work 1 & 2
ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
assertEquals(0, eventList.size(), "Compensation should not have fired yet.");
// general compensation should now cause the compensation handlers to fire in
// reverse order
ksession.signalEvent("Compensation", compensationEvent, processInstance.getId());
assertEquals(2, eventList.size(), "Compensation should have fired.");
// complete work 3 and finish
ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.
the class WorkItemTest method testReachNonRegisteredWorkItemHandler.
@Test
public void testReachNonRegisteredWorkItemHandler() {
String processId = "org.company.actions";
String workName = "Unnexistent Task";
ExecutableProcess process = getWorkItemProcess(processId, workName);
InternalProcessRuntime ksession = createProcessRuntime(process);
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("UserName", "John Doe");
parameters.put("Person", new Person("John Doe"));
ProcessInstance processInstance = null;
try {
processInstance = ksession.startProcess("org.company.actions", parameters);
fail("should fail if WorkItemHandler for" + workName + "is not registered");
} catch (Throwable e) {
}
assertEquals(ProcessInstance.STATE_ERROR, processInstance.getState());
}
use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.
the class WorkItemTest method testCancelNonRegisteredWorkItemHandler.
@Test
public void testCancelNonRegisteredWorkItemHandler() {
String processId = "org.company.actions";
String workName = "Unnexistent Task";
ExecutableProcess process = getWorkItemProcess(processId, workName);
InternalProcessRuntime ksession = createProcessRuntime(process);
ksession.getWorkItemManager().registerWorkItemHandler(workName, new DoNothingWorkItemHandler());
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("UserName", "John Doe");
parameters.put("Person", new Person("John Doe"));
ProcessInstance processInstance = ksession.startProcess("org.company.actions", parameters);
String processInstanceId = processInstance.getId();
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
ksession.getWorkItemManager().registerWorkItemHandler(workName, null);
try {
ksession.abortProcessInstance(processInstanceId);
fail("should fail if WorkItemHandler for" + workName + "is not registered");
} catch (WorkItemHandlerNotFoundException wihnfe) {
}
assertEquals(ProcessInstance.STATE_ABORTED, processInstance.getState());
}
use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.
the class ProcessEventSupport method fireAfterSLAViolated.
public void fireAfterSLAViolated(final ProcessInstance instance, ProcessRuntime runtime) {
final Iterator<ProcessEventListener> iter = getEventListenersIterator();
final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
final SLAViolatedEvent event = new SLAViolatedEventImpl(instance, runtime);
if (iter.hasNext()) {
do {
ProcessEventListener listener = iter.next();
if (listener instanceof DelayedExecution) {
delayedListeners.add(listener);
} else {
listener.afterSLAViolated(event);
}
} while (iter.hasNext());
}
unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
delayedListeners.forEach(l -> l.afterSLAViolated(e));
}));
}
Aggregations