Search in sources :

Example 36 with DescriptionCol52

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

the class GuidedDTDRLPersistenceTest method testLHSWithBRLColumn_ParseToDRL_FreeFormLine.

@Test
public // This test checks a Decision Table involving BRL columns is correctly converted into DRL
void testLHSWithBRLColumn_ParseToDRL_FreeFormLine() {
    GuidedDecisionTable52 dtable = new GuidedDecisionTable52();
    // Row 0 should become an IPattern in the resulting RuleModel as it contains values for all Template fields in the BRL Column
    // Row 1 should *NOT* become an IPattern in the resulting RuleModel as it does *NOT* contain values for all Template fields in the BRL Column
    // Row 2 should *NOT* become an IPattern in the resulting RuleModel as it does *NOT* contain values for all Template fields in the BRL Column
    // Row 3 should *NOT* become an IPattern 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 Column
    BRLConditionColumn brl1 = new BRLConditionColumn();
    // BRL Column definition
    List<IPattern> brl1Definition = new ArrayList<IPattern>();
    FreeFormLine brl1DefinitionFreeFormLine = new FreeFormLine();
    brl1DefinitionFreeFormLine.setText("Smurf( name == \"@{name}\", age == @{age} )");
    brl1Definition.add(brl1DefinitionFreeFormLine);
    brl1.setDefinition(brl1Definition);
    // Setup BRL column bindings
    BRLConditionVariableColumn brl1Variable1 = new BRLConditionVariableColumn("name", DataType.TYPE_STRING);
    BRLConditionVariableColumn brl1Variable2 = new BRLConditionVariableColumn("age", DataType.TYPE_NUMERIC_INTEGER);
    brl1.getChildColumns().add(brl1Variable1);
    brl1.getChildColumns().add(brl1Variable2);
    dtable.getConditions().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("Smurf( name == \"Pupa\", age == 50 )", ruleStartIndex);
    assertFalse(pattern1StartIndex == -1);
    // Row 1
    ruleStartIndex = drl.indexOf("//from row number: 2");
    assertFalse(ruleStartIndex == -1);
    pattern1StartIndex = drl.indexOf("Smurf(", ruleStartIndex);
    assertTrue(pattern1StartIndex == -1);
    // Row 2
    ruleStartIndex = drl.indexOf("//from row number: 3");
    assertFalse(ruleStartIndex == -1);
    pattern1StartIndex = drl.indexOf("Smurf(", ruleStartIndex);
    assertTrue(pattern1StartIndex == -1);
    // Row 3
    ruleStartIndex = drl.indexOf("//from row number: 4");
    assertFalse(ruleStartIndex == -1);
    pattern1StartIndex = drl.indexOf("Smurf(", ruleStartIndex);
    assertTrue(pattern1StartIndex == -1);
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ArrayList(java.util.ArrayList) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 37 with DescriptionCol52

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

the class GuidedDTDRLPersistenceTest method testLHSOtherwisePatternDate.

@Test
public void testLHSOtherwisePatternDate() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[][] row = new String[3][];
    String[][] data = new String[3][];
    row[0] = new String[] { "1", "desc1", "01-Jan-1980", "20-Jun-1985" };
    List<DTCellValue52> rowDTModel0 = DataUtilities.makeDataRowList(row[0]);
    data[0] = row[0];
    row[1] = new String[] { "2", "desc2", "01-Feb-1981", "21-Jun-1986" };
    List<DTCellValue52> rowDTModel1 = DataUtilities.makeDataRowList(row[1]);
    data[1] = row[1];
    row[2] = new String[] { "3", "desc3", null, null };
    List<DTCellValue52> rowDTModel2 = DataUtilities.makeDataRowList(row[2]);
    rowDTModel2.get(2).setOtherwise(true);
    rowDTModel2.get(3).setOtherwise(true);
    data[2] = row[2];
    final List<List<DTCellValue52>> allDTData = new ArrayList<List<DTCellValue52>>() {

        {
            add(rowDTModel0);
            add(rowDTModel1);
            add(rowDTModel2);
        }
    };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    List<CompositeColumn<? extends BaseColumn>> allPatterns = new ArrayList<CompositeColumn<? extends BaseColumn>>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("p1");
    p1.setFactType("Person");
    allPatterns.add(p1);
    ConditionCol52 col = new ConditionCol52();
    col.setFactField("dateOfBirth");
    col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    col.setFieldType(DataType.TYPE_DATE);
    col.setOperator("==");
    p1.getChildColumns().add(col);
    allColumns.add(col);
    Pattern52 p2 = new Pattern52();
    p2.setBoundName("p2");
    p2.setFactType("Person");
    allPatterns.add(p2);
    ConditionCol52 col2 = new ConditionCol52();
    col2.setFactField("dateOfBirth");
    col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    col2.setFieldType(DataType.TYPE_DATE);
    col2.setOperator("!=");
    p2.getChildColumns().add(col2);
    allColumns.add(col2);
    RuleModel rm = new RuleModel();
    TemplateDataProvider rowDataProvider0 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel0);
    p.doConditions(allColumns, allPatterns, rowDataProvider0, rowDTModel0, allDTData, rm);
    String drl0 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
    assertEquals(2, rm.lhs.length);
    assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
    assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
    assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
    assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
    assertTrue(drl0.indexOf("p1 : Person( dateOfBirth == \"01-Jan-1980\" )") > 0);
    assertTrue(drl0.indexOf("p2 : Person( dateOfBirth != \"20-Jun-1985\" )") > 0);
    TemplateDataProvider rowDataProvider1 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel1);
    p.doConditions(allColumns, allPatterns, rowDataProvider1, rowDTModel1, allDTData, rm);
    String drl1 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
    assertEquals(2, rm.lhs.length);
    assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
    assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
    assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
    assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
    assertTrue(drl1.indexOf("p1 : Person( dateOfBirth == \"01-Feb-1981\" )") > 0);
    assertTrue(drl1.indexOf("p2 : Person( dateOfBirth != \"21-Jun-1986\" )") > 0);
    TemplateDataProvider rowDataProvider2 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel2);
    p.doConditions(allColumns, allPatterns, rowDataProvider2, rowDTModel2, allDTData, rm);
    String drl2 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
    assertEquals(2, rm.lhs.length);
    assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
    assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
    assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
    assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
    assertTrue(drl2.indexOf("p1 : Person( dateOfBirth not in ( \"01-Jan-1980\", \"01-Feb-1981\" )") > 0);
    assertTrue(drl2.indexOf("p2 : Person( dateOfBirth in ( \"20-Jun-1985\", \"21-Jun-1986\" )") > 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) 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) List(java.util.List) ArrayList(java.util.ArrayList) 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 38 with DescriptionCol52

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

