Search in sources :

Example 16 with WorkItemNode

use of org.jbpm.workflow.core.node.WorkItemNode in project jbpm by kiegroup.

the class WorkItemNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, boolean includeMeta) {
    WorkItemNode workItemNode = (WorkItemNode) node;
    writeNode("workItem", 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("workItem", xmlDump);
}
Also used : WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Work(org.jbpm.process.core.Work)

Example 17 with WorkItemNode

use of org.jbpm.workflow.core.node.WorkItemNode in project jbpm by kiegroup.

the class SubProcessTest method testAsynchronousSubProcess.

@Test
public void testAsynchronousSubProcess() {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId("org.drools.core.process.process");
    process.setName("Process");
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    process.addNode(startNode);
    EndNode endNode = new EndNode();
    endNode.setName("EndNode");
    endNode.setId(2);
    process.addNode(endNode);
    SubProcessNode subProcessNode = new SubProcessNode();
    subProcessNode.setName("SubProcessNode");
    subProcessNode.setId(3);
    subProcessNode.setProcessId("org.drools.core.process.subprocess");
    process.addNode(subProcessNode);
    new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, subProcessNode, Node.CONNECTION_DEFAULT_TYPE);
    new ConnectionImpl(subProcessNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    RuleFlowProcess subProcess = new RuleFlowProcess();
    subProcess.setId("org.drools.core.process.subprocess");
    subProcess.setName("SubProcess");
    startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    subProcess.addNode(startNode);
    endNode = new EndNode();
    endNode.setName("EndNode");
    endNode.setId(2);
    subProcess.addNode(endNode);
    WorkItemNode workItemNode = new WorkItemNode();
    workItemNode.setName("WorkItem");
    Work work = new WorkImpl();
    work.setName("MyWork");
    workItemNode.setWork(work);
    workItemNode.setId(4);
    subProcess.addNode(workItemNode);
    new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, workItemNode, Node.CONNECTION_DEFAULT_TYPE);
    new ConnectionImpl(workItemNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    KieSession ksession = createKieSession(process, subProcess);
    ksession.getWorkItemManager().registerWorkItemHandler("MyWork", new WorkItemHandler() {

        public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
            logger.info("Executing work item");
            SubProcessTest.this.workItem = workItem;
        }

        public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
        }
    });
    ksession.startProcess("org.drools.core.process.process");
    TestProcessEventListener procEventListener = new TestProcessEventListener();
    ksession.addEventListener(procEventListener);
    assertNotNull(workItem);
    assertEquals(2, ksession.getProcessInstances().size());
    ksession.getWorkItemManager().completeWorkItem(workItem.getId(), null);
    assertEquals(0, ksession.getProcessInstances().size());
    verifyEventHistory(asyncEventOrder, procEventListener.getEventHistory());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) EndNode(org.jbpm.workflow.core.node.EndNode) SubProcessNode(org.jbpm.workflow.core.node.SubProcessNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Work(org.jbpm.process.core.Work) WorkImpl(org.jbpm.process.core.impl.WorkImpl) KieSession(org.kie.api.runtime.KieSession) WorkItemManager(org.kie.api.runtime.process.WorkItemManager) TestProcessEventListener(org.jbpm.process.test.TestProcessEventListener) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 18 with WorkItemNode

use of org.jbpm.workflow.core.node.WorkItemNode in project jbpm by kiegroup.

the class CompensationTest method createCompensationEventSubProcessProcess.

private RuleFlowProcess createCompensationEventSubProcessProcess(String processId, String[] workItemNames, final List<String> eventList) throws Exception {
    RuleFlowProcess process = new RuleFlowProcess();
    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");
    DroolsAction action = new DroolsConsequenceAction("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 : DroolsAction(org.jbpm.workflow.core.DroolsAction) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) DroolsAction(org.jbpm.workflow.core.DroolsAction) Action(org.jbpm.process.instance.impl.Action) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) ProcessContext(org.kie.api.runtime.process.ProcessContext) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) EndNode(org.jbpm.workflow.core.node.EndNode) NodeCreator(org.jbpm.process.test.NodeCreator) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode)

Example 19 with WorkItemNode

use of org.jbpm.workflow.core.node.WorkItemNode in project jbpm by kiegroup.

the class CompensationTest method createCompensationBoundaryEventProcess.

private RuleFlowProcess createCompensationBoundaryEventProcess(String processId, String[] workItemNames, final List<String> eventList) throws Exception {
    RuleFlowProcess process = new RuleFlowProcess();
    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();
    personDataType.setClassName("java.lang.String");
    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<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(process, WorkItemNode.class);
    NodeCreator<BoundaryEventNode> boundaryNodeCreator = new NodeCreator<BoundaryEventNode>(process, BoundaryEventNode.class);
    NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(process, ActionNode.class);
    // Create process
    StartNode startNode = startNodeCreator.createNode("start");
    Node lastNode = startNode;
    WorkItemNode[] workItemNodes = new WorkItemNode[3];
    for (int i = 0; i < 3; ++i) {
        workItemNodes[i] = workItemNodeCreator.createNode("work" + (i + 1));
        workItemNodes[i].getWork().setName(workItemNames[i]);
        connect(lastNode, workItemNodes[i]);
        lastNode = workItemNodes[i];
    }
    EndNode endNode = endNodeCreator.createNode("end");
    connect(workItemNodes[2], endNode);
    // Compensation (boundary event) handlers
    for (int i = 0; i < 3; ++i) {
        createBoundaryEventCompensationHandler(process, workItemNodes[i], eventList, "" + i + 1);
    }
    return process;
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) Variable(org.jbpm.process.core.context.variable.Variable) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) EndNode(org.jbpm.workflow.core.node.EndNode) Node(org.jbpm.workflow.core.Node) ArrayList(java.util.ArrayList) ActionNode(org.jbpm.workflow.core.node.ActionNode) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) EndNode(org.jbpm.workflow.core.node.EndNode) NodeCreator(org.jbpm.process.test.NodeCreator) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode)

