Search in sources :

Example 21 with EndNode

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

the class EndEventHandler method handleSignalNode.

public void handleSignalNode(final Node node, final Element element, final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
    EndNode endNode = (EndNode) node;
    org.w3c.dom.Node xmlNode = element.getFirstChild();
    while (xmlNode != null) {
        String nodeName = xmlNode.getNodeName();
        if ("dataInput".equals(nodeName)) {
            String id = ((Element) xmlNode).getAttribute("id");
            String inputName = ((Element) xmlNode).getAttribute("name");
            dataInputs.put(id, inputName);
        } else if ("dataInputAssociation".equals(nodeName)) {
            readEndDataInputAssociation(xmlNode, endNode);
        } else if ("signalEventDefinition".equals(nodeName)) {
            String signalName = ((Element) xmlNode).getAttribute("signalRef");
            String variable = (String) endNode.getMetaData("MappingVariable");
            signalName = checkSignalAndConvertToRealSignalNam(parser, signalName);
            endNode.setMetaData("EventType", "signal");
            endNode.setMetaData("Ref", signalName);
            endNode.setMetaData("Variable", variable);
            // check if signal should be send async
            if (dataInputs.containsValue("async")) {
                signalName = "ASYNC-" + signalName;
            }
            String signalExpression = getSignalExpression(endNode, signalName, variable);
            List<DroolsAction> actions = new ArrayList<DroolsAction>();
            actions.add(new DroolsConsequenceAction("mvel", signalExpression));
            endNode.setActions(EndNode.EVENT_NODE_ENTER, actions);
        }
        xmlNode = xmlNode.getNextSibling();
    }
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) EndNode(org.jbpm.workflow.core.node.EndNode) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList)

Example 22 with EndNode

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

the class EndEventHandler method createNode.

protected Node createNode(Attributes attrs) {
    EndNode node = new EndNode();
    node.setTerminate(false);
    return node;
}
Also used : EndNode(org.jbpm.workflow.core.node.EndNode)

Example 23 with EndNode

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

the class EndNodeHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
    EndNode endNode = (EndNode) node;
    String eventType = (String) endNode.getMetaData("EventType");
    String ref = (String) endNode.getMetaData("Ref");
    String variableRef = (String) endNode.getMetaData("Variable");
    writeNode("endEvent", endNode, xmlDump, metaDataType);
    if (endNode.isTerminate()) {
        xmlDump.append(">" + EOL);
        writeExtensionElements(endNode, xmlDump);
        xmlDump.append("        <terminateEventDefinition " + (endNode.getScope() == EndNode.PROCESS_SCOPE ? "tns:scope=\"process\"" : "") + "/>" + EOL);
        endNode("endEvent", xmlDump);
    } else {
        String scope = (String) endNode.getMetaData("customScope");
        List<DroolsAction> actions = endNode.getActions(EndNode.EVENT_NODE_ENTER);
        if (actions != null && !actions.isEmpty()) {
            if (actions.size() == 1) {
                DroolsConsequenceAction action = (DroolsConsequenceAction) actions.get(0);
                String s = action.getConsequence();
                if (s.startsWith("org.drools.core.process.instance.impl.WorkItemImpl workItem = new org.drools.core.process.instance.impl.WorkItemImpl();")) {
                    xmlDump.append(">" + EOL);
                    writeExtensionElements(endNode, xmlDump);
                    String variable = (String) endNode.getMetaData("MappingVariable");
                    if (variable != null) {
                        xmlDump.append("      <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + "      <dataInputAssociation>" + EOL + "        <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + "        <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + "      </dataInputAssociation>" + EOL + "      <inputSet>" + EOL + "        <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + "      </inputSet>" + EOL);
                    }
                    xmlDump.append("      <messageEventDefinition messageRef=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Message\"/>" + EOL);
                    endNode("endEvent", xmlDump);
                } else if ("signal".equals(eventType)) {
                    xmlDump.append(">" + EOL);
                    writeExtensionElements(endNode, xmlDump);
                    if (!s.startsWith("null")) {
                        xmlDump.append("      <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + "      <dataInputAssociation>" + EOL + "        <sourceRef>" + XmlDumper.replaceIllegalChars(variableRef) + "</sourceRef>" + EOL + "        <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + "      </dataInputAssociation>" + EOL + "      <inputSet>" + EOL + "        <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + "      </inputSet>" + EOL);
                    }
                    xmlDump.append("      <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(ref) + "\"/>" + EOL);
                    endNode("endEvent", xmlDump);
                } else if (s.startsWith(RUNTIME_SIGNAL_EVENT)) {
                    xmlDump.append(">" + EOL);
                    writeExtensionElements(endNode, xmlDump);
                    s = s.substring(44);
                    String type = s.substring(0, s.indexOf("\""));
                    s = s.substring(s.indexOf(",") + 2);
                    String variable = null;
                    if (!s.startsWith("null")) {
                        variable = s.substring(0, s.indexOf(")"));
                        xmlDump.append("      <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + "      <dataInputAssociation>" + EOL + "        <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + "        <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + "      </dataInputAssociation>" + EOL + "      <inputSet>" + EOL + "        <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + "      </inputSet>" + EOL);
                    }
                    xmlDump.append("      <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\"/>" + EOL);
                    endNode("endEvent", xmlDump);
                } else if (s.startsWith(PROCESS_INSTANCE_SIGNAL_EVENT) && "processInstance".equals(scope)) {
                    xmlDump.append(">" + EOL);
                    writeExtensionElements(endNode, xmlDump);
                    s = s.substring(43);
                    String type = s.substring(0, s.indexOf("\""));
                    s = s.substring(s.indexOf(",") + 2);
                    String variable = null;
                    if (!s.startsWith("null")) {
                        variable = s.substring(0, s.indexOf(")"));
                        xmlDump.append("      <dataInput id=\"" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input\" />" + EOL + "      <dataInputAssociation>" + EOL + "        <sourceRef>" + XmlDumper.replaceIllegalChars(variable) + "</sourceRef>" + EOL + "        <targetRef>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</targetRef>" + EOL + "      </dataInputAssociation>" + EOL + "      <inputSet>" + EOL + "        <dataInputRefs>" + XmlBPMNProcessDumper.getUniqueNodeId(endNode) + "_Input</dataInputRefs>" + EOL + "      </inputSet>" + EOL);
                    }
                    xmlDump.append("      <signalEventDefinition signalRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(type) + "\"/>" + EOL);
                    endNode("endEvent", xmlDump);
                } else if (s.startsWith(PROCESS_INSTANCE_SIGNAL_EVENT)) {
                    xmlDump.append(">" + EOL);
                    writeExtensionElements(endNode, xmlDump);
                    int begin = (PROCESS_INSTANCE_SIGNAL_EVENT + "Compensation\", ").length() - 2;
                    int end = s.length() - 3;
                    String compensationEvent = s.substring(begin, end);
                    String activityRef = "";
                    if (!compensationEvent.startsWith(CompensationScope.IMPLICIT_COMPENSATION_PREFIX)) {
                        // specific
                        activityRef = "activityRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(activityRef) + "\" ";
                    }
                    // else general: activityRef = "" (above)
                    xmlDump.append("      <compensateEventDefinition " + activityRef + "/>" + EOL);
                    endNode("endEvent", xmlDump);
                } else {
                    throw new IllegalArgumentException("Unknown action " + s);
                }
            }
        } else {
            endNode(xmlDump);
        }
    }
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) EndNode(org.jbpm.workflow.core.node.EndNode) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction)

