Search in sources :

Example 6 with ScenarioSimulationContext

use of org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext in project drools-wb by kiegroup.

the class AbstractDataManagementStrategyTest method storeDataBackground.

@Test
public void storeDataBackground() {
    ScenarioSimulationContext scenarioSimulationContextSpy = spy(scenarioSimulationContextLocal);
    doReturn(backgroundMock).when(scenarioSimulationContextSpy).getAbstractScesimModelByGridWidget(GridWidget.BACKGROUND);
    final FactModelTuple factModelTuple = getFactTuple();
    abstractDataManagementStrategySpy.storeData(factModelTuple, testToolsPresenterMock, scenarioSimulationContextSpy, GridWidget.BACKGROUND);
    verify(testToolsPresenterMock, times(1)).populateTestTools(testToolsPresenterDataArgumentCaptor.capture());
    assertNotNull(testToolsPresenterDataArgumentCaptor.getValue());
    assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getDataObjectFieldsMap());
    assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getHiddenFieldsMap());
    assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getInstanceFieldsMap());
    assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getPropertiesToHide());
    assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getSimpleJavaInstanceFieldsMap());
    assertNotNull(testToolsPresenterDataArgumentCaptor.getValue().getSimpleJavaTypeFieldsMap());
    assertEquals(GridWidget.BACKGROUND, testToolsPresenterDataArgumentCaptor.getValue().getGridWidget());
    verify(scenarioSimulationContextSpy, times(1)).setDataObjectFieldsMap(isA(SortedMap.class));
    verify(scenarioSimulationContextSpy, never()).setDataObjectsInstancesName(isA(Set.class));
    verify(backgroundGridModelMock, never()).setSimpleJavaTypeInstancesName(isA(Set.class));
}
Also used : ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) Set(java.util.Set) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) SortedMap(java.util.SortedMap) AbstractScenarioSimulationEditorTest(org.drools.workbench.screens.scenariosimulation.client.editor.AbstractScenarioSimulationEditorTest) Test(org.junit.Test)

Example 7 with ScenarioSimulationContext

use of org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext in project drools-wb by kiegroup.

the class ScenarioGridPanelProducer method init.

@PostConstruct
public void init() {
    scenarioSimulationContext = new ScenarioSimulationContext(simulationGridWidget, backgroundGridWidget);
    initializeGrid(simulationGridLayer, simulationGridPanel, new ScenarioGridModel(false), scenarioSimulationContext, 1, 0);
    initializeGrid(backgroundGridLayer, backgroundGridPanel, new BackgroundGridModel(false), scenarioSimulationContext, 0, 0);
}
Also used : ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) ScenarioGridModel(org.drools.workbench.screens.scenariosimulation.client.models.ScenarioGridModel) BackgroundGridModel(org.drools.workbench.screens.scenariosimulation.client.models.BackgroundGridModel) PostConstruct(javax.annotation.PostConstruct)

Example 8 with ScenarioSimulationContext

use of org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext in project drools-wb by kiegroup.

the class ScenarioGridPanelProducerTest method init.

@Test
public void init() {
    assertNull(scenarioGridPanelProducer.scenarioSimulationContext);
    scenarioGridPanelProducer.init();
    ScenarioSimulationContext retrieved = scenarioGridPanelProducer.scenarioSimulationContext;
    assertNotNull(retrieved);
    verify(scenarioGridPanelProducer, times(1)).initializeGrid(eq(scenarioGridLayerMock), eq(scenarioGridPanelMock), isA(ScenarioGridModel.class), eq(retrieved), eq(1), eq(0));
    verify(scenarioGridPanelProducer, times(1)).initializeGrid(eq(backgroundGridLayerMock), eq(backgroundGridPanelMock), isA(BackgroundGridModel.class), eq(retrieved), eq(0), eq(0));
}
Also used : ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) ScenarioGridModel(org.drools.workbench.screens.scenariosimulation.client.models.ScenarioGridModel) BackgroundGridModel(org.drools.workbench.screens.scenariosimulation.client.models.BackgroundGridModel) Test(org.junit.Test)

Example 9 with ScenarioSimulationContext

use of org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext in project drools-wb by kiegroup.

the class AbstractDataManagementStrategy method storeData.

/**
 * Store data in required target objects
 */
