[seam-commits] Seam SVN: r11174 - in branches/community/Seam_2_2: doc/Seam_Reference_Guide/en-US and 5 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Jun 18 20:17:25 EDT 2009


Author: tsurdilovic
Date: 2009-06-18 20:17:25 -0400 (Thu, 18 Jun 2009)
New Revision: 11174

Added:
   branches/community/Seam_2_2/examples/drools/resources/numberguess.rf
   branches/community/Seam_2_2/examples/drools/resources/pageflow.jpdl.jpg
Modified:
   branches/community/Seam_2_2/build/core.pom.xml
   branches/community/Seam_2_2/build/root.pom.xml
   branches/community/Seam_2_2/doc/Seam_Reference_Guide/en-US/Drools.xml
   branches/community/Seam_2_2/examples/build.xml
   branches/community/Seam_2_2/examples/drools/resources/WEB-INF/components.xml
   branches/community/Seam_2_2/examples/drools/resources/numberguess.drl
   branches/community/Seam_2_2/examples/drools/resources/numberguess.xls
   branches/community/Seam_2_2/examples/drools/resources/pageflow.jpdl.xml
   branches/community/Seam_2_2/seam-gen/ivy/ivy.xml
   branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsActionHandler.java
   branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsAssignmentHandler.java
   branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsDecisionHandler.java
   branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsHandler.java
   branches/community/Seam_2_2/src/main/org/jboss/seam/drools/ManagedWorkingMemory.java
   branches/community/Seam_2_2/src/main/org/jboss/seam/drools/RuleBase.java
Log:
JBSEAM-4219, JBSEAM-4241

Modified: branches/community/Seam_2_2/build/core.pom.xml
===================================================================
--- branches/community/Seam_2_2/build/core.pom.xml	2009-06-18 06:01:16 UTC (rev 11173)
+++ branches/community/Seam_2_2/build/core.pom.xml	2009-06-19 00:17:25 UTC (rev 11174)
@@ -252,7 +252,13 @@
       <optional>true</optional>
     </dependency>
     
+    <dependency>
+      	<groupId>org.drools</groupId>
+        <artifactId>drools-templates</artifactId>
+        <optional>true</optional>
+    </dependency>
     
+    
      <dependency>
      	<groupId>org.drools</groupId>
      	<artifactId>drools-decisiontables</artifactId>
@@ -264,6 +270,16 @@
           	</exclusion>
         </exclusions>
      </dependency>
+     
+     <dependency>
+      	<groupId>xstream</groupId>
+  		<artifactId>xstream</artifactId>      	
+      </dependency>
+      
+      <dependency>
+      	<groupId>xpp3</groupId>
+  		<artifactId>xpp3_min</artifactId>      	
+      </dependency>
  	 	
 	 <dependency>
 		<groupId>net.sourceforge.jexcelapi</groupId>

Modified: branches/community/Seam_2_2/build/root.pom.xml
===================================================================
--- branches/community/Seam_2_2/build/root.pom.xml	2009-06-18 06:01:16 UTC (rev 11173)
+++ branches/community/Seam_2_2/build/root.pom.xml	2009-06-19 00:17:25 UTC (rev 11174)
@@ -801,6 +801,12 @@
           </exclusion>
         </exclusions>
       </dependency>
+      
+      <dependency>
+      	<groupId>org.drools</groupId>
+        <artifactId>drools-templates</artifactId>
+        <version>${version.drools}</version>
+      </dependency>
 
       <dependency>
         <groupId>org.drools</groupId>
@@ -829,6 +835,18 @@
           </exclusion>
         </exclusions>
       </dependency>
+      
+      <dependency>
+      	<groupId>xstream</groupId>
+  		<artifactId>xstream</artifactId>
+  		<version>1.1.3</version>      	
+      </dependency>
+      
+      <dependency>
+      	<groupId>xpp3</groupId>
+  		<artifactId>xpp3_min</artifactId>
+  		<version>1.1.3.4.O</version>      	
+      </dependency>
 
       <dependency>
         <groupId>org.jboss.el</groupId>

Modified: branches/community/Seam_2_2/doc/Seam_Reference_Guide/en-US/Drools.xml
===================================================================
--- branches/community/Seam_2_2/doc/Seam_Reference_Guide/en-US/Drools.xml	2009-06-18 06:01:16 UTC (rev 11173)
+++ branches/community/Seam_2_2/doc/Seam_Reference_Guide/en-US/Drools.xml	2009-06-19 00:17:25 UTC (rev 11174)
@@ -44,6 +44,21 @@
     </drools:rule-files>
 </drools:rule-base>]]></programlisting>
 
