[jboss-svn-commits] JBL Code SVN: r24345 - in labs/jbossrules/trunk/drools-compiler/src: main/java/org/drools/guvnor/server/util and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Dec 10 21:18:42 EST 2008
Author: michael.neale at jboss.com
Date: 2008-12-10 21:18:42 -0500 (Wed, 10 Dec 2008)
New Revision: 24345
Added:
labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/guvnor/server/util/ExistingDecisionTable.xml
Modified:
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/dt/ActionSetFieldCol.java
labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/GuidedDTDRLPersistence.java
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/GuidedDTDRLPersistenceTest.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/GuidedDTXMLPersistenceTest.java
Log:
JBRULES-1892 Modify in web based decision tables
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/dt/ActionSetFieldCol.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/dt/ActionSetFieldCol.java 2008-12-11 00:14:04 UTC (rev 24344)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/dt/ActionSetFieldCol.java 2008-12-11 02:18:42 UTC (rev 24345)
@@ -24,4 +24,10 @@
* An optional comma separated list of values.
*/
public String valueList;
+
+
+ /**
+ * This will be true if it is meant to be a modify to the engine, when in inferencing mode.
+ */
+ public boolean update = false;
}
Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/GuidedDTDRLPersistence.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/GuidedDTDRLPersistence.java 2008-12-11 00:14:04 UTC (rev 24344)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/GuidedDTDRLPersistence.java 2008-12-11 02:18:42 UTC (rev 24345)
@@ -7,6 +7,7 @@
import org.drools.guvnor.client.modeldriven.brl.ActionInsertFact;
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.FactPattern;
import org.drools.guvnor.client.modeldriven.brl.IAction;
import org.drools.guvnor.client.modeldriven.brl.IPattern;
@@ -46,7 +47,7 @@
RuleModel rm = new RuleModel();
rm.name = getName(dt.tableName, num);
-
+
doMetadata(dt.getMetadataCols(), row, rm);
doAttribs(dt.getMetadataCols().size(), dt.attributeCols, row, rm);
doConditions(dt.getMetadataCols().size() + dt.attributeCols.size(), dt.conditionCols, row, rm);
@@ -55,7 +56,7 @@
if(dt.parentName != null){
rm.parentName = dt.parentName;
}
-
+
sb.append("#from row number: " + (i + 1) + "\n");
String rule = BRDRLPersistence.getInstance().marshal(rm);
sb.append(rule);
@@ -101,8 +102,18 @@
if (a == null) {
a = new LabelledAction();
a.boundName = sf.boundName;
- a.action = new ActionSetField(sf.boundName);
+ if (!sf.update) {
+ a.action = new ActionSetField(sf.boundName);
+ } else {
+ a.action = new ActionUpdateField(sf.boundName);
+ }
actions.add(a);
+ } else if (sf.update && !(a.action instanceof ActionUpdateField)) {
+ //lets swap it out for an update as the user has asked for it.
+ ActionSetField old = (ActionSetField) a.action;
+ ActionUpdateField update = new ActionUpdateField(sf.boundName);
+ update.fieldValues = old.fieldValues;
+ a.action = update;
}
ActionSetField asf = (ActionSetField) a.action;
ActionFieldValue val = new ActionFieldValue(sf.factField, cell, sf.type);
@@ -208,7 +219,7 @@
rm.attributes = attribs.toArray(new RuleAttribute[attribs.size()]);
}
}
-
+
void doMetadata(List<MetadataCol> metadataCols, String[] row, RuleModel rm) {
// setup temp list
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-11 00:14:04 UTC (rev 24344)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/BRLPersitenceTest.java 2008-12-11 02:18:42 UTC (rev 24345)
@@ -214,10 +214,10 @@
assertEquals(3, m2.rhs.length);
}
- private String loadResource(final String name) throws Exception {
+ public static String loadResource(final String name) throws Exception {
// System.err.println( getClass().getResource( name ) );
- final InputStream in = getClass().getResourceAsStream( name );
+ final InputStream in = BRLPersitenceTest.class.getResourceAsStream( name );
final Reader reader = new InputStreamReader( in );
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/GuidedDTDRLPersistenceTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/GuidedDTDRLPersistenceTest.java 2008-12-11 00:14:04 UTC (rev 24344)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/GuidedDTDRLPersistenceTest.java 2008-12-11 02:18:42 UTC (rev 24345)
@@ -196,7 +196,7 @@
assertEquals("bar2", rm.metadataList[1].value);
}
-
+
public void testLHS() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
String[] row = new String[] {"1", "desc", "a", "mike", "33 + 1", "age > 6", "stilton"};
@@ -288,6 +288,7 @@
ActionSetFieldCol asf2 = new ActionSetFieldCol();
asf2.boundName = "a";
asf2.factField = "field2";
+ asf2.update = true;
asf2.type = SuggestionCompletionEngine.TYPE_NUMERIC;
cols.add(asf2);
@@ -359,6 +360,7 @@
asf.boundName = "x";
asf.factField = "age";
asf.type = "String";
+
dt.actionCols.add(asf);
String[][] data = new String[][] {
@@ -368,16 +370,56 @@
String drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
+ //System.err.println(drl);
+
assertTrue(drl.indexOf("Context( )") > -1);
assertTrue(drl.indexOf("x.setAge") > drl.indexOf("Context( )"));
+ assertFalse(drl.indexOf("update( x );") > -1);
+ dt.data = new String[][] {
+ new String[] {"1", "desc", "", "old"}
+ };
+ drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
+ assertEquals(-1, drl.indexOf("Context( )"));
+
+ }
+
+ public void testUpdateModify() {
+ GuidedDecisionTable dt = new GuidedDecisionTable();
+ ConditionCol c = new ConditionCol();
+ c.boundName = "x";
+ c.factType = "Context";
+ c.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
+ dt.conditionCols.add(c);
+ ActionSetFieldCol asf = new ActionSetFieldCol();
+ asf.boundName = "x";
+ asf.factField = "age";
+ asf.type = "String";
+ asf.update = true;
+
+ dt.actionCols.add(asf);
+
+ String[][] data = new String[][] {
+ new String[] {"1", "desc", "y", "old"}
+ };
+ dt.data = data;
+
+ String drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
+
+ System.err.println(drl);
+
+ assertTrue(drl.indexOf("Context( )") > -1);
+ assertTrue(drl.indexOf("x.setAge") > drl.indexOf("Context( )"));
+
+
dt.data = new String[][] {
new String[] {"1", "desc", "", "old"}
};
drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
assertEquals(-1, drl.indexOf("Context( )"));
+ assertTrue(drl.indexOf("update( x );") > -1);
}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/GuidedDTXMLPersistenceTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/GuidedDTXMLPersistenceTest.java 2008-12-11 00:14:04 UTC (rev 24344)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/GuidedDTXMLPersistenceTest.java 2008-12-11 02:18:42 UTC (rev 24345)
@@ -2,6 +2,7 @@
import junit.framework.TestCase;
+import org.drools.guvnor.client.modeldriven.brl.RuleModel;
import org.drools.guvnor.client.modeldriven.dt.ActionInsertFactCol;
import org.drools.guvnor.client.modeldriven.dt.ActionSetFieldCol;
import org.drools.guvnor.client.modeldriven.dt.AttributeCol;
@@ -11,20 +12,41 @@
public class GuidedDTXMLPersistenceTest extends TestCase {
+// public void testXML() {
+
+// //final String xml = p.marshal( new RuleModel() );
+//
+// }
+
+ @Override
+ protected void setUp() throws Exception {
+ GuidedDTXMLPersistence.getInstance();
+ }
+
public void testRoundTrip() {
+
GuidedDecisionTable dt = new GuidedDecisionTable();
+
dt.actionCols.add(new ActionInsertFactCol());
- dt.actionCols.add(new ActionSetFieldCol());
+ ActionSetFieldCol set = new ActionSetFieldCol();
+ set.factField = "foo";
+ dt.actionCols.add(set);
+
dt.getMetadataCols().add(new MetadataCol());
+
dt.attributeCols.add(new AttributeCol());
+
dt.conditionCols.add(new ConditionCol());
+
dt.data = new String[][] {
new String[] {"hola"}
};
dt.tableName = "blah";
dt.descriptionWidth = 42;
+
String xml = GuidedDTXMLPersistence.getInstance().marshal(dt);
+ System.out.println(xml);
assertNotNull(xml);
assertEquals(-1, xml.indexOf("ActionSetField"));
assertEquals(-1, xml.indexOf("ConditionCol"));
@@ -41,4 +63,21 @@
}
+ public void testBackwardsCompatability() throws Exception {
+ String xml = BRLPersitenceTest.loadResource("ExistingDecisionTable.xml");
+ GuidedDecisionTable dt_ = GuidedDTXMLPersistence.getInstance().unmarshal(xml);
+ assertNotNull(dt_);
+ assertEquals(42, dt_.descriptionWidth);
+ assertEquals("blah", dt_.tableName);
+ assertEquals(1, dt_.getMetadataCols().size());
+ assertEquals(1, dt_.attributeCols.size());
+ assertEquals(2, dt_.actionCols.size());
+ assertEquals(1, dt_.conditionCols.size());
+
+ assertTrue(dt_.actionCols.get(1) instanceof ActionSetFieldCol );
+ ActionSetFieldCol asf = (ActionSetFieldCol) dt_.actionCols.get(1);
+ assertEquals("foo", asf.factField);
+ assertEquals(false, asf.update);
+ }
+
}
Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/guvnor/server/util/ExistingDecisionTable.xml
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/guvnor/server/util/ExistingDecisionTable.xml (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/guvnor/server/util/ExistingDecisionTable.xml 2008-12-11 02:18:42 UTC (rev 24345)
@@ -0,0 +1,34 @@
+<decision-table>
+ <tableName>blah</tableName>
+ <metadataCols>
+ <metadata-column>
+ <width>-1</width>
+ </metadata-column>
+ </metadataCols>
+ <attributeCols>
+ <attribute-column>
+ <width>-1</width>
+ </attribute-column>
+ </attributeCols>
+ <conditionCols>
+ <condition-column>
+ <width>-1</width>
+ <constraintValueType>0</constraintValueType>
+ </condition-column>
+ </conditionCols>
+ <actionCols>
+ <insert-fact-column>
+ <width>-1</width>
+ </insert-fact-column>
+ <set-field-col>
+ <width>-1</width>
+ <factField>foo</factField>
+ </set-field-col>
+ </actionCols>
+ <data>
+ <string-array>
+ <string>hola</string>
+ </string-array>
+ </data>
+ <descriptionWidth>42</descriptionWidth>
+</decision-table>
\ No newline at end of file
Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/guvnor/server/util/ExistingDecisionTable.xml
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list