use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor in project drools-wb by kiegroup.
the class AbstractDataManagementStrategy method getPropertiesToHide.
/**
* This method returns a <code>List</code> with the properties of a given <b>Type</b> (Fact, class, other dmn defined) instance,
* to be hidden from the right panel for the selected column.
* <p>
* If click happen on an already assigned property, <b>all</b> all the properties of given type should be shown;
* if, instead, click is on an unassigned property, the already assigned properties must be hidden.
* (e.g. inside GIVEN there is an "Author" group; if clicking on "books" property header, this method returns an <b>empty</b> <code>List</code>;
* if click is on an unassigned property column, this method returns a <code>List</code>.
* with all the <b>already assigned</b> Author's properties)
* @param selectedColumn
* @param abstractScesimGridModel
* @return
*/
protected <T extends AbstractScesimModel<E>, E extends AbstractScesimData> List<List<String>> getPropertiesToHide(ScenarioGridColumn selectedColumn, AbstractScesimGridModel<T, E> abstractScesimGridModel) {
List<List<String>> toReturn = new ArrayList<>();
if (!selectedColumn.isPropertyAssigned()) {
abstractScesimGridModel.getAbstractScesimModel().ifPresent(simulation -> {
final ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
List<ScenarioGridColumn> instanceColumns = abstractScesimGridModel.getInstanceScenarioGridColumns(selectedColumn);
toReturn.addAll(instanceColumns.stream().filter(ScenarioGridColumn::isPropertyAssigned).map(instanceColumn -> abstractScesimGridModel.getColumns().indexOf(instanceColumn)).map(columnIndex -> {
List<String> propertyNameElements = simulationDescriptor.getFactMappingByIndex(columnIndex).getExpressionElementsWithoutClass().stream().map(ExpressionElement::getStep).collect(Collectors.toList());
if (propertyNameElements.isEmpty()) {
propertyNameElements.add(VALUE);
}
return Collections.unmodifiableList(propertyNameElements);
}).collect(Collectors.toList()));
});
}
return toReturn;
}
use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor in project drools-wb by kiegroup.
the class AbstractDataManagementStrategy method getInstanceMap.
/**
* Returns a <code>Map</code> of the <b>instances</b> as defined in the grid and the mapped <code>FactModelTree</code>
* @param sourceMap
* @return
*/
public SortedMap<String, FactModelTree> getInstanceMap(SortedMap<String, FactModelTree> sourceMap) {
SortedMap<String, FactModelTree> toReturn = new TreeMap<>();
// map instance name to base class
if (model != null) {
final ScesimModelDescriptor simulationDescriptor = model.getSimulation().getScesimModelDescriptor();
final ScenarioSimulationModel.Type type = model.getSettings().getType();
simulationDescriptor.getUnmodifiableFactMappings().stream().filter(factMapping -> !Objects.equals(FactMappingType.OTHER, factMapping.getExpressionIdentifier().getType())).forEach(factMapping -> {
String dataObjectName = ScenarioSimulationModel.Type.DMN.equals(type) ? factMapping.getFactIdentifier().getClassName() : factMapping.getFactIdentifier().getClassNameWithoutPackage().replace("$", ".");
final String instanceName = factMapping.getFactAlias();
if (!instanceName.equals(dataObjectName)) {
final FactModelTree factModelTree = sourceMap.get(dataObjectName);
if (factModelTree != null) {
toReturn.put(instanceName, factModelTree);
}
}
});
}
return toReturn;
}
use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor in project drools-wb by kiegroup.
the class AbstractScenarioSimulationEditorTest method getSimulation.
protected Simulation getSimulation() {
Simulation toReturn = new Simulation();
ScesimModelDescriptor simulationDescriptor = toReturn.getScesimModelDescriptor();
simulationDescriptor.addFactMapping(FactIdentifier.INDEX.getName(), FactIdentifier.INDEX, ExpressionIdentifier.INDEX);
simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION.getName(), FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
Scenario scenario = toReturn.addData();
int row = toReturn.getUnmodifiableData().indexOf(scenario);
scenario.setDescription(null);
// Add GIVEN Fact
int id = 1;
ExpressionIdentifier givenExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.GIVEN);
final FactMapping givenFactMapping = simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, givenExpression);
givenFactMapping.setExpressionAlias(FactMapping.getPropertyPlaceHolder(id));
scenario.addMappingValue(FactIdentifier.EMPTY, givenExpression, null);
// Add EXPECT Fact
id = 2;
ExpressionIdentifier expectedExpression = ExpressionIdentifier.create(row + "|" + id, FactMappingType.EXPECT);
final FactMapping expectedFactMapping = simulationDescriptor.addFactMapping(FactMapping.getInstancePlaceHolder(id), FactIdentifier.EMPTY, expectedExpression);
expectedFactMapping.setExpressionAlias(FactMapping.getPropertyPlaceHolder(id));
scenario.addMappingValue(FactIdentifier.EMPTY, expectedExpression, null);
return toReturn;
}
use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor in project drools by kiegroup.
the class RuleScenarioRunnerHelper method verifyConditions.
@Override
protected void verifyConditions(ScesimModelDescriptor scesimModelDescriptor, ScenarioRunnerData scenarioRunnerData, ExpressionEvaluatorFactory expressionEvaluatorFactory, Map<String, Object> requestContext) {
for (InstanceGiven input : scenarioRunnerData.getGivens()) {
FactIdentifier factIdentifier = input.getFactIdentifier();
List<ScenarioExpect> assertionOnFact = scenarioRunnerData.getExpects().stream().filter(elem -> !elem.isNewFact()).filter(elem -> Objects.equals(elem.getFactIdentifier(), factIdentifier)).collect(toList());
// check if this fact has something to check
if (assertionOnFact.isEmpty()) {
continue;
}
getScenarioResultsFromGivenFacts(scesimModelDescriptor, assertionOnFact, input, expressionEvaluatorFactory).forEach(scenarioRunnerData::addResult);
}
}
use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor 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();
}
Aggregations