Search in sources :

Example 6 with ColumnUtilities

use of org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.ColumnUtilities in project drools-wb by kiegroup.

the class GuidedDecisionTableTest method testNoConstraints.

@SuppressWarnings("serial")
@Test
public void testNoConstraints() {
    final GuidedDecisionTable52 model = new GuidedDecisionTable52();
    final ModuleDataModelOracle loader = 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)).end().build();
    // Emulate server-to-client conversions
    final AsyncPackageDataModelOracle oracle = getOracle();
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    dataModel.setModelFields(loader.getModuleModelFields());
    populateDataModelOracle(mock(Path.class), model, oracle, dataModel);
    final ColumnUtilities utils = new ColumnUtilities(model, oracle);
    // add cols for LHS
    final RowNumberCol52 rnc = new RowNumberCol52();
    final DescriptionCol52 dc = new DescriptionCol52();
    final MetadataCol52 mdc = new MetadataCol52();
    mdc.setMetadata("cheese");
    final AttributeCol52 ac = new AttributeCol52();
    ac.setAttribute("salience");
    final ActionSetFieldCol52 asfc = new ActionSetFieldCol52();
    asfc.setBoundName("d1");
    asfc.setFactField("age");
    final ActionInsertFactCol52 aifc = new ActionInsertFactCol52();
    aifc.setBoundName("d2");
    aifc.setFactType("Driver");
    aifc.setFactField("age");
    final ConditionCol52 c1 = new ConditionCol52();
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("c1");
    p1.setFactType("Driver");
    c1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    p1.getChildColumns().add(c1);
    model.getConditions().add(p1);
    final ConditionCol52 c2 = new ConditionCol52();
    Pattern52 p2 = new Pattern52();
    p2.setBoundName("c2");
    p2.setFactType("Driver");
    c2.setFactField("age");
    c2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    p2.getChildColumns().add(c2);
    model.getConditions().add(p2);
    final ConditionCol52 c3 = new ConditionCol52();
    Pattern52 p3 = new Pattern52();
    p3.setBoundName("c3");
    p3.setFactType("Driver");
    c3.setOperator("==");
    c3.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    p3.getChildColumns().add(c3);
    model.getConditions().add(p3);
    final ConditionCol52 c4 = new ConditionCol52();
    Pattern52 p4 = new Pattern52();
    p4.setBoundName("c4");
    p4.setFactType("Driver");
    c4.setFactField("age");
    c4.setOperator("==");
    c4.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    p4.getChildColumns().add(c4);
    model.getConditions().add(p4);
    final ConditionCol52 c5 = new ConditionCol52();
    Pattern52 p5 = new Pattern52();
    p5.setBoundName("c5");
    p5.setFactType("Driver");
    c5.setConstraintValueType(BaseSingleFieldConstraint.TYPE_PREDICATE);
    p5.getChildColumns().add(c5);
    model.getConditions().add(p5);
    final ConditionCol52 c6 = new ConditionCol52();
    Pattern52 p6 = new Pattern52();
    p6.setBoundName("c6");
    p6.setFactType("Driver");
    c6.setConstraintValueType(BaseSingleFieldConstraint.TYPE_RET_VALUE);
    p6.getChildColumns().add(c6);
    model.getConditions().add(p6);
    assertTrue(utils.isConstraintValid(rnc));
    assertTrue(utils.isConstraintValid(dc));
    assertTrue(utils.isConstraintValid(mdc));
    assertTrue(utils.isConstraintValid(ac));
    assertTrue(utils.isConstraintValid(asfc));
    assertTrue(utils.isConstraintValid(aifc));
    assertFalse(utils.isConstraintValid(c1));
    assertFalse(utils.isConstraintValid(c2));
    assertFalse(utils.isConstraintValid(c3));
    assertTrue(utils.isConstraintValid(c4));
    assertTrue(utils.isConstraintValid(c5));
    assertTrue(utils.isConstraintValid(c6));
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) Path(org.uberfire.backend.vfs.Path) ColumnUtilities(org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.ColumnUtilities) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ActionInsertFactCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52) MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) AttributeCol52(org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) 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) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 7 with ColumnUtilities

use of org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.ColumnUtilities in project drools-wb by kiegroup.

the class GuidedDecisionTableTest method testConditionFormulaChoices.

