use of org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testRHSExecuteWorkItemWithBindings.
@Test
public void testRHSExecuteWorkItemWithBindings() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
String[] row = new String[] { "1", "desc", "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("work-item");
awi.setWorkItemDefinition(pwd);
PortableBooleanParameterDefinition p1 = new PortableBooleanParameterDefinition();
p1.setName("BooleanParameter");
p1.setValue(Boolean.TRUE);
p1.setBinding("$b");
pwd.addParameter(p1);
PortableFloatParameterDefinition p2 = new PortableFloatParameterDefinition();
p2.setName("FloatParameter");
p2.setValue(123.456f);
p2.setBinding("$f");
pwd.addParameter(p2);
PortableIntegerParameterDefinition p3 = new PortableIntegerParameterDefinition();
p3.setName("IntegerParameter");
p3.setValue(123);
p3.setBinding("$i");
pwd.addParameter(p3);
PortableStringParameterDefinition p4 = new PortableStringParameterDefinition();
p4.setName("StringParameter");
p4.setValue("hello");
p4.setBinding("$s");
pwd.addParameter(p4);
cols.add(awi);
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(1, rm.rhs.length);
// Examine RuleModel action
ActionExecuteWorkItem aw = (ActionExecuteWorkItem) rm.rhs[0];
assertNotNull(aw);
PortableWorkDefinition mpwd = aw.getWorkDefinition();
assertNotNull(mpwd);
assertEquals(4, mpwd.getParameters().size());
PortableBooleanParameterDefinition mp1 = (PortableBooleanParameterDefinition) mpwd.getParameter("BooleanParameter");
assertNotNull(mp1);
assertEquals(Boolean.TRUE, mp1.getValue());
assertEquals("$b", mp1.getBinding());
PortableFloatParameterDefinition mp2 = (PortableFloatParameterDefinition) mpwd.getParameter("FloatParameter");
assertNotNull(mp2);
assertEquals(new Float(123.456f), mp2.getValue());
assertEquals("$f", mp2.getBinding());
PortableIntegerParameterDefinition mp3 = (PortableIntegerParameterDefinition) mpwd.getParameter("IntegerParameter");
assertNotNull(mp3);
assertEquals(new Integer(123), mp3.getValue());
assertEquals("$i", mp3.getBinding());
PortableStringParameterDefinition mp4 = (PortableStringParameterDefinition) mpwd.getParameter("StringParameter");
assertNotNull(mp4);
assertEquals("hello", mp4.getValue());
assertEquals("$s", mp4.getBinding());
}
use of org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLHS.
@Test
public void testLHS() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
String[] row = new String[] { "1", "desc", "a", "mike", "33 + 1", "age > 6", "stilton" };
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 col = new ConditionCol52();
col.setFactField("name");
col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
col.setOperator("==");
p1.getChildColumns().add(col);
allColumns.add(col);
ConditionCol52 col2 = new ConditionCol52();
col2.setFactField("age");
col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_RET_VALUE);
col2.setOperator("<");
p1.getChildColumns().add(col2);
allColumns.add(col2);
ConditionCol52 col3 = new ConditionCol52();
col3.setConstraintValueType(BaseSingleFieldConstraint.TYPE_PREDICATE);
p1.getChildColumns().add(col3);
allColumns.add(col3);
Pattern52 p2 = new Pattern52();
p2.setBoundName("c");
p2.setFactType("Cheese");
allPatterns.add(p2);
ConditionCol52 col4 = new ConditionCol52();
col4.setFactField("type");
col4.setOperator("==");
col4.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
p2.getChildColumns().add(col4);
allColumns.add(col4);
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);
assertEquals(2, rm.lhs.length);
assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
assertEquals("Cheese", ((FactPattern) rm.lhs[1]).getFactType());
assertEquals("c", ((FactPattern) rm.lhs[1]).getBoundName());
// examine the first pattern
FactPattern person = (FactPattern) rm.lhs[0];
assertEquals(3, person.getConstraintList().getConstraints().length);
SingleFieldConstraint cons = (SingleFieldConstraint) person.getConstraint(0);
assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cons.getConstraintValueType());
assertEquals("name", cons.getFieldName());
assertEquals("==", cons.getOperator());
assertEquals("mike", cons.getValue());
cons = (SingleFieldConstraint) person.getConstraint(1);
assertEquals(BaseSingleFieldConstraint.TYPE_RET_VALUE, cons.getConstraintValueType());
assertEquals("age", cons.getFieldName());
assertEquals("<", cons.getOperator());
assertEquals("33 + 1", cons.getValue());
cons = (SingleFieldConstraint) person.getConstraint(2);
assertEquals(BaseSingleFieldConstraint.TYPE_PREDICATE, cons.getConstraintValueType());
assertEquals("age > 6", cons.getValue());
// examine the second pattern
FactPattern cheese = (FactPattern) rm.lhs[1];
assertEquals(1, cheese.getConstraintList().getConstraints().length);
cons = (SingleFieldConstraint) cheese.getConstraint(0);
assertEquals("type", cons.getFieldName());
assertEquals("==", cons.getOperator());
assertEquals("stilton", cons.getValue());
assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cons.getConstraintValueType());
}
use of org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLHSOtherwisePatternString.
@Test
public void testLHSOtherwisePatternString() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
String[][] row = new String[3][];
String[][] data = new String[3][];
row[0] = new String[] { "1", "desc1", "Michael1", "Michael1" };
List<DTCellValue52> rowDTModel0 = DataUtilities.makeDataRowList(row[0]);
data[0] = row[0];
row[1] = new String[] { "2", "desc2", "Michael2", "Michael2" };
List<DTCellValue52> rowDTModel1 = DataUtilities.makeDataRowList(row[1]);
data[1] = row[1];
row[2] = new String[] { "3", "desc3", "", "" };
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("name");
col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
col.setFieldType(DataType.TYPE_STRING);
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("name");
col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
col2.setFieldType(DataType.TYPE_STRING);
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( name == \"Michael1\" )") > 0);
assertTrue(drl0.indexOf("p2 : Person( name != \"Michael1\" )") > 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( name == \"Michael2\" )") > 0);
assertTrue(drl1.indexOf("p2 : Person( name != \"Michael2\" )") > 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( name not in ( \"Michael1\", \"Michael2\" )") > 0);
assertTrue(drl2.indexOf("p2 : Person( name in ( \"Michael1\", \"Michael2\" )") > 0);
}
use of org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLHSOtherwisePatternBoolean.
@Test
public void testLHSOtherwisePatternBoolean() {
GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
String[][] row = new String[2][];
String[][] data = new String[2][];
row[0] = new String[] { "1", "desc1", "true", "false" };
List<DTCellValue52> rowDTModel0 = DataUtilities.makeDataRowList(row[0]);
data[0] = row[0];
row[1] = new String[] { "3", "desc3", null, null };
List<DTCellValue52> rowDTModel1 = DataUtilities.makeDataRowList(row[1]);
rowDTModel1.get(2).setOtherwise(true);
rowDTModel1.get(3).setOtherwise(true);
data[1] = row[1];
final List<List<DTCellValue52>> allDTData = new ArrayList<List<DTCellValue52>>() {
{
add(rowDTModel0);
add(rowDTModel1);
}
};
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("alive");
col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
col.setFieldType(DataType.TYPE_BOOLEAN);
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("alive");
col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
col2.setFieldType(DataType.TYPE_BOOLEAN);
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( alive == true )") > 0);
assertTrue(drl0.indexOf("p2 : Person( alive != false )") > 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( alive not in ( true )") > 0);
assertTrue(drl1.indexOf("p2 : Person( alive in ( false )") > 0);
}
use of org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider 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);
}
Aggregations