[jboss-svn-commits] JBL Code SVN: r24364 - in labs/jbossrules/trunk/drools-compiler/src: main/java/org/drools/guvnor/client/modeldriven/brl and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Dec 12 03:03:40 EST 2008
Author: michael.neale at jboss.com
Date: 2008-12-12 03:03:40 -0500 (Fri, 12 Dec 2008)
New Revision: 24364
Added:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ActionGlobalCollectionAdd.java
Modified:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/SuggestionCompletionEngine.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/rules/SuggestionCompletionLoader.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRDRLPersistence.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRXMLPersistence.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/SuggestionCompletionEngineBuilder.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/rules/SuggestionCompletionLoaderTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/BRDRLPersistenceTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/BRLPersitenceTest.java
Log:
JBRULES-1893
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/SuggestionCompletionEngine.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/SuggestionCompletionEngine.java 2008-12-12 05:37:24 UTC (rev 24363)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/SuggestionCompletionEngine.java 2008-12-12 08:03:40 UTC (rev 24364)
@@ -84,6 +84,12 @@
*/
public Map<String, String[]> dataEnumLists = new HashMap(); //TODO this is a PROBLEM as its not always String[]
+
+ /**
+ * This will show the names of globals that are a collection type.
+ */
+ public String[] globalCollections;
+
/** Operators (from the grammar):
* op=( '=='
| '>'
@@ -113,6 +119,7 @@
private transient Map dataEnumLookupFields;
+
// /**
// * For bulk loading up the data (from a previous rule save)
// *
Added: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ActionGlobalCollectionAdd.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ActionGlobalCollectionAdd.java (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/ActionGlobalCollectionAdd.java 2008-12-12 08:03:40 UTC (rev 24364)
@@ -0,0 +1,10 @@
+package org.drools.guvnor.client.modeldriven.brl;
+
+/**
+ * This is for adding a given fact to a global collection
+ * @author Michael Neale
+ */
+public class ActionGlobalCollectionAdd implements IAction {
+ public String globalName;
+ public String factName;
+}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/rules/SuggestionCompletionLoader.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/rules/SuggestionCompletionLoader.java 2008-12-12 05:37:24 UTC (rev 24363)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/rules/SuggestionCompletionLoader.java 2008-12-12 08:03:40 UTC (rev 24364)
@@ -266,6 +266,9 @@
this.builder.addGlobalType( global.getIdentifier(),
shortTypeName );
+ if (Collection.class.isAssignableFrom(clazz)) {
+ this.builder.addGlobalCollection(global.getIdentifier());
+ }
}
this.builder.addGlobalType( global.getIdentifier(),
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRDRLPersistence.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRDRLPersistence.java 2008-12-12 05:37:24 UTC (rev 24363)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRDRLPersistence.java 2008-12-12 08:03:40 UTC (rev 24364)
@@ -1,27 +1,7 @@
package org.drools.guvnor.server.util;
import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
-import org.drools.guvnor.client.modeldriven.brl.ActionFieldFunction;
-import org.drools.guvnor.client.modeldriven.brl.ActionFieldValue;
-import org.drools.guvnor.client.modeldriven.brl.ActionInsertFact;
-import org.drools.guvnor.client.modeldriven.brl.ActionInsertLogicalFact;
-import org.drools.guvnor.client.modeldriven.brl.ActionRetractFact;
-import org.drools.guvnor.client.modeldriven.brl.ActionSetField;
-import org.drools.guvnor.client.modeldriven.brl.ActionUpdateField;
-import org.drools.guvnor.client.modeldriven.brl.CompositeFactPattern;
-import org.drools.guvnor.client.modeldriven.brl.CompositeFieldConstraint;
-import org.drools.guvnor.client.modeldriven.brl.ConnectiveConstraint;
-import org.drools.guvnor.client.modeldriven.brl.DSLSentence;
-import org.drools.guvnor.client.modeldriven.brl.FactPattern;
-import org.drools.guvnor.client.modeldriven.brl.FieldConstraint;
-import org.drools.guvnor.client.modeldriven.brl.FreeFormLine;
-import org.drools.guvnor.client.modeldriven.brl.IAction;
-import org.drools.guvnor.client.modeldriven.brl.IPattern;
-import org.drools.guvnor.client.modeldriven.brl.ISingleFieldConstraint;
-import org.drools.guvnor.client.modeldriven.brl.RuleAttribute;
-import org.drools.guvnor.client.modeldriven.brl.RuleMetadata;
-import org.drools.guvnor.client.modeldriven.brl.RuleModel;
-import org.drools.guvnor.client.modeldriven.brl.SingleFieldConstraint;
+import org.drools.guvnor.client.modeldriven.brl.*;
import org.drools.util.ReflectiveVisitor;
/**
@@ -334,10 +314,6 @@
}
}
- /**
- * @param constr
- * @param constrDescr
- */
private void addFieldRestriction(final StringBuffer buf,
final int type,
final String operator,
@@ -443,6 +419,14 @@
buf.append( " );\n" );
}
+ public void visitActionGlobalCollectionAdd(final ActionGlobalCollectionAdd add) {
+ buf.append( "\t\t" );
+ if( isDSLEnhanced ) {
+ buf.append( ">" );
+ }
+ buf.append(add.globalName + ".add(" + add.factName + ");\n");
+ }
+
public void visitActionRetractFact(final ActionRetractFact action) {
buf.append( "\t\t" );
if( isDSLEnhanced ) {
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRXMLPersistence.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRXMLPersistence.java 2008-12-12 05:37:24 UTC (rev 24363)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRXMLPersistence.java 2008-12-12 08:03:40 UTC (rev 24364)
@@ -1,21 +1,6 @@
package org.drools.guvnor.server.util;
-import org.drools.guvnor.client.modeldriven.brl.ActionFieldValue;
-import org.drools.guvnor.client.modeldriven.brl.ActionInsertFact;
-import org.drools.guvnor.client.modeldriven.brl.ActionInsertLogicalFact;
-import org.drools.guvnor.client.modeldriven.brl.ActionRetractFact;
-import org.drools.guvnor.client.modeldriven.brl.ActionSetField;
-import org.drools.guvnor.client.modeldriven.brl.ActionUpdateField;
-import org.drools.guvnor.client.modeldriven.brl.CompositeFactPattern;
-import org.drools.guvnor.client.modeldriven.brl.CompositeFieldConstraint;
-import org.drools.guvnor.client.modeldriven.brl.ConnectiveConstraint;
-import org.drools.guvnor.client.modeldriven.brl.DSLSentence;
-import org.drools.guvnor.client.modeldriven.brl.FactPattern;
-import org.drools.guvnor.client.modeldriven.brl.FreeFormLine;
-import org.drools.guvnor.client.modeldriven.brl.RuleAttribute;
-import org.drools.guvnor.client.modeldriven.brl.RuleMetadata;
-import org.drools.guvnor.client.modeldriven.brl.RuleModel;
-import org.drools.guvnor.client.modeldriven.brl.SingleFieldConstraint;
+import org.drools.guvnor.client.modeldriven.brl.*;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
@@ -70,6 +55,8 @@
ActionInsertLogicalFact.class );
this.xt.alias("freeForm", FreeFormLine.class);
+ this.xt.alias("addToGlobal", ActionGlobalCollectionAdd.class);
+
}
public static BRLPersistence getInstance() {
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/SuggestionCompletionEngineBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/SuggestionCompletionEngineBuilder.java 2008-12-12 05:37:24 UTC (rev 24363)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/SuggestionCompletionEngineBuilder.java 2008-12-12 08:03:40 UTC (rev 24364)
@@ -16,10 +16,7 @@
package org.drools.guvnor.server.util;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
import org.drools.guvnor.client.modeldriven.brl.DSLSentence;
@@ -43,7 +40,9 @@
private List conditionDSLSentences = new ArrayList();
private List keywordDSLItems = new ArrayList();
private List anyScopeDSLItems = new ArrayList();
+ private List<String> globalCollections = new ArrayList();
+
public SuggestionCompletionEngineBuilder() {
}
@@ -61,6 +60,7 @@
this.conditionDSLSentences = new ArrayList();
this.keywordDSLItems = new ArrayList();
this.anyScopeDSLItems = new ArrayList();
+ this.globalCollections = new ArrayList<String>();
}
/**
@@ -127,6 +127,10 @@
type );
}
+ public void addGlobalCollection(String global) {
+ this.globalCollections.add(global);
+ }
+
/**
* Add a DSL sentence for an action.
*/
@@ -161,6 +165,7 @@
this.instance.conditionDSLSentences = makeArray(this.conditionDSLSentences);
this.instance.keywordDSLItems = makeArray(this.keywordDSLItems);
this.instance.anyScopeDSLItems = makeArray(this.anyScopeDSLItems);
+ this.instance.globalCollections = this.globalCollections.toArray(new String[globalCollections.size()]);
return this.instance;
}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/rules/SuggestionCompletionLoaderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/rules/SuggestionCompletionLoaderTest.java 2008-12-12 05:37:24 UTC (rev 24363)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/rules/SuggestionCompletionLoaderTest.java 2008-12-12 08:03:40 UTC (rev 24364)
@@ -74,8 +74,28 @@
String[] flds = (String[]) eng.fieldsForType.get("Person");
assertNotNull(flds);
+ assertEquals(0, eng.globalCollections.length);
+
}
+
+ public void testGlobalCollections() throws Exception {
+ SuggestionCompletionLoader loader = new SuggestionCompletionLoader();
+ SuggestionCompletionEngine eng = loader.getSuggestionEngine( "package foo \n global java.util.List ls", new ArrayList(), new ArrayList() );
+ assertNotNull(eng);
+ assertFalse(loader.hasErrors());
+
+ assertEquals(1, eng.getGlobalVariables().length);
+ assertEquals("ls", eng.getGlobalVariables()[0]);
+ assertEquals("List", eng.globalTypes.get("ls"));
+
+ assertNotNull(eng.globalCollections);
+ assertEquals(1, eng.globalCollections.length);
+ assertEquals("ls", eng.globalCollections[0]);
+
+
+ }
+
public void testSortOrderOfFields() throws Exception {
SuggestionCompletionLoader loader = new SuggestionCompletionLoader();
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/BRDRLPersistenceTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/BRDRLPersistenceTest.java 2008-12-12 05:37:24 UTC (rev 24363)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/BRDRLPersistenceTest.java 2008-12-12 08:03:40 UTC (rev 24364)
@@ -3,24 +3,10 @@
import junit.framework.TestCase;
import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
-import org.drools.guvnor.client.modeldriven.brl.ActionFieldValue;
-import org.drools.guvnor.client.modeldriven.brl.ActionInsertFact;
-import org.drools.guvnor.client.modeldriven.brl.ActionInsertLogicalFact;
-import org.drools.guvnor.client.modeldriven.brl.ActionRetractFact;
-import org.drools.guvnor.client.modeldriven.brl.ActionUpdateField;
-import org.drools.guvnor.client.modeldriven.brl.CompositeFactPattern;
-import org.drools.guvnor.client.modeldriven.brl.CompositeFieldConstraint;
-import org.drools.guvnor.client.modeldriven.brl.ConnectiveConstraint;
-import org.drools.guvnor.client.modeldriven.brl.DSLSentence;
-import org.drools.guvnor.client.modeldriven.brl.FactPattern;
-import org.drools.guvnor.client.modeldriven.brl.FreeFormLine;
-import org.drools.guvnor.client.modeldriven.brl.IAction;
-import org.drools.guvnor.client.modeldriven.brl.IPattern;
-import org.drools.guvnor.client.modeldriven.brl.ISingleFieldConstraint;
-import org.drools.guvnor.client.modeldriven.brl.RuleAttribute;
-import org.drools.guvnor.client.modeldriven.brl.RuleModel;
-import org.drools.guvnor.client.modeldriven.brl.SingleFieldConstraint;
+import org.drools.guvnor.client.modeldriven.brl.*;
+import java.util.Collection;
+
public class BRDRLPersistenceTest extends TestCase {
private BRLPersistence p;
@@ -627,4 +613,24 @@
}
+
+ public void testAddGlobal() {
+ String expected = "rule \"my rule\"\n\tno-loop true\n\tdialect \"mvel\"\n\twhen\n\t\tPerson( )\n"
+ + "\t\tAccident( )\n\tthen\n\t\tinsert( new Report() );\n\t\tresults.add(f);\nend\n";
+ final RuleModel m = new RuleModel();
+ m.addLhsItem(new FactPattern("Person"));
+ m.addLhsItem(new FactPattern("Accident"));
+ m.addAttribute(new RuleAttribute("no-loop", "true"));
+
+ m.addRhsItem(new ActionInsertFact("Report"));
+ ActionGlobalCollectionAdd add = new ActionGlobalCollectionAdd();
+ add.globalName = "results";
+ add.factName = "f";
+ m.addRhsItem(add);
+ m.name = "my rule";
+
+ final String drl = p.marshal(m);
+ assertEquals(expected, drl);
+ }
+
}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/BRLPersitenceTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/BRLPersitenceTest.java 2008-12-12 05:37:24 UTC (rev 24363)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/BRLPersitenceTest.java 2008-12-12 08:03:40 UTC (rev 24364)
@@ -7,22 +7,7 @@
import junit.framework.TestCase;
import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
-import org.drools.guvnor.client.modeldriven.brl.ActionFieldValue;
-import org.drools.guvnor.client.modeldriven.brl.ActionInsertFact;
-import org.drools.guvnor.client.modeldriven.brl.ActionRetractFact;
-import org.drools.guvnor.client.modeldriven.brl.ActionUpdateField;
-import org.drools.guvnor.client.modeldriven.brl.CompositeFactPattern;
-import org.drools.guvnor.client.modeldriven.brl.CompositeFieldConstraint;
-import org.drools.guvnor.client.modeldriven.brl.ConnectiveConstraint;
-import org.drools.guvnor.client.modeldriven.brl.DSLSentence;
-import org.drools.guvnor.client.modeldriven.brl.FactPattern;
-import org.drools.guvnor.client.modeldriven.brl.FreeFormLine;
-import org.drools.guvnor.client.modeldriven.brl.IAction;
-import org.drools.guvnor.client.modeldriven.brl.IPattern;
-import org.drools.guvnor.client.modeldriven.brl.ISingleFieldConstraint;
-import org.drools.guvnor.client.modeldriven.brl.RuleAttribute;
-import org.drools.guvnor.client.modeldriven.brl.RuleModel;
-import org.drools.guvnor.client.modeldriven.brl.SingleFieldConstraint;
+import org.drools.guvnor.client.modeldriven.brl.*;
public class BRLPersitenceTest extends TestCase {
@@ -45,14 +30,23 @@
"true" ) );
m.addRhsItem( new ActionInsertFact( "Report" ) );
+ ActionGlobalCollectionAdd ag = new ActionGlobalCollectionAdd();
+ ag.factName = "x";
+ ag.globalName = "g";
+ m.addRhsItem( ag);
m.name = "my rule";
final String xml = p.marshal( m );
- //System.out.println(xml);
+ System.out.println(xml);
assertTrue( xml.indexOf( "Person" ) > -1 );
assertTrue( xml.indexOf( "Accident" ) > -1 );
assertTrue( xml.indexOf( "no-loop" ) > -1 );
assertTrue( xml.indexOf( "org.drools" ) == -1 );
+ assertTrue( xml.indexOf( "addToGlobal" ) > -1 );
+
+ RuleModel rm_ = BRXMLPersistence.getInstance().unmarshal(xml);
+ assertEquals(2, rm_.rhs.length);
+
}
public void testMoreComplexRendering() {
More information about the jboss-svn-commits
mailing list