+		<para>
+             Support for Drools RuleFlow is also available and you can simply add a <literal>.rf</literal> or a <literal>.rfm</literal>
+             as part of your rule files as:
+         </para>
+         
+        <programlisting role="XML"><![CDATA[
+        <drools:rule-base name="policyPricingRules" rule-files="policyPricingRules.drl, policyPricingRulesFlow.rf"/>
+        ]]></programlisting>
+        
+        <para>
+             Note that when using the Drools 4.x RuleFlow (<literal>.rfm</literal>) format, you need to specify the -Ddrools.ruleflow.port=true
+             system property on server startup. This is however still an experimental feature and we advise to use the Drools5 (<literal>.rf</literal>)
+             format if possible.              
+        </para>
+
          <para>
              If you want to register a custom consequence exception handler through the RuleBaseConfiguration, you need to 
              write the handler, for example: 
@@ -151,6 +166,8 @@
 {
 	policyPricingWorkingMemory.insert(policy);
 	policyPricingWorkingMemory.insert(customer); 
+	// if we have a ruleflow, start the process
+	policyPricingWorkingMemory.startProcess(startProcessId)
     policyPricingWorkingMemory.fireAllRules();
 }]]></programlisting>
      
@@ -169,6 +186,8 @@
          
     <handler class="org.jboss.seam.drools.DroolsDecisionHandler">
         <workingMemoryName>orderApprovalRulesWorkingMemory</workingMemoryName>
+        <!-- if a ruleflow was added -->
+        <startProcessId>approvalruleflowid</startProcessId>
         <assertObjects>
             <element>#{customer}</element>
             <element>#{order}</element>
@@ -198,6 +217,12 @@
          </para>
          
          <para>
+            The <literal>&lt;retractObjects&gt;</literal> element on the other hand specifies EL 
+            expressions that return an object or collection of objects to be retracted from the 
+            <literal>WorkingMemory</literal>.
+         </para>
+         
+         <para>
              There is also support for using Drools for jBPM task assignments:
          </para>
          

Modified: branches/community/Seam_2_2/examples/build.xml
===================================================================
--- branches/community/Seam_2_2/examples/build.xml	2009-06-18 06:01:16 UTC (rev 11173)
+++ branches/community/Seam_2_2/examples/build.xml	2009-06-19 00:17:25 UTC (rev 11174)
@@ -327,6 +327,9 @@
 		<include name="drools-compiler.jar" if="drools.lib" />
 		<include name="drools-api.jar" if="drools.lib" />
 		<include name="drools-decisiontables.jar" if="drools.lib"/>
+		<include name="drools-templates.jar" if="drools.lib"/>
+		<include name="xstream.jar" if="drools.lib"/>
+		<include name="xpp3_min.jar" if="drools.lib"/>
 		<include name="jxl.jar" if="drools.lib"/>
 	</fileset>
 
@@ -477,6 +480,8 @@
 	<!-- binary resources to go in the jar -->
 		<fileset id="jar.binary.resources" dir="${resources.dir}">
 			<include name="*.xls" />
+			<include name="*.rf" />
+			<include name="*.rfm" />
 		</fileset>
 
 	<!-- resources to go in the jar for tomcat  -->

Modified: branches/community/Seam_2_2/examples/drools/resources/WEB-INF/components.xml
===================================================================
--- branches/community/Seam_2_2/examples/drools/resources/WEB-INF/components.xml	2009-06-18 06:01:16 UTC (rev 11173)
+++ branches/community/Seam_2_2/examples/drools/resources/WEB-INF/components.xml	2009-06-19 00:17:25 UTC (rev 11174)
@@ -12,6 +12,10 @@
     <drools:rule-base name="ruleBase" rule-files="numberguess.drl"/>
     <!-- use this in order to load from decision table instead -->        
     <!-- <drools:rule-base name="ruleBase" rule-files="numberguess.xls"/>  -->
+    <!--  use this in order to load from a drl and also add a ruleflow -->
+    <!-- <drools:rule-base name="ruleBase" rule-files="numberguess.drl, numberguess.rf"/>  -->
+    <!--  use this in order to load from a xls and also add a ruleflow -->
+    <!-- <drools:rule-base name="ruleBase" rule-files="numberguess.xls, numberguess.rf"/>  -->    
     <!--  use this if you want to register a custom consequence exception handler -->
     <!--  <drools:rule-base name="ruleBase" rule-files="numberguess.xls" consequence-exception-handler="#{gameConsequenceExceptionHandler}"/>  -->
     <drools:managed-working-memory name="workingMemory" rule-base="#{ruleBase}">

