Search in sources :

Example 6 with Pattern52

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

the class GuidedDTDRLPersistenceTest method testLimitedEntryActionInsert.

@Test
public void testLimitedEntryActionInsert() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    dt.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY);
    dt.setTableName("limited-entry");
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("p1");
    p1.setFactType("Smurf");
    dt.getConditions().add(p1);
    LimitedEntryActionInsertFactCol52 asf1 = new LimitedEntryActionInsertFactCol52();
    asf1.setFactType("Smurf");
    asf1.setBoundName("s1");
    asf1.setFactField("colour");
    asf1.setValue(new DTCellValue52("Blue"));
    dt.getActionCols().add(asf1);
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 1l, "desc", true }, new Object[] { 2l, "desc", false } }));
    GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
    String drl = p.marshal(dt);
    int index = -1;
    index = drl.indexOf("Smurf s1 = new Smurf();");
    assertTrue(index > -1);
    index = drl.indexOf("s1.setColour( \"Blue\" );", index + 1);
    assertTrue(index > -1);
    index = drl.indexOf("insert( s1 );", index + 1);
    assertTrue(index > -1);
    int indexRule2 = index;
    indexRule2 = drl.indexOf("Smurf s1 = new Smurf();", index + 1);
    assertFalse(indexRule2 > -1);
    indexRule2 = drl.indexOf("s1.setColour( \"Blue\" );", index + 1);
    assertFalse(indexRule2 > -1);
    indexRule2 = drl.indexOf("insert(s1 );", index + 1);
    assertFalse(indexRule2 > -1);
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) LimitedEntryActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) Test(org.junit.Test)

Example 7 with Pattern52

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

the class GuidedDTDRLPersistenceTest method testNoOperator.

@Test
public void testNoOperator() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] { "1", "desc", "a", "> 42" };
    String[][] data = new String[1][];
    data[0] = row;
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    List<CompositeColumn<? extends BaseColumn>> allPatterns = new ArrayList<CompositeColumn<? extends BaseColumn>>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    allColumns.add(new MetadataCol52());
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("p1");
    p1.setFactType("Person");
    allPatterns.add(p1);
    ConditionCol52 col1 = new ConditionCol52();
    col1.setFactField("age");
    col1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    col1.setOperator("");
    p1.getChildColumns().add(col1);
    allColumns.add(col1);
    RuleModel rm = new RuleModel();
    List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
    TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
    p.doConditions(allColumns, allPatterns, rowDataProvider, rowData, DataUtilities.makeDataLists(data), rm);
    String drl = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
    assertTrue(drl.indexOf("age > \"42\"") > 0);
}
Also used : ArrayList(java.util.ArrayList) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeColumn(org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn) MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) 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 8 with Pattern52

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

the class GuidedDTDRLPersistenceTest method testLimitedEntryLHSIsNullOperator.

@Test
public void testLimitedEntryLHSIsNullOperator() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    dt.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY);
    dt.setTableName("limited-entry");
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("p1");
    p1.setFactType("Smurf");
    dt.getConditions().add(p1);
    LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52();
    cc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    cc1.setFieldType(DataType.TYPE_STRING);
    cc1.setFactField("name");
    cc1.setOperator("== null");
    p1.getChildColumns().add(cc1);
    LimitedEntryConditionCol52 cc2 = new LimitedEntryConditionCol52();
    cc2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    cc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    cc2.setFactField("age");
    cc2.setOperator("== null");
    p1.getChildColumns().add(cc2);
    LimitedEntryConditionCol52 cc3 = new LimitedEntryConditionCol52();
    cc3.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    cc3.setFieldType(DataType.TYPE_DATE);
    cc3.setFactField("dateOfBirth");
    cc3.setOperator("== null");
    p1.getChildColumns().add(cc3);
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 1l, "desc", true, true, true }, new Object[] { 2l, "desc", false, false, false } }));
    GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
    String drl = p.marshal(dt);
    int index = -1;
    index = drl.indexOf("Smurf( name == null , age == null , dateOfBirth == null )");
    assertTrue(index > -1);
    index = drl.indexOf("Smurf( )", index + 1);
    assertFalse(index > -1);
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) Test(org.junit.Test)

Example 9 with Pattern52

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

the class GuidedDTDRLPersistenceTest method testInWithSimpleSingleLiteralValue.

