Search in sources :

Example 26 with ScesimModelDescriptor

use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor 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)

Example 27 with ScesimModelDescriptor

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

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

the class AbstractScesimGridModel method isSameSelectedColumnType.

/**
 * Returns <code>true</code> if type of the property mapped to the column at given index is the same as the provided one
 * @param columnIndex
 * @param className
 * @return
 */
public boolean isSameSelectedColumnType(int columnIndex, String className) {
    ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
    final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex);
    return factMappingByIndex.getClassName().equals(className);
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping)

Example 29 with ScesimModelDescriptor

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

the class TestUtils method getSimulation.

public static Simulation getSimulation(int numberOfColumns, int numberOfRows) {
    Simulation simulation = new Simulation();
    ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
    simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
    // generate simulationDescriptor
    IntStream.range(0, numberOfColumns).forEach(columnIndex -> {
        simulationDescriptor.addFactMapping(FactIdentifier.create(getFactName(columnIndex), String.class.getCanonicalName()), ExpressionIdentifier.create(getColName(columnIndex), FactMappingType.EXPECT));
    });
    // generate scenarios
    IntStream.range(0, numberOfRows).forEach(rowIndex -> {
        final Scenario scenario = simulation.addData();
        scenario.setDescription(getRowName(rowIndex));
        IntStream.range(0, numberOfColumns).forEach(columnIndex -> {
            scenario.addMappingValue(FactIdentifier.create(getFactName(columnIndex), String.class.getCanonicalName()), ExpressionIdentifier.create(getColName(columnIndex), FactMappingType.EXPECT), getCellValue(columnIndex, rowIndex));
        });
    });
    return simulation;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Simulation(org.drools.scenariosimulation.api.model.Simulation) Scenario(org.drools.scenariosimulation.api.model.Scenario)

Aggregations

ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)29 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)18 ArrayList (java.util.ArrayList)11 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)11 List (java.util.List)9 Map (java.util.Map)9 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)9 Set (java.util.Set)8 Simulation (org.drools.scenariosimulation.api.model.Simulation)8 Objects (java.util.Objects)7 ExpressionElement (org.drools.scenariosimulation.api.model.ExpressionElement)7 FactMappingType (org.drools.scenariosimulation.api.model.FactMappingType)7 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)7 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)7 Collections (java.util.Collections)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)6 FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)6 Scenario (org.drools.scenariosimulation.api.model.Scenario)6 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)5