use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class ProcessHandler method start.
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
String id = attrs.getValue("id");
String name = attrs.getValue("name");
String packageName = attrs.getValue("http://www.jboss.org/drools", "packageName");
String dynamic = attrs.getValue("http://www.jboss.org/drools", "adHoc");
String version = attrs.getValue("http://www.jboss.org/drools", "version");
RuleFlowProcess process = new RuleFlowProcess();
process.setAutoComplete(true);
process.setId(id);
if (name == null) {
name = id;
}
process.setName(name);
process.setType("RuleFlow");
if (packageName == null) {
packageName = "org.drools.bpmn2";
}
process.setPackageName(packageName);
if ("true".equals(dynamic)) {
process.setDynamic(true);
process.setAutoComplete(false);
}
if (version != null) {
process.setVersion(version);
}
((ProcessBuildData) parser.getData()).addProcess(process);
// register the definitions object as metadata of process.
process.setMetaData("Definitions", parser.getParent());
// register bpmn2 imports as meta data of process
Object typedImports = ((ProcessBuildData) parser.getData()).getMetaData("Bpmn2Imports");
if (typedImports != null) {
process.setMetaData("Bpmn2Imports", typedImports);
}
// register item definitions as meta data of process
Object itemDefinitions = ((ProcessBuildData) parser.getData()).getMetaData("ItemDefinitions");
if (itemDefinitions != null) {
process.setMetaData("ItemDefinitions", itemDefinitions);
}
// for unique id's of nodes, start with one to avoid returning wrong nodes for dynamic nodes
parser.getMetaData().put("idGen", new AtomicInteger(1));
return process;
}
use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class ProcessHandler method end.
@SuppressWarnings("unchecked")
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
parser.endElementBuilder();
RuleFlowProcess process = (RuleFlowProcess) parser.getCurrent();
List<IntermediateLink> throwLinks = (List<IntermediateLink>) process.getMetaData(LINKS);
linkIntermediateLinks(process, throwLinks);
List<SequenceFlow> connections = (List<SequenceFlow>) process.getMetaData(CONNECTIONS);
linkConnections(process, connections);
linkBoundaryEvents(process);
// This must be done *after* linkConnections(process, connections)
// because it adds hidden connections for compensations
List<Association> associations = (List<Association>) process.getMetaData(ASSOCIATIONS);
linkAssociations((Definitions) process.getMetaData("Definitions"), process, associations);
List<Lane> lanes = (List<Lane>) process.getMetaData(LaneHandler.LANES);
assignLanes(process, lanes);
postProcessNodes(process, process);
return process;
}
use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class XMLBPMNProcessDumperTest method testConditionExpression.
/**
* TESTS
*/
@Test
public void testConditionExpression() throws Exception {
// JBPM-4069 : XmlBPMNProcessDumper.dump() misses conditionExpression in sequenceFlow
String filename = "BPMN2-GatewaySplit-SequenceConditions.bpmn2";
String original = BPMN2XMLTest.slurp(XMLBPMNProcessDumperTest.class.getResourceAsStream("/" + filename));
KieBase kbase = createKnowledgeBase(filename);
RuleFlowProcess process = (RuleFlowProcess) kbase.getProcess("GatewayTest");
String result = XmlBPMNProcessDumper.INSTANCE.dump(process, XmlBPMNProcessDumper.META_DATA_USING_DI);
// Compare original with result using XMLUnit
Diff diff = new Diff(original, result);
diff.overrideDifferenceListener(new DifferenceListener() {
public int differenceFound(Difference diff) {
String nodeName = diff.getTestNodeDetail().getNode().getNodeName();
if (nodeName.equals("conditionExpression") || nodeName.equals("language")) {
logger.info(diff.toString());
return RETURN_ACCEPT_DIFFERENCE;
}
return RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL;
}
public void skippedComparison(Node one, Node two) {
logger.info("{} : {}", one.getLocalName(), two.getLocalName());
}
});
assertTrue("Original and generated output is not the same.", diff.identical());
}
use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class DynamicProcessTest method testDynamicProcess.
@Test
public void testDynamicProcess() throws Exception {
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.HelloWorld");
factory.name("HelloWorldProcess").version("1.0").packageName("org.jbpm").startNode(1).name("Start").done().humanTaskNode(2).name("Task1").actorId("krisv").taskName("MyTask").done().endNode(3).name("End").done().connection(1, 2).connection(2, 3);
final RuleFlowProcess process = factory.validate().getProcess();
Resource resource = ResourceFactory.newByteArrayResource(XmlRuleFlowProcessDumper.INSTANCE.dump(process).getBytes());
// source path or target path must be set to be added into kbase
resource.setSourcePath("/tmp/dynamicProcess.bpmn2");
KieBase kbase = createKnowledgeBaseFromResources(resource);
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler testHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", testHandler);
ksession.addEventListener(new ProcessEventListener() {
public void beforeVariableChanged(ProcessVariableChangedEvent arg0) {
}
public void beforeProcessStarted(ProcessStartedEvent arg0) {
logger.info("{}", arg0);
}
public void beforeProcessCompleted(ProcessCompletedEvent arg0) {
logger.info("{}", arg0);
}
public void beforeNodeTriggered(ProcessNodeTriggeredEvent arg0) {
logger.info("{}", arg0);
}
public void beforeNodeLeft(ProcessNodeLeftEvent arg0) {
logger.info("{}", arg0);
}
public void afterVariableChanged(ProcessVariableChangedEvent arg0) {
}
public void afterProcessStarted(ProcessStartedEvent arg0) {
}
public void afterProcessCompleted(ProcessCompletedEvent arg0) {
}
public void afterNodeTriggered(ProcessNodeTriggeredEvent arg0) {
}
public void afterNodeLeft(ProcessNodeLeftEvent arg0) {
}
});
final ProcessInstanceImpl processInstance = (ProcessInstanceImpl) ksession.startProcess("org.jbpm.HelloWorld");
HumanTaskNode node = new HumanTaskNode();
node.setName("Task2");
node.setId(4);
insertNodeInBetween(process, 2, 3, node);
((CommandBasedStatefulKnowledgeSession) ksession).getRunner().execute(new ExecutableCommand<Void>() {
public Void execute(Context context) {
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup(KieSession.class);
((ProcessInstanceImpl) ksession.getProcessInstance(processInstance.getId())).updateProcess(process);
return null;
}
});
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
ksession.dispose();
}
use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class BPMNPlaneHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
parser.endElementBuilder();
ProcessInfo processInfo = (ProcessInfo) parser.getCurrent();
List<Process> processes = ((ProcessBuildData) parser.getData()).getProcesses();
RuleFlowProcess process = null;
for (Process p : processes) {
if (p.getId() != null && p.getId().equals(processInfo.getProcessRef())) {
process = (RuleFlowProcess) p;
break;
}
}
if (process != null) {
for (NodeInfo nodeInfo : processInfo.getNodeInfos()) {
processNodeInfo(nodeInfo, process.getNodes());
}
postProcessNodeOffset(process.getNodes(), 0, 0);
for (ConnectionInfo connectionInfo : processInfo.getConnectionInfos()) {
if (connectionInfo.getBendpoints() != null) {
processConnectionInfo(connectionInfo, process.getNodes());
}
}
}
return processInfo;
}
Aggregations