Search in sources :

Example 1 with DefaultWorkItemManager

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);
}
Also used : InvalidTransitionException(io.automatiko.engine.api.workflow.workitem.InvalidTransitionException) Policy(io.automatiko.engine.api.workflow.workitem.Policy) DefaultWorkItemManager(io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager) InvalidLifeCyclePhaseException(io.automatiko.engine.api.workflow.workitem.InvalidLifeCyclePhaseException) NotAuthorizedException(io.automatiko.engine.api.workflow.workitem.NotAuthorizedException) LifeCyclePhase(io.automatiko.engine.api.workflow.workitem.LifeCyclePhase)

Example 2 with DefaultWorkItemManager

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);
    }
}
Also used : DefaultWorkItemManager(io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem)

Example 3 with DefaultWorkItemManager

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();
}
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 4 with DefaultWorkItemManager

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

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;
    }
}
Also used : DefaultWorkItemManager(io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager) HashMap(java.util.HashMap) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) WorkflowProcessInstance(io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance) ExceptionScopeInstance(io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)

Aggregations

DefaultWorkItemManager (io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager)9 WorkItemImpl (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl)3 WorkItem (io.automatiko.engine.api.runtime.process.WorkItem)2 InvalidLifeCyclePhaseException (io.automatiko.engine.api.workflow.workitem.InvalidLifeCyclePhaseException)2 LifeCyclePhase (io.automatiko.engine.api.workflow.workitem.LifeCyclePhase)2 WorkItemHandlerNotFoundException (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException)2 WorkflowProcessInstance (io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)2 WorkflowRuntimeException (io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException)2 HumanTaskWorkItem (io.automatiko.engine.api.runtime.process.HumanTaskWorkItem)1 ProcessWorkItemHandlerException (io.automatiko.engine.api.runtime.process.ProcessWorkItemHandlerException)1 InvalidTransitionException (io.automatiko.engine.api.workflow.workitem.InvalidTransitionException)1 NotAuthorizedException (io.automatiko.engine.api.workflow.workitem.NotAuthorizedException)1 Policy (io.automatiko.engine.api.workflow.workitem.Policy)1 WorkItemExecutionError (io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)1 EventTransformerImpl (io.automatiko.engine.workflow.base.core.event.EventTransformerImpl)1 ProcessEventSupport (io.automatiko.engine.workflow.base.core.event.ProcessEventSupport)1 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)1 ProcessInstance (io.automatiko.engine.workflow.base.instance.ProcessInstance)1 ExceptionScopeInstance (io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)1 HumanTaskWorkItemImpl (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskWorkItemImpl)1