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;
});
});
}
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;
}
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());
}
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)));
}
}
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);
}
});
}
Aggregations