Search in sources :

Example 16 with GraphWriteMethods

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);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods)

Example 17 with GraphWriteMethods

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);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods)

Example 18 with GraphWriteMethods

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);
}
Also used : ConstellationAbstractMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker) GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) SimpleEditPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin) SpatialConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.SpatialConcept) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) MarkerCache(au.gov.asd.tac.constellation.views.mapview.utilities.MarkerCache) ConstellationLineMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationLineMarker) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) Shape(au.gov.asd.tac.constellation.utilities.geospatial.Shape) ServiceProvider(org.openide.util.lookup.ServiceProvider) PluginTags(au.gov.asd.tac.constellation.plugins.templates.PluginTags) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) ConstellationPolygonMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPolygonMarker) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) InteractiveGraphPluginRegistry(au.gov.asd.tac.constellation.graph.interaction.InteractiveGraphPluginRegistry) IOException(java.io.IOException) ConstellationAbstractMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationAbstractMarker) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) Collectors(java.util.stream.Collectors) PluginNotificationLevel(au.gov.asd.tac.constellation.plugins.PluginNotificationLevel) PluginInfo(au.gov.asd.tac.constellation.plugins.PluginInfo) List(java.util.List) AnalyticConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept) ConstellationMultiMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationMultiMarker) VisualSchemaPluginRegistry(au.gov.asd.tac.constellation.graph.schema.visual.VisualSchemaPluginRegistry) NbBundle(org.openide.util.NbBundle) Shape(au.gov.asd.tac.constellation.utilities.geospatial.Shape) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ConstellationMultiMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationMultiMarker) IOException(java.io.IOException) ConstellationLineMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationLineMarker) ConstellationPolygonMarker(au.gov.asd.tac.constellation.views.mapview.markers.ConstellationPolygonMarker) MarkerCache(au.gov.asd.tac.constellation.views.mapview.utilities.MarkerCache) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple)

Example 19 with GraphWriteMethods

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);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) TableViewState(au.gov.asd.tac.constellation.views.tableview.state.TableViewState) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) 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 20 with GraphWriteMethods

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);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Aggregations

GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)40 Test (org.testng.annotations.Test)26 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)16 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)15 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)10 HashMap (java.util.HashMap)9 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)8 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 Map (java.util.Map)8 Attribute (au.gov.asd.tac.constellation.graph.Attribute)7 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)7 ArrayList (java.util.ArrayList)7 AnalyticConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept)6 SimpleEditPlugin (au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin)6 List (java.util.List)6 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)5 PluginInfo (au.gov.asd.tac.constellation.plugins.PluginInfo)5 PluginType (au.gov.asd.tac.constellation.plugins.PluginType)5