use of org.drools.scenariosimulation.api.model.BackgroundData in project drools-wb by kiegroup.
the class SimulationSettingsCreationStrategy method createBackground.
default Background createBackground(Path context, String dmnFilePath) {
Background toReturn = new Background();
ScesimModelDescriptor simulationDescriptor = toReturn.getScesimModelDescriptor();
int index = toReturn.getUnmodifiableData().size() + 1;
BackgroundData backgroundData = toReturn.addData();
BackgroundDataWithIndex backgroundDataWithIndex = new BackgroundDataWithIndex(index, backgroundData);
// Add GIVEN Fact
createEmptyColumn(simulationDescriptor, backgroundDataWithIndex, 1, GIVEN, simulationDescriptor.getFactMappings().size());
return toReturn;
}
use of org.drools.scenariosimulation.api.model.BackgroundData in project drools-wb by kiegroup.
the class ScenarioSimulationEditorPresenter method refreshModelContent.
protected void refreshModelContent(SimulationRunResult newData) {
view.hideBusyIndicator();
if (this.model == null) {
return;
}
// refresh simulation data
Simulation simulation = this.model.getSimulation();
for (ScenarioWithIndex scenarioWithIndex : newData.getScenarioWithIndex()) {
int index = scenarioWithIndex.getIndex() - 1;
simulation.replaceData(index, scenarioWithIndex.getScesimData());
}
scenarioMainGridWidget.refreshContent(simulation);
context.getStatus().setSimulation(simulation);
// refresh background data
boolean hasBackgroundError = false;
Background background = this.model.getBackground();
for (BackgroundDataWithIndex backgroundDataWithIndex : newData.getBackgroundDataWithIndex()) {
int index = backgroundDataWithIndex.getIndex() - 1;
BackgroundData scesimData = backgroundDataWithIndex.getScesimData();
background.replaceData(index, scesimData);
hasBackgroundError |= scesimData.getUnmodifiableFactMappingValues().stream().anyMatch(elem -> !FactMappingValueStatus.SUCCESS.equals(elem.getStatus()));
}
scenarioBackgroundGridWidget.refreshContent(background);
context.getStatus().setBackground(background);
if (hasBackgroundError) {
sendNotification(ScenarioSimulationEditorConstants.INSTANCE.backgroundErrorNotification(), NotificationEvent.NotificationType.ERROR);
selectBackgroundTab();
}
dataManagementStrategy.setModel(model);
abstractScenarioSimulationDocksHandler.expandTestResultsDock();
scenarioSimulationEditorWrapper.onRefreshedModelContent(newData);
}
use of org.drools.scenariosimulation.api.model.BackgroundData in project drools-wb by kiegroup.
the class ScenarioSimulationEditorPresenterTest method refreshModelContent.
@Test
public void refreshModelContent() {
when(scenarioSimulationModelMock.getSimulation()).thenReturn(simulationMock);
List<ScenarioWithIndex> scenarioWithIndex = new ArrayList<>();
int scenarioNumber = 1;
int scenarioIndex = scenarioNumber - 1;
Scenario scenario = mock(Scenario.class);
scenarioWithIndex.add(new ScenarioWithIndex(scenarioNumber, scenario));
List<BackgroundDataWithIndex> backgroundDataWithIndex = new ArrayList<>();
BackgroundData backgroundData = mock(BackgroundData.class);
backgroundDataWithIndex.add(new BackgroundDataWithIndex(scenarioNumber, backgroundData));
TestResultMessage testResultMessage = mock(TestResultMessage.class);
SimulationRunResult testRunResult = new SimulationRunResult(scenarioWithIndex, backgroundDataWithIndex, new SimulationRunMetadata(), testResultMessage);
presenterSpy.refreshModelContent(testRunResult);
verify(scenarioSimulationViewMock, times(1)).hideBusyIndicator();
verify(simulationMock, times(1)).replaceData(eq(scenarioIndex), eq(scenario));
assertEquals(scenarioSimulationModelMock, presenterSpy.getModel());
verify(scenarioGridWidgetSpy, times(1)).refreshContent(eq(simulationMock));
assertEquals(scenarioSimulationContextLocal.getStatus().getSimulation(), simulationMock);
verify(backgroundMock, times(1)).replaceData(eq(scenarioIndex), eq(backgroundData));
verify(backgroundGridWidgetSpy, times(1)).refreshContent(eq(backgroundMock));
assertEquals(scenarioSimulationContextLocal.getStatus().getBackground(), backgroundMock);
assertEquals(scenarioSimulationModelMock, presenterSpy.getModel());
verify(abstractScenarioSimulationDocksHandlerMock, times(1)).expandTestResultsDock();
verify(dataManagementStrategyMock, times(1)).setModel(eq(scenarioSimulationModelMock));
verify(scenarioSimulationEditorWrapperMock, times(1)).onRefreshedModelContent(eq(testRunResult));
}
use of org.drools.scenariosimulation.api.model.BackgroundData in project drools by kiegroup.
the class AbstractRunnerHelper method extractBackgroundValues.
protected List<InstanceGiven> extractBackgroundValues(Background background, ClassLoader classLoader, ExpressionEvaluatorFactory expressionEvaluatorFactory) {
List<InstanceGiven> backgrounds = new ArrayList<>();
boolean hasError = false;
for (BackgroundData row : background.getUnmodifiableData()) {
try {
List<InstanceGiven> givens = extractGivenValues(background.getScesimModelDescriptor(), row.getUnmodifiableFactMappingValues(), classLoader, expressionEvaluatorFactory);
backgrounds.addAll(givens);
} catch (ScenarioException e) {
hasError = true;
}
}
if (hasError) {
throw new ScenarioException("Error in BACKGROUND data");
}
return backgrounds;
}
Aggregations