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