Search in sources :

Example 1 with ActionSetFieldCol52

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

the class GuidedDTDRLPersistence method doActions.

void doActions(List<BaseColumn> allColumns, List<ActionCol52> actionCols, TemplateDataProvider rowDataProvider, List<DTCellValue52> row, RuleModel rm) {
    List<LabelledAction> actions = new ArrayList<LabelledAction>();
    for (ActionCol52 c : actionCols) {
        if (c instanceof LimitedEntryBRLActionColumn) {
            doAction(allColumns, (LimitedEntryBRLActionColumn) c, actions, rowDataProvider, row, rm);
        } else if (c instanceof BRLActionColumn) {
            doAction(allColumns, (BRLActionColumn) c, actions, rowDataProvider, row, rm);
        } else {
            int index = allColumns.indexOf(c);
            DTCellValue52 dcv = row.get(index);
            String cell = "";
            if (c instanceof LimitedEntryCol) {
                if (dcv.getBooleanValue() == true) {
                    LimitedEntryCol lec = (LimitedEntryCol) c;
                    cell = GuidedDTDRLUtilities.convertDTCellValueToString(lec.getValue());
                }
            } else {
                cell = GuidedDTDRLUtilities.convertDTCellValueToString(dcv);
            }
            if (validCell(cell, dcv.getDataType())) {
                if (c instanceof ActionWorkItemInsertFactCol52) {
                    doAction(actions, (ActionWorkItemInsertFactCol52) c, cell);
                } else if (c instanceof ActionInsertFactCol52) {
                    doAction(actions, (ActionInsertFactCol52) c, cell);
                } else if (c instanceof ActionWorkItemSetFieldCol52) {
                    doAction(actions, (ActionWorkItemSetFieldCol52) c, cell);
                } else if (c instanceof ActionSetFieldCol52) {
                    doAction(actions, (ActionSetFieldCol52) c, cell);
                } else if (c instanceof ActionRetractFactCol52) {
                    doAction(actions, cell);
                } else if (c instanceof ActionWorkItemCol52) {
                    doAction(actions, (ActionWorkItemCol52) c, cell);
                }
            }
        }
    }
    rm.rhs = new IAction[actions.size()];
    for (int i = 0; i < rm.rhs.length; i++) {
        rm.rhs[i] = actions.get(i).action;
    }
}
Also used : ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) ActionWorkItemInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemInsertFactCol52) ActionRetractFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52) ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) ArrayList(java.util.ArrayList) ActionWorkItemSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemSetFieldCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) LimitedEntryCol(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol) LimitedEntryBRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryBRLActionColumn) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) LimitedEntryBRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryBRLActionColumn)

Example 2 with ActionSetFieldCol52

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

the class GuidedDecisionTableUpgradeHelper1 method makeNewColumn.

private ActionSetFieldCol52 makeNewColumn(ActionSetFieldCol c) {
    ActionSetFieldCol52 nc = new ActionSetFieldCol52();
    nc.setBoundName(c.boundName);
    nc.setDefaultValue(new DTCellValue52(c.defaultValue));
    nc.setFactField(c.factField);
    nc.setHeader(c.header);
    nc.setHideColumn(c.hideColumn);
    nc.setType(c.type);
    nc.setUpdate(c.update);
    nc.setValueList(c.valueList);
    nc.setWidth(c.width);
    return nc;
}
Also used : DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)

Example 3 with ActionSetFieldCol52

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

the class GuidedDTDRLPersistenceTest method testInOperator.

