Search in sources :

Example 16 with ScesimModelDescriptor

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;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) Map(java.util.Map) AbstractScesimGridModel(org.drools.workbench.screens.scenariosimulation.client.models.AbstractScesimGridModel) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) TestToolsPresenterData(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsPresenterData) Set(java.util.Set) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) Collectors(java.util.stream.Collectors) TestToolsView(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsView) Objects(java.util.Objects) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) List(java.util.List) TreeMap(java.util.TreeMap) Collections(java.util.Collections) SortedMap(java.util.SortedMap) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)

Example 17 with ScesimModelDescriptor

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;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) Map(java.util.Map) AbstractScesimGridModel(org.drools.workbench.screens.scenariosimulation.client.models.AbstractScesimGridModel) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) TestToolsPresenterData(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsPresenterData) Set(java.util.Set) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) Collectors(java.util.stream.Collectors) TestToolsView(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsView) Objects(java.util.Objects) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) List(java.util.List) TreeMap(java.util.TreeMap) Collections(java.util.Collections) SortedMap(java.util.SortedMap) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) TreeMap(java.util.TreeMap) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel)

Example 18 with ScesimModelDescriptor

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;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) Scenario(org.drools.scenariosimulation.api.model.Scenario)

Example 19 with ScesimModelDescriptor

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);
    }
}
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) InstanceGiven(org.drools.scenariosimulation.backend.runner.model.InstanceGiven) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier)

Example 20 with ScesimModelDescriptor

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();
}
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

ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)29 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)18 ArrayList (java.util.ArrayList)11 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)11 List (java.util.List)9 Map (java.util.Map)9 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)9 Set (java.util.Set)8 Simulation (org.drools.scenariosimulation.api.model.Simulation)8 Objects (java.util.Objects)7 ExpressionElement (org.drools.scenariosimulation.api.model.ExpressionElement)7 FactMappingType (org.drools.scenariosimulation.api.model.FactMappingType)7 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)7 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)7 Collections (java.util.Collections)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)6 FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)6 Scenario (org.drools.scenariosimulation.api.model.Scenario)6 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)5