Search in sources :

Example 1 with DataAccessState

use of au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState in project constellation by constellation-app.

the class DataAccessStateIoProvider method readObject.

@Override
public void readObject(final int attributeId, final int elementId, final JsonNode jnode, final GraphWriteMethods graph, final Map<Integer, Integer> vertexMap, final Map<Integer, Integer> transactionMap, final GraphByteReader byteReader, ImmutableObjectCache cache) throws IOException {
    final DataAccessState state = new DataAccessState();
    if (!jnode.isNull() && jnode.isArray()) {
        for (int i = 0; i < jnode.size(); i++) {
            state.newTab();
            final JsonNode tab = jnode.get(i).get(GLOBAL_OBJECT);
            final Iterator<String> globalParameterNames = tab.fieldNames();
            while (globalParameterNames.hasNext()) {
                final String globalParameterName = globalParameterNames.next();
                state.add(globalParameterName, tab.get(globalParameterName).isNull() ? null : tab.get(globalParameterName).textValue());
            }
        // TODO: retrieve plugin state information
        }
    }
    graph.setObjectValue(attributeId, elementId, state);
}
Also used : DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with DataAccessState

use of au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState in project constellation by constellation-app.

the class DataAccessStateIoProviderNGTest method readObjectObjectJson.

@Test
public void readObjectObjectJson() throws IOException {
    final ObjectMapper objectMapper = new ObjectMapper();
    JsonNode root = objectMapper.readTree("{}");
    final GraphWriteMethods graph = mock(GraphWriteMethods.class);
    dataAccessStateIoProvider.readObject(ATTRIBUTE_ID, ELEMENT_ID, root, graph, null, null, null, null);
    final ArgumentCaptor<DataAccessState> captor = ArgumentCaptor.forClass(DataAccessState.class);
    verify(graph).setObjectValue(eq(ATTRIBUTE_ID), eq(ELEMENT_ID), captor.capture());
    final List<Map<String, String>> state = captor.getValue().getState();
    assertTrue(state.isEmpty());
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) JsonNode(com.fasterxml.jackson.databind.JsonNode) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 3 with DataAccessState

use of au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState in project constellation by constellation-app.

the class DataAccessStateIoProviderNGTest method readObjectNullJson.

@Test
public void readObjectNullJson() throws IOException {
    final ObjectMapper objectMapper = new ObjectMapper();
    JsonNode root = objectMapper.readTree("null");
    final GraphWriteMethods graph = mock(GraphWriteMethods.class);
    dataAccessStateIoProvider.readObject(ATTRIBUTE_ID, ELEMENT_ID, root, graph, null, null, null, null);
    final ArgumentCaptor<DataAccessState> captor = ArgumentCaptor.forClass(DataAccessState.class);
    verify(graph).setObjectValue(eq(ATTRIBUTE_ID), eq(ELEMENT_ID), captor.capture());
    final List<Map<String, String>> state = captor.getValue().getState();
    assertTrue(state.isEmpty());
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) JsonNode(com.fasterxml.jackson.databind.JsonNode) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 4 with DataAccessState

use of au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState in project constellation by constellation-app.

the class DataAccessStateIoProviderNGTest method writeObject.

@Test
public void writeObject() throws IOException {
    final DataAccessState state = new DataAccessState();
    state.newTab();
    state.add("key1", "value1");
    state.add("key2", "value2");
    state.newTab();
    state.add("key3", "value3");
    final Attribute attribute = mock(Attribute.class);
    when(attribute.getId()).thenReturn(ATTRIBUTE_ID);
    when(attribute.getName()).thenReturn("ATTR NAME");
    final GraphWriteMethods graph = mock(GraphWriteMethods.class);
    when(graph.isDefaultValue(ATTRIBUTE_ID, ELEMENT_ID)).thenReturn(false);
    when(graph.getObjectValue(ATTRIBUTE_ID, ELEMENT_ID)).thenReturn(state);
    final JsonFactory factory = new JsonFactory();
    final ByteArrayOutputStream output = new ByteArrayOutputStream();
    JsonGenerator jsonGenerator = factory.createGenerator(output);
    // The code is written with the assumption that it is called within a document
    // that has already started being written. Without starting the object in the test
    // the code would throw invalid json exceptions.
    jsonGenerator.writeStartObject();
    dataAccessStateIoProvider.writeObject(attribute, ELEMENT_ID, jsonGenerator, graph, null, false);
    jsonGenerator.writeEndObject();
    jsonGenerator.flush();
    final ObjectMapper objectMapper = new ObjectMapper();
    final JsonNode expected = objectMapper.readTree(new FileInputStream(getClass().getResource("resources/dataAccessStateWrite.json").getPath()));
    final JsonNode actual = objectMapper.readTree(new String(output.toByteArray(), StandardCharsets.UTF_8));
    assertEquals(actual, expected);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) Attribute(au.gov.asd.tac.constellation.graph.Attribute) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) JsonNode(com.fasterxml.jackson.databind.JsonNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 5 with DataAccessState

use of au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState in project constellation by constellation-app.

the class DataAccessUtilities method loadDataAccessState.

/**
 * Load the data access graph state and update the data access view.
 * <p/>
 * Currently only looking at string parameter types and only shows the first
 * step if it exists.
 *
 * @param dataAccessPane the data access pane
 * @param graph the active graph to load the state from
 */
public static void loadDataAccessState(final DataAccessPane dataAccessPane, final Graph graph) {
    if (graph != null && dataAccessPane.getDataAccessTabPane().getCurrentTab() != null) {
        final ReadableGraph readableGraph = graph.getReadableGraph();
        try {
            final int dataAccessStateAttribute = DataAccessConcept.MetaAttribute.DATAACCESS_STATE.get(readableGraph);
            if (dataAccessStateAttribute != Graph.NOT_FOUND) {
                final DataAccessState dataAccessState = readableGraph.getObjectValue(dataAccessStateAttribute, 0);
                if (dataAccessState != null && !dataAccessState.getState().isEmpty()) {
                    // TODO: support multiple tabs (not just first one in state) and not
                    // introduce memory leaks
                    final Map<String, String> tabState = dataAccessState.getState().get(0);
                    final Tab step = dataAccessPane.getDataAccessTabPane().getTabPane().getTabs().get(0);
                    DataAccessTabPane.getQueryPhasePane(step).getGlobalParametersPane().getParams().getParameters().entrySet().stream().forEach(param -> {
                        final PluginParameter<?> pp = param.getValue();
                        final String paramvalue = tabState.get(param.getKey());
                        if (paramvalue != null) {
                            pp.setStringValue(paramvalue);
                        }
                    });
                }
            }
        } finally {
            readableGraph.release();
        }
    }
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) DataAccessState(au.gov.asd.tac.constellation.views.dataaccess.state.DataAccessState) Tab(javafx.scene.control.Tab)

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