Search in sources :

Example 21 with WorkItemNode

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

the class CompensationTest method createNestedCompensationBoundaryEventProcess.

private RuleFlowProcess createNestedCompensationBoundaryEventProcess(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<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 : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) Variable(org.jbpm.process.core.context.variable.Variable) CompositeContextNode(org.jbpm.workflow.core.node.CompositeContextNode) 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) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) EndNode(org.jbpm.workflow.core.node.EndNode) NodeCreator(org.jbpm.process.test.NodeCreator) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode)

Example 22 with WorkItemNode

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

the class EventSubProcessTest method testNestedEventSubProcess.

@Test
public void testNestedEventSubProcess() throws Exception {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setAutoComplete(true);
    String processId = "org.jbpm.process.event.subprocess";
    process.setId(processId);
    process.setName("Event SubProcess Process");
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("event");
    ObjectDataType personDataType = new ObjectDataType();
    personDataType.setClassName("org.drools.Person");
    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<CompositeNode> compNodeCreator = new NodeCreator<CompositeNode>(process, CompositeNode.class);
    // outer process
    StartNode startNode = startNodeCreator.createNode("start0");
    CompositeNode compositeNode = compNodeCreator.createNode("comp0");
    connect(startNode, compositeNode);
    EndNode endNode = endNodeCreator.createNode("end0");
    connect(compositeNode, endNode);
    // 1rst level nested subprocess
    startNodeCreator.setNodeContainer(compositeNode);
    endNodeCreator.setNodeContainer(compositeNode);
    compNodeCreator.setNodeContainer(compositeNode);
    startNode = startNodeCreator.createNode("start1");
    compositeNode = compNodeCreator.createNode("comp1");
    connect(startNode, compositeNode);
    endNode = endNodeCreator.createNode("end1");
    connect(compositeNode, endNode);
    // 2nd level subprocess
    startNodeCreator.setNodeContainer(compositeNode);
    endNodeCreator.setNodeContainer(compositeNode);
    NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(compositeNode, WorkItemNode.class);
    startNode = startNodeCreator.createNode("start2");
    WorkItemNode workItemNode = workItemNodeCreator.createNode("workItem2");
    Work work = new WorkImpl();
    String workItemName = "play";
    work.setName(workItemName);
    workItemNode.setWork(work);
    connect(startNode, workItemNode);
    endNode = endNodeCreator.createNode("end2");
    connect(workItemNode, endNode);
    // (3rd level) event sub process in 2nd level subprocess
    NodeCreator<EventSubProcessNode> espNodeCreator = new NodeCreator<EventSubProcessNode>(compositeNode, EventSubProcessNode.class);
    EventSubProcessNode espNode = espNodeCreator.createNode("eventSub2");
    EventTypeFilter eventFilter = new EventTypeFilter();
    String EVENT_NAME = "subEvent";
    eventFilter.setType(EVENT_NAME);
    espNode.addEvent(eventFilter);
    startNodeCreator.setNodeContainer(espNode);
    endNodeCreator.setNodeContainer(espNode);
    NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(espNode, ActionNode.class);
    startNode = startNodeCreator.createNode("start3*");
    ActionNode actionNode = actionNodeCreator.createNode("print3*");
    actionNode.setName("Print");
    final List<String> eventList = new ArrayList<String>();
    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("end3*");
    connect(actionNode, endNode);
    // run process
    KieSession ksession = createKieSession(process);
    TestProcessEventListener procEventListener = new TestProcessEventListener();
    ksession.addEventListener(procEventListener);
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    ksession.getWorkItemManager().registerWorkItemHandler(workItemName, workItemHandler);
    ProcessInstance processInstance = ksession.startProcess(processId);
    processInstance.signalEvent(EVENT_NAME, null);
    assertEquals("Event " + EVENT_NAME + " did not fire!", 1, eventList.size());
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    verifyEventHistory(nestedEventOrder, procEventListener.getEventHistory());
}
Also used : TestWorkItemHandler(org.jbpm.process.test.TestWorkItemHandler) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) DroolsAction(org.jbpm.workflow.core.DroolsAction) Action(org.jbpm.process.instance.impl.Action) Variable(org.jbpm.process.core.context.variable.Variable) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) EventSubProcessNode(org.jbpm.workflow.core.node.EventSubProcessNode) ArrayList(java.util.ArrayList) ActionNode(org.jbpm.workflow.core.node.ActionNode) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) ProcessContext(org.kie.api.runtime.process.ProcessContext) EventTypeFilter(org.jbpm.process.core.event.EventTypeFilter) 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) DroolsAction(org.jbpm.workflow.core.DroolsAction) StartNode(org.jbpm.workflow.core.node.StartNode) CompositeNode(org.jbpm.workflow.core.node.CompositeNode) EndNode(org.jbpm.workflow.core.node.EndNode) NodeCreator(org.jbpm.process.test.NodeCreator) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) TestProcessEventListener(org.jbpm.process.test.TestProcessEventListener) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 23 with WorkItemNode

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

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(org.jbpm.workflow.core.node.WorkItemNode) Work(org.jbpm.process.core.Work)

