use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52 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);
}
use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52 in project drools-wb by kiegroup.
the class RowExpanderTest 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(7, columns.size());
assertEquals(1, columns.get(0).values.size());
assertEquals(1, columns.get(1).values.size());
assertEquals(1, columns.get(2).values.size());
assertEquals(2, columns.get(3).values.size());
assertEquals(2, columns.get(4).values.size());
assertEquals(1, columns.get(5).values.size());
assertEquals(1, columns.get(6).values.size());
assertEquals(Boolean.TRUE, columns.get(3).values.get(0).getBooleanValue());
assertEquals(Boolean.FALSE, columns.get(3).values.get(1).getBooleanValue());
assertEquals(Boolean.TRUE, columns.get(4).values.get(0).getBooleanValue());
assertEquals(Boolean.FALSE, columns.get(4).values.get(1).getBooleanValue());
assertEquals(Boolean.FALSE, columns.get(5).values.get(0).getBooleanValue());
assertEquals(Boolean.FALSE, columns.get(6).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("", rows.get(0).get(2).getStringValue());
assertEquals(Boolean.TRUE, rows.get(0).get(3).getBooleanValue());
assertEquals(Boolean.TRUE, rows.get(0).get(4).getBooleanValue());
assertEquals(Boolean.FALSE, rows.get(0).get(5).getBooleanValue());
assertEquals(Boolean.FALSE, rows.get(0).get(6).getBooleanValue());
assertEquals("", rows.get(1).get(0).getStringValue());
assertEquals("", rows.get(1).get(1).getStringValue());
assertEquals("", rows.get(1).get(2).getStringValue());
assertEquals(Boolean.TRUE, 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(Boolean.FALSE, rows.get(1).get(6).getBooleanValue());
assertEquals("", rows.get(2).get(0).getStringValue());
assertEquals("", rows.get(2).get(1).getStringValue());
assertEquals("", rows.get(2).get(2).getStringValue());
assertEquals(Boolean.FALSE, rows.get(2).get(3).getBooleanValue());
assertEquals(Boolean.TRUE, rows.get(2).get(4).getBooleanValue());
assertEquals(Boolean.FALSE, rows.get(2).get(5).getBooleanValue());
assertEquals(Boolean.FALSE, rows.get(2).get(6).getBooleanValue());
assertEquals("", rows.get(3).get(0).getStringValue());
assertEquals("", rows.get(3).get(1).getStringValue());
assertEquals("", rows.get(3).get(2).getStringValue());
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());
assertEquals(Boolean.FALSE, rows.get(3).get(6).getBooleanValue());
}
use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52 in project drools-wb by kiegroup.
the class LimitedEntryActionInsertFactCol52DefinitionBuilderTest method simpleAction.
@Test
public void simpleAction() {
final AtomicBoolean calledBack = new AtomicBoolean(false);
final LimitedEntryActionInsertFactCol52 aif = new LimitedEntryActionInsertFactCol52();
aif.setFactType("Person");
aif.setFactField("name");
aif.setValue(new DTCellValue52("Michael"));
model.getActionCols().add(aif);
builder.generateDefinition(dtPresenter, aif, (String definition) -> {
calledBack.set(true);
assertEquals("Person fact0 = new Person();<br/>" + "fact0.setName( \"Michael\" );<br/>" + "insert( fact0 );", definition);
});
assertTrue(calledBack.get());
}
use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52 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.LimitedEntryActionInsertFactCol52 in project drools-wb by kiegroup.
the class ActionInsertFactFieldsPageViewImpl method initialiseChosenFields.
private void initialiseChosenFields() {
chosenFieldsContainer.add(chosenFieldsWidget);
chosenFieldsWidget.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
chosenFieldsWidget.setMinimumWidth(130);
final Label lstEmpty = new Label(GuidedDecisionTableConstants.INSTANCE.DecisionTableWizardNoChosenFields());
lstEmpty.setStyleName(WizardCellListResources.INSTANCE.cellListStyle().cellListEmptyItem());
chosenFieldsWidget.setEmptyListWidget(lstEmpty);
final MultiSelectionModel<ActionInsertFactCol52> selectionModel = new MultiSelectionModel<ActionInsertFactCol52>(System::identityHashCode);
chosenFieldsWidget.setSelectionModel(selectionModel);
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
@Override
public void onSelectionChange(final SelectionChangeEvent event) {
chosenFieldsSelections = new HashSet<ActionInsertFactCol52>();
final Set<ActionInsertFactCol52> selections = selectionModel.getSelectedSet();
for (ActionInsertFactCol52 a : selections) {
chosenFieldsSelections.add(a);
}
chosenConditionsSelected(chosenFieldsSelections);
}
private void chosenConditionsSelected(final Set<ActionInsertFactCol52> cws) {
btnRemove.setEnabled(true);
if (cws.size() == 1) {
chosenFieldsSelection = cws.iterator().next();
fieldDefinition.setVisible(true);
validateFieldHeader();
populateFieldDefinition();
} else {
chosenFieldsSelection = null;
fieldDefinition.setVisible(false);
txtColumnHeader.setEnabled(false);
txtValueList.setEnabled(false);
defaultValueContainer.setVisible(false);
}
}
private void populateFieldDefinition() {
// Fields common to all table formats
txtColumnHeader.setEnabled(true);
txtColumnHeader.setText(chosenFieldsSelection.getHeader());
criteriaExtendedEntry.setVisible(presenter.getTableFormat() == GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY);
criteriaLimitedEntry.setVisible(presenter.getTableFormat() == GuidedDecisionTable52.TableFormat.LIMITED_ENTRY);
// Fields specific to the table format
switch(presenter.getTableFormat()) {
case EXTENDED_ENTRY:
txtValueList.setEnabled(!presenter.hasEnums(chosenFieldsSelection));
txtValueList.setText(chosenFieldsSelection.getValueList());
makeDefaultValueWidget();
defaultValueContainer.setVisible(true);
break;
case LIMITED_ENTRY:
makeLimitedValueWidget();
limitedEntryValueContainer.setVisible(true);
break;
}
}
private void makeLimitedValueWidget() {
if (!(chosenFieldsSelection instanceof LimitedEntryActionInsertFactCol52)) {
return;
}
LimitedEntryActionInsertFactCol52 lea = (LimitedEntryActionInsertFactCol52) chosenFieldsSelection;
if (lea.getValue() == null) {
lea.setValue(factory.makeNewValue(chosenFieldsSelection));
}
limitedEntryValueWidgetContainer.setWidget(factory.getWidget(chosenFieldsSelection, lea.getValue()));
}
});
}
Aggregations