use of org.drools.scenariosimulation.backend.expression.ExpressionEvaluator 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;
}
Aggregations