use of org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLimitedEntryAttributes.
@Test
public void testLimitedEntryAttributes() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY);
dt.setTableName("limited-entry");
AttributeCol52 attr = new AttributeCol52();
attr.setAttribute("salience");
dt.getAttributeCols().add(attr);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "100" }, new String[] { "2", "desc", "200" } }));
GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
String drl = p.marshal(dt);
assertTrue(drl.indexOf("salience 100") > -1);
assertTrue(drl.indexOf("salience 200") > -1);
}
use of org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method test2Rules.
@Test
public void test2Rules() throws Exception {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.setTableName("michael");
AttributeCol52 attr = new AttributeCol52();
attr.setAttribute("salience");
attr.setDefaultValue(new DTCellValue52("66"));
dt.getAttributeCols().add(attr);
Pattern52 p1 = new Pattern52();
p1.setBoundName("f1");
p1.setFactType("Driver");
ConditionCol52 con = new ConditionCol52();
con.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
con.setFactField("age");
con.setHeader("Driver f1 age");
con.setOperator("==");
p1.getChildColumns().add(con);
ConditionCol52 con2 = new ConditionCol52();
con2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
con2.setFactField("name");
con2.setHeader("Driver f1 name");
con2.setOperator("==");
p1.getChildColumns().add(con2);
ConditionCol52 con3 = new ConditionCol52();
con3.setConstraintValueType(BaseSingleFieldConstraint.TYPE_RET_VALUE);
con3.setFactField("rating");
con3.setHeader("Driver rating");
con3.setOperator("==");
p1.getChildColumns().add(con3);
dt.getConditions().add(p1);
Pattern52 p2 = new Pattern52();
p2.setBoundName("f2");
p2.setFactType("Driver");
ConditionCol52 con4 = new ConditionCol52();
con4.setConstraintValueType(BaseSingleFieldConstraint.TYPE_PREDICATE);
con4.setHeader("Driver 2 pimp");
con4.setFactField("(not needed)");
p2.getChildColumns().add(con4);
dt.getConditions().add(p2);
ActionInsertFactCol52 ins = new ActionInsertFactCol52();
ins.setBoundName("ins");
ins.setFactType("Cheese");
ins.setFactField("price");
ins.setType(DataType.TYPE_NUMERIC_INTEGER);
dt.getActionCols().add(ins);
ActionRetractFactCol52 ret = new ActionRetractFactCol52();
dt.getActionCols().add(ret);
ActionSetFieldCol52 set = new ActionSetFieldCol52();
set.setBoundName("f1");
set.setFactField("goo1");
set.setType(DataType.TYPE_STRING);
dt.getActionCols().add(set);
ActionSetFieldCol52 set2 = new ActionSetFieldCol52();
set2.setBoundName("f1");
set2.setFactField("goo2");
set2.setDefaultValue(new DTCellValue52("whee"));
set2.setType(DataType.TYPE_STRING);
dt.getActionCols().add(set2);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "42", "33", "michael", "age * 0.2", "age > 7", "6.60", "true", "gooVal1", "f2" }, new String[] { "2", "desc", "66", "39", "bob", "age * 0.3", "age > 7", "6.60", "", "gooVal1", "whee" } }));
GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
String drl = p.marshal(dt);
assertTrue(drl.indexOf("from row number") > -1);
assertTrue(drl.indexOf("rating == ( age * 0.2 )") > 0);
assertTrue(drl.indexOf("f2 : Driver( eval( age > 7 ))") > 0);
assertTrue(drl.indexOf("rating == ( age * 0.3 )") > drl.indexOf("rating == ( age * 0.2 )"));
assertTrue(drl.indexOf("f1.setGoo2( \"whee\" )") > 0);
assertTrue(drl.indexOf("salience 66") > 0);
}
use of org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testInterpolate.
@Test
public void testInterpolate() {
GuidedDecisionTable52 dt = new GuidedDecisionTable52();
dt.setTableName("michael");
AttributeCol52 attr = new AttributeCol52();
attr.setAttribute("salience");
attr.setDefaultValue(new DTCellValue52("66"));
dt.getAttributeCols().add(attr);
Pattern52 p1 = new Pattern52();
p1.setBoundName("f1");
p1.setFactType("Driver");
ConditionCol52 con = new ConditionCol52();
con.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
con.setFactField("age");
con.setHeader("Driver f1 age");
con.setOperator("==");
p1.getChildColumns().add(con);
ConditionCol52 con2 = new ConditionCol52();
con2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
con2.setFactField("name");
con2.setHeader("Driver f1 name");
con2.setOperator("==");
p1.getChildColumns().add(con2);
ConditionCol52 con3 = new ConditionCol52();
con3.setConstraintValueType(BaseSingleFieldConstraint.TYPE_RET_VALUE);
con3.setFactField("rating");
con3.setHeader("Driver rating");
con3.setOperator("==");
p1.getChildColumns().add(con3);
dt.getConditions().add(p1);
Pattern52 p2 = new Pattern52();
p2.setBoundName("f2");
p2.setFactType("Driver");
ConditionCol52 con4 = new ConditionCol52();
con4.setConstraintValueType(BaseSingleFieldConstraint.TYPE_PREDICATE);
con4.setHeader("Driver 2 pimp");
con4.setFactField("this.hasSomething($param)");
p2.getChildColumns().add(con4);
dt.getConditions().add(p2);
ActionInsertFactCol52 ins = new ActionInsertFactCol52();
ins.setBoundName("ins");
ins.setFactType("Cheese");
ins.setFactField("price");
ins.setType(DataType.TYPE_NUMERIC_INTEGER);
dt.getActionCols().add(ins);
ActionRetractFactCol52 ret = new ActionRetractFactCol52();
dt.getActionCols().add(ret);
ActionSetFieldCol52 set = new ActionSetFieldCol52();
set.setBoundName("f1");
set.setFactField("goo1");
set.setType(DataType.TYPE_STRING);
dt.getActionCols().add(set);
ActionSetFieldCol52 set2 = new ActionSetFieldCol52();
set2.setBoundName("f1");
set2.setFactField("goo2");
set2.setDefaultValue(new DTCellValue52("whee"));
set2.setType(DataType.TYPE_STRING);
dt.getActionCols().add(set2);
dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "42", "33", "michael", "age * 0.2", "BAM", "6.60", "true", "gooVal1", "f2" }, new String[] { "2", "desc", "66", "39", "bob", "age * 0.3", "BAM", "6.60", "", "gooVal1", "whee" } }));
GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
String drl = p.marshal(dt);
assertTrue(drl.indexOf("from row number") > -1);
assertTrue(drl.indexOf("rating == ( age * 0.2 )") > 0);
assertTrue(drl.indexOf("f2 : Driver( eval( this.hasSomething(BAM) ))") > 0);
assertTrue(drl.indexOf("rating == ( age * 0.3 )") > drl.indexOf("rating == ( age * 0.2 )"));
assertTrue(drl.indexOf("f1.setGoo2( \"whee\" )") > 0);
assertTrue(drl.indexOf("salience 66") > 0);
}
use of org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testAttribs.
@Test
public void testAttribs() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
Object[] row = new Object[] { "1", "desc", "a", null };
List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
allColumns.add(new RowNumberCol52());
allColumns.add(new DescriptionCol52());
List<AttributeCol52> attributeCols = new ArrayList<AttributeCol52>();
RuleModel rm = new RuleModel();
RuleAttribute[] orig = rm.attributes;
p.doAttribs(allColumns, attributeCols, DataUtilities.makeDataRowList(row), rm);
assertSame(orig, rm.attributes);
AttributeCol52 col1 = new AttributeCol52();
col1.setAttribute("salience");
AttributeCol52 col2 = new AttributeCol52();
col2.setAttribute("agenda-group");
attributeCols.add(col1);
attributeCols.add(col2);
allColumns.addAll(attributeCols);
p.doAttribs(allColumns, attributeCols, DataUtilities.makeDataRowList(row), rm);
assertEquals(1, rm.attributes.length);
assertEquals("salience", rm.attributes[0].getAttributeName());
assertEquals("a", rm.attributes[0].getValue());
row = new Object[] { "1", "desc", 1l, "b" };
p.doAttribs(allColumns, attributeCols, DataUtilities.makeDataRowList(row), rm);
assertEquals(2, rm.attributes.length);
assertEquals("salience", rm.attributes[0].getAttributeName());
assertEquals("1", rm.attributes[0].getValue());
assertEquals("agenda-group", rm.attributes[1].getAttributeName());
assertEquals("b", rm.attributes[1].getValue());
}
use of org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52 in project drools by kiegroup.
the class GuidedDecisionTableUpgradeHelper1 method makeNewColumn.
private AttributeCol52 makeNewColumn(AttributeCol c) {
AttributeCol52 nc = new AttributeCol52();
nc.setAttribute(c.attr);
nc.setDefaultValue(new DTCellValue52(c.defaultValue));
nc.setHideColumn(c.hideColumn);
nc.setReverseOrder(c.reverseOrder);
nc.setUseRowNumber(c.useRowNumber);
nc.setWidth(c.width);
return nc;
}
Aggregations