Search in sources :

Example 16 with FactMapping

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

the class AbstractScesimGridModel method commonAddRow.

protected void commonAddRow(int rowIndex, int columnIndexStart) {
    E scesimData = abstractScesimModel.addData(rowIndex);
    final ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
    IntStream.range(columnIndexStart, getColumnCount()).forEach(columnIndex -> {
        final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex);
        scesimData.addMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier(), null);
        ScenarioGridColumn column = ((ScenarioGridColumn) columns.get(columnIndex));
        String placeHolder = ScenarioSimulationUtils.getPlaceHolder(column.isInstanceAssigned(), column.isPropertyAssigned(), factMappingByIndex.getFactMappingValueType(), factMappingByIndex.getClassName());
        setCell(rowIndex, columnIndex, () -> {
            ScenarioGridCell newCell = new ScenarioGridCell(new ScenarioGridCellValue(null, placeHolder));
            if (ScenarioSimulationSharedUtils.isCollectionOrMap((factMappingByIndex.getClassName()))) {
                newCell.setListMap(ScenarioSimulationSharedUtils.isList((factMappingByIndex.getClassName())));
            }
            return newCell;
        });
    });
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)

Example 17 with FactMapping

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

the class AbstractScesimGridModel method setCell.

/**
 * This method <i>set</i> a cell value to the grid <b>and</b> to the underlying model
 * @param rowIndex
 * @param columnIndex
 * @param cellSupplier
 */
@Override
public Range setCell(int rowIndex, int columnIndex, Supplier<GridCell<?>> cellSupplier) {
    checkSimulation();
    Range toReturn = super.setCell(rowIndex, columnIndex, cellSupplier);
    try {
        Optional<?> optionalValue = getCellValue(getCell(rowIndex, columnIndex));
        Object rawValue = optionalValue.orElse(null);
        String cellValue = (rawValue instanceof String) ? (String) rawValue : null;
        E scenarioByIndex = abstractScesimModel.getDataByIndex(rowIndex);
        FactMapping factMappingByIndex = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
        FactIdentifier factIdentifier = factMappingByIndex.getFactIdentifier();
        ExpressionIdentifier expressionIdentifier = factMappingByIndex.getExpressionIdentifier();
        scenarioByIndex.addOrUpdateMappingValue(factIdentifier, expressionIdentifier, cellValue);
    } catch (Exception e) {
        toReturn = super.deleteCell(rowIndex, columnIndex);
        eventBus.fireEvent(new ScenarioGridReloadEvent(getGridWidget()));
    }
    return toReturn;
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ScenarioGridReloadEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioGridReloadEvent) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier)

Example 18 with FactMapping

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

the class AbstractScesimGridModel method isSameSelectedColumnProperty.

/**
 * Returns <code>true</code> if property mapped to the column at given index is the same as the provided one
 * @param columnIndex
 * @param propertyNameElements
 * @param factMappingValueType
 * @return
 */
public boolean isSameSelectedColumnProperty(int columnIndex, List<String> propertyNameElements, FactMappingValueType factMappingValueType) {
    String propertyName = String.join(".", propertyNameElements);
    ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
    final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex);
    String expressionElement = factMappingByIndex.getExpressionElements().stream().map(ExpressionElement::getStep).collect(Collectors.joining("."));
    return Objects.equals(expressionElement, propertyName) && Objects.equals(factMappingValueType, factMappingByIndex.getFactMappingValueType());
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping)

Example 19 with FactMapping

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

the class AbstractScesimGridModel method updateColumnProperty.

/**
 * This method update the type mapped inside a give column and updates the underlying model
 * @param columnIndex
 * @param column
 * @param propertyNameElements
 * @param lastLevelClassName
 * @param keepData
 */
public void updateColumnProperty(int columnIndex, final GridColumn<?> column, List<String> propertyNameElements, String lastLevelClassName, boolean keepData, FactMappingValueType valueType, ScenarioSimulationModel.Type type) {
    checkSimulation();
    List<GridCellValue<?>> originalValues = new ArrayList<>();
    if (keepData) {
        IntStream.range(0, getRowCount()).forEach(rowIndex -> originalValues.add(getCell(rowIndex, columnIndex).getValue()));
    }
    replaceColumn(columnIndex, column);
    final FactMapping factMappingByIndex = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
    factMappingByIndex.setFactMappingValueType(valueType);
    List<String> propertyNameElementsClone = getPropertyNameElementsWithoutAlias(propertyNameElements, factMappingByIndex.getFactIdentifier(), type);
    // This is because the value starts with the alias of the fact; i.e. it may be Book.name but also Bookkk.name,
    // while the first element of ExpressionElements is always the class name
    IntStream.range(0, propertyNameElementsClone.size()).forEach(stepIndex -> factMappingByIndex.addExpressionElement(propertyNameElementsClone.get(stepIndex), lastLevelClassName));
    if (keepData) {
        IntStream.range(0, getRowCount()).forEach(rowIndex -> setCellValue(rowIndex, columnIndex, originalValues.get(rowIndex)));
    }
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ArrayList(java.util.ArrayList) GridCellValue(org.uberfire.ext.wires.core.grids.client.model.GridCellValue) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)

Example 20 with FactMapping

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

the class AbstractScesimGridModel method refreshErrorsRow.

protected void refreshErrorsRow(int rowIndex) {
    ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
    E scesimDataByIndex = abstractScesimModel.getDataByIndex(rowIndex);
    IntStream.range(0, getColumnCount()).forEach(columnIndex -> {
        ScenarioGridCell cell = (ScenarioGridCell) getCell(rowIndex, columnIndex);
        if (cell == null) {
            return;
        }
        final FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(columnIndex);
        Optional<FactMappingValue> factMappingValue = scesimDataByIndex.getFactMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier());
        if (factMappingValue.isPresent()) {
            cell.setErrorMode(FactMappingValueStatus.SUCCESS != factMappingValue.get().getStatus());
        } else {
            cell.setErrorMode(false);
        }
    });
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ScenarioGridCell(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue)

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