Search in sources :

Example 51 with AttributeCol52

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);
}
Also used : AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Test(org.junit.Test)

Example 52 with AttributeCol52

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);
}
Also used : AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) LimitedEntryActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52) ActionRetractFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) LimitedEntryActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) Test(org.junit.Test)

Example 53 with AttributeCol52

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);
}
Also used : AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) LimitedEntryActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52) ActionRetractFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) LimitedEntryActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) Test(org.junit.Test)

Example 54 with AttributeCol52

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());
}
Also used : ArrayList(java.util.ArrayList) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 55 with AttributeCol52

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;
}
Also used : AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)

Aggregations

AttributeCol52 (org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52)86 Test (org.junit.Test)55 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)30 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)20 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)14 ArrayList (java.util.ArrayList)12 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)12 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)10 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)10 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)9 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)8 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)8 MetadataCol52 (org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52)7 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 ExcelParser (org.drools.decisiontable.parser.xls.ExcelParser)6 DataListener (org.drools.template.parser.DataListener)6 ConversionResult (org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult)6 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)5 IntegerUiColumn (org.drools.workbench.screens.guided.dtable.client.widget.table.columns.IntegerUiColumn)5