the class GuidedDTDRLPersistenceTest method testAttribs.

@Test
public void testAttribs() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    Object[] row = new Object[] { "1", "desc", "a", null };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    List<AttributeCol52> attributeCols = new ArrayList<AttributeCol52>();
    RuleModel rm = new RuleModel();
    RuleAttribute[] orig = rm.attributes;
    p.doAttribs(allColumns, attributeCols, DataUtilities.makeDataRowList(row), rm);
    assertSame(orig, rm.attributes);
    AttributeCol52 col1 = new AttributeCol52();
    col1.setAttribute("salience");
    AttributeCol52 col2 = new AttributeCol52();
    col2.setAttribute("agenda-group");
    attributeCols.add(col1);
    attributeCols.add(col2);
    allColumns.addAll(attributeCols);
    p.doAttribs(allColumns, attributeCols, DataUtilities.makeDataRowList(row), rm);
    assertEquals(1, rm.attributes.length);
    assertEquals("salience", rm.attributes[0].getAttributeName());
    assertEquals("a", rm.attributes[0].getValue());
    row = new Object[] { "1", "desc", 1l, "b" };
    p.doAttribs(allColumns, attributeCols, DataUtilities.makeDataRowList(row), rm);
    assertEquals(2, rm.attributes.length);
    assertEquals("salience", rm.attributes[0].getAttributeName());
    assertEquals("1", rm.attributes[0].getValue());
    assertEquals("agenda-group", rm.attributes[1].getAttributeName());
    assertEquals("b", rm.attributes[1].getValue());
}
Also used : ArrayList(java.util.ArrayList) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 39 with DescriptionCol52

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