Modified: branches/community/Seam_2_2/examples/drools/resources/numberguess.drl
===================================================================
--- branches/community/Seam_2_2/examples/drools/resources/numberguess.drl	2009-06-18 06:01:16 UTC (rev 11173)
+++ branches/community/Seam_2_2/examples/drools/resources/numberguess.drl	2009-06-19 00:17:25 UTC (rev 11174)
@@ -7,6 +7,7 @@
 global Game game
 
 rule High
+   ruleflow-group "Guess"	
    when 
       Guess(guess: value>randomNumber)
    then 
@@ -14,6 +15,7 @@
 end
 
 rule Low
+   ruleflow-group "Guess"
    when
       Guess(guess: value<randomNumber)
    then 
@@ -21,6 +23,7 @@
 end
 
 rule Win
+   ruleflow-group "Decision"
    when 
       Guess(value==randomNumber)
    then 
@@ -28,6 +31,7 @@
 end
 
 rule Lose
+   ruleflow-group "Decision"
    when 
       Game(guessCount==9)
    then
@@ -38,6 +42,7 @@
 end
 
 rule Increment
+   ruleflow-group "Increment"
    salience -10
    when
       Guess()

Added: branches/community/Seam_2_2/examples/drools/resources/numberguess.rf
===================================================================
--- branches/community/Seam_2_2/examples/drools/resources/numberguess.rf	                        (rev 0)
+++ branches/community/Seam_2_2/examples/drools/resources/numberguess.rf	2009-06-19 00:17:25 UTC (rev 11174)
@@ -0,0 +1,25 @@
+<?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="numberguess" id="numberguessid" package-name="org.jboss.seam.example.numberguess" version="" routerLayout="2" >
+
+  <header>
+  </header>
+
+  <nodes>
+    <ruleSet id="17" name="Increment" x="336" y="156" width="80" height="40" ruleFlowGroup="Increment" />
+    <ruleSet id="13" name="Decision" x="216" y="156" width="80" height="40" ruleFlowGroup="Decision" />
+    <start id="8" name="Start" x="84" y="24" width="80" height="40" />
+    <end id="21" name="End" x="336" y="264" width="80" height="40" />
+    <ruleSet id="5" name="Guess" x="84" y="156" width="80" height="40" ruleFlowGroup="Guess" />
+  </nodes>
+
+  <connections>
+    <connection from="13" to="17" />
+    <connection from="5" to="13" />
+    <connection from="17" to="21" />
+    <connection from="8" to="5" />
+  </connections>
+
+</process>
\ No newline at end of file


Property changes on: branches/community/Seam_2_2/examples/drools/resources/numberguess.rf
___________________________________________________________________
Name: svn:executable
   + *

Modified: branches/community/Seam_2_2/examples/drools/resources/numberguess.xls
===================================================================
(Binary files differ)

Added: branches/community/Seam_2_2/examples/drools/resources/pageflow.jpdl.jpg
===================================================================
(Binary files differ)


Property changes on: branches/community/Seam_2_2/examples/drools/resources/pageflow.jpdl.jpg
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: branches/community/Seam_2_2/examples/drools/resources/pageflow.jpdl.xml
===================================================================
--- branches/community/Seam_2_2/examples/drools/resources/pageflow.jpdl.xml	2009-06-18 06:01:16 UTC (rev 11173)
+++ branches/community/Seam_2_2/examples/drools/resources/pageflow.jpdl.xml	2009-06-19 00:17:25 UTC (rev 11174)
@@ -20,6 +20,8 @@
 
       <handler class="org.jboss.seam.drools.DroolsDecisionHandler">
          <workingMemoryName>workingMemory</workingMemoryName>
+         <!-- if a ruleflow was added, start a process -->
+         <startProcessId>numberguessid</startProcessId>
          <assertObjects>
             <element>#{game}</element>
             <element>#{guess}</element>

Modified: branches/community/Seam_2_2/seam-gen/ivy/ivy.xml
===================================================================
--- branches/community/Seam_2_2/seam-gen/ivy/ivy.xml	2009-06-18 06:01:16 UTC (rev 11173)
+++ branches/community/Seam_2_2/seam-gen/ivy/ivy.xml	2009-06-19 00:17:25 UTC (rev 11174)
@@ -27,6 +27,9 @@
 		<dependency org="org.drools" name="drools-compiler" rev="5.0.1" conf="default"/>
 		<dependency org="org.drools" name="drools-core" rev="5.0.1" conf="default"/>
 		<dependency org="org.drools" name="drools-decisiontables" rev="5.0.1" conf="default"/>
