Search in sources :

Example 16 with ExpressionIdentifier

use of org.drools.scenariosimulation.api.model.ExpressionIdentifier in project drools-wb by kiegroup.

the class AbstractScesimGridModel method commonAddColumn.

/**
 * This method <i>add</i> or <i>insert</i> a new column to the grid <b>and</b> to the underlying model, depending on the index value.
 * If index == -1 -> add, otherwise insert.
 * @param index
 * @param column
 * @param ei
 */
protected void commonAddColumn(final int index, final GridColumn<?> column, ExpressionIdentifier ei) {
    ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
    String instanceTitle = ((ScenarioGridColumn) column).getInformationHeaderMetaData().getTitle();
    String propertyTitle = ((ScenarioGridColumn) column).getPropertyHeaderMetaData().getTitle();
    final int columnIndex = index == -1 ? getColumnCount() : index;
    try {
        final FactMapping createdFactMapping = simulationDescriptor.addFactMapping(columnIndex, instanceTitle, ((ScenarioGridColumn) column).getFactIdentifier(), ei);
        createdFactMapping.setExpressionAlias(propertyTitle);
        if (index == -1) {
            // This is actually an append
            super.appendColumn(column);
        } else {
            super.insertColumn(index, column);
        }
        final Range instanceLimits = getInstanceLimits(columnIndex);
        IntStream.range(instanceLimits.getMinRowIndex(), instanceLimits.getMaxRowIndex() + 1).filter(currentIndex -> currentIndex != columnIndex).forEach(currentIndex -> simulationDescriptor.getFactMappingByIndex(currentIndex).setFactAlias(createdFactMapping.getFactAlias()));
    } catch (Exception e) {
        eventBus.fireEvent(new ScenarioNotificationEvent("Error during column creation: " + e.getMessage(), NotificationEvent.NotificationType.ERROR));
        eventBus.fireEvent(new ScenarioGridReloadEvent(getGridWidget()));
        return;
    }
    final List<E> unmodifiableScesimData = abstractScesimModel.getUnmodifiableData();
    String placeHolder = ((ScenarioGridColumn) column).getPlaceHolder();
    IntStream.range(0, unmodifiableScesimData.size()).forEach(rowIndex -> setCell(rowIndex, columnIndex, () -> new ScenarioGridCell(new ScenarioGridCellValue(null, placeHolder))));
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Arrays(java.util.Arrays) ScenarioNotificationEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioNotificationEvent) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) FactMappingValueType(org.drools.scenariosimulation.api.model.FactMappingValueType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioSimulationUtils(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils) BaseSingletonDOMElementFactory(org.uberfire.ext.wires.core.grids.client.widget.dom.single.impl.BaseSingletonDOMElementFactory) EventBus(com.google.gwt.event.shared.EventBus) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) GridCellValue(org.uberfire.ext.wires.core.grids.client.model.GridCellValue) ScenarioHeaderTextBoxSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioHeaderTextBoxSingletonDOMElementFactory) Optional(java.util.Optional) ScenarioSimulationEditorConstants(org.drools.workbench.screens.scenariosimulation.client.resources.i18n.ScenarioSimulationEditorConstants) ReloadTestToolsEvent(org.drools.workbench.screens.scenariosimulation.client.events.ReloadTestToolsEvent) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ScenarioGridReloadEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioGridReloadEvent) IntStream(java.util.stream.IntStream) ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationUtils.getPropertyNameElementsWithoutAlias) CollectionEditorSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.CollectionEditorSingletonDOMElementFactory) FactMappingValueStatus(org.drools.scenariosimulation.api.model.FactMappingValueStatus) OptionalDouble(java.util.OptionalDouble) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ScenarioSimulationSharedUtils(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils) ScenarioCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioCellTextAreaSingletonDOMElementFactory) ScenarioExpressionCellTextAreaSingletonDOMElementFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioExpressionCellTextAreaSingletonDOMElementFactory) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) AbstractMap(java.util.AbstractMap) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Collections(java.util.Collections) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioNotificationEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioNotificationEvent) ScenarioGridReloadEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioGridReloadEvent) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell)

Example 17 with ExpressionIdentifier

