Search in sources :

Example 16 with ActionRetractFactCol52

use of org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52 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 17 with ActionRetractFactCol52

use of org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52 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 18 with ActionRetractFactCol52

use of org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52 in project drools by kiegroup.

the class GuidedDTDRLPersistenceTest method testRHS.

@Test
public void testRHS() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] { "1", "desc", "a", "a condition", "actionsetfield1", "actionupdatefield2", "retract", "actioninsertfact1", "actioninsertfact2" };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    allColumns.add(new MetadataCol52());
    allColumns.add(new ConditionCol52());
    List<ActionCol52> cols = new ArrayList<ActionCol52>();
    ActionSetFieldCol52 asf1 = new ActionSetFieldCol52();
    asf1.setBoundName("a");
    asf1.setFactField("field1");
    asf1.setType(DataType.TYPE_STRING);
    cols.add(asf1);
    ActionSetFieldCol52 asf2 = new ActionSetFieldCol52();
    asf2.setBoundName("a");
    asf2.setFactField("field2");
    asf2.setUpdate(true);
    asf2.setType(DataType.TYPE_NUMERIC_INTEGER);
    cols.add(asf2);
    ActionRetractFactCol52 ret = new ActionRetractFactCol52();
    cols.add(ret);
    ActionInsertFactCol52 ins1 = new ActionInsertFactCol52();
    ins1.setBoundName("ins");
    ins1.setFactType("Cheese");
    ins1.setFactField("price");
    ins1.setType(DataType.TYPE_NUMERIC_INTEGER);
    cols.add(ins1);
    ActionInsertFactCol52 ins2 = new ActionInsertFactCol52();
    ins2.setBoundName("ins");
    ins2.setFactType("Cheese");
    ins2.setFactField("type");
    ins2.setType(DataType.TYPE_NUMERIC_INTEGER);
    cols.add(ins2);
    RuleModel rm = new RuleModel();
    allColumns.addAll(cols);
    List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
    TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
    p.doActions(allColumns, cols, rowDataProvider, rowData, rm);
    assertEquals(4, rm.rhs.length);
    // examine the set field action that is produced
    ActionSetField a1 = (ActionSetField) rm.rhs[0];
    assertEquals("a", a1.getVariable());
    assertEquals(1, a1.getFieldValues().length);
    assertEquals("field1", a1.getFieldValues()[0].getField());
    assertEquals("actionsetfield1", a1.getFieldValues()[0].getValue());
    assertEquals(DataType.TYPE_STRING, a1.getFieldValues()[0].getType());
    ActionSetField a2 = (ActionSetField) rm.rhs[1];
    assertEquals("a", a2.getVariable());
    assertEquals(1, a2.getFieldValues().length);
    assertEquals("field2", a2.getFieldValues()[0].getField());
    assertEquals("actionupdatefield2", a2.getFieldValues()[0].getValue());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, a2.getFieldValues()[0].getType());
    // examine the retract
    ActionRetractFact a3 = (ActionRetractFact) rm.rhs[2];
    assertEquals("retract", a3.getVariableName());
    // examine the insert
    ActionInsertFact a4 = (ActionInsertFact) rm.rhs[3];
    assertEquals("Cheese", a4.getFactType());
    assertEquals(2, a4.getFieldValues().length);
    assertEquals("price", a4.getFieldValues()[0].getField());
    assertEquals("actioninsertfact1", a4.getFieldValues()[0].getValue());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, a4.getFieldValues()[0].getType());
    assertEquals("type", a4.getFieldValues()[1].getField());
    assertEquals("actioninsertfact2", a4.getFieldValues()[1].getValue());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, a4.getFieldValues()[1].getType());
}
Also used : 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) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) ArrayList(java.util.ArrayList) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) 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) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) TemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider) Test(org.junit.Test)

Example 19 with ActionRetractFactCol52

use of org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52 in project drools by kiegroup.

the class GuidedDecisionTableUpgradeHelper1 method makeNewColumn.

private ActionRetractFactCol52 makeNewColumn(ActionRetractFactCol c) {
    ActionRetractFactCol52 nc = new ActionRetractFactCol52();
    nc.setDefaultValue(new DTCellValue52(c.defaultValue));
    nc.setHeader(c.header);
    nc.setHideColumn(c.hideColumn);
    nc.setWidth(c.width);
    return nc;
}
Also used : ActionRetractFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)

Example 20 with ActionRetractFactCol52

use of org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52 in project drools-wb by kiegroup.

the class ActionRetractFactPlugin method clone.

ActionRetractFactCol52 clone(final ActionRetractFactCol52 col52) {
    final ActionRetractFactCol52 clone;
    if (col52 instanceof LimitedEntryCol) {
        clone = new LimitedEntryActionRetractFactCol52();
        final DTCellValue52 oldValue = ((LimitedEntryCol) col52).getValue();
        final DTCellValue52 newValue = new DTCellValue52(oldValue.getStringValue());
        ((LimitedEntryCol) clone).setValue(newValue);
    } else {
        clone = new ActionRetractFactCol52();
    }
    clone.setHeader(col52.getHeader());
    clone.setHideColumn(col52.isHideColumn());
    return clone;
}
Also used : LimitedEntryActionRetractFactCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionRetractFactCol52) LimitedEntryActionRetractFactCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionRetractFactCol52) ActionRetractFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) LimitedEntryCol(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol)

Aggregations

ActionRetractFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52)31 Test (org.junit.Test)24 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)11 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)10 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)8 LimitedEntryActionRetractFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionRetractFactCol52)7 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)6 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)4 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)4 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)4 LimitedEntryActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)4 LimitedEntryActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52)4 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)4 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)4 BoundFactUiColumn (org.drools.workbench.screens.guided.dtable.client.widget.table.columns.BoundFactUiColumn)4 AttributeCol52 (org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52)3 BaseColumnFieldDiff (org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2