Search in sources :

Example 1 with StartNode

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

the class StartNodeInstanceTest method testStartNode.

@Test
public void testStartNode() {
    KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    MockNode mockNode = new MockNode();
    MockNodeInstanceFactory mockNodeFactory = new MockNodeInstanceFactory(new MockNodeInstance(mockNode));
    NodeInstanceFactoryRegistry.getInstance(ksession.getEnvironment()).register(mockNode.getClass(), mockNodeFactory);
    RuleFlowProcess process = new RuleFlowProcess();
    StartNode startNode = new StartNode();
    startNode.setId(1);
    startNode.setName("start node");
    mockNode.setId(2);
    new ConnectionImpl(startNode, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE, mockNode, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
    process.addNode(startNode);
    process.addNode(mockNode);
    RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
    processInstance.setProcess(process);
    processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
    assertEquals(ProcessInstance.STATE_PENDING, processInstance.getState());
    processInstance.start();
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    MockNodeInstance mockNodeInstance = mockNodeFactory.getMockNodeInstance();
    List<NodeInstance> triggeredBy = mockNodeInstance.getTriggers().get(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
    assertNotNull(triggeredBy);
    assertEquals(1, triggeredBy.size());
    assertSame(startNode.getId(), triggeredBy.get(0).getNodeId());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) KieBase(org.kie.api.KieBase) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) KieSession(org.kie.api.runtime.KieSession) NodeInstance(org.kie.api.runtime.process.NodeInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 2 with StartNode

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

the class SingleSessionCommandServiceTest method getProcessTimer.

private List<KiePackage> getProcessTimer() {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId("org.drools.test.TestProcess");
    process.setName("TestProcess");
    process.setPackageName("org.drools.test");
    StartNode start = new StartNode();
    start.setId(1);
    start.setName("Start");
    process.addNode(start);
    TimerNode timerNode = new TimerNode();
    timerNode.setId(2);
    timerNode.setName("Timer");
    Timer timer = new Timer();
    timer.setDelay("2000");
    timerNode.setTimer(timer);
    process.addNode(timerNode);
    new ConnectionImpl(start, Node.CONNECTION_DEFAULT_TYPE, timerNode, Node.CONNECTION_DEFAULT_TYPE);
    ActionNode actionNode = new ActionNode();
    actionNode.setId(3);
    actionNode.setName("Action");
    DroolsConsequenceAction action = new DroolsConsequenceAction();
    action.setDialect("java");
    action.setConsequence("System.out.println(\"Executed action\");");
    actionNode.setAction(action);
    process.addNode(actionNode);
    new ConnectionImpl(timerNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
    EndNode end = new EndNode();
    end.setId(6);
    end.setName("End");
    process.addNode(end);
    new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, end, Node.CONNECTION_DEFAULT_TYPE);
    KnowledgeBuilderImpl packageBuilder = new KnowledgeBuilderImpl();
    ProcessBuilderImpl processBuilder = new ProcessBuilderImpl(packageBuilder);
    processBuilder.buildProcess(process, null);
    return Arrays.asList(packageBuilder.getPackages());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) Timer(org.jbpm.process.core.timer.Timer) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) EndNode(org.jbpm.workflow.core.node.EndNode) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) ActionNode(org.jbpm.workflow.core.node.ActionNode) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) TimerNode(org.jbpm.workflow.core.node.TimerNode) ProcessBuilderImpl(org.jbpm.compiler.ProcessBuilderImpl)

Example 3 with StartNode

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

the class VariablePersistenceStrategyTest method getKnowledgeBaseForExtendingInterfaceVariablePersistence.

