use of au.gov.asd.tac.constellation.graph.GraphWriteMethods in project constellation by constellation-app.
the class GraphElement method setLongValue.
public final void setLongValue(String attribute, long value) {
final GraphWriteMethods writableGraph = graph.getWritableGraph();
int attributeId = graph.getReadableGraph().getAttribute(type, attribute);
if (attributeId == Graph.NOT_FOUND) {
attributeId = writableGraph.getSchema() != null ? writableGraph.getSchema().getFactory().ensureAttribute(writableGraph, type, attribute) : Graph.NOT_FOUND;
if (attributeId == Graph.NOT_FOUND) {
attributeId = writableGraph.addAttribute(type, LongAttributeDescription.ATTRIBUTE_NAME, attribute, "", 0, null);
}
}
writableGraph.setLongValue(attributeId, id, value);
}
use of au.gov.asd.tac.constellation.graph.GraphWriteMethods in project constellation by constellation-app.
the class GraphElement method setStringValue.
public final void setStringValue(String attribute, String value) {
final GraphWriteMethods writableGraph = graph.getWritableGraph();
int attributeId = graph.getReadableGraph().getAttribute(type, attribute);
if (attributeId == Graph.NOT_FOUND) {
attributeId = writableGraph.getSchema() != null ? writableGraph.getSchema().getFactory().ensureAttribute(writableGraph, type, attribute) : Graph.NOT_FOUND;
if (attributeId == Graph.NOT_FOUND) {
attributeId = writableGraph.addAttribute(type, StringAttributeDescription.ATTRIBUTE_NAME, attribute, "", null, null);
}
}
writableGraph.setStringValue(attributeId, id, value);
}
use of au.gov.asd.tac.constellation.graph.GraphWriteMethods in project constellation by constellation-app.
the class CopyCustomMarkersToGraphPlugin method edit.
@Override
protected void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
final int vertexIdentifierAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
final int vertexTypeAttributeId = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
final int vertexLatitudeAttributeId = SpatialConcept.VertexAttribute.LATITUDE.ensure(graph);
final int vertexLongitudeAttributeId = SpatialConcept.VertexAttribute.LONGITUDE.ensure(graph);
final int vertexPrecisionAttributeId = SpatialConcept.VertexAttribute.PRECISION.ensure(graph);
final int vertexShapeAttributeId = SpatialConcept.VertexAttribute.SHAPE.ensure(graph);
final MarkerCache markerCache = MarkerCache.getDefault();
for (final ConstellationAbstractMarker marker : markerCache.getCustomMarkers()) {
final String markerId = marker.getId() == null ? marker.toString() : marker.getId();
final int vertexId = graph.addVertex();
graph.setStringValue(vertexIdentifierAttributeId, vertexId, markerId);
graph.setObjectValue(vertexTypeAttributeId, vertexId, AnalyticConcept.VertexType.LOCATION);
graph.setFloatValue(vertexLatitudeAttributeId, vertexId, marker.getLocation().getLat());
graph.setFloatValue(vertexLongitudeAttributeId, vertexId, marker.getLocation().getLon());
graph.setFloatValue(vertexPrecisionAttributeId, vertexId, (float) marker.getRadius());
try {
final Shape.GeometryType geometryType;
if (marker instanceof ConstellationMultiMarker) {
geometryType = Shape.GeometryType.MULTI_POLYGON;
} else if (marker instanceof ConstellationPolygonMarker) {
geometryType = Shape.GeometryType.POLYGON;
} else if (marker instanceof ConstellationLineMarker) {
geometryType = Shape.GeometryType.LINE;
} else {
geometryType = Shape.GeometryType.POINT;
}
final List<Tuple<Double, Double>> coordinates = marker.getLocations().stream().map(location -> Tuple.create((double) location.getLon(), (double) location.getLat())).collect(Collectors.toList());
final String shape = Shape.generateShape(markerId, geometryType, coordinates);
graph.setStringValue(vertexShapeAttributeId, vertexId, shape);
} catch (final IOException ex) {
throw new PluginException(PluginNotificationLevel.ERROR, ex);
}
}
PluginExecution.withPlugin(VisualSchemaPluginRegistry.COMPLETE_SCHEMA).executeNow(graph);
PluginExecution.withPlugin(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(graph);
}
use of au.gov.asd.tac.constellation.graph.GraphWriteMethods in project constellation by constellation-app.
the class TableViewStateIoProviderNGTest method writeObject.
@Test
public void writeObject() throws IOException {
final GraphAttribute transactionGraphAttr = mock(GraphAttribute.class);
final GraphAttribute vertexGraphAttr = mock(GraphAttribute.class);
when(transactionGraphAttr.getElementType()).thenReturn(GraphElementType.TRANSACTION);
when(transactionGraphAttr.getName()).thenReturn("My Transaction");
when(vertexGraphAttr.getElementType()).thenReturn(GraphElementType.VERTEX);
when(vertexGraphAttr.getName()).thenReturn("My Vertex");
final TableViewState state = new TableViewState();
state.setSelectedOnly(true);
state.setElementType(GraphElementType.VERTEX);
state.setTransactionColumnAttributes(List.of(Tuple.create("transactionPrefix", transactionGraphAttr)));
state.setVertexColumnAttributes(List.of(Tuple.create("vertexPrefix", vertexGraphAttr)));
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();
tableViewStateIoProvider.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/tableViewStateWrite.json").getPath()));
final JsonNode actual = objectMapper.readTree(new String(output.toByteArray(), StandardCharsets.UTF_8));
assertEquals(actual, expected);
}
use of au.gov.asd.tac.constellation.graph.GraphWriteMethods in project constellation by constellation-app.
the class TableViewStateIoProviderNGTest method readObjectObjectJson.
@Test
public void readObjectObjectJson() throws IOException {
final ObjectMapper objectMapper = new ObjectMapper();
JsonNode root = objectMapper.readTree("{}");
final GraphWriteMethods graph = mock(GraphWriteMethods.class);
tableViewStateIoProvider.readObject(ATTRIBUTE_ID, ELEMENT_ID, root, graph, null, null, null, null);
verifyNoInteractions(graph);
}
Aggregations