Search in sources :

Example 16 with WorkItemNode

use of io.automatiko.engine.workflow.process.core.node.WorkItemNode in project automatiko-engine by automatiko-io.

the class CompensationTest method createCompensationEventSubProcessProcess.

private ExecutableProcess createCompensationEventSubProcessProcess(String processId, String[] workItemNames, final List<String> eventList) throws Exception {
    ExecutableProcess process = new ExecutableProcess();
    process.setAutoComplete(true);
    process.setId(processId);
    process.setName("CESP Process");
    process.setMetaData("Compensation", true);
    NodeCreator<StartNode> startNodeCreator = new NodeCreator<StartNode>(process, StartNode.class);
    NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(process, WorkItemNode.class);
    NodeCreator<CompositeContextNode> compNodeCreator = new NodeCreator<CompositeContextNode>(process, CompositeContextNode.class);
    NodeCreator<EndNode> endNodeCreator = new NodeCreator<EndNode>(process, EndNode.class);
    // outer process
    StartNode startNode = startNodeCreator.createNode("start0");
    WorkItemNode workItemNode = workItemNodeCreator.createNode("work0-pre");
    workItemNode.getWork().setName(workItemNames[0]);
    connect(startNode, workItemNode);
    CompositeNode compositeNode = compNodeCreator.createNode("sub0");
    connect(workItemNode, compositeNode);
    workItemNode = workItemNodeCreator.createNode("work0-post");
    workItemNode.getWork().setName(workItemNames[2]);
    connect(compositeNode, workItemNode);
    EndNode endNode = endNodeCreator.createNode("end0");
    connect(workItemNode, endNode);
    // 1rst level nested subprocess
    startNodeCreator.setNodeContainer(compositeNode);
    workItemNodeCreator.setNodeContainer(compositeNode);
    endNodeCreator.setNodeContainer(compositeNode);
    startNode = startNodeCreator.createNode("start1");
    workItemNode = workItemNodeCreator.createNode("work1");
    workItemNode.getWork().setName(workItemNames[1]);
    connect(startNode, workItemNode);
    endNode = endNodeCreator.createNode("end1");
    connect(workItemNode, endNode);
    // 2nd level nested event subprocess in 1rst level subprocess
    NodeCreator<EventSubProcessNode> espNodeCreator = new NodeCreator<EventSubProcessNode>(compositeNode, EventSubProcessNode.class);
    EventSubProcessNode espNode = espNodeCreator.createNode("eventSub1");
    EventTypeFilter eventFilter = new NonAcceptingEventTypeFilter();
    eventFilter.setType("Compensation");
    espNode.addEvent(eventFilter);
    addCompensationScope(espNode, process, (String) compositeNode.getMetaData("UniqueId"));
    startNodeCreator.setNodeContainer(espNode);
    endNodeCreator.setNodeContainer(espNode);
    NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(espNode, ActionNode.class);
    startNode = startNodeCreator.createNode("start1*");
    ActionNode actionNode = actionNodeCreator.createNode("action1*");
    actionNode.setName("Execute");
    ProcessAction action = new ConsequenceAction("java", null);
    action.setMetaData("Action", new Action() {

        public void execute(ProcessContext context) throws Exception {
            eventList.add("Executed action");
        }
    });
    actionNode.setAction(action);
    connect(startNode, actionNode);
    endNode = endNodeCreator.createNode("end1*");
    connect(actionNode, endNode);
    return process;
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Action(io.automatiko.engine.workflow.base.instance.impl.Action) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) ProcessContext(io.automatiko.engine.api.runtime.process.ProcessContext) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) NonAcceptingEventTypeFilter(io.automatiko.engine.workflow.base.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) NodeCreator(io.automatiko.engine.workflow.process.test.NodeCreator) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)

Example 17 with WorkItemNode

use of io.automatiko.engine.workflow.process.core.node.WorkItemNode in project automatiko-engine by automatiko-io.

the class CompensationTest method createNestedCompensationBoundaryEventProcess.

