Search in sources :

Example 1 with BRLActionVariableColumn

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

the class BRLRuleModelTest method testUpdateModifyMultipleFieldsWithMultipleSkipped4.

@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped4() {
    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);
    BRLActionColumn brlAction1 = new BRLActionColumn();
    ActionUpdateField auf1 = new ActionUpdateField("x");
    auf1.addFieldValue(new ActionFieldValue("f1", "$f1", DataType.TYPE_STRING));
    auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brlAction1.getDefinition().add(auf1);
    brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f1", DataType.TYPE_STRING, "Context", "f1"));
    ActionUpdateField auf2 = new ActionUpdateField("x");
    auf2.addFieldValue(new ActionFieldValue("f2", "$f2", DataType.TYPE_STRING));
    auf2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brlAction1.getDefinition().add(auf2);
    brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f2", DataType.TYPE_STRING, "Context", "f2"));
    ActionUpdateField auf3 = new ActionUpdateField("x");
    auf3.addFieldValue(new ActionFieldValue("f3", "$f3", DataType.TYPE_STRING));
    auf3.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brlAction1.getDefinition().add(auf3);
    brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f3", DataType.TYPE_STRING, "Context", "f3"));
    dt.getActionCols().add(brlAction1);
    dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "x", "v1", null, "v3" } }));
    String drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
    final String expected = "//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" + "    setF1( \"v1\" ),\n" + "    setF3( \"v3\" )\n" + "}\n" + "end\n";
    assertEqualsIgnoreWhitespace(expected, drl);
}
Also used : ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) Test(org.junit.Test)

Example 2 with BRLActionVariableColumn

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

the class GuidedDTDRLPersistenceTest method testRHSWithBRLColumn_ParseToDRL_FreeFormLine.

@Test
public // This test checks a Decision Table involving BRL columns is correctly converted into DRL
void testRHSWithBRLColumn_ParseToDRL_FreeFormLine() {
    GuidedDecisionTable52 dtable = new GuidedDecisionTable52();
    // Row 0 should become an IAction in the resulting RuleModel as it contains values for all Template fields in the BRL Column
    // Row 1 should *NOT* become an IAction in the resulting RuleModel as it does *NOT* contain values for all Template fields in the BRL Column
    // Row 2 should *NOT* become an IAction in the resulting RuleModel as it does *NOT* contain values for all Template fields in the BRL Column
    // Row 3 should *NOT* become an IAction in the resulting RuleModel as it does *NOT* contain values for all Template fields in the BRL Column
    String[][] data = new String[][] { new String[] { "1", "desc", "Pupa", "50" }, new String[] { "2", "desc", "", "50" }, new String[] { "3", "desc", "Pupa", "" }, new String[] { "4", "desc", "", "" } };
    // Simple (mandatory) columns
    dtable.setRowNumberCol(new RowNumberCol52());
    dtable.setDescriptionCol(new DescriptionCol52());
    // BRL Action
    BRLActionColumn brl1 = new BRLActionColumn();
    // BRL Action definition
    List<IAction> brl1Definition = new ArrayList<IAction>();
    FreeFormLine brl1DefinitionFreeFormLine = new FreeFormLine();
    brl1DefinitionFreeFormLine.setText("System.out.println( \"name == @{name}, age == @{age}\" );");
    brl1Definition.add(brl1DefinitionFreeFormLine);
    brl1.setDefinition(brl1Definition);
    // Setup BRL column bindings
    BRLActionVariableColumn brl1Variable1 = new BRLActionVariableColumn("name", DataType.TYPE_STRING);
    BRLActionVariableColumn brl1Variable2 = new BRLActionVariableColumn("age", DataType.TYPE_NUMERIC_INTEGER);
    brl1.getChildColumns().add(brl1Variable1);
    brl1.getChildColumns().add(brl1Variable2);
    dtable.getActionCols().add(brl1);
    dtable.setData(DataUtilities.makeDataLists(data));
    // Now to test conversion
    int ruleStartIndex;
    int pattern1StartIndex;
    GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
    String drl = p.marshal(dtable);
    // Row 0
    ruleStartIndex = drl.indexOf("//from row number: 1");
    assertFalse(ruleStartIndex == -1);
    pattern1StartIndex = drl.indexOf("System.out.println( \"name == Pupa, age == 50\" );", ruleStartIndex);
    assertFalse(pattern1StartIndex == -1);
    // Row 1
    ruleStartIndex = drl.indexOf("//from row number: 2");
    assertFalse(ruleStartIndex == -1);
    pattern1StartIndex = drl.indexOf("System.out.println(", ruleStartIndex);
    assertTrue(pattern1StartIndex == -1);
    // Row 2
    ruleStartIndex = drl.indexOf("//from row number: 3");
    assertFalse(ruleStartIndex == -1);
    pattern1StartIndex = drl.indexOf("System.out.println(", ruleStartIndex);
    assertTrue(pattern1StartIndex == -1);
    // Row 3
    ruleStartIndex = drl.indexOf("//from row number: 4");
    assertFalse(ruleStartIndex == -1);
    pattern1StartIndex = drl.indexOf("System.out.println(", ruleStartIndex);
    assertTrue(pattern1StartIndex == -1);
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) IAction(org.drools.workbench.models.datamodel.rule.IAction) ArrayList(java.util.ArrayList) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 3 with BRLActionVariableColumn

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

