use of au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState in project constellation by constellation-app.
the class DataAccessUtilities method saveDataAccessState.
/**
* Build a data access state from the passed tab pane and save it to the graph.
* <p/>
* Currently only global parameters are saved.
*
* @param tabs the tab pane to build the new data access state from
* @param graph the active graph to save the state to
*/
public static void saveDataAccessState(final TabPane tabs, final Graph graph) {
if (graph != null) {
// Build a new data access state from the passed tabs
final DataAccessState dataAccessState = new DataAccessState();
tabs.getTabs().forEach(step -> {
dataAccessState.newTab();
DataAccessTabPane.getQueryPhasePane(step).getGlobalParametersPane().getParams().getParameters().entrySet().stream().filter(entry -> entry.getValue().getStringValue() != null).forEach(entry -> dataAccessState.add(entry.getKey(), entry.getValue().getStringValue()));
});
// Save the state onto the graph
WritableGraph wg = null;
try {
wg = graph.getWritableGraph("Update Data Access State", true);
final int dataAccessStateAttribute = DataAccessConcept.MetaAttribute.DATAACCESS_STATE.ensure(wg);
wg.setObjectValue(dataAccessStateAttribute, 0, dataAccessState);
} catch (final InterruptedException ex) {
Exceptions.printStackTrace(ex);
Thread.currentThread().interrupt();
} finally {
if (wg != null) {
wg.commit();
}
}
}
}
use of au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState in project constellation by constellation-app.
the class DataAccessUtilitiesNGTest method loadDataAccessState.
@Test
public void loadDataAccessState() {
// Create current data access view state and set some parameters
// The code currenly only looks at the first tab so parameter2
// value will be ignored
final DataAccessState currentState = new DataAccessState();
currentState.newTab();
currentState.add("parameter1", "parameter1_new_value");
currentState.newTab();
currentState.add("parameter2", "parameter2_new_value");
// mock graph
final Graph graph = mock(Graph.class);
final ReadableGraph rGraph = mock(ReadableGraph.class);
when(graph.getReadableGraph()).thenReturn(rGraph);
// mock data access state attribute in graph
when(rGraph.getAttribute(GraphElementType.META, "dataaccess_state")).thenReturn(2);
when(rGraph.getObjectValue(2, 0)).thenReturn(currentState);
// mock tab pane
final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
final TabPane tabPane = mock(TabPane.class);
final Tab currentTab = mock(Tab.class);
when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
when(dataAccessTabPane.getCurrentTab()).thenReturn(currentTab);
when(dataAccessTabPane.getTabPane()).thenReturn(tabPane);
when(tabPane.getTabs()).thenReturn(FXCollections.observableArrayList(currentTab, mock(Tab.class)));
try (final MockedStatic<DataAccessTabPane> daTabPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class)) {
final QueryPhasePane queryPhasePane = mock(QueryPhasePane.class);
daTabPaneMockedStatic.when(() -> DataAccessTabPane.getQueryPhasePane(currentTab)).thenReturn(queryPhasePane);
final GlobalParametersPane globalParametersPane = mock(GlobalParametersPane.class);
final PluginParameters globalPluginParameters = mock(PluginParameters.class);
final PluginParameter pluginParameter1 = mock(PluginParameter.class);
final PluginParameter pluginParameter2 = mock(PluginParameter.class);
when(queryPhasePane.getGlobalParametersPane()).thenReturn(globalParametersPane);
when(globalParametersPane.getParams()).thenReturn(globalPluginParameters);
when(globalPluginParameters.getParameters()).thenReturn(Map.of("parameter1", pluginParameter1, "parameter2", pluginParameter2));
DataAccessUtilities.loadDataAccessState(dataAccessPane, graph);
verify(pluginParameter1).setStringValue("parameter1_new_value");
verify(pluginParameter2, never()).setStringValue(anyString());
verify(rGraph).release();
}
}
use of au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState in project constellation by constellation-app.
the class DataAccessUtilitiesNGTest method loadDataAccessState_empty_state.
@Test
public void loadDataAccessState_empty_state() {
// mock graph
final Graph graph = mock(Graph.class);
final ReadableGraph rGraph = mock(ReadableGraph.class);
when(graph.getReadableGraph()).thenReturn(rGraph);
// mock data access state attribute in graph
when(rGraph.getAttribute(GraphElementType.META, "dataaccess_state")).thenReturn(2);
when(rGraph.getObjectValue(2, 0)).thenReturn(new DataAccessState());
// mock tab pane
final DataAccessPane dataAccessPane = mock(DataAccessPane.class);
final DataAccessTabPane dataAccessTabPane = mock(DataAccessTabPane.class);
final Tab currentTab = mock(Tab.class);
when(dataAccessPane.getDataAccessTabPane()).thenReturn(dataAccessTabPane);
when(dataAccessTabPane.getCurrentTab()).thenReturn(currentTab);
try (final MockedStatic<DataAccessTabPane> daTabPaneMockedStatic = Mockito.mockStatic(DataAccessTabPane.class)) {
DataAccessUtilities.loadDataAccessState(dataAccessPane, graph);
daTabPaneMockedStatic.verifyNoInteractions();
verify(rGraph).release();
}
}
use of au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState in project constellation by constellation-app.
the class DataAccessStateIoProvider method writeObject.
@Override
public void writeObject(final Attribute attr, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException {
if (verbose || !graph.isDefaultValue(attr.getId(), elementId)) {
final DataAccessState state = (DataAccessState) graph.getObjectValue(attr.getId(), elementId);
if (state == null) {
jsonGenerator.writeNullField(attr.getName());
} else {
jsonGenerator.writeArrayFieldStart(attr.getName());
for (final Map<String, String> tab : state.getState()) {
jsonGenerator.writeStartObject();
jsonGenerator.writeObjectFieldStart(GLOBAL_OBJECT);
for (final Entry<String, String> globalParameter : tab.entrySet()) {
jsonGenerator.writeStringField(globalParameter.getKey(), globalParameter.getValue());
}
jsonGenerator.writeEndObject();
jsonGenerator.writeObjectFieldStart(PLUGINS_OBJECT);
// TODO: write plugin state information
jsonGenerator.writeEndObject();
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndArray();
}
}
}
use of au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState in project constellation by constellation-app.
the class DataAccessStateIoProviderNGTest method readObject.
@Test
public void readObject() throws IOException {
final ObjectMapper objectMapper = new ObjectMapper();
final JsonNode jsonNode = objectMapper.readTree(new FileInputStream(getClass().getResource("resources/dataAccessStateRead.json").getPath()));
final GraphWriteMethods graph = mock(GraphWriteMethods.class);
dataAccessStateIoProvider.readObject(ATTRIBUTE_ID, ELEMENT_ID, jsonNode, graph, null, null, null, null);
// Capture the call on the graph setter, pulling out the state
final ArgumentCaptor<DataAccessState> captor = ArgumentCaptor.forClass(DataAccessState.class);
verify(graph, times(1)).setObjectValue(eq(ATTRIBUTE_ID), eq(ELEMENT_ID), captor.capture());
final List<Map<String, String>> state = captor.getValue().getState();
// Verify that there are two tabs
assertEquals(state.size(), 2);
// Verify the contents of tab 1
final Map<String, String> expectedTab1 = new HashMap<>();
expectedTab1.put("key1", "value1");
expectedTab1.put("key2", null);
expectedTab1.put("key3", null);
assertEquals(state.get(0), expectedTab1);
// Verify the contents of tab 4
final Map<String, String> expectedTab2 = new HashMap<>();
expectedTab2.put("key4", "value4");
assertEquals(state.get(1), expectedTab2);
}
Aggregations