Search in sources :

Example 21 with ScesimModelDescriptor

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

the class ScenarioCsvImportExportTest method generateHeader.

@Test
public void generateHeader() throws IOException {
    ScesimModelDescriptor simulationDescriptor = new ScesimModelDescriptor();
    FactMapping test1FactMapping = createFactMapping(simulationDescriptor, 1);
    FactMapping test2FactMapping = createFactMapping(simulationDescriptor, 2);
    scenarioCsvImportExport.generateHeader(Arrays.asList(test1FactMapping, test2FactMapping), printer);
    System.out.println("output.toString() = " + output.toString());
    String[] result = output.toString().split("\r\n");
    assertEquals(3, result.length);
    assertEquals("GIVEN,GIVEN", result[0]);
    assertEquals(instanceName + 1 + "," + instanceName + 2, result[1]);
    assertEquals(propertyName + 1 + "," + propertyName + 2, result[2]);
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Test(org.junit.Test)

Example 22 with ScesimModelDescriptor

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

the class ScenarioCsvImportExportTest method createDummySimulation.

private Simulation createDummySimulation(int numberOfColumn, int numberOfRow) {
    Simulation simulation = new Simulation();
    ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
    simulationDescriptor.addFactMapping(FactIdentifier.INDEX, ExpressionIdentifier.INDEX).setExpressionAlias("Index");
    simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION).setExpressionAlias("Description");
    for (int col = 0; col < numberOfColumn; col += 1) {
        createFactMapping(simulationDescriptor, col);
    }
    for (int row = 0; row < numberOfRow; row += 1) {
        Scenario scenario = simulation.addData();
        scenario.addMappingValue(FactIdentifier.INDEX, ExpressionIdentifier.INDEX, row);
        scenario.setDescription("My scenario " + row);
        for (int col = 2; col < numberOfColumn + 2; col += 1) {
            FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(col);
            scenario.addMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier(), "value_" + row + "_" + (col - 2));
        }
    }
    return simulation;
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Simulation(org.drools.scenariosimulation.api.model.Simulation) Scenario(org.drools.scenariosimulation.api.model.Scenario)

Example 23 with ScesimModelDescriptor

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

the class DMNSimulationSettingsCreationStrategyTest method addEmptyColumnIfNeeded.

@Test
public void addEmptyColumnIfNeeded() {
    Simulation simulation = new Simulation();
    ScenarioWithIndex scenarioWithIndex = new ScenarioWithIndex(1, simulation.addData());
    ExpressionIdentifier givenExpressionIdentifier = ExpressionIdentifier.create("given1", GIVEN);
    ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
    simulationDescriptor.addFactMapping(FactIdentifier.EMPTY, givenExpressionIdentifier);
    dmnSimulationCreationStrategy.addEmptyColumnsIfNeeded(simulation, scenarioWithIndex);
    assertEquals(2, simulationDescriptor.getFactMappings().size());
    assertTrue(simulationDescriptor.getFactMappings().stream().anyMatch(elem -> EXPECT.equals(elem.getExpressionIdentifier().getType())));
    simulation = new Simulation();
    scenarioWithIndex = new ScenarioWithIndex(1, simulation.addData());
    ExpressionIdentifier expectExpressionIdentifier = ExpressionIdentifier.create("expect1", EXPECT);
    simulationDescriptor = simulation.getScesimModelDescriptor();
    simulationDescriptor.addFactMapping(FactIdentifier.EMPTY, expectExpressionIdentifier);
    dmnSimulationCreationStrategy.addEmptyColumnsIfNeeded(simulation, scenarioWithIndex);
    assertEquals(2, simulationDescriptor.getFactMappings().size());
    assertTrue(simulationDescriptor.getFactMappings().stream().anyMatch(elem -> GIVEN.equals(elem.getExpressionIdentifier().getType())));
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Arrays(java.util.Arrays) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) GIVEN(org.drools.scenariosimulation.api.model.FactMappingType.GIVEN) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) DMNTypeService(org.drools.workbench.screens.scenariosimulation.service.DMNTypeService) Matchers.eq(org.mockito.Matchers.eq) Map(java.util.Map) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) Mockito.doReturn(org.mockito.Mockito.doReturn) AbstractDMNTest(org.drools.workbench.screens.scenariosimulation.backend.server.AbstractDMNTest) Settings(org.drools.scenariosimulation.api.model.Settings) Matchers.any(org.mockito.Matchers.any) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) Assert.assertFalse(org.junit.Assert.assertFalse) Simulation(org.drools.scenariosimulation.api.model.Simulation) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) EXPECT(org.drools.scenariosimulation.api.model.FactMappingType.EXPECT) SortedMap(java.util.SortedMap) Mockito.mock(org.mockito.Mockito.mock) DMNType(org.kie.dmn.api.core.DMNType) Mock(org.mockito.Mock) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) RunWith(org.junit.runner.RunWith) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) DECISION(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree.Type.DECISION) Path(org.uberfire.backend.vfs.Path) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) Before(org.junit.Before) OTHER(org.drools.scenariosimulation.api.model.FactMappingType.OTHER) Assert.assertNotNull(org.junit.Assert.assertNotNull) Background(org.drools.scenariosimulation.api.model.Background) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) TreeMap(java.util.TreeMap) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Simulation(org.drools.scenariosimulation.api.model.Simulation) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) AbstractDMNTest(org.drools.workbench.screens.scenariosimulation.backend.server.AbstractDMNTest) Test(org.junit.Test)

Example 24 with ScesimModelDescriptor

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

the class DMNSimulationSettingsCreationStrategyTest method findNewIndexOfGroup.

@Test
public void findNewIndexOfGroup() {
    ScesimModelDescriptor simulationDescriptorGiven = new ScesimModelDescriptor();
    ExpressionIdentifier givenExpressionIdentifier = ExpressionIdentifier.create("given1", GIVEN);
    simulationDescriptorGiven.addFactMapping(FactIdentifier.EMPTY, givenExpressionIdentifier);
    assertEquals(1, dmnSimulationCreationStrategy.findNewIndexOfGroup(simulationDescriptorGiven, GIVEN));
    assertEquals(1, dmnSimulationCreationStrategy.findNewIndexOfGroup(simulationDescriptorGiven, EXPECT));
    ScesimModelDescriptor simulationDescriptorExpect = new ScesimModelDescriptor();
    ExpressionIdentifier expectExpressionIdentifier = ExpressionIdentifier.create("expect1", EXPECT);
    simulationDescriptorExpect.addFactMapping(FactIdentifier.EMPTY, expectExpressionIdentifier);
    assertEquals(0, dmnSimulationCreationStrategy.findNewIndexOfGroup(simulationDescriptorExpect, GIVEN));
    assertEquals(1, dmnSimulationCreationStrategy.findNewIndexOfGroup(simulationDescriptorExpect, EXPECT));
    assertThatThrownBy(() -> dmnSimulationCreationStrategy.findNewIndexOfGroup(new ScesimModelDescriptor(), OTHER)).isInstanceOf(IllegalArgumentException.class).hasMessage("This method can be invoked only with GIVEN or EXPECT as FactMappingType");
}
Also used : ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) AbstractDMNTest(org.drools.workbench.screens.scenariosimulation.backend.server.AbstractDMNTest) Test(org.junit.Test)

Example 25 with ScesimModelDescriptor

use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor 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)

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