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