public FactMapping(String factAlias, FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { this.factAlias = factAlias; this.expressionIdentifier = expressionIdentifier; this.className = factIdentifier.getClassName(); this.factIdentifier = factIdentifier; }
public FactMapping(String factAlias, FactIdentifier factIdentifier, ExpressionIdentifier expressionIdentifier) { this.factAlias = factAlias; this.expressionIdentifier = expressionIdentifier; this.className = factIdentifier.getClassName(); this.factIdentifier = factIdentifier; }
protected SortedMap<String, FactModelTree> getInstanceMap(SortedMap<String, FactModelTree> sourceMap) { SortedMap<String, FactModelTree> toReturn = new TreeMap<>(); // map instance name to base class if (model != null) { final SimulationDescriptor simulationDescriptor = model.getSimulation().getSimulationDescriptor(); simulationDescriptor.getUnmodifiableFactMappings() .stream() .filter(factMapping -> !Objects.equals(FactMappingType.OTHER, factMapping.getExpressionIdentifier().getType())) .forEach(factMapping -> { String dataObjectName = factMapping.getFactIdentifier().getClassName(); if (dataObjectName.contains(".")) { dataObjectName = dataObjectName.substring(dataObjectName.lastIndexOf(".") + 1); } final String instanceName = factMapping.getFactAlias(); if (!instanceName.equals(dataObjectName)) { final FactModelTree factModelTree = sourceMap.get(dataObjectName); if (factModelTree != null) { toReturn.put(instanceName, factModelTree); } } }); } return toReturn; }
public List<ScenarioGiven> extractGivenValues(SimulationDescriptor simulationDescriptor, List<FactMappingValue> factMappingValues, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator) { List<ScenarioGiven> scenarioGiven = new ArrayList<>(); Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifier = groupByFactIdentifierAndFilter(factMappingValues, FactMappingType.GIVEN); for (Map.Entry<FactIdentifier, List<FactMappingValue>> entry : groupByFactIdentifier.entrySet()) { FactIdentifier factIdentifier = entry.getKey(); // for each fact, create a map of path to fields and values to set Map<List<String>, Object> paramsForBean = getParamsForBean(simulationDescriptor, factIdentifier, entry.getValue(), classLoader, expressionEvaluator); Object bean = getDirectMapping(paramsForBean) .orElseGet(() -> createObject(factIdentifier.getClassName(), paramsForBean, classLoader)); scenarioGiven.add(new ScenarioGiven(factIdentifier, bean)); } return scenarioGiven; }
@Override public RequestContext executeScenario(KieContainer kieContainer, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluator expressionEvaluator, SimulationDescriptor simulationDescriptor) { if (!ScenarioSimulationModel.Type.RULE.equals(simulationDescriptor.getType())) { throw new ScenarioException("Impossible to run a not-RULE simulation with RULE runner"); } RuleScenarioExecutableBuilder ruleScenarioExecutableBuilder = createBuilder(kieContainer); scenarioRunnerData.getGivens().stream().map(ScenarioGiven::getValue).forEach(ruleScenarioExecutableBuilder::insert); // all new facts should be verified internally to the working memory scenarioRunnerData.getExpects().stream() .filter(ScenarioExpect::isNewFact) .flatMap(output -> output.getExpectedResult().stream() .map(factMappingValue -> new ScenarioResult(output.getFactIdentifier(), factMappingValue))) .forEach(scenarioResult -> { Class<?> clazz = ScenarioBeanUtil.loadClass(scenarioResult.getFactIdentifier().getClassName(), kieContainer.getClassLoader()); scenarioRunnerData.addResult(scenarioResult); ruleScenarioExecutableBuilder.addInternalCondition(clazz, createExtractorFunction(expressionEvaluator, scenarioResult.getFactMappingValue(), simulationDescriptor), scenarioResult); }); return ruleScenarioExecutableBuilder.run(); }