use of org.drools.scenariosimulation.api.model.ExpressionIdentifier in project drools-wb by kiegroup.

the class ScenarioGridModel method insertRowGridOnly.

/**
 * This method <i>insert</i> a row to the grid and populate it with values taken from given <code>Scenario</code>
 * @param row
 */
@Override
public void insertRowGridOnly(final int rowIndex, final GridRow row, final Scenario scenario) {
    insertRowGridOnly(rowIndex, row);
    scenario.getUnmodifiableFactMappingValues().forEach(value -> {
        FactIdentifier factIdentifier = value.getFactIdentifier();
        ExpressionIdentifier expressionIdentifier = value.getExpressionIdentifier();
        if (value.getRawValue() == null || value.getRawValue() instanceof String) {
            // Let' put a placeholder
            String stringValue = (String) value.getRawValue();
            int columnIndex = abstractScesimModel.getScesimModelDescriptor().getIndexByIdentifier(factIdentifier, expressionIdentifier);
            final FactMapping factMappingByIndex = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
            String placeHolder = ((ScenarioGridColumn) columns.get(columnIndex)).getPlaceHolder();
            setCell(rowIndex, columnIndex, () -> {
                ScenarioGridCell newCell = new ScenarioGridCell(new ScenarioGridCellValue(stringValue, placeHolder));
                if (ScenarioSimulationSharedUtils.isCollectionOrMap((factMappingByIndex.getClassName()))) {
                    newCell.setListMap(ScenarioSimulationSharedUtils.isList((factMappingByIndex.getClassName())));
                }
                return newCell;
            });
        } else {
            throw new UnsupportedOperationException("Only string is supported at the moment");
        }
    });
    updateIndexColumn();
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)

Example 18 with ExpressionIdentifier

use of org.drools.scenariosimulation.api.model.ExpressionIdentifier in project drools-wb by kiegroup.

the class BackgroundGridModel method insertRowGridOnly.

/**
 * This method <i>insert</i> a row to the grid and populate it with values taken from given <code>Scenario</code>
 * @param row
 */
@Override
public void insertRowGridOnly(final int rowIndex, final GridRow row, final BackgroundData abstractScesimData) {
    insertRowGridOnly(rowIndex, row);
    abstractScesimData.getUnmodifiableFactMappingValues().forEach(value -> {
        FactIdentifier factIdentifier = value.getFactIdentifier();
        ExpressionIdentifier expressionIdentifier = value.getExpressionIdentifier();
        if (value.getRawValue() == null || value.getRawValue() instanceof String) {
            String stringValue = (String) value.getRawValue();
            int columnIndex = abstractScesimModel.getScesimModelDescriptor().getIndexByIdentifier(factIdentifier, expressionIdentifier);
            final FactMapping factMappingByIndex = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
            String placeHolder = ((ScenarioGridColumn) columns.get(columnIndex)).getPlaceHolder();
            setCell(rowIndex, columnIndex, () -> {
                ScenarioGridCell newCell = new ScenarioGridCell(new ScenarioGridCellValue(stringValue, placeHolder));
                if (ScenarioSimulationSharedUtils.isCollectionOrMap((factMappingByIndex.getClassName()))) {
                    newCell.setListMap(ScenarioSimulationSharedUtils.isList((factMappingByIndex.getClassName())));
                }
                return newCell;
            });
        } else {
            throw new UnsupportedOperationException("Only string is supported at the moment");
        }
    });
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)

Example 19 with ExpressionIdentifier

use of org.drools.scenariosimulation.api.model.ExpressionIdentifier in project drools-wb by kiegroup.

the class ScenarioGridTest method setup.

