use of io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager in project automatiko-engine by automatiko-io.
the class BaseHumanTaskLifeCycle method transitionTo.
@Override
public Map<String, Object> transitionTo(WorkItem workItem, WorkItemManager manager, Transition<Map<String, Object>> transition) {
logger.debug("Transition method invoked for work item {} to transition to {}, currently in phase {} and status {}", workItem.getId(), transition.phase(), workItem.getPhaseId(), workItem.getPhaseStatus());
HumanTaskWorkItemImpl humanTaskWorkItem = (HumanTaskWorkItemImpl) workItem;
LifeCyclePhase targetPhase = phases.get(transition.phase());
if (targetPhase == null) {
logger.debug("Target life cycle phase '{}' does not exist in {}", transition.phase(), this.getClass().getSimpleName());
throw new InvalidLifeCyclePhaseException(transition.phase());
}
LifeCyclePhase currentPhase = phases.get(humanTaskWorkItem.getPhaseId());
if (!targetPhase.canTransition(currentPhase)) {
logger.debug("Target life cycle phase '{}' cannot transition from current state '{}'", targetPhase.id(), currentPhase.id());
throw new InvalidTransitionException("Cannot transition from " + humanTaskWorkItem.getPhaseId() + " to " + targetPhase.id());
}
if (!targetPhase.id().equals(Active.ID) && !targetPhase.id().equals(Abort.ID) && !humanTaskWorkItem.enforce(transition.policies().toArray(new Policy[transition.policies().size()]))) {
throw new NotAuthorizedException("User is not authorized to access task instance with id " + humanTaskWorkItem.getId());
}
humanTaskWorkItem.setPhaseId(targetPhase.id());
humanTaskWorkItem.setPhaseStatus(targetPhase.status());
targetPhase.apply(humanTaskWorkItem, transition);
if (transition.data() != null) {
logger.debug("Updating data for work item {}", targetPhase.id(), humanTaskWorkItem.getId());
humanTaskWorkItem.getResults().putAll(transition.data());
}
logger.debug("Transition for work item {} to {} done, currently in phase {} and status {}", workItem.getId(), transition.phase(), workItem.getPhaseId(), workItem.getPhaseStatus());
if (targetPhase.isCompleting()) {
logger.debug("Target life cycle phase '{}' is completing, completing work item {}", targetPhase.id(), humanTaskWorkItem.getId());
// since target life cycle phase is terminating completing work item
((DefaultWorkItemManager) manager).internalCompleteWorkItem(humanTaskWorkItem);
} else if (targetPhase.isTerminating()) {
logger.debug("Target life cycle phase '{}' is terminating, aborting work item {}", targetPhase.id(), humanTaskWorkItem.getId());
((DefaultWorkItemManager) manager).internalAbortWorkItem(humanTaskWorkItem);
}
return data(humanTaskWorkItem);
}
use of io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager in project automatiko-engine by automatiko-io.
the class ProtobufProcessMarshaller method readWorkItems.
public void readWorkItems(MarshallerReaderContext context) throws IOException {
AutomatikoMessages.ProcessData _pdata = (AutomatikoMessages.ProcessData) context.parameterObject;
InternalProcessRuntime wm = context.getProcessRuntime();
for (AutomatikoMessages.WorkItem _workItem : _pdata.getExtension(AutomatikoMessages.workItem)) {
WorkItem workItem = readWorkItem(context, _workItem);
((DefaultWorkItemManager) wm.getWorkItemManager()).internalAddWorkItem((WorkItem) workItem);
}
}
use of io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager 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.DefaultWorkItemManager 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.DefaultWorkItemManager in project automatiko-engine by automatiko-io.
the class WorkItemNodeInstance method exceptionHandlingCompleted.
private void exceptionHandlingCompleted(ProcessInstance processInstance, ProcessWorkItemHandlerException handlerException) {
if (handlerException == null) {
handlerException = (ProcessWorkItemHandlerException) ((WorkflowProcessInstance) processInstance).getVariable("Error");
}
switch(handlerException.getStrategy()) {
case ABORT:
getProcessInstance().getProcessRuntime().getWorkItemManager().abortWorkItem(getWorkItem().getId());
break;
case RETHROW:
String exceptionName = handlerException.getCause().getClass().getName();
ExceptionScopeInstance exceptionScopeInstance = (ExceptionScopeInstance) resolveContextInstance(ExceptionScope.EXCEPTION_SCOPE, exceptionName);
if (exceptionScopeInstance == null) {
throw new WorkflowRuntimeException(this, getProcessInstance(), "Unable to execute work item " + handlerException.getMessage(), handlerException.getCause());
}
exceptionScopeInstance.handleException(this, exceptionName, handlerException.getCause());
break;
case RETRY:
Map<String, Object> parameters = new HashMap<>(getWorkItem().getParameters());
parameters.putAll(processInstance.getVariables());
((DefaultWorkItemManager) getProcessInstance().getProcessRuntime().getWorkItemManager()).retryWorkItem(getWorkItem().getId(), parameters);
break;
case COMPLETE:
getProcessInstance().getProcessRuntime().getWorkItemManager().completeWorkItem(getWorkItem().getId(), processInstance.getVariables());
break;
default:
break;
}
}
Aggregations