Example 24 with WorkItemNode

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

the class TaskHandler method end.

public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    final Element element = parser.endElementBuilder();
    Node node = (Node) parser.getCurrent();
    // determine type of event definition, so the correct type of node can be generated
    handleNode(node, element, uri, localName, parser);
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    int uniqueIdGen = 1;
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("multiInstanceLoopCharacteristics".equals(nodeName)) {
            // create new timerNode
            ForEachNode forEachNode = new ForEachNode();
            forEachNode.setId(node.getId());
            String uniqueId = (String) node.getMetaData().get("UniqueId");
            forEachNode.setMetaData("UniqueId", uniqueId);
            node.setMetaData("UniqueId", uniqueId + ":" + uniqueIdGen++);
            forEachNode.addNode(node);
            forEachNode.linkIncomingConnections(NodeImpl.CONNECTION_DEFAULT_TYPE, node.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE);
            forEachNode.linkOutgoingConnections(node.getId(), NodeImpl.CONNECTION_DEFAULT_TYPE, NodeImpl.CONNECTION_DEFAULT_TYPE);
            Node orignalNode = node;
            node = forEachNode;
            handleForEachNode(node, element, uri, localName, parser);
            // remove output collection data output of for each to avoid problems when running in variable strict mode
            if (orignalNode instanceof WorkItemNode) {
                ((WorkItemNode) orignalNode).adjustOutMapping(forEachNode.getOutputCollectionExpression());
            }
            break;
        }
        xmlNode = xmlNode.getNextSibling();
    }
    // replace node in case it's milestone
    if (node instanceof WorkItemNode && ((WorkItemNode) node).getWork().getName().equals("Milestone")) {
        WorkItemNode workItemNode = (WorkItemNode) node;
        String milestoneCondition = (String) ((WorkItemNode) node).getWork().getParameter("Condition");
        if (milestoneCondition == null) {
            // if not given that means once activated it's achieved
            milestoneCondition = "";
        }
        MilestoneNode milestoneNode = new MilestoneNode();
        milestoneNode.setId(workItemNode.getId());
        milestoneNode.setConstraint(milestoneCondition);
        milestoneNode.setMetaData(workItemNode.getMetaData());
        milestoneNode.setName(workItemNode.getName());
        milestoneNode.setNodeContainer(workItemNode.getNodeContainer());
        node = milestoneNode;
    }
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    nodeContainer.addNode(node);
    ((ProcessBuildData) parser.getData()).addNode(node);
    return node;
}
Also used : ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData) Element(org.w3c.dom.Element) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Node(org.jbpm.workflow.core.Node) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) ForEachNode(org.jbpm.workflow.core.node.ForEachNode) NodeContainer(org.jbpm.workflow.core.NodeContainer) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode)

