use of org.jbpm.workflow.core.node.EndNode 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.EndNode 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.EndNode 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.EndNode in project jbpm by kiegroup.
the class ProcessHandler method handleIntermediateOrEndThrowCompensationEvent.
protected void handleIntermediateOrEndThrowCompensationEvent(ExtendedNodeImpl throwEventNode) {
if (throwEventNode.getMetaData("compensation-activityRef") != null) {
String activityRef = (String) throwEventNode.getMetaData().remove("compensation-activityRef");
NodeContainer nodeParent = (NodeContainer) throwEventNode.getNodeContainer();
if (nodeParent instanceof EventSubProcessNode) {
boolean compensationEventSubProcess = false;
List<Trigger> startTriggers = ((EventSubProcessNode) nodeParent).findStartNode().getTriggers();
CESP_CHECK: for (Trigger trigger : startTriggers) {
if (trigger instanceof EventTrigger) {
for (EventFilter filter : ((EventTrigger) trigger).getEventFilters()) {
if (((EventTypeFilter) filter).getType().equals("Compensation")) {
compensationEventSubProcess = true;
break CESP_CHECK;
}
}
}
}
if (compensationEventSubProcess) {
// BPMN2 spec, p. 252, p. 248: intermediate and end compensation event visibility scope
nodeParent = (NodeContainer) ((NodeImpl) nodeParent).getNodeContainer();
}
}
String parentId;
if (nodeParent instanceof RuleFlowProcess) {
parentId = ((RuleFlowProcess) nodeParent).getId();
} else {
parentId = (String) ((NodeImpl) nodeParent).getMetaData("UniqueId");
}
String compensationEvent;
if (activityRef.length() == 0) {
// general/implicit compensation
compensationEvent = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + parentId;
} else {
// specific compensation
compensationEvent = activityRef;
}
DroolsConsequenceAction compensationAction = new DroolsConsequenceAction("java", PROCESS_INSTANCE_SIGNAL_EVENT + "Compensation\", \"" + compensationEvent + "\");");
if (throwEventNode instanceof ActionNode) {
((ActionNode) throwEventNode).setAction(compensationAction);
} else if (throwEventNode instanceof EndNode) {
List<DroolsAction> actions = new ArrayList<DroolsAction>();
actions.add(compensationAction);
((EndNode) throwEventNode).setActions(EndNode.EVENT_NODE_ENTER, actions);
}
}
}
use of org.jbpm.workflow.core.node.EndNode in project jbpm by kiegroup.
the class EndEventHandler method handleMessageNode.
@SuppressWarnings("unchecked")
public void handleMessageNode(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 ("dataInputAssociation".equals(nodeName)) {
readEndDataInputAssociation(xmlNode, endNode);
} else if ("messageEventDefinition".equals(nodeName)) {
String messageRef = ((Element) xmlNode).getAttribute("messageRef");
Map<String, Message> messages = (Map<String, Message>) ((ProcessBuildData) parser.getData()).getMetaData("Messages");
if (messages == null) {
throw new IllegalArgumentException("No messages found");
}
Message message = messages.get(messageRef);
if (message == null) {
throw new IllegalArgumentException("Could not find message " + messageRef);
}
String variable = (String) endNode.getMetaData("MappingVariable");
endNode.setMetaData("MessageType", message.getType());
List<DroolsAction> actions = new ArrayList<DroolsAction>();
actions.add(new DroolsConsequenceAction("java", "org.drools.core.process.instance.impl.WorkItemImpl workItem = new org.drools.core.process.instance.impl.WorkItemImpl();" + EOL + "workItem.setName(\"Send Task\");" + EOL + "workItem.setNodeInstanceId(kcontext.getNodeInstance().getId());" + EOL + "workItem.setProcessInstanceId(kcontext.getProcessInstance().getId());" + EOL + "workItem.setNodeId(kcontext.getNodeInstance().getNodeId());" + EOL + "workItem.setParameter(\"MessageType\", \"" + message.getType() + "\");" + EOL + (variable == null ? "" : "workItem.setParameter(\"Message\", " + variable + ");" + EOL) + "workItem.setDeploymentId((String) kcontext.getKnowledgeRuntime().getEnvironment().get(\"deploymentId\"));" + EOL + "((org.drools.core.process.instance.WorkItemManager) kcontext.getKnowledgeRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);"));
endNode.setActions(EndNode.EVENT_NODE_ENTER, actions);
}
xmlNode = xmlNode.getNextSibling();
}
}
Aggregations