Search in sources :

Example 16 with GuidedDecisionTable52

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

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

the class BRLRuleModelTest method testRuleModelWithRHSBoundFactsUsageWithActionInsertFact.

@Test
public void testRuleModelWithRHSBoundFactsUsageWithActionInsertFact() {
    final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    // Setup Decision Table columns
    final Pattern52 p1 = new Pattern52();
    p1.setFactType("Driver");
    p1.setBoundName("$d");
    dt.getConditions().add(p1);
    final ActionInsertFactCol52 ins = new ActionInsertFactCol52();
    ins.setBoundName("$ins");
    ins.setFactField("rating");
    ins.setFactType("Person");
    ins.setType(DataType.TYPE_STRING);
    dt.getActionCols().add(ins);
    final BRLRuleModel model = new BRLRuleModel(dt);
    // Checks
    assertTrue(model.isBoundFactUsed("$ins"));
    assertFalse(model.isBoundFactUsed("$cheese"));
}
Also used : 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) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) Test(org.junit.Test)

Example 18 with GuidedDecisionTable52

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

the class BRLRuleModelTest method testRuleModelWithRHSBoundFactsUsageWithActionRetractFact.

@Test
public void testRuleModelWithRHSBoundFactsUsageWithActionRetractFact() {
    final GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    // Setup Decision Table columns
    final Pattern52 p1 = new Pattern52();
    p1.setFactType("Driver");
    p1.setBoundName("$d");
    dt.getConditions().add(p1);
    final ActionRetractFactCol52 del = new ActionRetractFactCol52();
    dt.getActionCols().add(del);
    dt.getData().add(Arrays.asList(new DTCellValue52(1), new DTCellValue52("description"), new DTCellValue52("$d")));
    final BRLRuleModel model = new BRLRuleModel(dt);
    // Checks
    assertTrue(model.isBoundFactUsed("$d"));
    assertFalse(model.isBoundFactUsed("$cheese"));
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) 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) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) Test(org.junit.Test)

Example 19 with GuidedDecisionTable52

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

the class BRLRuleModelTest method testLHSNonEmptyStringValuesFreeFormLine.

@Test
public void testLHSNonEmptyStringValuesFreeFormLine() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    dt.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY);
    dt.setTableName("extended-entry");
    BRLConditionColumn brlCondition = new BRLConditionColumn();
    FreeFormLine ffl = new FreeFormLine();
    ffl.setText("p1 : Smurf( name ==\"@{$f1}\", age == @{$f2} )");
    brlCondition.getDefinition().add(ffl);
    brlCondition.getChildColumns().add(new BRLConditionVariableColumn("$f1", DataType.TYPE_STRING, "Smurf", "name"));
    brlCondition.getChildColumns().add(new BRLConditionVariableColumn("$f2", DataType.TYPE_NUMERIC_INTEGER, "Smurf", "age"));
    dt.getConditions().add(brlCondition);
    GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
    // Test 1
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 1l, "desc-row1", "Pupa", null } }));
    String drl1 = p.marshal(dt);
    final String expected1 = "//from row number: 1\n" + "//desc-row1\n" + "rule \"Row 1 extended-entry\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "  then\n" + "end";
    assertEqualsIgnoreWhitespace(expected1, drl1);
    // Test 2
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 2l, "desc-row2", null, 35l } }));
    String drl2 = p.marshal(dt);
    final String expected2 = "//from row number: 1\n" + "//desc-row2\n" + "rule \"Row 2 extended-entry\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "  then\n" + "end";
    assertEqualsIgnoreWhitespace(expected2, drl2);
    // Test 3
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 3l, "desc-row3", "Pupa", 35l } }));
    String drl3 = p.marshal(dt);
    final String expected3 = "//from row number: 1\n" + "//desc-row3\n" + "rule \"Row 3 extended-entry\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    p1 : Smurf( name == \"Pupa\", age == 35 )\n" + "  then\n" + "end";
    assertEqualsIgnoreWhitespace(expected3, drl3);
    // Test 4
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 4l, "desc-row4", null, null } }));
    String drl4 = p.marshal(dt);
    final String expected4 = "//from row number: 1\n" + "//desc-row4\n" + "rule \"Row 4 extended-entry\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "  then\n" + "end";
    assertEqualsIgnoreWhitespace(expected4, drl4);
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) Test(org.junit.Test)

Example 20 with GuidedDecisionTable52

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

the class BRLRuleModelTest method testDecisionTableColumnsWithLHSBoundFacts.

@Test
public void testDecisionTableColumnsWithLHSBoundFacts() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    Pattern52 p1 = new Pattern52();
    p1.setFactType("Driver");
    p1.setBoundName("$p1");
    ConditionCol52 c1 = new ConditionCol52();
    c1.setFactField("name");
    c1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    c1.setBinding("$c1");
    p1.getChildColumns().add(c1);
    dt.getConditions().add(p1);
    BRLConditionColumn brlCondition = new BRLConditionColumn();
    FactPattern fp = new FactPattern("Driver");
    fp.setBoundName("$brl1");
    SingleFieldConstraint sfc1 = new SingleFieldConstraint();
    sfc1.setFieldBinding("$sfc1");
    sfc1.setOperator("==");
    sfc1.setFactType("Driver");
    sfc1.setFieldName("name");
    sfc1.setFieldType(DataType.TYPE_STRING);
    fp.addConstraint(sfc1);
    brlCondition.getDefinition().add(fp);
    dt.getConditions().add(brlCondition);
    ActionInsertFactCol52 ins = new ActionInsertFactCol52();
    ins.setBoundName("$ins");
    ins.setFactField("rating");
    ins.setFactType("Person");
    ins.setType(DataType.TYPE_STRING);
    dt.getActionCols().add(ins);
    BRLRuleModel model = new BRLRuleModel(dt);
    assertNotNull(model.getLHSBoundFacts());
    assertEquals(2, model.getLHSBoundFacts().size());
    assertTrue(model.getLHSBoundFacts().contains("$p1"));
    assertTrue(model.getLHSBoundFacts().contains("$brl1"));
    assertNotNull(model.getLHSBindingType("$p1"));
    assertEquals("Driver", model.getLHSBindingType("$p1"));
    assertNotNull(model.getLHSBindingType("$brl1"));
    assertEquals("Driver", model.getLHSBindingType("$brl1"));
    FactPattern r1 = model.getLHSBoundFact("$p1");
    assertNotNull(r1);
    assertTrue(r1 instanceof Pattern52FactPatternAdaptor);
    Pattern52FactPatternAdaptor raif1 = (Pattern52FactPatternAdaptor) r1;
    assertEquals("Driver", raif1.getFactType());
    FactPattern r2 = model.getLHSBoundFact("$brl1");
    assertNotNull(r2);
    assertEquals("Driver", r2.getFactType());
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) 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) Pattern52FactPatternAdaptor(org.drools.workbench.models.guided.dtable.shared.model.adaptors.Pattern52FactPatternAdaptor) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) Test(org.junit.Test)

Aggregations

GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)262 Test (org.junit.Test)193 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)92 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)74 Path (org.uberfire.backend.vfs.Path)52 ArrayList (java.util.ArrayList)51 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)51 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)47 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)39 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)37 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)35 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)33 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)33 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)33 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)32 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)31 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)27 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)27 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)26 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)26