@Test
public void testInOperator() {
    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("in");
    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);
    ConditionCol52 con4 = new ConditionCol52();
    con4.setConstraintValueType(BaseSingleFieldConstraint.TYPE_PREDICATE);
    con4.setHeader("Driver 2 pimp");
    con4.setFactField("(not needed)");
    p1.getChildColumns().add(con4);
    dt.getConditions().add(p1);
    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, manik", "age * 0.2", "age > 7", "6.60", "true", "gooVal1", "f2" }, new String[] { "2", "desc", "", "39", "bob, frank", "age * 0.3", "age > 7", "6.60", "", "gooVal1", null } }));
    GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
    String drl = p.marshal(dt);
    assertTrue(drl.indexOf("name in ( \"michael\",") > 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 4 with ActionSetFieldCol52

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

the class GuidedDTXMLPersistenceTest method testRoundTrip.

@Test
public void testRoundTrip() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    dt.getActionCols().add(new ActionInsertFactCol52());
    ActionSetFieldCol52 set = new ActionSetFieldCol52();
    set.setFactField("foo");
    dt.getActionCols().add(set);
    dt.getMetadataCols().add(new MetadataCol52());
    dt.getAttributeCols().add(new AttributeCol52());
    Pattern52 p = new Pattern52();
    ConditionCol52 c = new ConditionCol52();
    p.getChildColumns().add(c);
    dt.getConditions().add(p);
    dt.setData(upgrader.makeDataLists(new String[][] { new String[] { "1", "hola" } }));
    dt.setTableName("blah");
    String xml = GuidedDTXMLPersistence.getInstance().marshal(dt);
    System.out.println(xml);
    assertNotNull(xml);
    assertEquals(-1, xml.indexOf("ActionSetField"));
    assertEquals(-1, xml.indexOf("ConditionCol"));
    assertEquals(-1, xml.indexOf("GuidedDecisionTable"));
    GuidedDecisionTable52 dt_ = GuidedDTXMLPersistence.getInstance().unmarshal(xml);
    assertNotNull(dt_);
    assertEquals("blah", dt_.getTableName());
    assertEquals(1, dt_.getMetadataCols().size());
    assertEquals(1, dt_.getAttributeCols().size());
    assertEquals(2, dt_.getActionCols().size());
    assertEquals(1, dt_.getConditions().size());
    assertEquals(1, dt_.getConditions().get(0).getChildColumns().size());
}
Also used : MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) Test(org.junit.Test)

Example 5 with ActionSetFieldCol52

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

the class GuidedDTDRLPersistenceTest method testUpdateModifyMultipleFields.

@Test
public void testUpdateModifyMultipleFields() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("x");
    p1.setFactType("Context");
    ConditionCol52 c = new ConditionCol52();
    c.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    p1.getChildColumns().add(c);
    dt.getConditions().add(p1);
    ActionSetFieldCol52 asf1 = new ActionSetFieldCol52();
    asf1.setBoundName("x");
    asf1.setFactField("age");
    asf1.setType(DataType.TYPE_NUMERIC_INTEGER);
    asf1.setUpdate(true);
    dt.getActionCols().add(asf1);
    ActionSetFieldCol52 asf2 = new ActionSetFieldCol52();
    asf2.setBoundName("x");
    asf2.setFactField("name");
    asf2.setType(DataType.TYPE_STRING);
    asf2.setUpdate(true);
    dt.getActionCols().add(asf2);
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { "1", "desc", "x", 55l, "Fred" } }));
    String drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
    final String expected1 = "//from row number: 1\n" + "//desc\n" + "rule \"Row 1 null\"\n" + "dialect \"mvel\"\n" + "when\n" + "  x : Context( )\n" + "then\n" + "  modify( x ) {\n" + "    setAge( 55 ), \n" + "    setName( \"Fred\" )\n" + "}\n" + "end\n";
    assertEqualsIgnoreWhitespace(expected1, drl);
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { "1", "desc", "x", null, "Fred" } }));
    drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
    final String expected2 = "//from row number: 1\n" + "//desc\n" + "rule \"Row 1 null\"\n" + "dialect \"mvel\"\n" + "when\n" + "  x : Context( )\n" + "then\n" + "  modify( x ) {\n" + "    setName( \"Fred\" )\n" + "}\n" + "end\n";
    assertEqualsIgnoreWhitespace(expected2, drl);
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { "1", "desc", "x", 55l, null } }));
    drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
    final String expected3 = "//from row number: 1\n" + "//desc\n" + "rule \"Row 1 null\"\n" + "dialect \"mvel\"\n" + "when\n" + "  x : Context( )\n" + "then\n" + "  modify( x ) {\n" + "    setAge( 55 ) \n" + "}\n" + "end\n";
    assertEqualsIgnoreWhitespace(expected3, drl);
}
Also used : 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) LimitedEntryActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) Test(org.junit.Test)

Aggregations

ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)75 Test (org.junit.Test)49 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)39 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)38 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)29 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)27 LimitedEntryActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52)23 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)16 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)16 LimitedEntryActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)12 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)12 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)12 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)12 Path (org.uberfire.backend.vfs.Path)12 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)11 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)11 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)10 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)9 ActionRetractFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionRetractFactCol52)8 AttributeCol52 (org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52)8