Search in sources :

Example 6 with SimulationRunResult

use of org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult 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);
}
Also used : AbstractScenarioSimulationDocksHandler(org.drools.workbench.screens.scenariosimulation.client.handlers.AbstractScenarioSimulationDocksHandler) ScenarioNotificationEvent(org.drools.workbench.screens.scenariosimulation.client.events.ScenarioNotificationEvent) TestToolsPresenter(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsPresenter) ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) AbstractDMODataManagementStrategy(org.drools.workbench.screens.scenariosimulation.client.editor.strategies.AbstractDMODataManagementStrategy) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) DefaultPlaceRequest(org.uberfire.mvp.impl.DefaultPlaceRequest) CustomBusyPopup(org.drools.workbench.screens.scenariosimulation.client.popup.CustomBusyPopup) FactMappingValidationError(org.drools.workbench.screens.scenariosimulation.model.FactMappingValidationError) Observes(javax.enterprise.event.Observes) BackgroundDataWithIndex(org.drools.scenariosimulation.api.model.BackgroundDataWithIndex) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) SettingsView(org.drools.workbench.screens.scenariosimulation.client.rightpanel.SettingsView) AbstractScenarioSimulationProducer(org.drools.workbench.screens.scenariosimulation.client.producers.AbstractScenarioSimulationProducer) EventBus(com.google.gwt.event.shared.EventBus) TextFileExport(org.uberfire.ext.editor.commons.client.file.exports.TextFileExport) SettingsPresenter(org.drools.workbench.screens.scenariosimulation.client.rightpanel.SettingsPresenter) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback) UberfireDocksInteractionEvent(org.uberfire.client.workbench.docks.UberfireDocksInteractionEvent) Collectors(java.util.stream.Collectors) CheatSheetView(org.drools.workbench.screens.scenariosimulation.client.rightpanel.CheatSheetView) List(java.util.List) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) ObservablePath(org.uberfire.backend.vfs.ObservablePath) ScenarioSimulationHasBusyIndicatorDefaultErrorCallback(org.drools.workbench.screens.scenariosimulation.client.handlers.ScenarioSimulationHasBusyIndicatorDefaultErrorCallback) Simulation(org.drools.scenariosimulation.api.model.Simulation) ScenarioMenuItemFactory(org.drools.workbench.screens.scenariosimulation.client.factories.ScenarioMenuItemFactory) ScenarioSimulationEditorConstants(org.drools.workbench.screens.scenariosimulation.client.resources.i18n.ScenarioSimulationEditorConstants) SimulationRunResult(org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult) IntStream(java.util.stream.IntStream) RedoEvent(org.drools.workbench.screens.scenariosimulation.client.events.RedoEvent) PlaceStatus(org.uberfire.client.mvp.PlaceStatus) FactMappingValueStatus(org.drools.scenariosimulation.api.model.FactMappingValueStatus) ErrorCallback(org.jboss.errai.common.client.api.ErrorCallback) PlaceManager(org.uberfire.client.mvp.PlaceManager) GWT(com.google.gwt.core.client.GWT) Supplier(java.util.function.Supplier) ScenarioSimulationEditorI18nServerManager(org.drools.workbench.screens.scenariosimulation.client.resources.i18n.ScenarioSimulationEditorI18nServerManager) ImportEvent(org.drools.workbench.screens.scenariosimulation.client.events.ImportEvent) Inject(javax.inject.Inject) CSV(org.drools.workbench.screens.scenariosimulation.service.ImportExportType.CSV) ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) ConfirmPopupPresenter(org.drools.workbench.screens.scenariosimulation.client.popup.ConfirmPopupPresenter) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) MenuItem(org.uberfire.workbench.model.menu.MenuItem) CommonConstants(org.kie.workbench.common.widgets.client.resources.i18n.CommonConstants) SCESIMEDITOR_ID(org.drools.workbench.screens.scenariosimulation.client.handlers.AbstractScenarioSimulationDocksHandler.SCESIMEDITOR_ID) ScenarioSimulationResourceType(org.drools.workbench.screens.scenariosimulation.client.type.ScenarioSimulationResourceType) DataManagementStrategy(org.drools.workbench.screens.scenariosimulation.client.editor.strategies.DataManagementStrategy) Path(org.uberfire.backend.vfs.Path) Command(org.uberfire.mvp.Command) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) TextContent(org.uberfire.ext.editor.commons.client.file.exports.TextContent) UndoEvent(org.drools.workbench.screens.scenariosimulation.client.events.UndoEvent) BackgroundData(org.drools.scenariosimulation.api.model.BackgroundData) Background(org.drools.scenariosimulation.api.model.Background) DomGlobal(elemental2.dom.DomGlobal) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) TestToolsView(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsView) Type(org.drools.scenariosimulation.api.model.ScenarioSimulationModel.Type) AtomicLong(java.util.concurrent.atomic.AtomicLong) MarshallingWrapper(org.jboss.errai.enterprise.client.jaxrs.MarshallingWrapper) Dependent(javax.enterprise.context.Dependent) FileMenuBuilder(org.kie.workbench.common.widgets.client.menu.FileMenuBuilder) ScenarioGridWidget(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridWidget) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) BusyPopup(org.uberfire.ext.widgets.common.client.common.BusyPopup) Simulation(org.drools.scenariosimulation.api.model.Simulation) Background(org.drools.scenariosimulation.api.model.Background) BackgroundDataWithIndex(org.drools.scenariosimulation.api.model.BackgroundDataWithIndex) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) BackgroundData(org.drools.scenariosimulation.api.model.BackgroundData)

Example 7 with SimulationRunResult

use of org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult 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));
}
Also used : SimulationRunResult(org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult) BackgroundDataWithIndex(org.drools.scenariosimulation.api.model.BackgroundDataWithIndex) TestResultMessage(org.guvnor.common.services.shared.test.TestResultMessage) ArrayList(java.util.ArrayList) SimulationRunMetadata(org.drools.scenariosimulation.api.model.SimulationRunMetadata) ScenarioWithIndex(org.drools.scenariosimulation.api.model.ScenarioWithIndex) BackgroundData(org.drools.scenariosimulation.api.model.BackgroundData) Scenario(org.drools.scenariosimulation.api.model.Scenario) Test(org.junit.Test)

Aggregations

SimulationRunResult (org.drools.workbench.screens.scenariosimulation.model.SimulationRunResult)7 ScenarioWithIndex (org.drools.scenariosimulation.api.model.ScenarioWithIndex)5 Test (org.junit.Test)5 Path (org.uberfire.backend.vfs.Path)4 ArrayList (java.util.ArrayList)3 Scenario (org.drools.scenariosimulation.api.model.Scenario)3 TestResultMessage (org.guvnor.common.services.shared.test.TestResultMessage)3 Background (org.drools.scenariosimulation.api.model.Background)2 BackgroundData (org.drools.scenariosimulation.api.model.BackgroundData)2 BackgroundDataWithIndex (org.drools.scenariosimulation.api.model.BackgroundDataWithIndex)2 ScesimModelDescriptor (org.drools.scenariosimulation.api.model.ScesimModelDescriptor)2 ScenarioSimulationHasBusyIndicatorDefaultErrorCallback (org.drools.workbench.screens.scenariosimulation.client.handlers.ScenarioSimulationHasBusyIndicatorDefaultErrorCallback)2 GWT (com.google.gwt.core.client.GWT)1 EventBus (com.google.gwt.event.shared.EventBus)1 DomGlobal (elemental2.dom.DomGlobal)1 List (java.util.List)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1