+		<dependency org="org.drools" name="drools-templates" rev="5.0.1" conf="default"/>
+		<dependency org="xstream" name="xstream" rev="1.1.3" conf="default"/>
+		<dependency org="xpp3" name="xpp3_min" rev="1.1.3.4.O" conf="default"/>
 		<dependency org="org.eclipse.jdt" name="core" rev="3.2.3.v_686_R32x" conf="default"/>
 		<dependency org="org.codehaus.groovy" name="groovy-all" rev="1.5.4" conf="default"/>
 		<dependency org="org.hibernate" name="hibernate-validator" rev="3.0.0.GA" conf="default"/>

Modified: branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsActionHandler.java
===================================================================
--- branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsActionHandler.java	2009-06-18 06:01:16 UTC (rev 11173)
+++ branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsActionHandler.java	2009-06-19 00:17:25 UTC (rev 11174)
@@ -2,6 +2,7 @@
 
 import java.util.List;
 
+import org.drools.WorkingMemory;
 import org.jbpm.graph.def.ActionHandler;
 import org.jbpm.graph.exe.ExecutionContext;
 
@@ -11,6 +12,7 @@
  * 
  * @author Jeff Delong
  * @author Gavin King
+ * @author Tihomir Surdilovic
  *
  */
 public class DroolsActionHandler extends DroolsHandler implements ActionHandler
@@ -18,11 +20,18 @@
    private static final long serialVersionUID = 7752070876220597913L;
    
    public List<String> assertObjects;
+   public List<String> retractObjects;
    public String workingMemoryName;
+   public String startProcessId;
    
    public void execute(ExecutionContext executionContext) throws Exception
    {
-      getWorkingMemory(workingMemoryName, assertObjects, executionContext).fireAllRules();
+      WorkingMemory workingMemory = getWorkingMemory(workingMemoryName, assertObjects, retractObjects, executionContext);
+      if(startProcessId != null && startProcessId.trim().length() > 0 ) 
+      {
+         workingMemory.startProcess(startProcessId);
+      }
+      workingMemory.fireAllRules();
    }
    
 }
\ No newline at end of file

Modified: branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsAssignmentHandler.java
===================================================================
--- branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsAssignmentHandler.java	2009-06-18 06:01:16 UTC (rev 11173)
+++ branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsAssignmentHandler.java	2009-06-19 00:17:25 UTC (rev 11174)
@@ -21,11 +21,17 @@
    
    public String workingMemoryName;
    public List<String> assertObjects;
+   public List<String> retractObjects;
+   public String startProcessId;
    
    public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception
    {
-      WorkingMemory workingMemory = getWorkingMemory(workingMemoryName, assertObjects, executionContext);
+      WorkingMemory workingMemory = getWorkingMemory(workingMemoryName, assertObjects, retractObjects, executionContext);
       workingMemory.setGlobal( "assignable", assignable );
+      if(startProcessId != null && startProcessId.trim().length() > 0 ) 
+      {
+         workingMemory.startProcess(startProcessId);
+      }
       workingMemory.fireAllRules();
    }
    

Modified: branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsDecisionHandler.java
===================================================================
--- branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsDecisionHandler.java	2009-06-18 06:01:16 UTC (rev 11173)
+++ branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsDecisionHandler.java	2009-06-19 00:17:25 UTC (rev 11174)
@@ -19,12 +19,18 @@
    private static final long serialVersionUID = -8900810376838166513L;
    
    public List<String> assertObjects;
+   public List<String> retractObjects;
    public String workingMemoryName;
+   public String startProcessId;
    
    public String decide(ExecutionContext executionContext) throws Exception
    {
-      WorkingMemory workingMemory = getWorkingMemory(workingMemoryName, assertObjects, executionContext);
+      WorkingMemory workingMemory = getWorkingMemory(workingMemoryName, assertObjects, retractObjects, executionContext);
       workingMemory.setGlobal( "decision", new Decision() );
+      if(startProcessId != null && startProcessId.trim().length() > 0 ) 
+      {
+         workingMemory.startProcess(startProcessId);
+      }
       workingMemory.fireAllRules();
       return ( (Decision) workingMemory.getGlobal("decision") ).getOutcome();
    }