public void storeData(final FactModelTuple factModelTuple, final TestToolsView.Presenter testToolsPresenter, final ScenarioSimulationContext context, final GridWidget gridWidget) {
    // Instantiate a map of already assigned properties
    final Map<String, List<List<String>>> propertiesToHide = getPropertiesToHide(context.getAbstractScesimGridModelByGridWidget(gridWidget));
    final SortedMap<String, FactModelTree> visibleFacts = factModelTuple.getVisibleFacts();
    final Map<Boolean, List<Map.Entry<String, FactModelTree>>> partitionBy = visibleFacts.entrySet().stream().collect(Collectors.partitioningBy(stringFactModelTreeEntry -> stringFactModelTreeEntry.getValue().isSimple()));
    final SortedMap<String, FactModelTree> complexDataObjects = new TreeMap<>(partitionBy.get(false).stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
    final SortedMap<String, FactModelTree> simpleDataObjects = new TreeMap<>(partitionBy.get(true).stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
    // Update context
    SortedMap<String, FactModelTree> dataObjectFieldsMap = new TreeMap<>();
    dataObjectFieldsMap.putAll(visibleFacts);
    dataObjectFieldsMap.putAll(factModelTuple.getHiddenFacts());
    context.setDataObjectFieldsMap(dataObjectFieldsMap);
    // Update model
    // Avoid Collections.emptySortedMap() due to "The method emptySortedMap() is undefined for the type Collections" error
    SortedMap<String, FactModelTree> instanceFieldsMap = new TreeMap<>();
    SortedMap<String, FactModelTree> simpleJavaTypeInstanceFieldsMap = new TreeMap<>();
    if (GridWidget.SIMULATION.equals(gridWidget)) {
        instanceFieldsMap = getInstanceMap(complexDataObjects);
        simpleJavaTypeInstanceFieldsMap = getInstanceMap(simpleDataObjects);
        Set<String> dataObjectsInstancesName = new HashSet<>(visibleFacts.keySet());
        dataObjectsInstancesName.addAll(instanceFieldsMap.keySet());
        context.setDataObjectsInstancesName(dataObjectsInstancesName);
        Set<String> simpleJavaTypeInstancesName = new HashSet<>(simpleDataObjects.keySet());
        simpleJavaTypeInstancesName.addAll(simpleJavaTypeInstanceFieldsMap.keySet());
        context.getAbstractScesimGridModelByGridWidget(gridWidget).setSimpleJavaTypeInstancesName(simpleJavaTypeInstancesName);
    }
    // Update right panel
    TestToolsPresenterData testToolsPresenterData = new TestToolsPresenterData(complexDataObjects, simpleDataObjects, instanceFieldsMap, simpleJavaTypeInstanceFieldsMap, factModelTuple.getHiddenFacts(), propertiesToHide, gridWidget);
    testToolsPresenter.populateTestTools(testToolsPresenterData);
}
Also used : ScenarioSimulationModel(org.drools.scenariosimulation.api.model.ScenarioSimulationModel) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) FactModelTuple(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple) GridWidget(org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ExpressionElement(org.drools.scenariosimulation.api.model.ExpressionElement) ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) AbstractScesimModel(org.drools.scenariosimulation.api.model.AbstractScesimModel) VALUE(org.drools.scenariosimulation.api.utils.ConstantsHolder.VALUE) Map(java.util.Map) AbstractScesimGridModel(org.drools.workbench.screens.scenariosimulation.client.models.AbstractScesimGridModel) ScesimModelDescriptor(org.drools.scenariosimulation.api.model.ScesimModelDescriptor) TestToolsPresenterData(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsPresenterData) Set(java.util.Set) FactMappingType(org.drools.scenariosimulation.api.model.FactMappingType) Collectors(java.util.stream.Collectors) TestToolsView(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsView) Objects(java.util.Objects) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) List(java.util.List) TreeMap(java.util.TreeMap) Collections(java.util.Collections) SortedMap(java.util.SortedMap) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) TreeMap(java.util.TreeMap) FactModelTree(org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTree) ArrayList(java.util.ArrayList) List(java.util.List) TestToolsPresenterData(org.drools.workbench.screens.scenariosimulation.client.rightpanel.TestToolsPresenterData) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) HashSet(java.util.HashSet)

Example 10 with ScenarioSimulationContext

use of org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext in project drools-wb by kiegroup.

the class SetGridCellValueCommand method internalExecute.

@Override
protected void internalExecute(ScenarioSimulationContext context) {
    final ScenarioSimulationContext.Status status = context.getStatus();
    AbstractScesimModel<AbstractScesimData> abstractScesimModel = context.getAbstractScesimModelByGridWidget(gridWidget);
    int columnIndex = status.getColumnIndex();
    FactMapping factMapping = abstractScesimModel.getScesimModelDescriptor().getFactMappingByIndex(columnIndex);
    ScenarioGridColumn selectedColumn = (ScenarioGridColumn) context.getAbstractScesimGridModelByGridWidget(gridWidget).getColumns().get(columnIndex);
    String placeholder = ScenarioSimulationUtils.getPlaceHolder(selectedColumn.isInstanceAssigned(), selectedColumn.isPropertyAssigned(), factMapping.getFactMappingValueType(), factMapping.getClassName());
    context.getAbstractScesimGridModelByGridWidget(gridWidget).setCellValue(status.getRowIndex(), columnIndex, new ScenarioGridCellValue(status.getGridCellValue(), placeholder));
    context.getAbstractScesimGridModelByGridWidget(gridWidget).resetError(status.getRowIndex(), columnIndex);
}
Also used : ScenarioSimulationContext(org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext) FactMapping(org.drools.scenariosimulation.api.model.FactMapping) AbstractScesimData(org.drools.scenariosimulation.api.model.AbstractScesimData) ScenarioGridColumn(org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn) ScenarioGridCellValue(org.drools.workbench.screens.scenariosimulation.client.values.ScenarioGridCellValue)

Aggregations

ScenarioSimulationContext (org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationContext)10 FactModelTuple (org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple)5 SortedMap (java.util.SortedMap)4 Set (java.util.Set)3 GridWidget (org.drools.workbench.screens.scenariosimulation.client.enums.GridWidget)3 ScenarioGridModel (org.drools.workbench.screens.scenariosimulation.client.models.ScenarioGridModel)3 ScenarioGridColumn (org.drools.workbench.screens.scenariosimulation.client.widgets.ScenarioGridColumn)3 Before (org.junit.Before)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 AbstractScesimData (org.drools.scenariosimulation.api.model.AbstractScesimData)2 Background (org.drools.scenariosimulation.api.model.Background)2 ScenarioSimulationModel (org.drools.scenariosimulation.api.model.ScenarioSimulationModel)2 ScenarioSimulationViolation (org.drools.workbench.screens.scenariosimulation.client.commands.ScenarioSimulationViolation)2 AbstractScenarioSimulationEditorTest (org.drools.workbench.screens.scenariosimulation.client.editor.AbstractScenarioSimulationEditorTest)2 BackgroundGridModel (org.drools.workbench.screens.scenariosimulation.client.models.BackgroundGridModel)2