Search in sources :

Example 1 with RuleScenarioExecutableBuilder

use of org.drools.scenariosimulation.backend.fluent.RuleScenarioExecutableBuilder in project drools by kiegroup.

the class RuleScenarioRunnerHelper method executeScenario.

@Override
protected Map<String, Object> executeScenario(KieContainer kieContainer, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluatorFactory expressionEvaluatorFactory, ScesimModelDescriptor scesimModelDescriptor, Settings settings) {
    if (!Type.RULE.equals(settings.getType())) {
        throw new ScenarioException("Impossible to run a not-RULE simulation with RULE runner");
    }
    RuleScenarioExecutableBuilder ruleScenarioExecutableBuilder = createBuilderWrapper(kieContainer, settings);
    if (settings.getRuleFlowGroup() != null) {
        ruleScenarioExecutableBuilder.setActiveRuleFlowGroup(settings.getRuleFlowGroup());
    }
    loadInputData(scenarioRunnerData.getBackgrounds(), ruleScenarioExecutableBuilder);
    loadInputData(scenarioRunnerData.getGivens(), ruleScenarioExecutableBuilder);
    // all new facts should be verified internally to the working memory
    scenarioRunnerData.getExpects().stream().filter(ScenarioExpect::isNewFact).flatMap(output -> output.getExpectedResult().stream().map(ScenarioResult::new)).forEach(scenarioResult -> {
        Class<?> clazz = ScenarioBeanUtil.loadClass(scenarioResult.getFactIdentifier().getClassName(), kieContainer.getClassLoader());
        ExpressionEvaluator expressionEvaluator = expressionEvaluatorFactory.getOrCreate(scenarioResult.getFactMappingValue());
        scenarioRunnerData.addResult(scenarioResult);
        ruleScenarioExecutableBuilder.addInternalCondition(clazz, createExtractorFunction(expressionEvaluator, scenarioResult.getFactMappingValue(), scesimModelDescriptor), scenarioResult);
    });
    return ruleScenarioExecutableBuilder.run();
}
Also used : ScenarioExpect(org.drools.scenariosimulation.backend.runner.model.ScenarioExpect) RuleScenarioExecutableBuilder(org.drools.scenariosimulation.backend.fluent.RuleScenarioExecutableBuilder) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ValueWrapper(org.drools.scenariosimulation.backend.runner.model.ValueWrapper) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScenarioBeanUtil.fillBean(org.drools.scenariosimulation.backend.util.ScenarioBeanUtil.fillBean) Map(java.util.Map) COVERAGE_LISTENER(org.drools.scenariosimulation.backend.fluent.RuleScenarioExecutableBuilder.COVERAGE_LISTENER) ScenarioResult(org.drools.scenariosimulation.backend.runner.model.ScenarioResult) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) RuleScenarioExecutableBuilder.createBuilder(org.drools.scenariosimulation.backend.fluent.RuleScenarioExecutableBuilder.createBuilder) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) ScenarioBeanWrapper(org.drools.scenariosimulation.backend.util.ScenarioBeanWrapper) CoverageAgendaListener(org.drools.scenariosimulation.backend.fluent.CoverageAgendaListener) Settings(org.drools.scenariosimulation.api.model.Settings) ScenarioExpect(org.drools.scenariosimulation.backend.runner.model.ScenarioExpect) ScenarioRunnerData(org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) ScenarioBeanUtil(org.drools.scenariosimulation.backend.util.ScenarioBeanUtil) Set(java.util.Set) ConstantsHolder(org.drools.scenariosimulation.api.utils.ConstantsHolder) KieContainer(org.kie.api.runtime.KieContainer) Objects(java.util.Objects) Type(org.drools.scenariosimulation.api.model.ScenarioSimulationModel.Type) 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) RULES_AVAILABLE(org.drools.scenariosimulation.backend.fluent.RuleScenarioExecutableBuilder.RULES_AVAILABLE) InstanceGiven(org.drools.scenariosimulation.backend.runner.model.InstanceGiven) ScenarioResult(org.drools.scenariosimulation.backend.runner.model.ScenarioResult) ExpressionEvaluator(org.drools.scenariosimulation.backend.expression.ExpressionEvaluator) RuleScenarioExecutableBuilder(org.drools.scenariosimulation.backend.fluent.RuleScenarioExecutableBuilder)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Function (java.util.function.Function)1 Collectors.toList (java.util.stream.Collectors.toList)1 ExpressionElement (org.drools.scenariosimulation.api.model.ExpressionElement)1 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)1 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)1 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)1 FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)1 Type (org.drools.scenariosimulation.api.model.ScenarioSimulationModel.Type)1 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)1 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)1 Settings (org.drools.scenariosimulation.api.model.Settings)1 ConstantsHolder (org.drools.scenariosimulation.api.utils.ConstantsHolder)1 ExpressionEvaluator (org.drools.scenariosimulation.backend.expression.ExpressionEvaluator)1 ExpressionEvaluatorFactory (org.drools.scenariosimulation.backend.expression.ExpressionEvaluatorFactory)1