Example 20 with WorkItemNode

use of org.jbpm.workflow.core.node.WorkItemNode in project jbpm by kiegroup.

the class CompensationTest method createNestedCompensationEventSubProcessProcess.

private RuleFlowProcess createNestedCompensationEventSubProcessProcess(String processId, String[] workItemNames, final List<String> eventList) throws Exception {
    RuleFlowProcess process = new RuleFlowProcess();
    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
    CompositeContextNode compositeNode = compNodeCreator.createNode("sub0");
    {
        StartNode startNode = startNodeCreator.createNode("start0");
        WorkItemNode workItemNode = workItemNodeCreator.createNode("work0-pre");
        workItemNode.getWork().setName(workItemNames[0]);
        connect(startNode, workItemNode);
        connect(workItemNode, compositeNode);
        EndNode endNode = endNodeCreator.createNode("end0");
        connect(compositeNode, endNode);
    }
    // 1rst level nested subprocess (contains compensation visibility scope)
    CompositeContextNode compensationScopeContainerNode = compositeNode;
    {
        startNodeCreator.setNodeContainer(compositeNode);
        workItemNodeCreator.setNodeContainer(compositeNode);
        compNodeCreator.setNodeContainer(compositeNode);
        endNodeCreator.setNodeContainer(compositeNode);
        StartNode startNode = startNodeCreator.createNode("start1");
        CompositeContextNode subCompNode = compNodeCreator.createNode("sub1");
        connect(startNode, subCompNode);
        WorkItemNode workItemNode = workItemNodeCreator.createNode("work1-post");
        workItemNode.getWork().setName(workItemNames[2]);
        connect(subCompNode, workItemNode);
        EndNode endNode = endNodeCreator.createNode("end1");
        connect(workItemNode, endNode);
        compositeNode = subCompNode;
    }
    // 2nd level nested subprocess
    {
        startNodeCreator.setNodeContainer(compositeNode);
        workItemNodeCreator.setNodeContainer(compositeNode);
        endNodeCreator.setNodeContainer(compositeNode);
        StartNode startNode = startNodeCreator.createNode("start2");
        WorkItemNode workItemNode = workItemNodeCreator.createNode("work2");
        workItemNode.getWork().setName(workItemNames[1]);
        connect(startNode, workItemNode);
        EndNode endNode = endNodeCreator.createNode("end2");
        connect(workItemNode, endNode);
    }
    // 3nd level nested event subprocess in 2nd level subprocess
    {
        NodeCreator<EventSubProcessNode> espNodeCreator = new NodeCreator<EventSubProcessNode>(compositeNode, EventSubProcessNode.class);
        EventSubProcessNode espNode = espNodeCreator.createNode("eventSub2");
        startNodeCreator.setNodeContainer(espNode);
        endNodeCreator.setNodeContainer(espNode);
        NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(espNode, ActionNode.class);
        EventTypeFilter eventFilter = new NonAcceptingEventTypeFilter();
        eventFilter.setType("Compensation");
        espNode.addEvent(eventFilter);
        addCompensationScope(espNode, compensationScopeContainerNode, (String) compositeNode.getMetaData("UniqueId"));
        StartNode startNode = startNodeCreator.createNode("start3*");
        ActionNode actionNode = actionNodeCreator.createNode("action3*");
        actionNode.setName("Execute");
        DroolsAction action = new DroolsConsequenceAction("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 endNode = endNodeCreator.createNode("end3*");
        connect(actionNode, endNode);
    }
    return process;
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) DroolsAction(org.jbpm.workflow.core.DroolsAction) Action(org.jbpm.process.instance.impl.Action) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) ActionNode(org.jbpm.workflow.core.node.ActionNode) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) ProcessContext(org.kie.api.runtime.process.ProcessContext) NonAcceptingEventTypeFilter(org.jbpm.process.core.event.NonAcceptingEventTypeFilter) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) EndNode(org.jbpm.workflow.core.node.EndNode) NodeCreator(org.jbpm.process.test.NodeCreator) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode)

Aggregations

WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)33 EndNode (org.jbpm.workflow.core.node.EndNode)15 StartNode (org.jbpm.workflow.core.node.StartNode)15 Work (org.jbpm.process.core.Work)14 ActionNode (org.jbpm.workflow.core.node.ActionNode)13 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)12 ArrayList (java.util.ArrayList)10 WorkImpl (org.jbpm.process.core.impl.WorkImpl)10 SubProcessNode (org.jbpm.workflow.core.node.SubProcessNode)9 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)8 Variable (org.jbpm.process.core.context.variable.Variable)7 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)7 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)7 RuleSetNode (org.jbpm.workflow.core.node.RuleSetNode)7 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)6 EventSubProcessNode (org.jbpm.workflow.core.node.EventSubProcessNode)6 ForEachNode (org.jbpm.workflow.core.node.ForEachNode)6 NodeCreator (org.jbpm.process.test.NodeCreator)5 DroolsAction (org.jbpm.workflow.core.DroolsAction)5 Node (org.jbpm.workflow.core.Node)5