Example 25 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, int metaDataType) {
    WorkItemNode workItemNode = (WorkItemNode) node;
    String type = workItemNode.getWork().getName();
    if ("Manual Task".equals(type)) {
        writeNode("manualTask", workItemNode, xmlDump, metaDataType);
        xmlDump.append(">" + EOL);
        writeExtensionElements(workItemNode, xmlDump);
        endNode("manualTask", xmlDump);
        return;
    }
    if ("Service Task".equals(type)) {
        writeNode("serviceTask", workItemNode, xmlDump, metaDataType);
        String impl = "Other";
        if (workItemNode.getWork().getParameter("implementation") != null) {
            impl = (String) workItemNode.getWork().getParameter("implementation");
        }
        xmlDump.append("operationRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_ServiceOperation\" implementation=\"" + impl + "\" >" + EOL);
        writeExtensionElements(workItemNode, xmlDump);
        xmlDump.append("      <ioSpecification>" + EOL + "        <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param\" name=\"Parameter\" />" + EOL + "        <dataOutput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result\" name=\"Result\" />" + EOL + "        <inputSet>" + EOL + "          <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param</dataInputRefs>" + EOL + "        </inputSet>" + EOL + "        <outputSet>" + EOL + "          <dataOutputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result</dataOutputRefs>" + EOL + "        </outputSet>" + EOL + "      </ioSpecification>" + EOL);
        String inMapping = workItemNode.getInMapping("Parameter");
        if (inMapping != null) {
            xmlDump.append("      <dataInputAssociation>" + EOL + "        <sourceRef>" + XmlDumper.replaceIllegalChars(inMapping) + "</sourceRef>" + EOL + "        <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param</targetRef>" + EOL + "      </dataInputAssociation>" + EOL);
        }
        String outMapping = workItemNode.getOutMapping("Result");
        if (outMapping != null) {
            xmlDump.append("      <dataOutputAssociation>" + EOL + "        <sourceRef>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result</sourceRef>" + EOL + "        <targetRef>" + XmlDumper.replaceIllegalChars(outMapping) + "</targetRef>" + EOL + "      </dataOutputAssociation>" + EOL);
        }
        endNode("serviceTask", xmlDump);
        return;
    }
    if ("Send Task".equals(type)) {
        writeNode("sendTask", workItemNode, xmlDump, metaDataType);
        xmlDump.append("messageRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_Message\" implementation=\"Other\" >" + EOL);
        writeExtensionElements(workItemNode, xmlDump);
        xmlDump.append("      <ioSpecification>" + EOL + "        <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param\" name=\"Message\" />" + EOL + "        <inputSet>" + EOL + "          <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param</dataInputRefs>" + EOL + "        </inputSet>" + EOL + "        <outputSet/>" + EOL + "      </ioSpecification>" + EOL);
        String inMapping = workItemNode.getInMapping("Message");
        if (inMapping != null) {
            xmlDump.append("      <dataInputAssociation>" + EOL + "        <sourceRef>" + XmlDumper.replaceIllegalChars(inMapping) + "</sourceRef>" + EOL + "        <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_param</targetRef>" + EOL + "      </dataInputAssociation>" + EOL);
        }
        endNode("sendTask", xmlDump);
        return;
    }
    if ("Receive Task".equals(type)) {
        writeNode("receiveTask", workItemNode, xmlDump, metaDataType);
        String messageId = (String) workItemNode.getWork().getParameter("MessageId");
        xmlDump.append("messageRef=\"" + messageId + "\" implementation=\"Other\" >" + EOL);
        writeExtensionElements(workItemNode, xmlDump);
        xmlDump.append("      <ioSpecification>" + EOL + "        <dataOutput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result\" name=\"Message\" />" + EOL + "        <inputSet/>" + EOL + "        <outputSet>" + EOL + "          <dataOutputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result</dataOutputRefs>" + EOL + "        </outputSet>" + EOL + "      </ioSpecification>" + EOL);
        String outMapping = workItemNode.getOutMapping("Message");
        if (outMapping != null) {
            xmlDump.append("      <dataOutputAssociation>" + EOL + "        <sourceRef>" + XmlBPMNProcessDumper.getUniqueNodeId(workItemNode) + "_result</sourceRef>" + EOL + "        <targetRef>" + XmlDumper.replaceIllegalChars(outMapping) + "</targetRef>" + EOL + "      </dataOutputAssociation>" + EOL);
        }
        endNode("receiveTask", xmlDump);
        return;
    }
    writeNode("task", workItemNode, xmlDump, metaDataType);
    Object isForCompensationObject = workItemNode.getMetaData("isForCompensation");
    if (isForCompensationObject != null && ((Boolean) isForCompensationObject)) {
        xmlDump.append("isForCompensation=\"true\" ");
    }
    xmlDump.append("tns:taskName=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\" >" + EOL);
    writeExtensionElements(workItemNode, xmlDump);
    writeIO(workItemNode, xmlDump);
    endNode("task", xmlDump);
}
Also used : 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