Search in sources :

Example 11 with ExpressionIdentifier

use of org.drools.scenariosimulation.api.model.ExpressionIdentifier in project drools by kiegroup.

the class AbstractRunnerHelper method groupByFactIdentifierAndFilter.

protected Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifierAndFilter(List<FactMappingValue> factMappingValues, FactMappingType type) {
    Map<FactIdentifier, List<FactMappingValue>> groupByFactIdentifier = new HashMap<>();
    for (FactMappingValue factMappingValue : factMappingValues) {
        FactIdentifier factIdentifier = factMappingValue.getFactIdentifier();
        if (isFactMappingValueToSkip(factMappingValue)) {
            continue;
        }
        ExpressionIdentifier expressionIdentifier = factMappingValue.getExpressionIdentifier();
        if (expressionIdentifier == null) {
            throw new IllegalArgumentException("ExpressionIdentifier malformed");
        }
        if (!Objects.equals(expressionIdentifier.getType(), type)) {
            continue;
        }
        groupByFactIdentifier.computeIfAbsent(factIdentifier, key -> new ArrayList<>()).add(factMappingValue);
    }
    return groupByFactIdentifier;
}
Also used : FactMappingValueStatus(org.drools.scenariosimulation.api.model.FactMappingValueStatus) ScenarioResultMetadata(org.drools.scenariosimulation.backend.runner.model.ScenarioResultMetadata) LoggerFactory(org.slf4j.LoggerFactory) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier) HashMap(java.util.HashMap) ValueWrapper.errorWithValidValue(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.errorWithValidValue) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) Scenario(org.drools.scenariosimulation.api.model.Scenario) ValueWrapper(org.drools.scenariosimulation.backend.runner.model.ValueWrapper) Map(java.util.Map) ValueWrapper.errorWithMessage(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.errorWithMessage) ScenarioResult(org.drools.scenariosimulation.backend.runner.model.ScenarioResult) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) ScenarioSimulationServerMessages(org.drools.scenariosimulation.backend.util.ScenarioSimulationServerMessages) Logger(org.slf4j.Logger) BackgroundData(org.drools.scenariosimulation.api.model.BackgroundData) Settings(org.drools.scenariosimulation.api.model.Settings) ScenarioExpect(org.drools.scenariosimulation.backend.runner.model.ScenarioExpect) ScenarioRunnerData(org.drools.scenariosimulation.backend.runner.model.ScenarioRunnerData) Background(org.drools.scenariosimulation.api.model.Background) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) Set(java.util.Set) KieContainer(org.kie.api.runtime.KieContainer) ValueWrapper.of(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.of) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) ValueWrapper.errorWithCollectionPathToValue(org.drools.scenariosimulation.backend.runner.model.ValueWrapper.errorWithCollectionPathToValue) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) 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) ExpressionEvaluatorResult(org.drools.scenariosimulation.backend.expression.ExpressionEvaluatorResult) ScenarioSimulationSharedUtils.isCollectionOrMap(org.drools.scenariosimulation.api.utils.ScenarioSimulationSharedUtils.isCollectionOrMap) InstanceGiven(org.drools.scenariosimulation.backend.runner.model.InstanceGiven) HashMap(java.util.HashMap) FactMappingValue(org.drools.scenariosimulation.api.model.FactMappingValue) ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) FactIdentifier(org.drools.scenariosimulation.api.model.FactIdentifier)

Example 12 with ExpressionIdentifier

use of org.drools.scenariosimulation.api.model.ExpressionIdentifier 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 13 with ExpressionIdentifier

use of org.drools.scenariosimulation.api.model.ExpressionIdentifier 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 14 with ExpressionIdentifier

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

the class AbstractScesimGridModel method commonAddColumn.

/**
 * This method <i>add</i> or <i>insert</i> a new column to the grid <b>and</b> to the underlying model, depending on the index value.
 * If index == -1 -> add, otherwise insert. It automatically creates default <code>FactIdentifier</code>  (for String class) and <code>ExpressionIdentifier</code>
 * @param index
 * @param column
 */
protected void commonAddColumn(final int index, final GridColumn<?> column) {
    String group = ((ScenarioGridColumn) column).getInformationHeaderMetaData().getColumnGroup();
    String columnId = ((ScenarioGridColumn) column).getInformationHeaderMetaData().getColumnId();
    final ExpressionIdentifier ei = ExpressionIdentifier.create(columnId, FactMappingType.valueOf(group));
    commonAddColumn(index, column, ei);
}
Also used : ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier)

Example 15 with ExpressionIdentifier

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

the class AbstractScesimGridModel method replaceColumn.

/**
 * This method replace a column at columnIndex position with a new column. It also save and restore width of the columns
 * @param columnIndex
 * @param column
 */
protected void replaceColumn(int columnIndex, GridColumn<?> column) {
    List<Double> widthsToRestore = getColumns().stream().map(GridColumn::getWidth).collect(Collectors.toList());
    deleteColumn(columnIndex);
    String group = ((ScenarioGridColumn) column).getInformationHeaderMetaData().getColumnGroup();
    String columnId = ((ScenarioGridColumn) column).getInformationHeaderMetaData().getColumnId();
    ExpressionIdentifier ei = ExpressionIdentifier.create(columnId, FactMappingType.valueOf(group));
    commonAddColumn(columnIndex, column, ei);
    /* Restoring the expected columns dimension, overriding the automatic resizing */
    IntStream.range(0, widthsToRestore.size()).forEach(index -> getColumns().get(index).setWidth(widthsToRestore.get(index)));
}
Also used : ExpressionIdentifier(org.drools.scenariosimulation.api.model.ExpressionIdentifier) OptionalDouble(java.util.OptionalDouble)

Aggregations

ExpressionIdentifier (org.drools.scenariosimulation.api.model.ExpressionIdentifier)19 FactMapping (org.drools.scenariosimulation.api.model.FactMapping)11 FactIdentifier (org.drools.scenariosimulation.api.model.FactIdentifier)9 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)7 FactMappingValue (org.drools.scenariosimulation.api.model.FactMappingValue)6 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Scenario (org.drools.scenariosimulation.api.model.Scenario)4 ExpressionEvaluator (org.drools.scenariosimulation.backend.expression.ExpressionEvaluator)4 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Background (org.drools.scenariosimulation.api.model.Background)3 FactMappingType (org.drools.scenariosimulation.api.model.FactMappingType)3 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)3 Settings (org.drools.scenariosimulation.api.model.Settings)3 ScenarioGridCellValue (org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)3 ScenarioGridCell (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridCell)3 Before (org.junit.Before)3