private ExecutableProcess createNestedCompensationBoundaryEventProcess(String processId, String[] workItemNames, final List<String> eventList) throws Exception {
    ExecutableProcess process = new ExecutableProcess();
    process.setAutoComplete(true);
    process.setId(processId);
    process.setName("CESP Process");
    process.setMetaData("Compensation", true);
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("event");
    ObjectDataType personDataType = new ObjectDataType(java.lang.String.class);
    variable.setType(personDataType);
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    NodeCreator<StartNode> startNodeCreator = new NodeCreator<StartNode>(process, StartNode.class);
    NodeCreator<EndNode> endNodeCreator = new NodeCreator<EndNode>(process, EndNode.class);
    NodeCreator<CompositeContextNode> compNodeCreator = new NodeCreator<CompositeContextNode>(process, CompositeContextNode.class);
    // process level
    CompositeContextNode compositeNode = compNodeCreator.createNode("sub0");
    {
        StartNode startNode = startNodeCreator.createNode("start0");
        connect(startNode, compositeNode);
        EndNode endNode = endNodeCreator.createNode("end0");
        connect(compositeNode, endNode);
    }
    // 1rst level nested subprocess (contains compensation visibility scope)
    {
        startNodeCreator.setNodeContainer(compositeNode);
        compNodeCreator.setNodeContainer(compositeNode);
        endNodeCreator.setNodeContainer(compositeNode);
        StartNode startNode = startNodeCreator.createNode("start1");
        CompositeContextNode subCompNode = compNodeCreator.createNode("sub1");
        connect(startNode, subCompNode);
        EndNode endNode = endNodeCreator.createNode("end1");
        connect(subCompNode, endNode);
        compositeNode = subCompNode;
    }
    // 2nd level nested subprocess (contains compensation visibility scope)
    NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(compositeNode, WorkItemNode.class);
    {
        startNodeCreator.setNodeContainer(compositeNode);
        compNodeCreator.setNodeContainer(compositeNode);
        endNodeCreator.setNodeContainer(compositeNode);
        StartNode startNode = startNodeCreator.createNode("start2");
        CompositeContextNode subCompNode = compNodeCreator.createNode("sub2");
        connect(startNode, subCompNode);
        WorkItemNode workItemNode = workItemNodeCreator.createNode("work2");
        workItemNode.getWork().setName(workItemNames[2]);
        connect(subCompNode, workItemNode);
        EndNode endNode = endNodeCreator.createNode("end2");
        connect(workItemNode, endNode);
        createBoundaryEventCompensationHandler(compositeNode, workItemNode, eventList, "2");
        compositeNode = subCompNode;
    }
    // Fill 3rd level with process with compensation
    {
        startNodeCreator.setNodeContainer(compositeNode);
        workItemNodeCreator.setNodeContainer(compositeNode);
        endNodeCreator.setNodeContainer(compositeNode);
        StartNode startNode = startNodeCreator.createNode("start");
        Node lastNode = startNode;
        WorkItemNode[] workItemNodes = new WorkItemNode[3];
        for (int i = 0; i < 2; ++i) {
            workItemNodes[i] = workItemNodeCreator.createNode("work-comp-" + (i + 1));
            workItemNodes[i].getWork().setName(workItemNames[i]);
            connect(lastNode, workItemNodes[i]);
            lastNode = workItemNodes[i];
        }
        EndNode endNode = endNodeCreator.createNode("end");
        connect(workItemNodes[1], endNode);
        // Compensation (boundary event) handlers
        for (int i = 0; i < 2; ++i) {
            createBoundaryEventCompensationHandler(compositeNode, workItemNodes[i], eventList, "" + i + 1);
        }
    }
    return process;
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) BoundaryEventNode(io.automatiko.engine.workflow.process.core.node.BoundaryEventNode) Node(io.automatiko.engine.workflow.process.core.Node) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) EventSubProcessNode(io.automatiko.engine.workflow.process.core.node.EventSubProcessNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ArrayList(java.util.ArrayList) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) NodeCreator(io.automatiko.engine.workflow.process.test.NodeCreator) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)

Example 18 with WorkItemNode

use of io.automatiko.engine.workflow.process.core.node.WorkItemNode 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 19 with WorkItemNode

use of io.automatiko.engine.workflow.process.core.node.WorkItemNode in project automatiko-engine by automatiko-io.

