Search in sources :

Example 31 with ProcessInstance

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);
    }
}
Also used : ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance)

Example 32 with ProcessInstance

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());
}
Also used : TestWorkItemHandler(io.automatiko.engine.workflow.process.test.TestWorkItemHandler) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance)

Example 33 with ProcessInstance

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());
}
Also used : HashMap(java.util.HashMap) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) Person(io.automatiko.engine.workflow.process.test.Person) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) Test(org.junit.jupiter.api.Test)

Example 34 with ProcessInstance

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());
}
Also used : HashMap(java.util.HashMap) DoNothingWorkItemHandler(io.automatiko.engine.workflow.base.instance.impl.demo.DoNothingWorkItemHandler) WorkItemHandlerNotFoundException(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) Person(io.automatiko.engine.workflow.process.test.Person) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) Test(org.junit.jupiter.api.Test)

Example 35 with ProcessInstance

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));
    }));
}
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) SLAViolatedEvent(io.automatiko.engine.api.event.process.SLAViolatedEvent)

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