[jboss-svn-commits] JBL Code SVN: r29097 - in labs/jbossrules/trunk/drools-compiler/src: test/java/org/drools/guvnor/server/util and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Aug 27 23:27:14 EDT 2009
Author: michael.neale at jboss.com
Date: 2009-08-27 23:27:14 -0400 (Thu, 27 Aug 2009)
New Revision: 29097
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/GuidedDTDRLPersistence.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/GuidedDTDRLPersistenceTest.java
Log:
GUVNOR-442 support for "in" for GDST
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 2009-08-28 02:45:09 UTC (rev 29096)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/BRDRLPersistence.java 2009-08-28 03:27:14 UTC (rev 29097)
@@ -328,9 +328,13 @@
buf.append(" )");
break;
case ISingleFieldConstraint.TYPE_LITERAL:
- buf.append('"');
- buf.append(value);
- buf.append('"');
+ if (operator.equals("in")) {
+ buf.append(value);
+ } else {
+ buf.append('"');
+ buf.append(value);
+ buf.append('"');
+ }
break;
default:
buf.append(value);
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 2009-08-28 02:45:09 UTC (rev 29096)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/guvnor/server/util/GuidedDTDRLPersistence.java 2009-08-28 03:27:14 UTC (rev 29097)
@@ -2,6 +2,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.StringTokenizer;
import org.drools.guvnor.client.modeldriven.brl.ActionFieldValue;
import org.drools.guvnor.client.modeldriven.brl.ActionInsertFact;
@@ -181,7 +182,12 @@
}
} else {
sfc.operator = c.operator;
- sfc.value = cell;
+ if (c.operator.equals("in")) {
+ sfc.value = makeInList(cell);
+ } else {
+ sfc.value = cell;
+ }
+
}
sfc.constraintValueType = c.constraintValueType;
fp.addConstraint(sfc);
@@ -205,9 +211,27 @@
rm.lhs = patterns.toArray(new IPattern[patterns.size()]);
}
+ /**
+ * take a CSV list and turn it into DRL syntax
+ */
+ String makeInList(String cell) {
+ if (cell.startsWith("(")) return cell;
+ String res = "";
+ StringTokenizer st = new StringTokenizer(cell, ",");
+ while (st.hasMoreTokens()) {
+ String t = st.nextToken().trim();
+ if (t.startsWith("\"")) {
+ res += t;
+ } else {
+ res += "\"" + t + "\"";
+ }
+ if (st.hasMoreTokens()) res += ", ";
+ }
+ return "(" + res + ")";
+ }
- private boolean no(String operator) {
+ private boolean no(String operator) {
return operator == null || "".equals(operator);
}
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 2009-08-28 02:45:09 UTC (rev 29096)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/guvnor/server/util/GuidedDTDRLPersistenceTest.java 2009-08-28 03:27:14 UTC (rev 29097)
@@ -210,6 +210,103 @@
}
+
+ public void testInOperator() {
+ GuidedDecisionTable dt = new GuidedDecisionTable();
+ dt.tableName = "michael";
+
+ AttributeCol attr = new AttributeCol();
+ attr.attr = "salience";
+ attr.defaultValue = "66";
+ dt.attributeCols.add(attr);
+
+ ConditionCol con = new ConditionCol();
+ con.boundName = "f1";
+ con.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
+ con.factField = "age";
+ con.factType = "Driver";
+ con.header = "Driver f1 age";
+ con.operator = "==";
+ dt.conditionCols.add(con);
+
+ ConditionCol con2 = new ConditionCol();
+ con2.boundName = "f1";
+ con2.constraintValueType = ISingleFieldConstraint.TYPE_LITERAL;
+ con2.factField = "name";
+ con2.factType = "Driver";
+ con2.header = "Driver f1 name";
+ con2.operator = "in";
+ dt.conditionCols.add(con2);
+
+ ConditionCol con3 = new ConditionCol();
+ con3.boundName = "f1";
+ con3.constraintValueType = ISingleFieldConstraint.TYPE_RET_VALUE;
+ con3.factField = "rating";
+ con3.factType = "Driver";
+ con3.header = "Driver rating";
+ con3.operator = "==";
+ dt.conditionCols.add(con3);
+
+
+ ConditionCol con4 = new ConditionCol();
+ con4.boundName = "f2";
+ con4.constraintValueType = ISingleFieldConstraint.TYPE_PREDICATE;
+ con4.factType = "Driver";
+ con4.header = "Driver 2 pimp";
+ con4.factField = "(not needed)";
+ dt.conditionCols.add(con4);
+
+
+ ActionInsertFactCol ins = new ActionInsertFactCol();
+ ins.boundName = "ins";
+ ins.factType = "Cheese";
+ ins.factField = "price";
+ ins.type = SuggestionCompletionEngine.TYPE_NUMERIC;
+ dt.actionCols.add(ins);
+
+ ActionRetractFactCol ret = new ActionRetractFactCol();
+ ret.boundName = "f2";
+ dt.actionCols.add(ret);
+
+ ActionSetFieldCol set = new ActionSetFieldCol();
+ set.boundName = "f1";
+ set.factField = "goo1";
+ set.type = SuggestionCompletionEngine.TYPE_STRING;
+ dt.actionCols.add(set);
+
+ ActionSetFieldCol set2 = new ActionSetFieldCol();
+ set2.boundName = "f1";
+ set2.factField = "goo2";
+ set2.defaultValue = "whee";
+ set2.type = SuggestionCompletionEngine.TYPE_STRING;
+ dt.actionCols.add(set2);
+
+ dt.data = new String[][] {
+ new String[] {"1", "desc", "42", "33", "michael, manik", "age * 0.2", "age > 7", "6.60", "true", "gooVal1", null},
+ new String[] {"2", "desc", "", "39", "bob, frank", "age * 0.3", "age > 7", "6.60", "", "gooVal1", ""}
+ };
+
+
+
+ GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
+ String drl = p.marshal(dt);
+
+
+ assertTrue(drl.indexOf("name in (\"michael\",") > 0);
+
+
+ }
+
+ public void testCellCSV() {
+ GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
+ assertEquals("(\"Michael\", \"Mark\", \"Peter\")", p.makeInList("Michael, Mark, Peter"));
+ assertEquals("(\"Michael\")", p.makeInList("Michael"));
+ assertEquals("(\"Michael\")", p.makeInList("\"Michael\""));
+ assertEquals("(\"Michael\", \"Ma rk\", \"Peter\")", p.makeInList("Michael, \"Ma rk\", Peter"));
+ assertEquals("(WEE WAAH)", p.makeInList("(WEE WAAH)"));
+ }
+
+
public void testCellVal() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
assertFalse(p.validCell(null));
More information about the jboss-svn-commits
mailing list