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