use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor 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);
}
});
}
use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor in project drools-wb by kiegroup.
the class AbstractScesimGridModel method checkSamePropertyHeader.
/**
* Check if given <b>headerName</b> is the same as the <b>element steps</b> mapped to the given column
* @param columnIndex
* @param propertyNameElements
* @throws IllegalStateException if the given <b>propertyNameElements</b> (corrected for the class name) represents the <b>element steps</b> of the given column
*/
public void checkSamePropertyHeader(int columnIndex, List<String> propertyNameElements) {
ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
final FactMapping factMapping = simulationDescriptor.getFactMappingByIndex(columnIndex);
List<String> columnPropertyName = factMapping.getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(Collectors.toList());
if (!Objects.equals(columnPropertyName, propertyNameElements)) {
throw new IllegalStateException(String.join(".", propertyNameElements) + " is not the same property of the current column.");
}
}
use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor 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.ScesimModelDescriptor 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.ScesimModelDescriptor 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