use of org.drools.scenariosimulation.api.model.FactIdentifier 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.FactIdentifier in project drools-wb by kiegroup.
the class AbstractScesimGridModel method checkValidAndUniqueInstanceHeaderTitle.
/**
* Verify the given value is not already used as instance header name <b>between different groups</b>
* @param instanceHeaderCellValue
* @param columnIndex
* @throws IllegalArgumentException if the given <b>instanceHeaderCellValue</b> contains a <i>dot</i> <b>OR</b>
* it has already been used inside the <b>group (GIVEN/EXPECT)</b> of the given column
*/
protected void checkValidAndUniqueInstanceHeaderTitle(String instanceHeaderCellValue, int columnIndex) {
if (instanceHeaderCellValue.contains(".")) {
throw new IllegalArgumentException(ScenarioSimulationEditorConstants.INSTANCE.instanceTitleWithPeriodsError());
}
Range instanceLimits = getInstanceLimits(columnIndex);
ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
FactIdentifier factIdentifier = simulationDescriptor.getFactMappingByIndex(columnIndex).getFactIdentifier();
if (IntStream.range(0, getColumnCount()).filter(index -> index < instanceLimits.getMinRowIndex() || index > instanceLimits.getMaxRowIndex()).filter(index -> !Objects.equals(factIdentifier, simulationDescriptor.getFactMappingByIndex(index).getFactIdentifier())).mapToObj(index -> (ScenarioGridColumn) getColumns().get(index)).filter(elem -> elem.getInformationHeaderMetaData() != null).map(ScenarioGridColumn::getInformationHeaderMetaData).anyMatch(elem -> Objects.equals(elem.getTitle(), instanceHeaderCellValue))) {
throw new IllegalArgumentException(ScenarioSimulationEditorConstants.INSTANCE.instanceTitleAssignedError(instanceHeaderCellValue));
}
}
use of org.drools.scenariosimulation.api.model.FactIdentifier in project drools-wb by kiegroup.
the class AbstractScesimGridModel method checkUniquePropertyHeaderTitle.
/**
* Verify if the given value is not already used as property header name <b>inside the same instance</b>
* @param propertyHeaderCellValue
* @param columnIndex
* @throws IllegalArgumentException if the given <b>propertyHeaderCellValue</b> has already been used
* inside the <b>instance</b> of the given column
*/
protected void checkUniquePropertyHeaderTitle(String propertyHeaderCellValue, int columnIndex) {
ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
FactIdentifier factIdentifier = simulationDescriptor.getFactMappingByIndex(columnIndex).getFactIdentifier();
if (IntStream.range(0, getColumnCount()).filter(index -> index != columnIndex).filter(index -> Objects.equals(factIdentifier, simulationDescriptor.getFactMappingByIndex(index).getFactIdentifier())).mapToObj(index -> (ScenarioGridColumn) getColumns().get(index)).filter(elem -> elem.getPropertyHeaderMetaData() != null).map(ScenarioGridColumn::getPropertyHeaderMetaData).anyMatch(elem -> Objects.equals(elem.getTitle(), propertyHeaderCellValue))) {
throw new IllegalArgumentException(ScenarioSimulationEditorConstants.INSTANCE.propertyTitleAssignedError(propertyHeaderCellValue));
}
}
use of org.drools.scenariosimulation.api.model.FactIdentifier in project drools-wb by kiegroup.
the class AbstractScesimGridModel method updateFactMapping.
/**
* If the <code>FactIdentifier</code> of the given <code>FactMapping</code> equals the one at <b>index</b>, update the <code>FactMapping.FactAlias</code> at <b>index</b>
* position with the provided <b>value</b>
* @param simulationDescriptor
* @param factMappingReference
* @param index
* @param value
*/
protected void updateFactMapping(ScesimModelDescriptor simulationDescriptor, FactMapping factMappingReference, int index, String value, ScenarioHeaderMetaData.MetadataType metadataType) {
final FactIdentifier factIdentifierReference = factMappingReference.getFactIdentifier();
FactMapping factMappingToCheck = simulationDescriptor.getFactMappingByIndex(index);
final FactIdentifier factIdentifierToCheck = factMappingToCheck.getFactIdentifier();
boolean toUpdate = (Objects.equals(FactIdentifier.EMPTY, factIdentifierReference) && (Objects.equals(factIdentifierToCheck, factIdentifierReference) && Objects.equals(factMappingReference.getFactAlias(), factMappingToCheck.getFactAlias()))) || (Objects.equals(factIdentifierToCheck, factIdentifierReference));
if (toUpdate) {
switch(metadataType) {
case INSTANCE:
((ScenarioGridColumn) columns.get(index)).getInformationHeaderMetaData().setTitle(value);
factMappingToCheck.setFactAlias(value);
break;
case PROPERTY:
if (Objects.equals(factMappingToCheck.getFullExpression(), factMappingReference.getFullExpression())) {
((ScenarioGridColumn) columns.get(index)).getPropertyHeaderMetaData().setTitle(value);
factMappingToCheck.setExpressionAlias(value);
}
break;
default:
break;
}
}
}
use of org.drools.scenariosimulation.api.model.FactIdentifier in project drools-wb by kiegroup.
the class AbstractScesimGridModel method checkAlreadyAssignedProperty.
/**
* Check if property mapped to the column at given index is already assigned to
* another column of the same <b>instance</b>
* @param columnIndex
* @param propertyNameElements
* @throws IllegalStateException if the given <code>propertyNameElements</code> are already mapped to a column of the same <b>instance</b>
*/
public void checkAlreadyAssignedProperty(int columnIndex, List<String> propertyNameElements) {
Range instanceLimits = getInstanceLimits(columnIndex);
ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
FactIdentifier factIdentifier = simulationDescriptor.getFactMappingByIndex(columnIndex).getFactIdentifier();
// We have to keep the original List unmodified
List<String> propertyNameElementsClone = new ArrayList<>();
propertyNameElementsClone.add(factIdentifier.getClassNameWithoutPackage());
propertyNameElementsClone.addAll(propertyNameElements.subList(1, propertyNameElements.size()));
if (IntStream.range(instanceLimits.getMinRowIndex(), instanceLimits.getMaxRowIndex() + 1).filter(index -> index != columnIndex).mapToObj(simulationDescriptor::getFactMappingByIndex).anyMatch(factMapping -> {
List<String> factMappingPropertyNameElements = factMapping.getExpressionElements().stream().map(ExpressionElement::getStep).collect(Collectors.toList());
return Objects.equals(factMappingPropertyNameElements, propertyNameElementsClone);
})) {
throw new IllegalStateException(String.join(".", propertyNameElements) + " has already been used in the current instance.");
}
}
Aggregations