[rules-users] Using the ForEach component in RuleFlow

Darshan darshan.vartak at polaris.co.in
Fri Jun 4 06:30:46 EDT 2010



I am trying to use ForEach component in the process flow. I need to call a
set of rules in loop. I have this subFlow created inside ForEach component.
The collection set in the working memory becomes available to the ForEach
component and infact even in subFlow the OnEntryAction and OnExitAction can
access the integerObject from the collection. But when it comes to executing
the rules, looks like the integerObject is not available to the rule and
none of the rules are executed. If I add a dummy rule without any condition
it does get executed but only once. Have anybody tried similar kind of
scenario. If yes please send me some example, as I am really stuch out here
trying to call rules in a loop.

I am attaching the souce code along with this post. Please have a look.

Here is how the ForEach flow looks like  
http://drools-java-rules-engine.46999.n3.nabble.com/file/n870012/ForEachFlow.jpg 

Here is my SubFlow layout
http://drools-java-rules-engine.46999.n3.nabble.com/file/n870012/subProcessFlow.jpg 


Here is the output of Java Program

Setting numberList
Entry 1
Entry 2
Exit 1
Entry 3
Exit 2
Entry 4
Exit 3
Entry 5
Exit 4
Entry 6
Exit 5
Entry 7
Exit 6
Entry 8
Exit 7
Entry 9
Exit 8
Entry 10
Exit 9
Entry 11
Exit 10
Entry 12
Exit 11
Entry 13
Exit 12
Entry 14
Exit 13
Entry 15
Exit 14
Entry 16
Exit 15
Entry 17
Exit 16
Entry 18
Exit 17
Entry 19
Exit 18
Exit 19
Rules executed



testSubFlowForEach.rf looks like this

<?xml version="1.0" encoding="UTF-8"?> 
<process xmlns="http://drools.org/drools-5.0/process"
         xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
         xs:schemaLocation="http://drools.org/drools-5.0/process
drools-processes-5.0.xsd"
         type="RuleFlow" name="testForEach" id="processForEach"
package-name="com.sample" >

  <header>
    <imports>
      <import name="java.util.ArrayList" />
      <import name="com.sample.IntegerObject" />
    </imports>
    <variables>
      <variable name="numberList" >
        <type
name="org.drools.process.core.datatype.impl.type.ObjectDataType"
className="java.util.ArrayList" />
      </variable>
      <variable name="integerObject" >
        <type
name="org.drools.process.core.datatype.impl.type.ObjectDataType"
className="com.sample.IntegerObject" />
      </variable>
    </variables>
  </header>

  <nodes>
    <start id="1" name="Start" x="224" y="15" width="80" height="40" />
    <forEach id="2" name="processForEach" x="163" y="111" width="203"
height="268" variableName="integerObject" collectionExpression="numberList"
>
      <nodes>
    <subProcess id="13" name="SubProcess" x="55" y="110" width="80"
height="40" processId="testSubFlow" independent="false" >
      <mapping type="in" from="integerObject" to="integerObject" />
      <onEntry>
        <action type="expression" dialect="java" >System.out.println("Entry
" + ((IntegerObject) integerObject).getIntVal());</action>
      </onEntry>
      <onExit>
        <action type="expression" dialect="java" >System.out.println("Exit "
+ ((IntegerObject) integerObject).getIntVal());</action>
      </onExit>
    </subProcess>
      </nodes>
      <connections>
      </connections>
      <in-ports>
        <in-port type="DROOLS_DEFAULT" nodeId="13"
nodeInType="DROOLS_DEFAULT" />
      </in-ports>
      <out-ports>
        <out-port type="DROOLS_DEFAULT" nodeId="13"
nodeOutType="DROOLS_DEFAULT" />
      </out-ports>
    </forEach>
    <end id="5" name="End" x="230" y="456" width="80" height="40" />
  </nodes>

  <connections>
    <connection from="1" to="2" />
    <connection from="2" to="5" />
  </connections>

</process>


http://drools-java-rules-engine.46999.n3.nabble.com/file/n870012/testForEach.zip
testForEach.zip 
-- 
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Using-the-ForEach-component-in-RuleFlow-tp870012p870012.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list