Search in sources :

Example 26 with Simulation

use of org.drools.scenariosimulation.api.model.Simulation in project drools-wb by kiegroup.

the class RULESimulationSettingsCreationStrategyTest method createSimulation.

@Test
public void createSimulation() throws Exception {
    final Simulation retrieved = ruleSimulationSettingsCreationStrategy.createSimulation(pathMock, value);
    assertNotNull(retrieved);
}
Also used : Simulation(org.drools.scenariosimulation.api.model.Simulation) Test(org.junit.Test)

Example 27 with Simulation

use of org.drools.scenariosimulation.api.model.Simulation in project drools-wb by kiegroup.

the class DMNSimulationSettingsCreationStrategy method createSimulation.

@Override
public Simulation createSimulation(Path context, String dmnFilePath) {
    final FactModelTuple factModelTuple = getFactModelTuple(context, dmnFilePath);
    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);
    ScenarioWithIndex scenarioWithIndex = createScesimDataWithIndex(toReturn, simulationDescriptor, ScenarioWithIndex::new);
    AtomicInteger id = new AtomicInteger(1);
    final Collection<FactModelTree> visibleFactTrees = factModelTuple.getVisibleFacts().values();
    final Map<String, FactModelTree> hiddenValues = factModelTuple.getHiddenFacts();
    visibleFactTrees.stream().sorted((a, b) -> {
        Type aType = a.getType();
        Type bType = b.getType();
        int inputFirstOrder = Type.INPUT.equals(aType) ? -1 : 1;
        return aType.equals(bType) ? 0 : inputFirstOrder;
    }).forEach(factModelTree -> {
        FactIdentifier factIdentifier = FactIdentifier.create(factModelTree.getFactName(), factModelTree.getFactName(), factModelTree.getImportPrefix());
        FactMappingExtractor factMappingExtractor = new FactMappingExtractor(factIdentifier, scenarioWithIndex.getIndex(), id, convert(factModelTree.getType()), simulationDescriptor, scenarioWithIndex.getScesimData());
        addFactMapping(factMappingExtractor, factModelTree, new ArrayList<>(), hiddenValues);
    });
    addEmptyColumnsIfNeeded(toReturn, scenarioWithIndex);
    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) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) GIVEN(org.drools.scenariosimulation.api.model.FactMappingType.GIVEN) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) Type(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree.Type) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScenarioSimulationSharedUtils(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils) DMNTypeService(org.drools.workbench.screens.scenariosimulation.service.DMNTypeService) Map(java.util.Map) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Path(org.uberfire.backend.vfs.Path) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Collection(java.util.Collection) Settings(org.drools.scenariosimulation.api.model.Settings) Set(java.util.Set) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) ApplicationScoped(javax.enterprise.context.ApplicationScoped) EXPECT(org.drools.scenariosimulation.api.model.FactMappingType.EXPECT) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) Type(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree.Type) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) Simulation(org.drools.scenariosimulation.api.model.Simulation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex)

Example 28 with Simulation

use of org.drools.scenariosimulation.api.model.Simulation in project drools-wb by kiegroup.

the class AbstractScenarioGridCommand method setCurrentContext.

@Override
protected CommandResult<ScenarioSimulationViolation> setCurrentContext(ScenarioSimulationContext context) {
    try {
        final Simulation simulationToRestore = restorableStatus.getSimulation();
        final Background backgroundToRestore = restorableStatus.getBackground();
        if (simulationToRestore == null) {
            throw new IllegalStateException("Simulation is null in restorable status");
        }
        if (backgroundToRestore == null) {
            throw new IllegalStateException("Background is null in restorable status");
        }
        final ScenarioSimulationContext.Status originalStatus = context.getStatus().cloneStatus();
        ScenarioSimulationModel.Type type = context.getScenarioSimulationModel().getSettings().getType();
        context.getSimulationGrid().getModel().clearSelections();
        context.getBackgroundGrid().getModel().clearSelections();
        context.getSimulationGrid().setContent(simulationToRestore, type);
        context.getScenarioSimulationEditorPresenter().getModel().setSimulation(simulationToRestore);
        context.getBackgroundGrid().setContent(backgroundToRestore, type);
        context.getScenarioSimulationEditorPresenter().getModel().setBackground(backgroundToRestore);
        context.getScenarioSimulationEditorPresenter().reloadTestTools(true);
        context.setStatus(restorableStatus);
        restorableStatus = originalStatus;
        return commonExecution(context);
    } catch (Exception e) {
        return new CommandResultImpl<>(CommandResult.Type.ERROR, Collections.singleton(new ScenarioSimulationViolation(e.getMessage())));
    }
}
Also used : ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) ScenarioSimulationViolation(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationViolation) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel)

