Search in sources :

Example 51 with ModelField

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));
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) Path(org.uberfire.backend.vfs.Path) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ArrayList(java.util.ArrayList) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) PackageDataModelOracleBaselinePayload(org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 52 with ModelField

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;
}
Also used : ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)

Example 53 with ModelField

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();
    });
}
Also used : ModelField(org.kie.soup.project.datamodel.oracle.ModelField)

Example 54 with ModelField

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;
}
Also used : ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ModuleDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)

Example 55 with ModelField

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);
}
Also used : ConditionColumnPlugin(org.drools.workbench.screens.guided.dtable.client.wizard.column.plugins.ConditionColumnPlugin) ModelField(org.kie.soup.project.datamodel.oracle.ModelField) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ModelField (org.kie.soup.project.datamodel.oracle.ModelField)70 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)36 Test (org.junit.Test)34 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)34 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)25 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)24 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)24 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)24 Path (org.uberfire.backend.vfs.Path)24 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)23 ArrayList (java.util.ArrayList)20 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)19 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)14 List (java.util.List)13 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)11 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)11 ModuleDataModelOracleImpl (org.kie.soup.project.datamodel.commons.oracle.ModuleDataModelOracleImpl)10 LimitedEntryActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)9 LimitedEntryActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52)9 PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)9