@Test
public void testInWithSimpleSingleLiteralValue() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    dt.setTableName("in_operator");
    Pattern52 p1 = new Pattern52();
    p1.setFactType("Person");
    ConditionCol52 con = new ConditionCol52();
    con.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    con.setFieldType(DataType.TYPE_STRING);
    con.setFactField("field1");
    con.setHeader("Person field1");
    con.setOperator("in");
    p1.getChildColumns().add(con);
    dt.getConditions().add(p1);
    dt.setData(DataUtilities.makeDataLists(new String[][] { new String[] { "1", "desc1", "ak1,mk1" }, new String[] { "2", "desc2", "(ak2,mk2)" }, new String[] { "3", "desc3", "( ak3, mk3 )" }, new String[] { "4", "desc4", "( \"ak4\", \"mk4\" )" }, new String[] { "5", "desc5", "( \"ak5 \", \" mk5\" )" } }));
    GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
    String drl = p.marshal(dt);
    String expected = "//from row number: 1\n" + "//desc1\n" + "rule \"Row 1 in_operator\"\n" + "dialect \"mvel\"\n" + "when\n" + "  Person( field1 in ( \"ak1\", \"mk1\" ) )\n" + "then\n" + "end\n" + "//from row number: 2\n" + "//desc2\n" + "rule \"Row 2 in_operator\"\n" + "dialect \"mvel\"\n" + "when\n" + "  Person( field1 in ( \"ak2\", \"mk2\" ) )\n" + "then\n" + "end\n" + "//from row number: 3\n" + "//desc3\n" + "rule \"Row 3 in_operator\"\n" + "dialect \"mvel\"\n" + "when\n" + "  Person( field1 in ( \"ak3\", \"mk3\" ) )\n" + "then\n" + "end\n" + "//from row number: 4\n" + "//desc4\n" + "rule \"Row 4 in_operator\"\n" + "dialect \"mvel\"\n" + "when\n" + "  Person( field1 in ( \"ak4\", \"mk4\" ) )\n" + "then\n" + "end\n" + "//from row number: 5\n" + "//desc5\n" + "rule \"Row 5 in_operator\"\n" + "dialect \"mvel\"\n" + "when\n" + "  Person( field1 in ( \"ak5 \", \" mk5\" ) )\n" + "then\n" + "end";
    assertEqualsIgnoreWhitespace(expected, 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) Test(org.junit.Test)

Example 10 with Pattern52

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

the class GuidedDTDRLPersistenceTest method testLimitedEntryLHSNotInOperator.

@Test
public void testLimitedEntryLHSNotInOperator() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    dt.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY);
    dt.setTableName("limited-entry");
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("p1");
    p1.setFactType("Smurf");
    dt.getConditions().add(p1);
    LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52();
    cc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    cc1.setFieldType(DataType.TYPE_STRING);
    cc1.setFactField("name");
    cc1.setOperator("not in");
    cc1.setValue(new DTCellValue52("Pupa, Brains"));
    p1.getChildColumns().add(cc1);
    LimitedEntryConditionCol52 cc2 = new LimitedEntryConditionCol52();
    cc2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    cc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    cc2.setFactField("age");
    cc2.setOperator("not in");
    cc2.setValue(new DTCellValue52("55, 66"));
    p1.getChildColumns().add(cc2);
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 1l, "desc", true, true }, new Object[] { 2l, "desc", false, false } }));
    GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
    String drl = p.marshal(dt);
    int index = -1;
    index = drl.indexOf("Smurf( name not in ( \"Pupa\", \"Brains\" ) , age not in ( 55, 66 ) )");
    assertTrue(index > -1);
    index = drl.indexOf("Smurf( )", index + 1);
    assertFalse(index > -1);
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) Test(org.junit.Test)

Aggregations

Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)243 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)184 Test (org.junit.Test)180 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)92 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)66 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)45 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)39 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)34 ArrayList (java.util.ArrayList)31 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)31 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)28 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)27 Path (org.uberfire.backend.vfs.Path)27 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)26 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)26 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)26 StringUiColumn (org.drools.workbench.screens.guided.dtable.client.widget.table.columns.StringUiColumn)25 IntegerUiColumn (org.drools.workbench.screens.guided.dtable.client.widget.table.columns.IntegerUiColumn)24 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)24 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)24