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());
}
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());
}
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;
}
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;
}
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);
}
Aggregations