Search in sources :

Example 11 with WorkItemImpl

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

the class ProtobufProcessMarshaller method readWorkItem.

public static WorkItem readWorkItem(MarshallerReaderContext context, AutomatikoMessages.WorkItem _workItem, boolean includeVariables) throws IOException {
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setId(_workItem.getId());
    workItem.setProcessInstanceId(_workItem.getProcessInstancesId());
    workItem.setName(_workItem.getName());
    workItem.setState(_workItem.getState());
    workItem.setNodeId(_workItem.getNodeId());
    workItem.setNodeInstanceId(_workItem.getNodeInstanceId());
    if (includeVariables) {
        for (AutomatikoMessages.Variable _variable : _workItem.getVariableList()) {
            try {
                Object value = unmarshallVariableValue(context, _variable);
                workItem.setParameter(_variable.getName(), value);
            } catch (ClassNotFoundException e) {
                throw new IllegalArgumentException("Could not reload parameter " + _variable.getName() + " for work item " + _workItem);
            }
        }
    }
    return workItem;
}
Also used : Variable(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Variable) WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl)

Example 12 with WorkItemImpl

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

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

the class StartNodeInstance method handleAssignment.

private void handleAssignment(Assignment assignment, Object result) {
    AssignmentAction action = (AssignmentAction) assignment.getMetaData("Action");
    if (action == null) {
        return;
    }
    try {
        ProcessContext context = new ProcessContext(getProcessInstance().getProcessRuntime());
        context.setNodeInstance(this);
        WorkItemImpl workItem = new WorkItemImpl();
        workItem.setResult("workflowdata", result);
        workItem.setResult("event", result);
        action.execute(workItem, context);
    } catch (WorkItemExecutionError e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException("unable to execute Assignment", e);
    }
}
Also used : AssignmentAction(io.automatiko.engine.workflow.base.instance.impl.AssignmentAction) WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl) ProcessContext(io.automatiko.engine.workflow.base.core.context.ProcessContext) WorkItemExecutionError(io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)

Example 14 with WorkItemImpl

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

the class HumanTaskNodeInstance method assignWorkItem.

protected String assignWorkItem(WorkItem workItem) {
    String actorId = null;
    // if this human task node is part of a swimlane, check whether an actor
    // has already been assigned to this swimlane
    String swimlaneName = getHumanTaskNode().getSwimlane();
    SwimlaneContextInstance swimlaneContextInstance = getSwimlaneContextInstance(swimlaneName);
    if (swimlaneContextInstance != null) {
        actorId = swimlaneContextInstance.getActorId(swimlaneName);
        ((WorkItemImpl) workItem).setParameter("SwimlaneActorId", actorId);
    }
    // actor is specified for this human task
    if (actorId == null) {
        actorId = (String) workItem.getParameter(ACTOR_ID);
        if (actorId != null && swimlaneContextInstance != null && actorId.split(separator).length == 1) {
            swimlaneContextInstance.setActorId(swimlaneName, actorId);
            ((WorkItemImpl) workItem).setParameter("SwimlaneActorId", actorId);
        }
    }
    processAssigment(ACTOR_ID, workItem, ((HumanTaskWorkItemImpl) workItem).getPotentialUsers());
    processAssigment(GROUP_ID, workItem, ((HumanTaskWorkItemImpl) workItem).getPotentialGroups());
    processAssigment(GROUPS, workItem, ((HumanTaskWorkItemImpl) workItem).getPotentialGroups());
    processAssigment(EXCLUDED_OWNER_ID, workItem, ((HumanTaskWorkItemImpl) workItem).getExcludedUsers());
    processAssigment(BUSINESSADMINISTRATOR_ID, workItem, ((HumanTaskWorkItemImpl) workItem).getAdminUsers());
    processAssigment(BUSINESSADMINISTRATOR_GROUP_ID, workItem, ((HumanTaskWorkItemImpl) workItem).getAdminGroups());
    // parameter
    return (String) workItem.getParameter(ACTOR_ID);
}
Also used : SwimlaneContextInstance(io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance) WorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl) HumanTaskWorkItemImpl(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskWorkItemImpl)

Example 15 with WorkItemImpl

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

WorkItemImpl (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemImpl)21 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)6 ExpressionEvaluator (io.automatiko.engine.api.expression.ExpressionEvaluator)4 WorkItemExecutionError (io.automatiko.engine.api.workflow.workitem.WorkItemExecutionError)4 Date (java.util.Date)4 ProcessContext (io.automatiko.engine.workflow.base.core.context.ProcessContext)3 VariableScopeInstance (io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance)3 AssignmentAction (io.automatiko.engine.workflow.base.instance.impl.AssignmentAction)3 DefaultWorkItemManager (io.automatiko.engine.workflow.base.instance.impl.workitem.DefaultWorkItemManager)3 WorkItemHandlerNotFoundException (io.automatiko.engine.workflow.base.instance.impl.workitem.WorkItemHandlerNotFoundException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Matcher (java.util.regex.Matcher)3 DataTransformer (io.automatiko.engine.api.runtime.process.DataTransformer)2 WorkItemHandler (io.automatiko.engine.api.runtime.process.WorkItemHandler)2 HumanTaskWorkItemImpl (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskWorkItemImpl)2 WorkflowProcess (io.automatiko.engine.workflow.process.core.WorkflowProcess)2 NodeInstance (io.automatiko.engine.workflow.process.instance.NodeInstance)2 NodeInstanceResolverFactory (io.automatiko.engine.workflow.process.instance.impl.NodeInstanceResolverFactory)2 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)1