the class GuidedDTDRLPersistenceTest method testRHSActionWorkItemInsertFacts1.

@Test
public // Test all Actions inserting Facts are correctly converted to RuleModel
void testRHSActionWorkItemInsertFacts1() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] { "1", "desc", "true", "true", "true", "true", "true" };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    List<ActionCol52> cols = new ArrayList<ActionCol52>();
    ActionWorkItemCol52 awi = new ActionWorkItemCol52();
    PortableWorkDefinition pwd = new PortableWorkDefinition();
    pwd.setName("WorkItem");
    awi.setWorkItemDefinition(pwd);
    PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
    p1.setName("BooleanResult");
    pwd.addResult(p1);
    PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
    p2.setName("FloatResult");
    pwd.addResult(p2);
    PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
    p3.setName("IntegerResult");
    pwd.addResult(p3);
    PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
    p4.setName("StringResult");
    pwd.addResult(p4);
    cols.add(awi);
    ActionWorkItemInsertFactCol52 asf1 = new ActionWorkItemInsertFactCol52();
    asf1.setBoundName("$r");
    asf1.setFactField("ResultBooleanField");
    asf1.setType(DataType.TYPE_BOOLEAN);
    asf1.setWorkItemName("WorkItem");
    asf1.setWorkItemResultParameterName("BooleanResult");
    asf1.setParameterClassName(Boolean.class.getName());
    cols.add(asf1);
    ActionWorkItemInsertFactCol52 asf2 = new ActionWorkItemInsertFactCol52();
    asf2.setBoundName("$r");
    asf2.setFactField("ResultFloatField");
    asf2.setType(DataType.TYPE_NUMERIC_FLOAT);
    asf2.setWorkItemName("WorkItem");
    asf2.setWorkItemResultParameterName("FloatResult");
    asf2.setParameterClassName(Float.class.getName());
    cols.add(asf2);
    ActionWorkItemInsertFactCol52 asf3 = new ActionWorkItemInsertFactCol52();
    asf3.setBoundName("$r");
    asf3.setFactField("ResultIntegerField");
    asf3.setType(DataType.TYPE_NUMERIC_INTEGER);
    asf3.setWorkItemName("WorkItem");
    asf3.setWorkItemResultParameterName("IntegerResult");
    asf3.setParameterClassName(Integer.class.getName());
    cols.add(asf3);
    ActionWorkItemInsertFactCol52 asf4 = new ActionWorkItemInsertFactCol52();
    asf4.setBoundName("$r");
    asf4.setFactField("ResultStringField");
    asf4.setType(DataType.TYPE_STRING);
    asf4.setWorkItemName("WorkItem");
    asf4.setWorkItemResultParameterName("StringResult");
    asf4.setParameterClassName(String.class.getName());
    cols.add(asf4);
    RuleModel rm = new RuleModel();
    allColumns.addAll(cols);
    List<DTCellValue52> rowData = DataUtilities.makeDataRowList(row);
    TemplateDataProvider rowDataProvider = new GuidedDTTemplateDataProvider(allColumns, rowData);
    p.doActions(allColumns, cols, rowDataProvider, rowData, rm);
    assertEquals(2, rm.rhs.length);
    // Examine RuleModel actions
    ActionExecuteWorkItem aw = (ActionExecuteWorkItem) rm.rhs[0];
    assertNotNull(aw);
    ActionInsertFact aif = (ActionInsertFact) rm.rhs[1];
    assertNotNull(aif);
    // Check ActionExecuteWorkItem
    PortableWorkDefinition mpwd = aw.getWorkDefinition();
    assertNotNull(mpwd);
    assertEquals(4, mpwd.getResults().size());
    PortableBooleanParameterDefinition mp1 = (PortableBooleanParameterDefinition) mpwd.getResult("BooleanResult");
    assertNotNull(mp1);
    PortableFloatParameterDefinition mp2 = (PortableFloatParameterDefinition) mpwd.getResult("FloatResult");
    assertNotNull(mp2);
    PortableIntegerParameterDefinition mp3 = (PortableIntegerParameterDefinition) mpwd.getResult("IntegerResult");
    assertNotNull(mp3);
    PortableStringParameterDefinition mp4 = (PortableStringParameterDefinition) mpwd.getResult("StringResult");
    assertNotNull(mp4);
    // Check ActionInsertFact
    assertEquals(aif.getBoundName(), "$r");
    assertEquals(4, aif.getFieldValues().length);
    ActionFieldValue fv1 = aif.getFieldValues()[0];
    assertNotNull(fv1);
    assertTrue(fv1 instanceof ActionWorkItemFieldValue);
    ActionWorkItemFieldValue wifv1 = (ActionWorkItemFieldValue) fv1;
    assertEquals("ResultBooleanField", wifv1.getField());
    assertEquals(DataType.TYPE_BOOLEAN, wifv1.getType());
    assertEquals("WorkItem", wifv1.getWorkItemName());
    assertEquals("BooleanResult", wifv1.getWorkItemParameterName());
    assertEquals(Boolean.class.getName(), wifv1.getWorkItemParameterClassName());
    ActionFieldValue fv2 = aif.getFieldValues()[1];
    assertNotNull(fv2);
    assertTrue(fv2 instanceof ActionWorkItemFieldValue);
    ActionWorkItemFieldValue wifv2 = (ActionWorkItemFieldValue) fv2;
    assertEquals("ResultFloatField", wifv2.getField());
    assertEquals(DataType.TYPE_NUMERIC_FLOAT, wifv2.getType());
    assertEquals("WorkItem", wifv2.getWorkItemName());
    assertEquals("FloatResult", wifv2.getWorkItemParameterName());
    assertEquals(Float.class.getName(), wifv2.getWorkItemParameterClassName());
    ActionFieldValue fv3 = aif.getFieldValues()[2];
    assertNotNull(fv3);
    assertTrue(fv3 instanceof ActionWorkItemFieldValue);
    ActionWorkItemFieldValue wifv3 = (ActionWorkItemFieldValue) fv3;
    assertEquals("ResultIntegerField", wifv3.getField());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, wifv3.getType());
    assertEquals("WorkItem", wifv3.getWorkItemName());
    assertEquals("IntegerResult", wifv3.getWorkItemParameterName());
    assertEquals(Integer.class.getName(), wifv3.getWorkItemParameterClassName());
    ActionFieldValue fv4 = aif.getFieldValues()[3];
    assertNotNull(fv4);
    assertTrue(fv4 instanceof ActionWorkItemFieldValue);
    ActionWorkItemFieldValue wifv4 = (ActionWorkItemFieldValue) fv4;
    assertEquals("ResultStringField", wifv4.getField());
    assertEquals(DataType.TYPE_STRING, wifv4.getType());
    assertEquals("WorkItem", wifv4.getWorkItemName());
    assertEquals("StringResult", wifv4.getWorkItemParameterName());
    assertEquals(String.class.getName(), wifv4.getWorkItemParameterClassName());
}
Also used : PortableIntegerParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableIntegerParameterDefinition) ActionWorkItemFieldValue(org.drools.workbench.models.datamodel.rule.ActionWorkItemFieldValue) PortableFloatParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableFloatParameterDefinition) ActionWorkItemCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemCol52) ArrayList(java.util.ArrayList) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) PortableWorkDefinition(org.drools.workbench.models.datamodel.workitems.PortableWorkDefinition) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) PortableBooleanParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableBooleanParameterDefinition) ActionExecuteWorkItem(org.drools.workbench.models.datamodel.rule.ActionExecuteWorkItem) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) TemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider) ActionWorkItemInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionWorkItemInsertFactCol52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) PortableStringParameterDefinition(org.drools.workbench.models.datamodel.workitems.PortableStringParameterDefinition) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 40 with DescriptionCol52

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

