use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLimitedEntryConditionsConstraints1.
@Test
public void testLimitedEntryConditionsConstraints1() {
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("==");
cc1.setValue(new DTCellValue52("Pupa"));
p1.getChildColumns().add(cc1);
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( name == \"Pupa\" )");
assertTrue(index > -1);
index = drl.indexOf("Smurf( name == \"Pupa\" )", index + 1);
assertFalse(index > -1);
}
use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52 in project drools by kiegroup.
the class GuidedDTDRLPersistenceTest method testLimitedEntryLHSInOperator.
@Test
public void testLimitedEntryLHSInOperator() {
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("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("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 in ( \"Pupa\", \"Brains\" ) , age in ( 55, 66 ) )");
assertTrue(index > -1);
index = drl.indexOf("Smurf( )", index + 1);
assertFalse(index > -1);
}
use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52 in project drools-wb by kiegroup.
the class Validator method isConditionLimitedEntryValueValid.
public boolean isConditionLimitedEntryValueValid(ConditionCol52 c) {
if (!(c instanceof LimitedEntryConditionCol52)) {
return true;
}
LimitedEntryConditionCol52 lec = (LimitedEntryConditionCol52) c;
boolean doesOperatorNeedValue = doesOperatorNeedValue(lec);
boolean hasValue = hasValue(lec);
return (doesOperatorNeedValue && hasValue) || (!doesOperatorNeedValue && !hasValue);
}
use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52 in project drools-wb by kiegroup.
the class RowExpanderTests method testExpansionWithLimitedEntry.
@Test
@SuppressWarnings("serial")
public void testExpansionWithLimitedEntry() {
GuidedDecisionTable52 model = new GuidedDecisionTable52();
model.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY);
final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Driver").addField(new ModelField("age", Integer.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_NUMERIC_INTEGER)).addField(new ModelField("name", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).addField(new ModelField("dateOfBirth", Boolean.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_DATE)).addField(new ModelField("approved", Boolean.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_BOOLEAN)).end().build();
// Emulate server-to-client conversions
final AsyncPackageDataModelOracle oracle = getOracle();
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
dataModel.setModelFields(projectLoader.getModuleModelFields());
populateDataModelOracle(mock(Path.class), model, oracle, dataModel);
Pattern52 p1 = new Pattern52();
p1.setBoundName("c1");
p1.setFactType("Driver");
LimitedEntryConditionCol52 c1 = new LimitedEntryConditionCol52();
c1.setFactField("name");
c1.setOperator("==");
c1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
c1.setValue(new DTCellValue52("Mike"));
p1.getChildColumns().add(c1);
model.getConditions().add(p1);
Pattern52 p2 = new Pattern52();
p2.setBoundName("c2");
p2.setFactType("Driver");
LimitedEntryConditionCol52 c2 = new LimitedEntryConditionCol52();
c2.setFactField("age");
c2.setOperator("==");
c2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
c1.setValue(new DTCellValue52(25));
p2.getChildColumns().add(c2);
model.getConditions().add(p2);
LimitedEntryActionSetFieldCol52 a1 = new LimitedEntryActionSetFieldCol52();
a1.setBoundName("c1");
a1.setFactField("name");
a1.setValue(new DTCellValue52("a1name"));
model.getActionCols().add(a1);
LimitedEntryActionInsertFactCol52 a2 = new LimitedEntryActionInsertFactCol52();
a2.setBoundName("a2");
a2.setFactType("Driver");
a2.setFactField("name");
a2.setValue(new DTCellValue52("a2name"));
model.getActionCols().add(a2);
RowExpander re = new RowExpander(model, oracle);
List<RowExpander.ColumnValues> columns = re.getColumns();
assertEquals(6, columns.size());
assertEquals(1, columns.get(0).values.size());
assertEquals(1, columns.get(1).values.size());
assertEquals(2, columns.get(2).values.size());
assertEquals(2, columns.get(3).values.size());
assertEquals(1, columns.get(4).values.size());
assertEquals(1, columns.get(5).values.size());
assertEquals(Boolean.TRUE, columns.get(2).values.get(0).getBooleanValue());
assertEquals(Boolean.FALSE, columns.get(2).values.get(1).getBooleanValue());
assertEquals(Boolean.TRUE, columns.get(3).values.get(0).getBooleanValue());
assertEquals(Boolean.FALSE, columns.get(3).values.get(1).getBooleanValue());
assertEquals(Boolean.FALSE, columns.get(4).values.get(0).getBooleanValue());
assertEquals(Boolean.FALSE, columns.get(5).values.get(0).getBooleanValue());
RowExpander.RowIterator i = re.iterator();
List<List<DTCellValue52>> rows = new ArrayList<List<DTCellValue52>>();
while (i.hasNext()) {
List<DTCellValue52> row = i.next();
rows.add(row);
}
assertEquals(4, rows.size());
assertEquals("", rows.get(0).get(0).getStringValue());
assertEquals("", rows.get(0).get(1).getStringValue());
assertEquals(Boolean.TRUE, rows.get(0).get(2).getBooleanValue());
assertEquals(Boolean.TRUE, rows.get(0).get(3).getBooleanValue());
assertEquals(Boolean.FALSE, rows.get(0).get(4).getBooleanValue());
assertEquals(Boolean.FALSE, rows.get(0).get(5).getBooleanValue());
assertEquals("", rows.get(1).get(0).getStringValue());
assertEquals("", rows.get(1).get(1).getStringValue());
assertEquals(Boolean.TRUE, rows.get(1).get(2).getBooleanValue());
assertEquals(Boolean.FALSE, rows.get(1).get(3).getBooleanValue());
assertEquals(Boolean.FALSE, rows.get(1).get(4).getBooleanValue());
assertEquals(Boolean.FALSE, rows.get(1).get(5).getBooleanValue());
assertEquals("", rows.get(2).get(0).getStringValue());
assertEquals("", rows.get(2).get(1).getStringValue());
assertEquals(Boolean.FALSE, rows.get(2).get(2).getBooleanValue());
assertEquals(Boolean.TRUE, rows.get(2).get(3).getBooleanValue());
assertEquals(Boolean.FALSE, rows.get(2).get(4).getBooleanValue());
assertEquals(Boolean.FALSE, rows.get(2).get(5).getBooleanValue());
assertEquals("", rows.get(3).get(0).getStringValue());
assertEquals("", rows.get(3).get(1).getStringValue());
assertEquals(Boolean.FALSE, rows.get(3).get(2).getBooleanValue());
assertEquals(Boolean.FALSE, rows.get(3).get(3).getBooleanValue());
assertEquals(Boolean.FALSE, rows.get(3).get(4).getBooleanValue());
assertEquals(Boolean.FALSE, rows.get(3).get(5).getBooleanValue());
}
use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52 in project drools-wb by kiegroup.
the class LimitedEntryConditionCol52DefinitionBuilderTest method conditionIsNotPartOfAPattern.
@Test
public void conditionIsNotPartOfAPattern() {
final BaseColumn column = new LimitedEntryConditionCol52();
builder.generateDefinition(dtPresenter, column, (String definition) -> {
fail("ConditionCol52 was not part of a Pattern52 and hence should not be handled by ConditionCol52DefinitionBuilder");
});
}
Aggregations