@Before
public void setup() {
    simulation = getSimulation();
    when(scenarioGridColumnMock.getPropertyHeaderMetaData()).thenReturn(propertyHeaderMetadataMock);
    when(scenarioGridModelMock.getAbstractScesimModel()).thenReturn(Optional.of(simulation));
    when(scenarioGridModelMock.getGridWidget()).thenReturn(GridWidget.SIMULATION);
    when(scenarioGridModelMock.getScenarioExpressionCellTextAreaSingletonDOMElementFactory()).thenReturn(expressionCellTextAreaSingletonDOMElementFactoryMock);
    when(scenarioGridModelMock.getCollectionEditorSingletonDOMElementFactory()).thenReturn(collectionEditorSingletonDOMElementFactory);
    factIdentifierGiven = FactIdentifier.create("GIVEN", "GIVEN");
    factIdentifierInteger = FactIdentifier.create("Integer", "java.lang.Integer");
    factMappingDescription = new FactMapping(EXPRESSION_ALIAS_DESCRIPTION, FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
    factMappingGiven = new FactMapping(EXPRESSION_ALIAS_GIVEN, factIdentifierGiven, new ExpressionIdentifier("GIVEN", FactMappingType.GIVEN));
    factMappingInteger = new FactMapping(EXPRESSION_ALIAS_INTEGER, factIdentifierInteger, new ExpressionIdentifier("GIVEN", FactMappingType.GIVEN));
    scenarioGridSpy = spy(new ScenarioGrid(scenarioGridModelMock, scenarioGridLayerMock, scenarioGridRendererMock, scenarioContextMenuRegistryMock) {

        @Override
        protected <T extends AbstractScesimData> void appendRow(int rowIndex, T scesimData) {
        // do nothing
        }

        @Override
        protected ScenarioSimulationBuilders.HeaderBuilder getHeaderBuilderLocal(String instanceTitle, String propertyTitle, String columnId, String columnGroup, FactMappingType factMappingType) {
            return headerBuilderMock;
        }

        @Override
        protected ScenarioGridColumn getScenarioGridColumnLocal(ScenarioSimulationBuilders.HeaderBuilder headerBuilder, String placeHolder) {
            return scenarioGridColumnMock;
        }

        @Override
        protected BaseGridRendererHelper getBaseGridRendererHelper() {
            return rendererHelperMock;
        }

        @Override
        public Viewport getViewport() {
            return viewportMock;
        }

        @Override
        protected ScenarioHeaderMetaData getColumnScenarioHeaderMetaData(final ScenarioGridColumn scenarioGridColumn, final int rowIndex) {
            return propertyHeaderMetadataMock;
        }

        @Override
        protected EnableTestToolsEvent getEnableTestToolsEvent(final ScenarioGrid scenarioGrid, final ScenarioGridColumn scenarioGridColumn, final ScenarioHeaderMetaData scenarioHeaderMetaData, int uiColumnIndex, String group) {
            return new EnableTestToolsEvent();
        }

        @Override
        public Layer getLayer() {
            return scenarioGridLayerMock;
        }
    });
    when(rendererHelperMock.getRenderingInformation()).thenReturn(renderingInformationMock);
    when(renderingInformationMock.getHeaderRowsHeight()).thenReturn(HEADER_ROWS_HEIGHT);
    when(renderingInformationMock.getFloatingBlockInformation()).thenReturn(floatingBlockInformationMock);
    when(propertyHeaderMetadataMock.getColumnGroup()).thenReturn(GRID_COLUMN_GROUP);
    scenarioGridSpy.setEventBus(eventBusMock);
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioSimulationBuilders(org.drools.workbench.screens.scenariosimulation.client.utils.ScenarioSimulationBuilders) HEADER_ROWS_HEIGHT(org.drools.workbench.screens.scenariosimulation.client.TestProperties.HEADER_ROWS_HEIGHT) TEST(org.drools.workbench.screens.scenariosimulation.client.TestProperties.TEST) ScenarioHeaderMetaData(org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) EnableTestToolsEvent(org.drools.workbench.screens.scenariosimulation.client.events.EnableTestToolsEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Before(org.junit.Before)

Aggregations

ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)19 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)11 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)9 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)7 FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)6 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Scenario (org.drools.scenariosimulation.api.model.Scenario)4 ExpressionEvaluator (org.drools.scenariosimulation.backend.expression.ExpressionEvaluator)4 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Background (org.drools.scenariosimulation.api.model.Background)3 FactMappingType (org.drools.scenariosimulation.api.model.FactMappingType)3 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)3 Settings (org.drools.scenariosimulation.api.model.Settings)3 ScenarioGridCellValue (org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)3 ScenarioGridCell (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell)3 Before (org.junit.Before)3