@SuppressWarnings("serial")
@Test
public void testConditionFormulaChoices() {
    final GuidedDecisionTable52 model = new GuidedDecisionTable52();
    final ModuleDataModelOracle loader = 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)).end().build();
    // Emulate server-to-client conversions
    final AsyncPackageDataModelOracle oracle = getOracle();
    final PackageDataModelOracleBaselinePayload dataModel = new PackageDataModelOracleBaselinePayload();
    dataModel.setModelFields(loader.getModuleModelFields());
    populateDataModelOracle(mock(Path.class), model, oracle, dataModel);
    final ColumnUtilities utils = new ColumnUtilities(model, oracle);
    final ConditionCol52 c1 = new ConditionCol52();
    final Pattern52 p1 = new Pattern52();
    p1.setBoundName("c1");
    p1.setFactType("Driver");
    c1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_RET_VALUE);
    c1.setFieldType(DataType.TYPE_STRING);
    c1.setValueList("getAge()>10,getAge()>20,getAge()>30");
    p1.getChildColumns().add(c1);
    model.getConditions().add(p1);
    assertTrue(utils.getValueList(c1).length > 0);
    assertTrue(utils.getValueList(c1).length == 3);
    assertEquals("getAge()>10", utils.getValueList(c1)[0]);
    assertEquals("getAge()>20", utils.getValueList(c1)[1]);
    assertEquals("getAge()>30", utils.getValueList(c1)[2]);
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) Path(org.uberfire.backend.vfs.Path) ColumnUtilities(org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.ColumnUtilities) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) 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) ModuleDataModelOracle(org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle) RawMVELEvaluator(org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator) Test(org.junit.Test)

Example 8 with ColumnUtilities

use of org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.ColumnUtilities in project drools-wb by kiegroup.

the class BaseSynchronizerTest method setup.

@Before
public void setup() {
    // Setup model related classes
    model = new GuidedDecisionTable52();
    uiModel = new GuidedDecisionTableUiModel(modelSynchronizer);
    incrementalDataModelServiceCaller = new CallerMock<>(incrementalDataModelService);
    final BRLRuleModel rm = new BRLRuleModel(model);
    final CellUtilities cellUtilities = new CellUtilities();
    final ColumnUtilities columnUtilities = new ColumnUtilities(model, oracle);
    final DependentEnumsUtilities enumsUtilities = new DependentEnumsUtilities(model, oracle);
    final GridWidgetCellFactory gridWidgetCellFactory = new GridWidgetCellFactoryImpl();
    // Setup mocks
    final GuidedDecisionTableModellerView.Presenter modellerPresenter = mock(GuidedDecisionTableModellerView.Presenter.class);
    final GuidedDecisionTableModellerView modellerView = mock(GuidedDecisionTableModellerView.class);
    final GridLayer gridLayer = mock(GridLayer.class);
    final AbsolutePanel domElementContainer = mock(AbsolutePanel.class);
    final GuidedDecisionTableView.Presenter dtablePresenter = mock(GuidedDecisionTableView.Presenter.class);
    final EventBus eventBus = mock(EventBus.class);
    when(dtablePresenter.getModellerPresenter()).thenReturn(modellerPresenter);
    when(modellerPresenter.getView()).thenReturn(modellerView);
    when(modellerView.getGridLayerView()).thenReturn(gridLayer);
    when(gridLayer.getDomElementContainer()).thenReturn(domElementContainer);
    when(domElementContainer.iterator()).thenReturn(mock(Iterator.class));
    // Setup column converters
    final List<BaseColumnConverter> converters = getConverters();
    gridWidgetColumnFactory.setConverters(converters);
    gridWidgetColumnFactory.initialise(model, oracle, columnUtilities, dtablePresenter);
    // Setup synchronizers
    final List<Synchronizer<? extends MetaData, ? extends MetaData, ? extends MetaData, ? extends MetaData, ? extends MetaData>> synchronizers = getSynchronizers();
    modelSynchronizer.setSynchronizers(synchronizers);
    modelSynchronizer.initialise(model, uiModel, cellUtilities, columnUtilities, enumsUtilities, gridWidgetCellFactory, gridWidgetColumnFactory, view, rm, eventBus, editable);
    // Dummy columns for Row number and Description
    uiModel.appendColumn(gridWidgetColumnFactory.convertColumn(new RowNumberCol52(), readOnly, view));
    uiModel.appendColumn(gridWidgetColumnFactory.convertColumn(new DescriptionCol52(), readOnly, view));
    ApplicationPreferences.setUp(new HashMap<String, String>() {

        {
            put(ApplicationPreferences.DATE_FORMAT, "dd-MM-yyyy");
        }
    });
}
Also used : ColumnUtilities(org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.ColumnUtilities) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) GuidedDecisionTableModellerView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableModellerView) AbsolutePanel(com.google.gwt.user.client.ui.AbsolutePanel) EventBus(com.google.gwt.event.shared.EventBus) GuidedDecisionTableView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView) GridWidgetCellFactoryImpl(org.drools.workbench.screens.guided.dtable.client.widget.table.model.converters.cell.impl.GridWidgetCellFactoryImpl) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) MetaData(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.Synchronizer.MetaData) GuidedDecisionTableUiModel(org.drools.workbench.screens.guided.dtable.client.widget.table.model.GuidedDecisionTableUiModel) Iterator(java.util.Iterator) BaseColumnConverter(org.drools.workbench.screens.guided.dtable.client.widget.table.model.converters.column.BaseColumnConverter) Synchronizer(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.Synchronizer) BRLRuleModel(org.drools.workbench.models.guided.dtable.shared.model.BRLRuleModel) DependentEnumsUtilities(org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.DependentEnumsUtilities) CellUtilities(org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.CellUtilities) GridLayer(org.uberfire.ext.wires.core.grids.client.widget.layer.GridLayer) GridWidgetCellFactory(org.drools.workbench.screens.guided.dtable.client.widget.table.model.converters.cell.GridWidgetCellFactory) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Before(org.junit.Before)

