Search in sources :

Example 1 with WorkItemHandlerNotFoundException

use of io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException 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 2 with WorkItemHandlerNotFoundException

use of io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException in project automatiko-engine by automatiko-io.

the class WorkItemNodeInstance method cancel.

@Override
public void cancel() {
    WorkItem item = getWorkItem();
    if (item != null && item.getState() != COMPLETED && item.getState() != ABORTED) {
        try {
            ((DefaultWorkItemManager) getProcessInstance().getProcessRuntime().getWorkItemManager()).internalAbortWorkItem(item.getId());
        } catch (WorkItemHandlerNotFoundException wihnfe) {
            getProcessInstance().setState(STATE_ABORTED);
            throw wihnfe;
        }
    }
    if (exceptionHandlingProcessInstanceId != null) {
        ProcessInstance processInstance = (ProcessInstance) getProcessInstance().getProcessRuntime().getProcessInstance(exceptionHandlingProcessInstanceId);
        if (processInstance != null) {
            processInstance.setState(STATE_ABORTED);
        }
    }
    super.cancel();
}
Also used : DefaultWorkItemManager(io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager) WorkItemHandlerNotFoundException(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem)

Example 3 with WorkItemHandlerNotFoundException

use of io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException 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 4 with WorkItemHandlerNotFoundException

use of io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException in project automatiko-engine by automatiko-io.

the class WorkItemNodeInstance method internalTrigger.

@Override
public void internalTrigger(final NodeInstance from, String type) {
    super.internalTrigger(from, type);
    // if node instance was cancelled, abort
    if (getNodeInstanceContainer().getNodeInstance(getId()) == null) {
        return;
    }
    WorkItemNode workItemNode = getWorkItemNode();
    createWorkItem(workItemNode);
    if (workItemNode.isWaitForCompletion()) {
        addWorkItemListener();
    }
    ((WorkItemImpl) workItem).setNodeInstanceId(this.getId());
    ((WorkItemImpl) workItem).setNodeId(getNodeId());
    workItem.setNodeInstance(this);
    workItem.setProcessInstance(getProcessInstance());
    setProcessId();
    try {
        ((DefaultWorkItemManager) getProcessInstance().getProcessRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);
    } catch (WorkItemHandlerNotFoundException wihnfe) {
        getProcessInstance().setState(STATE_ABORTED);
        throw wihnfe;
    } catch (ProcessWorkItemHandlerException handlerException) {
        this.workItemId = workItem.getId();
        removeEventListeners();
        handleWorkItemHandlerException(handlerException, workItem);
    } catch (WorkItemExecutionError e) {
        removeEventListeners();
        handleException(e.getErrorCode(), e);
    } catch (Exception e) {
        removeEventListeners();
        String exceptionName = e.getClass().getName();
        handleException(exceptionName, e);
    }
    if (!workItemNode.isWaitForCompletion()) {
        triggerCompleted();
    }
    this.workItemId = workItem.getId();
}
Also used : DefaultWorkItemManager(io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl) WorkItemHandlerNotFoundException(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException) ProcessWorkItemHandlerException(io.automatiko.engine.api.runtime.process.ProcessWorkItemHandlerException) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError) WorkItemHandlerNotFoundException(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException) ProcessWorkItemHandlerException(io.automatiko.engine.api.runtime.process.ProcessWorkItemHandlerException) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)

Example 5 with WorkItemHandlerNotFoundException

use of io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException 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)

Aggregations

WorkItemHandlerNotFoundException (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException)6 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)4 WorkItemHandler (io.automatiko.engine.api.runtime.process.WorkItemHandler)3 WorkItemImpl (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl)3 WorkItem (io.automatiko.engine.api.runtime.process.WorkItem)2 DefaultWorkItemManager (io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager)2 WorkflowProcessInstance (io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)2 HashMap (java.util.HashMap)2 HumanTaskWorkItem (io.automatiko.engine.api.runtime.process.HumanTaskWorkItem)1 ProcessWorkItemHandlerException (io.automatiko.engine.api.runtime.process.ProcessWorkItemHandlerException)1 WorkItemNotFoundException (io.automatiko.engine.api.runtime.process.WorkItemNotFoundException)1 WorkItemExecutionError (io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)1 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)1 ProcessInstance (io.automatiko.engine.workflow.base.instance.ProcessInstance)1 DoNothingWorkItemHandler (io.automatiko.engine.workflow.base.instance.impl.demo.DoNothingWorkItemHandler)1 WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)1 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)1 WorkflowRuntimeException (io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)1 Person (io.automatiko.engine.workflow.process.test.Person)1 AbstractBaseTest (io.automatiko.engine.workflow.test.util.AbstractBaseTest)1