the class GuidedDTDRLPersistenceTest method testRHSWithBRLColumn_ParseToDRL_MultipleActions.

@Test
public // This test checks a Decision Table involving BRL columns is correctly converted into DRL
void testRHSWithBRLColumn_ParseToDRL_MultipleActions() {
    GuidedDecisionTable52 dtable = new GuidedDecisionTable52();
    // All three rows are entered, some columns with optional data
    String[][] data = new String[][] { new String[] { "1", "desc", "Pupa", "50" }, new String[] { "2", "desc", "", "50" }, new String[] { "3", "desc", "Pupa", "" } };
    // Simple (mandatory) columns
    dtable.setRowNumberCol(new RowNumberCol52());
    dtable.setDescriptionCol(new DescriptionCol52());
    // BRL Column
    BRLActionColumn brl1 = new BRLActionColumn();
    // BRL Column definition
    List<IAction> brl1Definition = new ArrayList<IAction>();
    ActionInsertFact brl1DefinitionAction1 = new ActionInsertFact("Baddie");
    ActionFieldValue brl1DefinitionAction1FieldValue1 = new ActionFieldValue("name", "Gargamel", DataType.TYPE_STRING);
    brl1DefinitionAction1FieldValue1.setNature(BaseSingleFieldConstraint.TYPE_LITERAL);
    brl1DefinitionAction1.addFieldValue(brl1DefinitionAction1FieldValue1);
    brl1Definition.add(brl1DefinitionAction1);
    ActionInsertFact brl1DefinitionAction2 = new ActionInsertFact("Smurf");
    ActionFieldValue brl1DefinitionAction2FieldValue1 = new ActionFieldValue("name", "$name", DataType.TYPE_STRING);
    brl1DefinitionAction2FieldValue1.setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brl1DefinitionAction2.addFieldValue(brl1DefinitionAction2FieldValue1);
    ActionFieldValue brl1DefinitionAction2FieldValue2 = new ActionFieldValue("age", "$age", DataType.TYPE_NUMERIC_INTEGER);
    brl1DefinitionAction2FieldValue2.setNature(BaseSingleFieldConstraint.TYPE_TEMPLATE);
    brl1DefinitionAction2.addFieldValue(brl1DefinitionAction2FieldValue2);
    brl1Definition.add(brl1DefinitionAction2);
    brl1.setDefinition(brl1Definition);
    // Setup BRL column bindings
    BRLActionVariableColumn brl1Variable1 = new BRLActionVariableColumn("$name", DataType.TYPE_STRING, "Person", "name");
    brl1.getChildColumns().add(brl1Variable1);
    BRLActionVariableColumn brl1Variable2 = new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Person", "age");
    brl1.getChildColumns().add(brl1Variable2);
    dtable.getActionCols().add(brl1);
    dtable.setData(DataUtilities.makeDataLists(data));
    // Now to test conversion
    int ruleStartIndex;
    int action1StartIndex;
    int action2StartIndex;
    GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
    String drl = p.marshal(dtable);
    // Row 0
    ruleStartIndex = drl.indexOf("//from row number: 1");
    assertFalse(ruleStartIndex == -1);
    action1StartIndex = drl.indexOf("Baddie fact0 = new Baddie();", ruleStartIndex);
    assertFalse(action1StartIndex == -1);
    action1StartIndex = drl.indexOf("fact0.setName( \"Gargamel\" );", action1StartIndex);
    assertFalse(action1StartIndex == -1);
    action1StartIndex = drl.indexOf("insert( fact0 );", action1StartIndex);
    assertFalse(action1StartIndex == -1);
    action2StartIndex = drl.indexOf("Smurf fact1 = new Smurf();", ruleStartIndex);
    assertFalse(action2StartIndex == -1);
    action2StartIndex = drl.indexOf("fact1.setName( \"Pupa\" );", action2StartIndex);
    assertFalse(action2StartIndex == -1);
    action2StartIndex = drl.indexOf("fact1.setAge( 50 );", action2StartIndex);
    assertFalse(action2StartIndex == -1);
    action2StartIndex = drl.indexOf("insert( fact1 );", action2StartIndex);
    assertFalse(action2StartIndex == -1);
    // Row 1
    ruleStartIndex = drl.indexOf("//from row number: 2");
    int ruleEndIndex = drl.indexOf("//from row number: 3");
    assertFalse(ruleStartIndex == -1);
    action1StartIndex = drl.indexOf("Baddie fact0 = new Baddie();", ruleStartIndex);
    assertFalse(action1StartIndex == -1);
    action1StartIndex = drl.indexOf("fact0.setName( \"Gargamel\" );", action1StartIndex);
    assertFalse(action1StartIndex == -1);
    action1StartIndex = drl.indexOf("insert( fact0 );", action1StartIndex);
    assertFalse(action1StartIndex == -1);
    action2StartIndex = drl.indexOf("Smurf fact1 = new Smurf();", ruleStartIndex);
    assertFalse(action2StartIndex == -1);
    action2StartIndex = drl.indexOf("fact1.setName( \"Pupa\" );", ruleStartIndex);
    assertFalse(action2StartIndex < ruleEndIndex);
    action2StartIndex = drl.indexOf("fact1.setAge( 50 );", ruleStartIndex);
    assertFalse(action2StartIndex == -1);
    action2StartIndex = drl.indexOf("insert( fact1 );", ruleStartIndex);
    assertFalse(action2StartIndex == -1);
    // Row 2
    ruleStartIndex = drl.indexOf("//from row number: 3");
    assertFalse(ruleStartIndex == -1);
    action1StartIndex = drl.indexOf("Baddie fact0 = new Baddie();", ruleStartIndex);
    assertFalse(action1StartIndex == -1);
    action1StartIndex = drl.indexOf("fact0.setName( \"Gargamel\" );", action1StartIndex);
    assertFalse(action1StartIndex == -1);
    action1StartIndex = drl.indexOf("insert( fact0 );", action1StartIndex);
    assertFalse(action1StartIndex == -1);
    action2StartIndex = drl.indexOf("Smurf fact1 = new Smurf();", ruleStartIndex);
    assertFalse(action2StartIndex == -1);
    action2StartIndex = drl.indexOf("fact1.setName( \"Pupa\" );", ruleStartIndex);
    assertFalse(action2StartIndex == -1);
    action2StartIndex = drl.indexOf("fact1.setAge( 50 );", ruleStartIndex);
    assertTrue(action2StartIndex == -1);
    action2StartIndex = drl.indexOf("insert( fact1 );", ruleStartIndex);
    assertFalse(action2StartIndex == -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) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Aggregations

DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)68 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)66 Test (org.junit.Test)59 ArrayList (java.util.ArrayList)47 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)43 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)33 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)24 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)23 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)23 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)22 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)22 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)21 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)21 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)21 GuidedDTTemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider)19 TemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider)19 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)19 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)18 IOException (java.io.IOException)17 InputStream (java.io.InputStream)17