private KieBase getKnowledgeBaseForExtendingInterfaceVariablePersistence(String processId, final String variableText) {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId(processId);
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("x");
    ObjectDataType extendingSerializableDataType = new ObjectDataType();
    extendingSerializableDataType.setClassName(MyVariableExtendingSerializable.class.getName());
    variable.setType(extendingSerializableDataType);
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    WorkItemNode workItemNode = new WorkItemNode();
    workItemNode.setName("workItemNode");
    workItemNode.setId(2);
    Work work = new WorkImpl();
    work.setName("MyWork");
    workItemNode.setWork(work);
    ActionNode actionNode = new ActionNode();
    actionNode.setName("Print");
    DroolsAction action = new DroolsConsequenceAction("java", null);
    action.setMetaData("Action", new Action() {

        public void execute(ProcessContext context) throws Exception {
            Assert.assertEquals(variableText, ((MyVariableExtendingSerializable) context.getVariable("x")).getText());
            ;
        }
    });
    actionNode.setAction(action);
    actionNode.setId(3);
    EndNode endNode = new EndNode();
    endNode.setName("EndNode");
    endNode.setId(4);
    connect(startNode, workItemNode);
    connect(workItemNode, actionNode);
    connect(actionNode, endNode);
    process.addNode(startNode);
    process.addNode(workItemNode);
    process.addNode(actionNode);
    process.addNode(endNode);
    KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    ((KnowledgeBaseImpl) kbase).addProcess(process);
    return kbase;
}
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) Variable(org.jbpm.process.core.context.variable.Variable) DroolsConsequenceAction(org.jbpm.workflow.core.impl.DroolsConsequenceAction) ArrayList(java.util.ArrayList) ActionNode(org.jbpm.workflow.core.node.ActionNode) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) KnowledgeBaseImpl(org.drools.core.impl.KnowledgeBaseImpl) ProcessContext(org.kie.api.runtime.process.ProcessContext) NamingException(javax.naming.NamingException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) HeuristicMixedException(javax.transaction.HeuristicMixedException) RollbackException(javax.transaction.RollbackException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) MyVariableExtendingSerializable(org.jbpm.persistence.session.objects.MyVariableExtendingSerializable) EndNode(org.jbpm.workflow.core.node.EndNode) KieBase(org.kie.api.KieBase) WorkItemNode(org.jbpm.workflow.core.node.WorkItemNode) Work(org.jbpm.process.core.Work) WorkImpl(org.jbpm.process.core.impl.WorkImpl)

Example 4 with StartNode

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

the class WorkItemPersistenceTest method getWorkItemProcess.

