Search in sources :

Example 6 with DataAccessState

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();
            }
        }
    }
}
Also used : TopComponent(org.openide.windows.TopComponent) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) InvocationTargetException(java.lang.reflect.InvocationTargetException) Graph(au.gov.asd.tac.constellation.graph.Graph) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) SwingUtilities(javax.swing.SwingUtilities) TabPane(javafx.scene.control.TabPane) Tab(javafx.scene.control.Tab) Exceptions(org.openide.util.Exceptions) WindowManager(org.openide.windows.WindowManager) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Map(java.util.Map) DataAccessViewTopComponent(au.gov.asd.tac.constellation.views.dataaccess.DataAccessViewTopComponent) DataAccessConcept(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessConcept) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph)

Example 7 with DataAccessState

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();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) TabPane(javafx.scene.control.TabPane) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) Tab(javafx.scene.control.Tab) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) QueryPhasePane(au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane) GlobalParametersPane(au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Test(org.testng.annotations.Test)

Example 8 with DataAccessState

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();
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) DataAccessTabPane(au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane) WritableGraph(au.gov.asd.tac.constellation.graph.WritableGraph) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) Tab(javafx.scene.control.Tab) DataAccessPane(au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane) Test(org.testng.annotations.Test)

Example 9 with DataAccessState

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();
        }
    }
}
Also used : DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState)

Example 10 with DataAccessState

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);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Aggregations

DataAccessState (au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState)11 Test (org.testng.annotations.Test)7 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Tab (javafx.scene.control.Tab)5 Graph (au.gov.asd.tac.constellation.graph.Graph)4 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)4 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)4 DataAccessTabPane (au.gov.asd.tac.constellation.views.dataaccess.components.DataAccessTabPane)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Map (java.util.Map)4 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)3 DataAccessPane (au.gov.asd.tac.constellation.views.dataaccess.panes.DataAccessPane)3 HashMap (java.util.HashMap)3 TabPane (javafx.scene.control.TabPane)3 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)2 GlobalParametersPane (au.gov.asd.tac.constellation.views.dataaccess.panes.GlobalParametersPane)2 QueryPhasePane (au.gov.asd.tac.constellation.views.dataaccess.panes.QueryPhasePane)2 FileInputStream (java.io.FileInputStream)2 Attribute (au.gov.asd.tac.constellation.graph.Attribute)1