Search in sources :

Example 21 with GuidedDecisionTable52

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

the class BRLRuleModelTest method testOnlyDecisionTableColumns.

@Test
public void testOnlyDecisionTableColumns() {
    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);
    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.getAllVariables());
    assertEquals(3, model.getAllVariables().size());
    assertTrue(model.getAllVariables().contains("$p1"));
    assertTrue(model.getAllVariables().contains("$c1"));
    assertTrue(model.getAllVariables().contains("$ins"));
}
Also used : 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) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) Test(org.junit.Test)

Example 22 with GuidedDecisionTable52

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

Example 23 with GuidedDecisionTable52

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

the class BRLRuleModelTest method testUpdateModifyMultipleFieldsWithMultipleSkipped3.

@Test
public void testUpdateModifyMultipleFieldsWithMultipleSkipped3() {
    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, 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" + "    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 24 with GuidedDecisionTable52

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

the class BRLRuleModelTest method testRuleModelRHSBoundFacts.

@Test
public void testRuleModelRHSBoundFacts() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    // Setup Decision Table columns
    ActionInsertFactCol52 ins = new ActionInsertFactCol52();
    ins.setBoundName("$ins");
    ins.setFactField("rating");
    ins.setFactType("Person");
    ins.setType(DataType.TYPE_STRING);
    dt.getActionCols().add(ins);
    // Setup RuleModel columns (new BRLActionColumn being added)
    BRLRuleModel model = new BRLRuleModel(dt);
    ActionInsertFact aif = new ActionInsertFact("Person");
    aif.setBoundName("$aif");
    aif.addFieldValue(new ActionFieldValue("rating", null, DataType.TYPE_STRING));
    aif.getFieldValues()[0].setNature(BaseSingleFieldConstraint.TYPE_LITERAL);
    model.addRhsItem(aif);
    // Checks
    assertNotNull(model.getRHSBoundFacts());
    assertEquals(2, model.getRHSBoundFacts().size());
    assertTrue(model.getRHSBoundFacts().contains("$ins"));
    assertTrue(model.getRHSBoundFacts().contains("$aif"));
    ActionInsertFact r1 = model.getRHSBoundFact("$ins");
    assertNotNull(r1);
    assertTrue(r1 instanceof ActionInsertFactCol52ActionInsertFactAdaptor);
    ActionInsertFactCol52ActionInsertFactAdaptor raif1 = (ActionInsertFactCol52ActionInsertFactAdaptor) r1;
    assertEquals("Person", raif1.getFactType());
    assertEquals("rating", raif1.getFieldValues()[0].getField());
    assertEquals(DataType.TYPE_STRING, raif1.getFieldValues()[0].getType());
    assertNull(raif1.getFieldValues()[0].getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, raif1.getFieldValues()[0].getNature());
    ActionInsertFact r2 = model.getRHSBoundFact("$aif");
    assertNotNull(r2);
    assertTrue(r2 instanceof ActionInsertFact);
    ActionInsertFact raif2 = (ActionInsertFact) r2;
    assertEquals("Person", raif2.getFactType());
    assertEquals("rating", raif2.getFieldValues()[0].getField());
    assertEquals(DataType.TYPE_STRING, raif2.getFieldValues()[0].getType());
    assertNull(raif2.getFieldValues()[0].getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, raif2.getFieldValues()[0].getNature());
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) ActionInsertFactCol52ActionInsertFactAdaptor(org.drools.workbench.models.guided.dtable.shared.model.adaptors.ActionInsertFactCol52ActionInsertFactAdaptor) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) Test(org.junit.Test)

Example 25 with GuidedDecisionTable52

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

the class BRLRuleModelTest method testRuleModelLHSBoundFacts.

@Test
public void testRuleModelLHSBoundFacts() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    // Setup Decision Table columns
    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);
    // Setup RuleModel columns (new BRLConditionColumn being added)
    BRLRuleModel model = new BRLRuleModel(dt);
    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);
    model.addLhsItem(fp);
    // Checks
    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 : 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) 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