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);
}
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());
}
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());
}
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);
}
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();
}
}
}
Aggregations