Example 9 with ColumnUtilities

use of org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.ColumnUtilities in project drools-wb by kiegroup.

the class ConditionColumnPlugin method assertDefaultValue.

void assertDefaultValue() {
    final CellUtilities cellUtilities = new CellUtilities();
    final AsyncPackageDataModelOracle oracle = presenter.getDataModelOracle();
    final ColumnUtilities columnUtilities = new ColumnUtilities(model(), oracle);
    final List<String> valueList = Arrays.asList(columnUtilities.getValueList(editingCol));
    if (valueList.size() > 0) {
        final String defaultValue = cellUtilities.asString(editingCol().getDefaultValue());
        if (!valueList.contains(defaultValue)) {
            editingCol.getDefaultValue().clearValues();
        }
    } else {
        // Ensure the Default Value has been updated to represent the column's data-type.
        final DTCellValue52 defaultValue = editingCol().getDefaultValue();
        final DataType.DataTypes dataType = columnUtilities.getDataType(editingPattern(), editingCol());
        cellUtilities.convertDTCellValueType(dataType, defaultValue);
    }
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ColumnUtilities(org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.ColumnUtilities) CellUtilities(org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.CellUtilities) DataType(org.kie.soup.project.datamodel.oracle.DataType) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)

Example 10 with ColumnUtilities

use of org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.ColumnUtilities in project drools-wb by kiegroup.

the class DefaultWidgetFactory method dataType.

private DataType.DataTypes dataType() {
    final ColumnUtilities columnUtilities = columnUtilities();
    final DTColumnConfig52 column = getPlugin().editingCol();
    if (column instanceof ActionSetFieldCol52) {
        return columnUtilities.getDataType(getPlugin().editingPattern(), (ActionSetFieldCol52) column);
    } else if (column instanceof ConditionCol52) {
        return columnUtilities.getDataType(getPlugin().editingPattern(), (ConditionCol52) column);
    } else {
        return columnUtilities.getDataType(column);
    }
}
Also used : ColumnUtilities(org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.ColumnUtilities) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) DTColumnConfig52(org.drools.workbench.models.guided.dtable.shared.model.DTColumnConfig52) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)

Aggregations

ColumnUtilities (org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.ColumnUtilities)17 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)12 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)9 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)8 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)8 Test (org.junit.Test)7 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)7 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)7 Path (org.uberfire.backend.vfs.Path)7 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)5 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)5 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)5 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)4 AttributeCol52 (org.drools.workbench.models.guided.dtable.shared.model.AttributeCol52)4 CellUtilities (org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.CellUtilities)4 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)2 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)2 BaseColumnConverter (org.drools.workbench.screens.guided.dtable.client.widget.table.model.converters.column.BaseColumnConverter)2 DependentEnumsUtilities (org.drools.workbench.screens.guided.dtable.client.widget.table.utilities.DependentEnumsUtilities)2 Before (org.junit.Before)2