Search in sources :

Example 46 with ProcessInstance

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

the class DmnDecisionInProcessTest method testDmn.

@Test
public void testDmn() {
    String namespace = "https://kiegroup.org/dmn/_52CEF9FD-9943-4A89-96D5-6F66810CA4C1";
    String modelName = "PersonDecisions";
    String decisionName = "isAdult";
    ExecutableProcess process = createProcess(namespace, modelName, decisionName);
    Map<String, Object> parameters = new HashMap<>();
    Person person = new Person("John", 25);
    parameters.put("person", person);
    parameters.put("isAdult", false);
    ProcessRuntime runtime = createProcessRuntime(process);
    ProcessInstance pi = runtime.startProcess("process", parameters);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi.getState());
    boolean result = (boolean) pi.getVariables().get("isAdult");
    assertEquals(true, result);
}
Also used : ProcessRuntime(io.automatiko.engine.api.runtime.process.ProcessRuntime) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) HashMap(java.util.HashMap) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) Test(org.junit.jupiter.api.Test)

Example 47 with ProcessInstance

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

the class LightProcessRuntime method abortProcessInstance.

public void abortProcessInstance(String processInstanceId) {
    ProcessInstance processInstance = getProcessInstance(processInstanceId);
    if (processInstance == null) {
        throw new IllegalArgumentException("Could not find process instance for id " + processInstanceId);
    }
    ((io.automatiko.engine.workflow.base.instance.ProcessInstance) processInstance).setState(ProcessInstance.STATE_ABORTED);
}
Also used : ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance)

Example 48 with ProcessInstance

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

the class LightWorkItemManager method internalAbortWorkItem.

public void internalAbortWorkItem(String id) {
    WorkItemImpl workItem = (WorkItemImpl) workItems.get(id);
    // work item may have been aborted
    if (workItem != null) {
        workItem.setCompleteDate(new Date());
        WorkItemHandler handler = this.workItemHandlers.get(workItem.getName());
        if (handler != null) {
            ProcessInstance processInstance = workItem.getProcessInstance();
            Transition<?> transition = new TransitionToAbort(Collections.emptyList());
            eventSupport.fireBeforeWorkItemTransition(processInstance, workItem, transition, null);
            handler.abortWorkItem(workItem, this);
            workItem.setPhaseId(ID);
            workItem.setPhaseStatus(STATUS);
            eventSupport.fireAfterWorkItemTransition(processInstance, workItem, transition, null);
        } else {
            workItems.remove(workItem.getId());
            throw new WorkItemHandlerNotFoundException(workItem.getName());
        }
        workItems.remove(workItem.getId());
    }
}
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) Date(java.util.Date)

Example 49 with ProcessInstance

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

the class LightWorkItemManager method transitionWorkItem.

@SuppressWarnings("unchecked")
@Override
public void transitionWorkItem(String id, Transition<?> transition) {
    WorkItem workItem = workItems.get(id);
    // work item may have been aborted
    if (workItem != null) {
        WorkItemHandler handler = this.workItemHandlers.get(workItem.getName());
        if (handler != null) {
            ProcessInstance processInstance = workItem.getProcessInstance();
            eventSupport.fireBeforeWorkItemTransition(processInstance, workItem, transition, null);
            try {
                handler.transitionToPhase(workItem, this, transition);
            } catch (UnsupportedOperationException e) {
                ((WorkItemImpl) workItem).setResults((Map<String, Object>) transition.data());
                workItem.setPhaseId(Complete.ID);
                workItem.setPhaseStatus(Complete.STATUS);
                completePhase.apply(workItem, transition);
                internalCompleteWorkItem(workItem);
            }
            eventSupport.fireAfterWorkItemTransition(processInstance, workItem, transition, null);
        } else {
            throw new WorkItemHandlerNotFoundException(workItem.getName());
        }
    } else {
        throw new WorkItemNotFoundException("Work Item (" + id + ") does not exist", id);
    }
}
Also used : WorkItemHandler(io.automatiko.engine.api.runtime.process.WorkItemHandler) WorkItemNotFoundException(io.automatiko.engine.api.runtime.process.WorkItemNotFoundException) WorkItemHandlerNotFoundException(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 50 with ProcessInstance

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

the class LightWorkItemManager method internalAbortWorkItem.

public void internalAbortWorkItem(WorkItem workItem) {
    ProcessInstance processInstance = workItem.getProcessInstance();
    ((WorkItemImpl) workItem).setState(ABORTED);
    // process instance may have finished already
    if (processInstance != null) {
        processInstance.signalEvent("workItemAborted", workItem);
    }
    workItems.remove(workItem.getId());
}
Also used : WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance)

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