Example 24 with EndNode

use of org.jbpm.workflow.core.node.EndNode 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 25 with EndNode

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

the class EndNodeInstanceTest method testEndNode.

@Test
public void testEndNode() {
    KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    MockNode mockNode = new MockNode();
    MockNodeInstanceFactory factory = new MockNodeInstanceFactory(new MockNodeInstance(mockNode));
    NodeInstanceFactoryRegistry.getInstance(ksession.getEnvironment()).register(mockNode.getClass(), factory);
    WorkflowProcessImpl process = new WorkflowProcessImpl();
    Node endNode = new EndNode();
    endNode.setId(1);
    endNode.setName("end node");
    mockNode.setId(2);
    new ConnectionImpl(mockNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    process.addNode(mockNode);
    process.addNode(endNode);
    RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
    processInstance.setState(ProcessInstance.STATE_ACTIVE);
    processInstance.setProcess(process);
    processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
    MockNodeInstance mockNodeInstance = (MockNodeInstance) processInstance.getNodeInstance(mockNode);
    mockNodeInstance.triggerCompleted();
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) EndNode(org.jbpm.workflow.core.node.EndNode) KieBase(org.kie.api.KieBase) EndNode(org.jbpm.workflow.core.node.EndNode) Node(org.jbpm.workflow.core.Node) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

EndNode (org.jbpm.workflow.core.node.EndNode)42 StartNode (org.jbpm.workflow.core.node.StartNode)32 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)30 ActionNode (org.jbpm.workflow.core.node.ActionNode)29 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)27 ArrayList (java.util.ArrayList)25 DroolsAction (org.jbpm.workflow.core.DroolsAction)21 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)19 Test (org.junit.Test)18 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)16 Action (org.jbpm.process.instance.impl.Action)16 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)16 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)16 KieSession (org.kie.api.runtime.KieSession)16 ProcessContext (org.kie.api.runtime.process.ProcessContext)16 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)15 Variable (org.jbpm.process.core.context.variable.Variable)14 EventNode (org.jbpm.workflow.core.node.EventNode)13 Work (org.jbpm.process.core.Work)10 TestProcessEventListener (org.jbpm.process.test.TestProcessEventListener)10