use of org.drools.scenariosimulation.api.model.FactMappingValue in project drools by kiegroup.
the class AbstractRunnerHelper method getParamsForBean.
protected Map<List<String>, Object> getParamsForBean(ScesimModelDescriptor scesimModelDescriptor, FactIdentifier factIdentifier, List<FactMappingValue> factMappingValues, ExpressionEvaluatorFactory expressionEvaluatorFactory) {
Map<List<String>, Object> paramsForBean = new HashMap<>();
boolean hasError = false;
for (FactMappingValue factMappingValue : factMappingValues) {
ExpressionIdentifier expressionIdentifier = factMappingValue.getExpressionIdentifier();
FactMapping factMapping = scesimModelDescriptor.getFactMapping(factIdentifier, expressionIdentifier).orElseThrow(() -> new IllegalStateException("Wrong expression, this should not happen"));
List<String> pathToField = factMapping.getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(toList());
ExpressionEvaluator expressionEvaluator = expressionEvaluatorFactory.getOrCreate(factMappingValue);
try {
Object value = expressionEvaluator.evaluateLiteralExpression((String) factMappingValue.getRawValue(), factMapping.getClassName(), factMapping.getGenericTypes());
paramsForBean.put(pathToField, value);
} catch (RuntimeException e) {
factMappingValue.setExceptionMessage(e.getMessage());
hasError = true;
}
}
if (hasError) {
throw new ScenarioException("Error in one or more input values");
}
return paramsForBean;
}
use of org.drools.scenariosimulation.api.model.FactMappingValue in project drools by kiegroup.
the class AbstractRunnerHelper method groupByFactIdentifierAndFilter.
protected Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifierAndFilter(List<FactMappingValue> factMappingValues, FactMappingType type) {
Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifier = new HashMap<>();
for (FactMappingValue factMappingValue : factMappingValues) {
FactIdentifier factIdentifier = factMappingValue.getFactIdentifier();
if (isFactMappingValueToSkip(factMappingValue)) {
continue;
}
ExpressionIdentifier expressionIdentifier = factMappingValue.getExpressionIdentifier();
if (expressionIdentifier == null) {
throw new IllegalArgumentException("ExpressionIdentifier malformed");
}
if (!Objects.equals(expressionIdentifier.getType(), type)) {
continue;
}
groupByFactIdentifier.computeIfAbsent(factIdentifier, key -> new ArrayList<>()).add(factMappingValue);
}
return groupByFactIdentifier;
}
use of org.drools.scenariosimulation.api.model.FactMappingValue in project drools by kiegroup.
the class AbstractRunnerHelper method extractExpectedValues.
protected List<ScenarioExpect> extractExpectedValues(List<FactMappingValue> factMappingValues) {
List<ScenarioExpect> scenarioExpect = new ArrayList<>();
Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifier = groupByFactIdentifierAndFilter(factMappingValues, FactMappingType.EXPECT);
Set<FactIdentifier> inputFacts = factMappingValues.stream().filter(elem -> FactMappingType.GIVEN.equals(elem.getExpressionIdentifier().getType())).filter(elem -> !isFactMappingValueToSkip(elem)).map(FactMappingValue::getFactIdentifier).collect(Collectors.toSet());
for (Map.Entry<FactIdentifier, List<FactMappingValue>> entry : groupByFactIdentifier.entrySet()) {
FactIdentifier factIdentifier = entry.getKey();
scenarioExpect.add(new ScenarioExpect(factIdentifier, entry.getValue(), !inputFacts.contains(factIdentifier)));
}
return scenarioExpect;
}
use of org.drools.scenariosimulation.api.model.FactMappingValue in project drools-wb by kiegroup.
the class ScenarioSimulationMainGridPanelMouseMoveHandler method manageBodyCoordinates.
@Override
protected boolean manageBodyCoordinates(Integer uiRowIndex, Integer uiColumnIndex) {
/* In this case, the mouse is out ot the GridLayer, then return false, without perform any action */
if (uiColumnIndex == -1 || uiRowIndex == -1) {
return false;
}
/* If the mouse position is the same of the previous one and the popover is already open, it does nothing.
* It returns true because the click happened on an column of a grid row */
if (uiRowIndex.equals(currentlyShownBodyRowIndex) && uiColumnIndex.equals(currentlyShownBodyColumnIndex) && errorReportPopupPresenter.isShown()) {
return true;
}
/* It updates the coordinates of the current shown cell */
currentlyShownBodyRowIndex = uiRowIndex;
currentlyShownBodyColumnIndex = uiColumnIndex;
final Optional<AbstractScesimModel<? extends AbstractScesimData>> optionalAbstractScesimModel = scenarioGrid.getModel().getAbstractScesimModel();
final AbstractScesimModel<? extends AbstractScesimData> scesimModel = optionalAbstractScesimModel.orElseThrow(IllegalStateException::new);
final AbstractScesimData scenarioByIndex = scesimModel.getDataByIndex(uiRowIndex);
final FactMapping factMapping = scesimModel.getScesimModelDescriptor().getFactMappingByIndex(uiColumnIndex);
final Optional<FactMappingValue> factMappingValueOptional = scenarioByIndex.getFactMappingValue(factMapping);
factMappingValueOptional.ifPresent(factMappingValue -> manageFactMappingValue(factMappingValue, uiRowIndex, uiColumnIndex));
return true;
}
Aggregations