Modified: branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsHandler.java
===================================================================
--- branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsHandler.java	2009-06-18 06:01:16 UTC (rev 11173)
+++ branches/community/Seam_2_2/src/main/org/jboss/seam/drools/DroolsHandler.java	2009-06-19 00:17:25 UTC (rev 11174)
@@ -19,26 +19,50 @@
  */
 public class DroolsHandler
 {
-   protected WorkingMemory getWorkingMemory(String workingMemoryName, List<String> expressions, ExecutionContext executionContext) 
+   protected WorkingMemory getWorkingMemory(String workingMemoryName, List<String> expressions, List<String> retractions, ExecutionContext executionContext) 
          throws ELException
    {
       WorkingMemory workingMemory = (WorkingMemory) Component.getInstance(workingMemoryName, true);
       
-      for (String objectName: expressions)
+      if(expressions != null && expressions.size() > 0) 
       {
-         Object object = Expressions.instance().createValueExpression(objectName).getValue();
-         //Object object = new SeamVariableResolver().resolveVariable(objectName);
-         // assert the object into the rules engine
-         if (object instanceof Iterable)
+         for (String objectName: expressions)
          {
-            for (Object element: (Iterable) object)
+            Object object = Expressions.instance().createValueExpression(objectName).getValue();
+            //Object object = new SeamVariableResolver().resolveVariable(objectName);
+            // assert the object into the rules engine
+            if (object instanceof Iterable)
             {
-               assertObject(workingMemory, element);
+               for (Object element: (Iterable) object)
+               {
+                  assertObject(workingMemory, element);
+               }
             }
+            else
+            {
+               assertObject(workingMemory, object);
+            }
          }
-         else
+      }
+      
+      if(retractions != null && retractions.size() > 0) 
+      {
+         for (String objectName: retractions)
          {
-            assertObject(workingMemory, object);
+            Object object = Expressions.instance().createValueExpression(objectName).getValue();
+            //Object object = new SeamVariableResolver().resolveVariable(objectName);
+            // retract the object from the rules engine
+            if (object instanceof Iterable)
+            {
+               for (Object element: (Iterable) object)
+               {
+                  retractObject(workingMemory, element);
+               }
+            }
+            else
+            {
+               retractObject(workingMemory, object);
+            }
          }
       }
       
@@ -60,4 +84,13 @@
          workingMemory.update(fact, element);
       }
    }
+   
+   private void retractObject(WorkingMemory workingMemory, Object element)
+   {
+      FactHandle fact = workingMemory.getFactHandle(element);
+      if (fact != null)
+      {
+         workingMemory.retract(fact);
+      }
+   } 
 }

Modified: branches/community/Seam_2_2/src/main/org/jboss/seam/drools/ManagedWorkingMemory.java
===================================================================
--- branches/community/Seam_2_2/src/main/org/jboss/seam/drools/ManagedWorkingMemory.java	2009-06-18 06:01:16 UTC (rev 11173)
+++ branches/community/Seam_2_2/src/main/org/jboss/seam/drools/ManagedWorkingMemory.java	2009-06-19 00:17:25 UTC (rev 11174)
@@ -106,7 +106,7 @@
                } 
                else 
                {
-                  log.debug("event Listener is not of valid type - bypassing.");
+                  log.debug("event Listener " + eventListener + " is not of valid type - bypassing.");
                }
             }
             catch (Exception e)

Modified: branches/community/Seam_2_2/src/main/org/jboss/seam/drools/RuleBase.java
===================================================================
--- branches/community/Seam_2_2/src/main/org/jboss/seam/drools/RuleBase.java	2009-06-18 06:01:16 UTC (rev 11173)
+++ branches/community/Seam_2_2/src/main/org/jboss/seam/drools/RuleBase.java	2009-06-19 00:17:25 UTC (rev 11174)
@@ -70,7 +70,14 @@
                InputStreamReader source = new InputStreamReader(new ByteArrayInputStream(currentXMLBytes)); 
                
                builder.addPackageFromDrl(source);
-            } else {             
+            } 
+            else if(isRuleFlow(ruleFile)) 
+            {
+               log.debug("adding ruleflow: " + ruleFile);
+               builder.addRuleFlow( new InputStreamReader(stream) );
+            } 
+            else 
+            {                
                // read in the source
                Reader drlReader = new InputStreamReader(stream);
                
@@ -160,4 +167,9 @@
       return fileName != null && fileName.length() > 0 && fileName.endsWith(".xls");
    }
    
+   private boolean isRuleFlow(String fileName) 
+   {
+      //support both new drools5 and older drools4 formats
+      return fileName != null && fileName.length() > 0 && (fileName.endsWith(".rf") || fileName.endsWith(".rfm"));
+   } 
 }




More information about the seam-commits mailing list