use of org.kie.soup.project.datamodel.oracle.ModelField in project drools-wb by kiegroup.
the class RowExpanderTests method testExpansionObjectUniqueness.
@Test
public // GUVNOR-1960
void testExpansionObjectUniqueness() {
GuidedDecisionTable52 model = new GuidedDecisionTable52();
final ModuleDataModelOracle projectLoader = ModuleDataModelOracleBuilder.newModuleOracleBuilder(new RawMVELEvaluator()).addFact("Driver").addField(new ModelField("gender", String.class.getName(), ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.BOTH, DataType.TYPE_STRING)).end().build();
final PackageDataModelOracle packageLoader = PackageDataModelOracleBuilder.newPackageOracleBuilder(new RawMVELEvaluator()).setModuleOracle(projectLoader).addEnum("'Driver.gender' : ['M', 'F']", Thread.currentThread().getContextClassLoader()).build();
// Emulate server-to-client conversions
final AsyncPackageDataModelOracle oracle = getOracle();
final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
dataModel.setModelFields(projectLoader.getModuleModelFields());
dataModel.setWorkbenchEnumDefinitions(packageLoader.getPackageWorkbenchDefinitions());
populateDataModelOracle(mock(Path.class), model, oracle, dataModel);
Pattern52 p1 = new Pattern52();
p1.setBoundName("c1");
p1.setFactType("Driver");
ConditionCol52 c1 = new ConditionCol52();
c1.setFactField("gender");
c1.setOperator("==");
c1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
p1.getChildColumns().add(c1);
model.getConditions().add(p1);
RowExpander re = new RowExpander(model, oracle);
List<RowExpander.ColumnValues> columns = re.getColumns();
assertEquals(3, columns.size());
assertEquals(1, columns.get(0).values.size());
assertEquals(1, columns.get(1).values.size());
assertEquals(2, columns.get(2).values.size());
RowExpander.RowIterator ri = re.iterator();
assertTrue(ri.hasNext());
List<List<DTCellValue52>> rows = new ArrayList<List<DTCellValue52>>();
while (ri.hasNext()) {
List<DTCellValue52> row = ri.next();
rows.add(row);
}
assertEquals(2, rows.size());
assertEquals("", rows.get(0).get(0).getStringValue());
assertEquals("", rows.get(0).get(1).getStringValue());
assertEquals("M", rows.get(0).get(2).getStringValue());
assertEquals("", rows.get(1).get(0).getStringValue());
assertEquals("", rows.get(1).get(1).getStringValue());
assertEquals("F", rows.get(1).get(2).getStringValue());
assertTrue(rows.get(0).get(0) != rows.get(1).get(0));
assertTrue(rows.get(0).get(1) != rows.get(1).get(1));
}
use of org.kie.soup.project.datamodel.oracle.ModelField in project drools-wb by kiegroup.
the class TestGuidedDecisionTreeFileIndexer method getModuleDataModelOracle.
@Override
protected ModuleDataModelOracle getModuleDataModelOracle(final Path path) {
final ModuleDataModelOracle dmo = new ModuleDataModelOracleImpl();
dmo.addModuleModelFields(new HashMap<String, ModelField[]>() {
{
put("org.drools.workbench.screens.guided.dtree.backend.server.indexing.classes.Applicant", new ModelField[] { new ModelField("age", "java.lang.Integer", ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.ACCESSOR, DataType.TYPE_NUMERIC_INTEGER) });
put("org.drools.workbench.screens.guided.dtree.backend.server.indexing.classes.Mortgage", new ModelField[] { new ModelField("amount", "java.lang.Integer", ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.ACCESSOR, DataType.TYPE_NUMERIC_INTEGER), new ModelField("applicant", "org.drools.workbench.screens.guided.dtree.backend.server.indexing.classes.Applicant", ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.ACCESSOR, "org.drools.workbench.screens.guided.dtree.backend.server.indexing.classes.Applicant") });
}
});
return dmo;
}
use of org.kie.soup.project.datamodel.oracle.ModelField in project drools-wb by kiegroup.
the class ActionFieldValueEditor method initializeFieldNames.
private void initializeFieldNames(final ActionFieldValue afv) {
fieldListBox.clear();
fieldListBox.setEnabled(false);
oracle.getFieldCompletions(className, (modelFields) -> {
fieldListBox.setEnabled(modelFields.length > 0);
if (modelFields.length == 0) {
fieldListBox.addItem(GuidedDecisionTreeConstants.INSTANCE.noFields());
return;
}
// Add them to the ListBox
int selectedIndex = -1;
for (ModelField modelField : modelFields) {
final String fieldName = modelField.getName();
if (!fieldName.equals(DataType.TYPE_THIS)) {
fieldListBox.addItem(fieldName);
if (fieldName.equals(afv.getFieldName())) {
selectedIndex = fieldListBox.getItemCount() - 1;
}
}
}
fieldListBox.addChangeHandler((event) -> {
final String fieldName = fieldListBox.getItemText(fieldListBox.getSelectedIndex());
afv.setFieldName(fieldName);
afv.setValue(null);
initialiseValue();
});
fieldListBox.setSelectedIndex(selectedIndex);
if (selectedIndex == -1) {
fieldListBox.setSelectedIndex(0);
final String fieldName = fieldListBox.getItemText(0);
afv.setFieldName(fieldName);
}
initialiseValue();
});
}
use of org.kie.soup.project.datamodel.oracle.ModelField in project drools-wb by kiegroup.
the class TestGuidedRuleDrlFileIndexer method getModuleDataModelOracle.
@Override
protected ModuleDataModelOracle getModuleDataModelOracle(final Path path) {
final ModuleDataModelOracle dmo = new ModuleDataModelOracleImpl();
dmo.addModuleModelFields(new HashMap<String, ModelField[]>() {
{
put("org.drools.workbench.screens.guided.rule.backend.server.indexing.classes.Applicant", new ModelField[] { new ModelField("age", "java.lang.Integer", ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.ACCESSOR, DataType.TYPE_NUMERIC_INTEGER) });
put("org.drools.workbench.screens.guided.rule.backend.server.indexing.classes.Mortgage", new ModelField[] { new ModelField("amount", "java.lang.Integer", ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.ACCESSOR, DataType.TYPE_NUMERIC_INTEGER), new ModelField("applicant", "org.drools.workbench.screens.guided.rule.backend.server.indexing.classes.Applicant", ModelField.FIELD_CLASS_TYPE.REGULAR_CLASS, ModelField.FIELD_ORIGIN.DECLARED, FieldAccessorsAndMutators.ACCESSOR, "org.drools.workbench.screens.guided.rule.backend.server.indexing.classes.Applicant") });
}
});
return dmo;
}
use of org.kie.soup.project.datamodel.oracle.ModelField in project drools-wb by kiegroup.
the class FieldPageTest method testFieldsCallbackWhenConstraintIsRetValue.
@Test
public void testFieldsCallbackWhenConstraintIsRetValue() throws Exception {
final ConditionColumnPlugin plugin = spy(new ConditionColumnPlugin(patternPage, calculationTypePage, fieldPage, operatorPage, valueOptionsPage, additionalInfoPage, changeEvent, translationService));
doReturn(BaseSingleFieldConstraint.TYPE_RET_VALUE).when(plugin).constraintValue();
when(page.plugin()).thenReturn(plugin);
when(pattern52.getFactType()).thenReturn("factType");
when(plugin.patternWrapper()).thenReturn(pattern52);
when(presenter.getDataModelOracle()).thenReturn(oracle);
when(oracle.hasEnums("factType", "modelField2")).thenReturn(true);
final List<String> expected = new ArrayList<String>() {
{
add("modelField1");
add("modelField3");
}
};
final List<String> result = new ArrayList<>();
final ModelField[] modelFields = new ModelField[] { modelField("modelField1", DataType.TYPE_OBJECT), modelField("modelField2", DataType.TYPE_OBJECT), modelField("modelField3", DataType.TYPE_OBJECT) };
final Callback<ModelField[]> fieldsCallback = page.fieldsCallback(result::add);
fieldsCallback.callback(modelFields);
assertEquals(expected, result);
}
Aggregations