private RuleFlowProcess getWorkItemProcess(String processId, String workName) {
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId(processId);
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("UserName");
    variable.setType(new StringDataType());
    variables.add(variable);
    variable = new Variable();
    variable.setName("MyObject");
    variable.setType(new ObjectDataType());
    variables.add(variable);
    variable = new Variable();
    variable.setName("Number");
    variable.setType(new IntegerDataType());
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    HumanTaskNode workItemNode = new HumanTaskNode();
    workItemNode.setName("workItemNode");
    workItemNode.setId(2);
    workItemNode.addInMapping("Attachment", "MyObject");
    workItemNode.addOutMapping("Result", "MyObject");
    workItemNode.addOutMapping("Result.length()", "Number");
    Work work = new WorkImpl();
    work.setName(workName);
    Set<ParameterDefinition> parameterDefinitions = new HashSet<ParameterDefinition>();
    ParameterDefinition parameterDefinition = new ParameterDefinitionImpl("ActorId", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    parameterDefinition = new ParameterDefinitionImpl("Content", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    parameterDefinition = new ParameterDefinitionImpl("Comment", new StringDataType());
    parameterDefinitions.add(parameterDefinition);
    work.setParameterDefinitions(parameterDefinitions);
    work.setParameter("ActorId", "#{UserName}");
    work.setParameter("Content", "#{Person.name}");
    workItemNode.setWork(work);
    EndNode endNode = new EndNode();
    endNode.setName("End");
    endNode.setId(3);
    connect(startNode, workItemNode);
    connect(workItemNode, endNode);
    process.addNode(startNode);
    process.addNode(workItemNode);
    process.addNode(endNode);
    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) IntegerDataType(org.jbpm.process.core.datatype.impl.type.IntegerDataType) ArrayList(java.util.ArrayList) ObjectDataType(org.jbpm.process.core.datatype.impl.type.ObjectDataType) ParameterDefinitionImpl(org.jbpm.process.core.impl.ParameterDefinitionImpl) StringDataType(org.jbpm.process.core.datatype.impl.type.StringDataType) EndNode(org.jbpm.workflow.core.node.EndNode) Work(org.jbpm.process.core.Work) WorkImpl(org.jbpm.process.core.impl.WorkImpl) HumanTaskNode(org.jbpm.workflow.core.node.HumanTaskNode) ParameterDefinition(org.jbpm.process.core.ParameterDefinition) HashSet(java.util.HashSet)

Example 5 with StartNode

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

the class StartEventHandler method writeNode.

public void writeNode(Node node, StringBuilder xmlDump, int metaDataType) {
    StartNode startNode = (StartNode) node;
    writeNode("startEvent", startNode, xmlDump, metaDataType);
    xmlDump.append(" isInterrupting=\"");
    if (startNode.isInterrupting()) {
        xmlDump.append("true");
    } else {
        xmlDump.append("false");
    }
    xmlDump.append("\">" + EOL);
    writeExtensionElements(startNode, xmlDump);
    List<Trigger> triggers = startNode.getTriggers();
    if (triggers != null) {
        if (triggers.size() > 1) {
            throw new IllegalArgumentException("Multiple start triggers not supported");
        }
        Trigger trigger = triggers.get(0);
        if (trigger instanceof ConstraintTrigger) {
            ConstraintTrigger constraintTrigger = (ConstraintTrigger) trigger;
            if (constraintTrigger.getHeader() == null) {
                xmlDump.append("      <conditionalEventDefinition>" + EOL);
                xmlDump.append("        <condition xsi:type=\"tFormalExpression\" language=\"" + XmlBPMNProcessDumper.RULE_LANGUAGE + "\">" + constraintTrigger.getConstraint() + "</condition>" + EOL);
                xmlDump.append("      </conditionalEventDefinition>" + EOL);
            }
        } else if (trigger instanceof EventTrigger) {
            EventTrigger eventTrigger = (EventTrigger) trigger;
            String mapping = null;
            String nameMapping = "event";
            if (!trigger.getInMappings().isEmpty()) {
                mapping = eventTrigger.getInMappings().keySet().iterator().next();
                nameMapping = eventTrigger.getInMappings().values().iterator().next();
            } else {
                mapping = (String) startNode.getMetaData("TriggerMapping");
            }
            if (mapping != null) {
                xmlDump.append("      <dataOutput id=\"_" + startNode.getId() + "_Output\" name=\"" + nameMapping + "\" />" + EOL + "      <dataOutputAssociation>" + EOL + "        <sourceRef>_" + startNode.getId() + "_Output</sourceRef>" + EOL + "        <targetRef>" + mapping + "</targetRef>" + EOL + "      </dataOutputAssociation>" + EOL);
            }
            String type = ((EventTypeFilter) eventTrigger.getEventFilters().get(0)).getType();
            if (type.startsWith("Message-")) {
                type = type.substring(8);
                xmlDump.append("      <messageEventDefinition messageRef=\"" + type + "\"/>" + EOL);
            } else if (type.startsWith("Error-")) {
                type = type.substring(6);
                String errorId = getErrorIdForErrorCode(type, startNode);
                xmlDump.append("      <errorEventDefinition errorRef=\"" + XmlBPMNProcessDumper.replaceIllegalCharsAttribute(errorId) + "\"/>" + EOL);
            } else if (type.startsWith("Escalation-")) {
                type = type.substring(11);
                xmlDump.append("      <escalationEventDefinition escalationRef=\"" + type + "\"/>" + EOL);
            } else if (type.equals("Compensation")) {
                xmlDump.append("      <compensateEventDefinition/>" + EOL);
            } else {
                xmlDump.append("      <signalEventDefinition signalRef=\"" + type + "\" />" + EOL);
            }
        } else {
            throw new IllegalArgumentException("Unsupported trigger type " + trigger);
        }
        if (startNode.getTimer() != null) {
            Timer timer = startNode.getTimer();
            xmlDump.append("      <timerEventDefinition>" + EOL);
            if (timer != null && (timer.getDelay() != null || timer.getDate() != null)) {
                if (timer.getTimeType() == Timer.TIME_DATE) {
                    xmlDump.append("        <timeDate xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDate()) + "</timeDate>" + EOL);
                } else if (timer.getTimeType() == Timer.TIME_DURATION) {
                    xmlDump.append("        <timeDuration xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeDuration>" + EOL);
                } else if (timer.getTimeType() == Timer.TIME_CYCLE) {
                    if (timer.getPeriod() != null) {
                        xmlDump.append("        <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "###" + XmlDumper.replaceIllegalChars(timer.getPeriod()) + "</timeCycle>" + EOL);
                    } else {
                        xmlDump.append("        <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeCycle>" + EOL);
                    }
                } else if (timer.getTimeType() == Timer.TIME_DATE) {
                    xmlDump.append("        <timeDate xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeDate>" + EOL);
                }
            }
            xmlDump.append("      </timerEventDefinition>" + EOL);
        }
    } else if (startNode.getTimer() != null) {
        Timer timer = startNode.getTimer();
        xmlDump.append("      <timerEventDefinition>" + EOL);
        if (timer != null && (timer.getDelay() != null || timer.getDate() != null)) {
            if (timer.getTimeType() == Timer.TIME_DATE) {
                xmlDump.append("        <timeDate xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDate()) + "</timeDate>" + EOL);
            } else if (timer.getTimeType() == Timer.TIME_DURATION) {
                xmlDump.append("        <timeDuration xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeDuration>" + EOL);
            } else if (timer.getTimeType() == Timer.TIME_CYCLE) {
                if (timer.getPeriod() != null) {
                    xmlDump.append("        <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "###" + XmlDumper.replaceIllegalChars(timer.getPeriod()) + "</timeCycle>" + EOL);
                } else {
                    xmlDump.append("        <timeCycle xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeCycle>" + EOL);
                }
            } else if (timer.getTimeType() == Timer.TIME_DATE) {
                xmlDump.append("        <timeDate xsi:type=\"tFormalExpression\">" + XmlDumper.replaceIllegalChars(timer.getDelay()) + "</timeDate>" + EOL);
            }
        }
        xmlDump.append("      </timerEventDefinition>" + EOL);
    }
    endNode("startEvent", xmlDump);
}
Also used : ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) StartNode(org.jbpm.workflow.core.node.StartNode) ConstraintTrigger(org.jbpm.workflow.core.node.ConstraintTrigger) EventTrigger(org.jbpm.workflow.core.node.EventTrigger) Trigger(org.jbpm.workflow.core.node.Trigger) Timer(org.jbpm.process.core.timer.Timer) EventTrigger(org.jbpm.workflow.core.node.EventTrigger)

Aggregations

StartNode (org.jbpm.workflow.core.node.StartNode)47 EndNode (org.jbpm.workflow.core.node.EndNode)34 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)32 ActionNode (org.jbpm.workflow.core.node.ActionNode)30 ArrayList (java.util.ArrayList)25 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)24 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)19 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)18 Test (org.junit.Test)18 DroolsAction (org.jbpm.workflow.core.DroolsAction)17 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)17 Action (org.jbpm.process.instance.impl.Action)16 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)16 EventNode (org.jbpm.workflow.core.node.EventNode)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 Work (org.jbpm.process.core.Work)11 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)11