Example 29 with Simulation

use of org.drools.scenariosimulation.api.model.Simulation in project drools-wb by kiegroup.

the class ScenarioSimulationEditorPresenterTest method cleanReadOnlyColumn.

@Test
public void cleanReadOnlyColumn() {
    Simulation simulation = new Simulation();
    ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
    FactMapping test1 = simulationDescriptor.addFactMapping(FactIdentifier.create("test1", String.class.getCanonicalName()), ExpressionIdentifier.create("", FactMappingType.GIVEN));
    FactMapping test2 = simulationDescriptor.addFactMapping(FactIdentifier.create("test2", String.class.getCanonicalName()), ExpressionIdentifier.create("", FactMappingType.GIVEN));
    test1.addExpressionElement("test", String.class.getCanonicalName());
    Scenario scenario = simulation.addData();
    scenario.addMappingValue(test1.getFactIdentifier(), test1.getExpressionIdentifier(), LOWER_CASE_VALUE);
    scenario.addMappingValue(test2.getFactIdentifier(), test2.getExpressionIdentifier(), LOWER_CASE_VALUE);
    presenterSpy.cleanReadOnlyColumn(simulation);
    assertNotNull(scenario.getFactMappingValue(test1.getFactIdentifier(), test1.getExpressionIdentifier()).get().getRawValue());
    assertNull(scenario.getFactMappingValue(test2.getFactIdentifier(), test2.getExpressionIdentifier()).get().getRawValue());
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) Matchers.anyString(org.mockito.Matchers.anyString) Scenario(org.drools.scenariosimulation.api.model.Scenario) Test(org.junit.Test)

Example 30 with Simulation

use of org.drools.scenariosimulation.api.model.Simulation in project drools-wb by kiegroup.

the class TestUtils method getSimulation.

public static Simulation getSimulation(int numberOfColumns, int numberOfRows) {
    Simulation simulation = new Simulation();
    ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
    simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
    // generate simulationDescriptor
    IntStream.range(0, numberOfColumns).forEach(columnIndex -> {
        simulationDescriptor.addFactMapping(FactIdentifier.create(getFactName(columnIndex), String.class.getCanonicalName()), ExpressionIdentifier.create(getColName(columnIndex), FactMappingType.EXPECT));
    });
    // generate scenarios
    IntStream.range(0, numberOfRows).forEach(rowIndex -> {
        final Scenario scenario = simulation.addData();
        scenario.setDescription(getRowName(rowIndex));
        IntStream.range(0, numberOfColumns).forEach(columnIndex -> {
            scenario.addMappingValue(FactIdentifier.create(getFactName(columnIndex), String.class.getCanonicalName()), ExpressionIdentifier.create(getColName(columnIndex), FactMappingType.EXPECT), getCellValue(columnIndex, rowIndex));
        });
    });
    return simulation;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Simulation(org.drools.scenariosimulation.api.model.Simulation) Scenario(org.drools.scenariosimulation.api.model.Scenario)

Aggregations

Simulation (org.drools.scenariosimulation.api.model.Simulation)30 Settings (org.drools.scenariosimulation.api.model.Settings)13 Test (org.junit.Test)13 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)12 Background (org.drools.scenariosimulation.api.model.Background)11 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)11 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)9 Path (org.uberfire.backend.vfs.Path)9 List (java.util.List)8 Before (org.junit.Before)7 Scenario (org.drools.scenariosimulation.api.model.Scenario)6 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)6 ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 AbstractScesimModel (org.drools.scenariosimulation.api.model.AbstractScesimModel)4 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)4 Inject (javax.inject.Inject)3 FactModelTuple (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple)3 Matchers.anyString (org.mockito.Matchers.anyString)3