use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple 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));
}
use of org.drools.workbench.screens.scenariosimulation.model.typedescriptor.FactModelTuple 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);
}
Aggregations