the class BRLRuleModelTest method testUpdateModifyMultipleFieldsWithMultipleSkipped2.

@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped2() {
    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);
    BRLActionColumn brlAction1 = new BRLActionColumn();
    ActionUpdateField auf1 = new ActionUpdateField("x");
    auf1.addFieldValue(new ActionFieldValue("f1", "$f1", DataType.TYPE_STRING));
    auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brlAction1.getDefinition().add(auf1);
    brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f1", DataType.TYPE_STRING, "Context", "f1"));
    ActionUpdateField auf2 = new ActionUpdateField("x");
    auf2.addFieldValue(new ActionFieldValue("f2", "$f2", DataType.TYPE_STRING));
    auf2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brlAction1.getDefinition().add(auf2);
    brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f2", DataType.TYPE_STRING, "Context", "f2"));
    ActionUpdateField auf3 = new ActionUpdateField("x");
    auf3.addFieldValue(new ActionFieldValue("f3", "$f3", DataType.TYPE_STRING));
    auf3.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brlAction1.getDefinition().add(auf3);
    brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f3", DataType.TYPE_STRING, "Context", "f3"));
    dt.getActionCols().add(brlAction1);
    dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "x", null, "v2", "v3" } }));
    String drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
    final String expected = "//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" + "    setF2( \"v2\" ),\n" + "    setF3( \"v3\" )\n" + "}\n" + "end\n";
    assertEqualsIgnoreWhitespace(expected, drl);
}
Also used : ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) Test(org.junit.Test)

Example 4 with BRLActionVariableColumn

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

the class BRLRuleModelTest 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);
    BRLActionColumn brlAction1 = new BRLActionColumn();
    ActionUpdateField auf1 = new ActionUpdateField("x");
    auf1.addFieldValue(new ActionFieldValue("age", "$age", DataType.TYPE_NUMERIC_INTEGER));
    auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brlAction1.getDefinition().add(auf1);
    brlAction1.getChildColumns().add(new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Context", "age"));
    dt.getActionCols().add(brlAction1);
    BRLActionColumn brlAction2 = new BRLActionColumn();
    ActionUpdateField auf2 = new ActionUpdateField("x");
    auf2.addFieldValue(new ActionFieldValue("name", "$name", DataType.TYPE_STRING));
    auf2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brlAction2.getDefinition().add(auf2);
    brlAction2.getChildColumns().add(new BRLActionVariableColumn("$name", DataType.TYPE_STRING, "Context", "name"));
    dt.getActionCols().add(brlAction2);
    dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "x", "55", "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 String[][] { new String[] { "1", "desc", "x", "", "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 String[][] { new String[] { "1", "desc", "x", "55", "" } }));
    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 : ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) Test(org.junit.Test)

Example 5 with BRLActionVariableColumn

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

the class BRLRuleModelTest method testUpdateModifyMultipleFieldsWithMultipleSkipped1.

@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped1() {
    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);
    BRLActionColumn brlAction1 = new BRLActionColumn();
    ActionUpdateField auf1 = new ActionUpdateField("x");
    auf1.addFieldValue(new ActionFieldValue("f1", "$f1", DataType.TYPE_STRING));
    auf1.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brlAction1.getDefinition().add(auf1);
    brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f1", DataType.TYPE_STRING, "Context", "f1"));
    ActionUpdateField auf2 = new ActionUpdateField("x");
    auf2.addFieldValue(new ActionFieldValue("f2", "$f2", DataType.TYPE_STRING));
    auf2.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brlAction1.getDefinition().add(auf2);
    brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f2", DataType.TYPE_STRING, "Context", "f2"));
    ActionUpdateField auf3 = new ActionUpdateField("x");
    auf3.addFieldValue(new ActionFieldValue("f3", "$f3", DataType.TYPE_STRING));
    auf3.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brlAction1.getDefinition().add(auf3);
    brlAction1.getChildColumns().add(new BRLActionVariableColumn("$f3", DataType.TYPE_STRING, "Context", "f3"));
    dt.getActionCols().add(brlAction1);
    dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc", "x", "v1", "v2", "v3" } }));
    String drl = GuidedDTDRLPersistence.getInstance().marshal(dt);
    final String expected = "//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" + "    setF1( \"v1\" ), \n" + "    setF2( \"v2\" ),\n" + "    setF3( \"v3\" )\n" + "}\n" + "end\n";
    assertEqualsIgnoreWhitespace(expected, drl);
}
Also used : ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) Test(org.junit.Test)

Aggregations

BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)72 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)56 Test (org.junit.Test)41 ArrayList (java.util.ArrayList)28 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)28 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)23 IAction (org.drools.workbench.models.datamodel.rule.IAction)20 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)20 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)19 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)18 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)18 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)17 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)16 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)13 RuleNameColumn (org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn)13 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)12 InputStream (java.io.InputStream)11 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)11 ConversionResult (org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult)11 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)11