[
https://jira.jboss.org/jira/browse/JBRULES-1844?page=com.atlassian.jira.p...
]
Mauricio Salatino commented on JBRULES-1844:
--------------------------------------------
I also update the current documentation in (Please correct my english):
drools-docs/drools-docs-flow/src/main/docbook/en-US/Chapter-Flow/Chapter-RuleFlow.xml
with:
<section>
<title>Defining processes using the Process API</title>
<para>While it is recommended to define processes using the graphical
editor or the underlying XML (to
shield yourself from internal APIs), it is also possible to define a process using
the Process API directly.
The most important process elements are defined in the org.drools.workflow.core and
the
org.drools.workflow.core.node packages.Note that creating a process using this API
can be rather complex
and error-prone, and should only be used if the above mentioned methods are not
sufficient (for example
when automatically generating processes from input that is not XML-based). You can
however use the process
validator (org.drools.ruleflow.core.validation.RuleFlowProcessValidator) to validate
processes that were
manually created using the API.
</para>
<para>Now we are looking some examples about how to build process using
the Process API:
This is a simple example of a basic process with a ruleset node only:
<programlisting>
RuleFlowProcessFactory.createProcess("org.drools.HelloWorldRuleSet")
.version("1.0")
.name("HelloWorldRuleSet")
.packageName("org.drools")
// nodes
.startNode(1).name("Start").done()
.ruleSetNode(2)
.name("RuleSet")
.ruleFlowGroup("someGroup").done()
.endNode(3).name("End").done()
//Connections
.connection(1, 2)
.connection(2, 3)
//Validate the process structure
.validate()
//Return the process
.done();
</programlisting>
</para>
<para>
You can see that we start calling the static createProcess() method from
the RuleFlowProcessFactory class.
This method creates a new process instance and then return the
RuleFlowProcessFactory that contain that instance.
</para>
<para>
So at this point you can set the version of the process, the name and the
package name. Also you can start
adding nodes to the current process. If you have autocompletion you can see
that you have available all the
current supported nodes.
</para>
<para>
When you start adding nodes to the process ,in the example calling the
startNode(), ruleSetNode() and endNode() methods,
you should see that this methods return a sub class of NodeFactory
instance. So at this point you should be able to
set the node properties until you call the done() method, that return the
current RuleFlowProcessFactory.
</para>
<para>
Notice that when you finised adding nodes you must connect them calling the
connection method, this will link your
currently added nodes.
</para>
<para>
Then you can validate the generated process calling the validate method.
</para>
<para>
Another interesting example is one with a Split and Join nodes:
<programlisting>
RuleFlowProcessFactory.createProcess("org.drools.HelloWorldJoinSplit")
.version("1.0")
.name("HelloWorldJoinSplit")
.packageName("org.drools")
// nodes
.startNode(1).name("Start").done()
.split(2).name("Split").type(Split.TYPE_AND).done()
.actionNode(3).name("Action 1").action("mvel",
"System.out.println(\"Inside Action 1\")").done()
.actionNode(4).name("Action 2").action("mvel",
"System.out.println(\"Inside Action 2\")").done()
.join(5).type(Join.TYPE_AND).done()
.endNode(6).name("End").done()
//Connections
.connection(1, 2)
.connection(2, 3)
.connection(2, 4)
.connection(3, 5)
.connection(4, 5)
.connection(5, 6)
//Validate the process structure
.validate()
//Return the process
.done();
</programlisting>
</para>
<para>
Here we see a simple Split / Join example, the only thing to add here is
that you need to pay
attention to the connections. Also to understand the behaviour of the
Split and Join node you should
look at the specified type of each one.
</para>
<para>
Now we can see a more complex example with a foreach node, where we have
nested nodes:
</para>
<para>
<programlisting>
RuleFlowProcessFactory.createProcess("org.drools.HelloWorldForeach")
.version("1.0")
.name("HelloWorldForeach")
.packageName("org.drools")
// nodes
.startNode(1).name("Start").done()
.foreachNode(2)
.linkIncomingConnections(3)
.linkOutgoingConnections(3)
.collectionExpression("persons")
.variable("child", new
ObjectDataType("org.drools.Person"))
.actionNode(3)
.action("mvel", "System.out.println(\"inside
the action\")").done()
.foreachNodeEnd()
.endNode(4).name("End").done()
//Connections
.connection(1, 2)
.connection(2, 4)
//Validate the process structure
.validate()
//Return the process
.done();
</programlisting>
</para>
<para>
Here we see how we can include one foreach node with a nested action node.
Note the linkIncommingConnections() and linkOutgoingConnections() methods
that are called to
link the foreach node with the internal action node. This methods must be
called before you start
adding nodes to this composite node. The same occurs with the
collectionExpression() and variable()
methods.
</para>
<para>
If you want to add more than one node inside the foreach node you can do
it, but you must connect
all the nodes inside the foreach node by calling the connection() method
inside the foreach node
to connect all the internal nodes. This must be done after the nodes
inclusion and before the call
of the foreachNodeEnd() method.
</para>
<para>
Note that you must call the foreachNodeEnd() method at the end of the
nodes
definition.
</para>
</section>
Fluent process API
------------------
Key: JBRULES-1844
URL:
https://jira.jboss.org/jira/browse/JBRULES-1844
Project: JBoss Drools
Issue Type: Feature Request
Security Level: Public(Everyone can see)
Components: drools-compiler (flow)
Affects Versions: 5.0.0.M2
Reporter: Mauricio Salatino
Assignee: Mauricio Salatino
Priority: Minor
Attachments: ClinicalPathwayXTest.java, ForeachNodeProcessAPITest.java,
ProcessFactoryTest.java, ProcessFactoryTest.java, ProcessFactoryTest.java,
RuleFlowProcessFactory.java, RuleFlowProcessFactory.java, RuleFlowProcessFactory.java,
RuleFlowProcessFactoryComposite.java, RuleFlowProcessFactoryComposite.java,
RuleFlowProcessFactoryForEach.java, RuleFlowProcessFactoryForEach.java,
RuleSetNodeProcessAPITest.java, SplitJoinProcessAPITest.java, TreatmentXTest.java,
TreatmentYTest.java
Create a more fluent API so you can create Ruleflows programatically. Second Approach. +
some examples
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira