Search in sources :

Example 21 with FactMappingValue

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;
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) HashMap(java.util.HashMap) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) ExpressionEvaluator(org.drools.scenariosimulation.backend.expression.ExpressionEvaluator) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Example 22 with FactMappingValue

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;
}
Also used : FactMappingValueStatus(org.drools.scenariosimulation.api.model.FactMappingValueStatus) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) LoggerFactory(org.slf4j.LoggerFactory) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) HashMap(java.util.HashMap) ValueWrapper.errorWithValidValue(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.errorWithValidValue) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) Scenario(org.drools.scenariosimulation.api.model.Scenario) ValueWrapper(org.drools.scenariosimulation.backend.runner.model.ValueWrapper) Map(java.util.Map) ValueWrapper.errorWithMessage(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.errorWithMessage) ScenarioResult(org.drools.scenariosimulation.backend.runner.model.ScenarioResult) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) ScenarioSimulationServerMessages(org.drools.scenariosimulation.backend.util.ScenarioSimulationServerMessages) Logger(org.slf4j.Logger) BackgroundData(org.drools.scenariosimulation.api.model.BackgroundData) Settings(org.drools.scenariosimulation.api.model.Settings) ScenarioExpect(org.drools.scenariosimulation.backend.runner.model.ScenarioExpect) ScenarioRunnerData(org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData) Background(org.drools.scenariosimulation.api.model.Background) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) Set(java.util.Set) KieContainer(org.kie.api.runtime.KieContainer) ValueWrapper.of(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.of) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) ValueWrapper.errorWithCollectionPathToValue(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.errorWithCollectionPathToValue) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ExpressionEvaluatorFactory(org.drools.scenariosimulation.backend.expression.ExpressionEvaluatorFactory) List(java.util.List) ExpressionEvaluator(org.drools.scenariosimulation.backend.expression.ExpressionEvaluator) Collectors.toList(java.util.stream.Collectors.toList) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ExpressionEvaluatorResult(org.drools.scenariosimulation.backend.expression.ExpressionEvaluatorResult) ScenarioSimulationSharedUtils.isCollectionOrMap(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils.isCollectionOrMap) InstanceGiven(org.drools.scenariosimulation.backend.runner.model.InstanceGiven) HashMap(java.util.HashMap) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier)

Example 23 with FactMappingValue

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;
}
Also used : ScenarioExpect(org.drools.scenariosimulation.backend.runner.model.ScenarioExpect) FactMappingValueStatus(org.drools.scenariosimulation.api.model.FactMappingValueStatus) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) LoggerFactory(org.slf4j.LoggerFactory) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) HashMap(java.util.HashMap) ValueWrapper.errorWithValidValue(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.errorWithValidValue) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) Scenario(org.drools.scenariosimulation.api.model.Scenario) ValueWrapper(org.drools.scenariosimulation.backend.runner.model.ValueWrapper) Map(java.util.Map) ValueWrapper.errorWithMessage(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.errorWithMessage) ScenarioResult(org.drools.scenariosimulation.backend.runner.model.ScenarioResult) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) ScenarioSimulationServerMessages(org.drools.scenariosimulation.backend.util.ScenarioSimulationServerMessages) Logger(org.slf4j.Logger) BackgroundData(org.drools.scenariosimulation.api.model.BackgroundData) Settings(org.drools.scenariosimulation.api.model.Settings) ScenarioExpect(org.drools.scenariosimulation.backend.runner.model.ScenarioExpect) ScenarioRunnerData(org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData) Background(org.drools.scenariosimulation.api.model.Background) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) Set(java.util.Set) KieContainer(org.kie.api.runtime.KieContainer) ValueWrapper.of(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.of) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) ValueWrapper.errorWithCollectionPathToValue(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.errorWithCollectionPathToValue) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ExpressionEvaluatorFactory(org.drools.scenariosimulation.backend.expression.ExpressionEvaluatorFactory) List(java.util.List) ExpressionEvaluator(org.drools.scenariosimulation.backend.expression.ExpressionEvaluator) Collectors.toList(java.util.stream.Collectors.toList) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ExpressionEvaluatorResult(org.drools.scenariosimulation.backend.expression.ExpressionEvaluatorResult) ScenarioSimulationSharedUtils.isCollectionOrMap(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils.isCollectionOrMap) InstanceGiven(org.drools.scenariosimulation.backend.runner.model.InstanceGiven) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) HashMap(java.util.HashMap) Map(java.util.Map) ScenarioSimulationSharedUtils.isCollectionOrMap(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils.isCollectionOrMap)

Example 24 with FactMappingValue

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;
}
Also used : FactMapping(org.drools.scenariosimulation.api.model.FactMapping) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel)

Aggregations

FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)24 Test (org.junit.Test)15 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)9 ArrayList (java.util.ArrayList)7 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)7 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)7 ExpressionEvaluator (org.drools.scenariosimulation.backend.expression.ExpressionEvaluator)7 ScenarioResult (org.drools.scenariosimulation.backend.runner.model.ScenarioResult)7 ScenarioExpect (org.drools.scenariosimulation.backend.runner.model.ScenarioExpect)6 ValueWrapper (org.drools.scenariosimulation.backend.runner.model.ValueWrapper)6 AbstractRuleCoverageTest (org.drools.scenariosimulation.backend.fluent.AbstractRuleCoverageTest)5 InstanceGiven (org.drools.scenariosimulation.backend.runner.model.InstanceGiven)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 Background (org.drools.scenariosimulation.api.model.Background)4 ScenarioRunnerData (org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData)4 Collectors.toList (java.util.stream.Collectors.toList)3 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)3 ExpressionEvaluatorResult (org.drools.scenariosimulation.backend.expression.ExpressionEvaluatorResult)3