the class HumanTaskNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
    WorkItemNode workItemNode = (WorkItemNode) node;
    writeNode("humanTask", workItemNode, xmlDump, includeMeta);
    visitParameters(workItemNode, xmlDump);
    xmlDump.append(">" + EOL);
    if (includeMeta) {
        writeMetaData(workItemNode, xmlDump);
    }
    Work work = workItemNode.getWork();
    visitWork(work, xmlDump, includeMeta);
    visitInMappings(workItemNode.getInMappings(), xmlDump);
    visitOutMappings(workItemNode.getOutMappings(), xmlDump);
    for (String eventType : workItemNode.getActionTypes()) {
        writeActions(eventType, workItemNode.getActions(eventType), xmlDump);
    }
    writeTimers(workItemNode.getTimers(), xmlDump);
    endNode("humanTask", xmlDump);
}
Also used : WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) Work(io.automatiko.engine.workflow.base.core.Work)

Example 20 with WorkItemNode

use of io.automatiko.engine.workflow.process.core.node.WorkItemNode in project automatiko-engine by automatiko-io.

the class DefinitionsHandler method postProcessInterfaces.

private void postProcessInterfaces(NodeContainer nodeContainer, List<Interface> interfaces) {
    for (Node node : nodeContainer.getNodes()) {
        if (node instanceof NodeContainer) {
            postProcessInterfaces((NodeContainer) node, interfaces);
        }
        if (node instanceof WorkItemNode && "Service Task".equals(((WorkItemNode) node).getMetaData("Type"))) {
            WorkItemNode workItemNode = (WorkItemNode) node;
            if (interfaces == null) {
                throw new IllegalArgumentException("No interfaces found");
            }
            String operationRef = (String) workItemNode.getMetaData("OperationRef");
            String implementation = (String) workItemNode.getMetaData("Implementation");
            Operation operation = null;
            for (Interface i : interfaces) {
                operation = i.getOperation(operationRef);
                if (operation != null) {
                    break;
                }
            }
            if (operation == null) {
                throw new IllegalArgumentException("Could not find operation " + operationRef);
            }
            // avoid overriding parameters set by data input associations
            if (workItemNode.getWork().getParameter("Interface") == null) {
                workItemNode.getWork().setParameter("Interface", operation.getInterface().getName());
            }
            if (workItemNode.getWork().getParameter("Operation") == null) {
                workItemNode.getWork().setParameter("Operation", operation.getName());
            }
            if (workItemNode.getWork().getParameter("ParameterType") == null && operation.getMessage() != null) {
                workItemNode.getWork().setParameter("ParameterType", operation.getMessage().getType());
            }
            // parameters to support web service invocation
            if (implementation != null) {
                workItemNode.getWork().setParameter("interfaceImplementationRef", operation.getInterface().getImplementationRef());
                workItemNode.getWork().setParameter("operationImplementationRef", operation.getImplementationRef());
                workItemNode.getWork().setParameter("implementation", implementation);
            }
        }
    }
}
Also used : Node(io.automatiko.engine.api.definition.process.Node) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) WorkItemNode(io.automatiko.engine.workflow.process.core.node.WorkItemNode) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) Operation(io.automatiko.engine.workflow.bpmn2.core.Interface.Operation) Interface(io.automatiko.engine.workflow.bpmn2.core.Interface)

Aggregations

WorkItemNode (io.automatiko.engine.workflow.process.core.node.WorkItemNode)26 Work (io.automatiko.engine.workflow.base.core.Work)10 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)10 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)10 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)10 ArrayList (java.util.ArrayList)8 CompositeNode (io.automatiko.engine.workflow.process.core.node.CompositeNode)7 EventSubProcessNode (io.automatiko.engine.workflow.process.core.node.EventSubProcessNode)7 ObjectDataType (io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType)6 WorkImpl (io.automatiko.engine.workflow.base.core.impl.WorkImpl)6 BoundaryEventNode (io.automatiko.engine.workflow.process.core.node.BoundaryEventNode)6 CompositeContextNode (io.automatiko.engine.workflow.process.core.node.CompositeContextNode)6 ForEachNode (io.automatiko.engine.workflow.process.core.node.ForEachNode)6 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)6 List (java.util.List)6 Map (java.util.Map)6 Node (io.automatiko.engine.api.definition.process.Node)5 EventTypeFilter (io.automatiko.engine.workflow.base.core.event.EventTypeFilter)5 Node (io.automatiko.engine.workflow.process.core.Node)5 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)4