Search in sources :

Example 41 with FactMapping

use of org.drools.scenariosimulation.api.model.FactMapping 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 42 with FactMapping

use of org.drools.scenariosimulation.api.model.FactMapping 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 43 with FactMapping

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

the class ScenarioSimulationMainGridPanelMouseMoveHandler method manageBodyCoordinates.

@Override
protected boolean manageBodyCoordinates(Integer uiRowIndex, Integer uiColumnIndex) {
    /* In this case, the mouse is out ot the GridLayer, then return false, without perform any action */
    if (uiColumnIndex == -1 || uiRowIndex == -1) {
        return false;
    }
    /* If the mouse position is the same of the previous one and the popover is already open, it does nothing.
         * It returns true because the click happened on an column of a grid row */
    if (uiRowIndex.equals(currentlyShownBodyRowIndex) && uiColumnIndex.equals(currentlyShownBodyColumnIndex) && errorReportPopupPresenter.isShown()) {
        return true;
    }
    /* It updates the coordinates of the current shown cell */
    currentlyShownBodyRowIndex = uiRowIndex;
    currentlyShownBodyColumnIndex = uiColumnIndex;
    final Optional<AbstractScesimModel<? extends AbstractScesimData>> optionalAbstractScesimModel = scenarioGrid.getModel().getAbstractScesimModel();
    final AbstractScesimModel<? extends AbstractScesimData> scesimModel = optionalAbstractScesimModel.orElseThrow(IllegalStateException::new);
    final AbstractScesimData scenarioByIndex = scesimModel.getDataByIndex(uiRowIndex);
    final FactMapping factMapping = scesimModel.getScesimModelDescriptor().getFactMappingByIndex(uiColumnIndex);
    final Optional<FactMappingValue> factMappingValueOptional = scenarioByIndex.getFactMappingValue(factMapping);
    factMappingValueOptional.ifPresent(factMappingValue -> manageFactMappingValue(factMappingValue, uiRowIndex, uiColumnIndex));
    return true;
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel)

Example 44 with FactMapping

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

the class SimulationGridModelTest method insertRowGridOnly.

@Test
public void insertRowGridOnly() {
    int setCellInvocations = scenarioMock.getUnmodifiableFactMappingValues().size();
    scenarioGridModelSpy.insertRowGridOnly(ROW_INDEX, gridRowMock, scenarioMock);
    verify(scenarioGridModelSpy, atLeast(1)).checkSimulation();
    verify(scenarioGridModelSpy, never()).insertRow(eq(ROW_INDEX), eq(gridRowMock));
    verify(scenarioGridModelSpy, times(1)).updateIndexColumn();
    verify(scenarioGridModelSpy, times(setCellInvocations)).setCell(anyInt(), anyInt(), isA(Supplier.class));
    reset(scenarioGridModelSpy);
    FactMapping factMappingByIndexMock = mock(FactMapping.class);
    when(factMappingByIndexMock.getClassName()).thenReturn(List.class.getName());
    when(simulationDescriptorMock.getFactMappingByIndex(2)).thenReturn(factMappingByIndexMock);
    scenarioGridModelSpy.insertRowGridOnly(ROW_INDEX, gridRowMock, scenarioMock);
    verify(scenarioGridModelSpy, atLeast(1)).checkSimulation();
    verify(scenarioGridModelSpy, never()).insertRow(eq(ROW_INDEX), eq(gridRowMock));
    verify(scenarioGridModelSpy, times(1)).updateIndexColumn();
    verify(scenarioGridModelSpy, times(setCellInvocations)).setCell(anyInt(), anyInt(), isA(Supplier.class));
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Supplier(java.util.function.Supplier) List(java.util.List) AbstractScenarioSimulationTest(org.drools.workbench.screens.scenariosimulation.client.AbstractScenarioSimulationTest) Test(org.junit.Test)

Example 45 with FactMapping

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

the class ScenarioSimulationEditorPresenterTest method cleanReadOnlyColumn.

@Test
public void cleanReadOnlyColumn() {
    Simulation simulation = new Simulation();
    ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
    FactMapping test1 = simulationDescriptor.addFactMapping(FactIdentifier.create("test1", String.class.getCanonicalName()), ExpressionIdentifier.create("", FactMappingType.GIVEN));
    FactMapping test2 = simulationDescriptor.addFactMapping(FactIdentifier.create("test2", String.class.getCanonicalName()), ExpressionIdentifier.create("", FactMappingType.GIVEN));
    test1.addExpressionElement("test", String.class.getCanonicalName());
    Scenario scenario = simulation.addData();
    scenario.addMappingValue(test1.getFactIdentifier(), test1.getExpressionIdentifier(), LOWER_CASE_VALUE);
    scenario.addMappingValue(test2.getFactIdentifier(), test2.getExpressionIdentifier(), LOWER_CASE_VALUE);
    presenterSpy.cleanReadOnlyColumn(simulation);
    assertNotNull(scenario.getFactMappingValue(test1.getFactIdentifier(), test1.getExpressionIdentifier()).get().getRawValue());
    assertNull(scenario.getFactMappingValue(test2.getFactIdentifier(), test2.getExpressionIdentifier()).get().getRawValue());
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) Matchers.anyString(org.mockito.Matchers.anyString) Scenario(org.drools.scenariosimulation.api.model.Scenario) Test(org.junit.Test)

Aggregations

FactMapping (org.drools.scenariosimulation.api.model.FactMapping)55 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)11 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)11 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)10 List (java.util.List)9 FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)8 Simulation (org.drools.scenariosimulation.api.model.Simulation)8 HashMap (java.util.HashMap)6 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)6 ScenarioGridCellValue (org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)6 ScenarioGridCell (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell)6 AbstractScesimModel (org.drools.scenariosimulation.api.model.AbstractScesimModel)5 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)5 FactModelTree (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree)5 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)4 FactMappingValidationError (org.drools.workbench.screens.scenariosimulation.model.FactMappingValidationError)4 Before (org.junit.Before)4 Map (java.util.Map)3