Search in sources :

Example 21 with GraphAttribute

use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.

the class GraphRecordStoreUtilities method copyTransactionsBetweenVertices.

/**
 * Take transactions between two constituents of an expanded composite and
 * add to a {@link RecordStore} copies of these transactions. This is used
 * when a composite node is contracted so that these transactions can be *
 * added back when it is expanded.
 *
 * @param graph A {@link GraphReadMethods} from which the
 * {@link RecordStore} will be created.
 * @param recordStore The {@link RecordStore} to add the transactions to.
 * @param fromVxId The vertex id of the first composite constituent.
 * @param toVxId The vertex id of the second composite constituent.
 * @param fromId The id of the first composite constituent to be used in the
 * {@link RecordStore}.
 * @param toId The id of the first composite constituent to be used in the
 * {@link RecordStore}.
 */
public static void copyTransactionsBetweenVertices(final GraphReadMethods graph, final RecordStore recordStore, final int fromVxId, final int toVxId, final String fromId, final String toId) {
    final int transactionAttributeCount = graph.getAttributeCount(GraphElementType.TRANSACTION);
    final Attribute[] transactionAttributes = new Attribute[transactionAttributeCount];
    for (int a = 0; a < transactionAttributeCount; a++) {
        int attributeId = graph.getAttribute(GraphElementType.TRANSACTION, a);
        transactionAttributes[a] = new GraphAttribute(graph, attributeId);
    }
    final int lxId = graph.getLink(fromVxId, toVxId);
    if (lxId != Graph.NOT_FOUND) {
        final int transactionCount = graph.getLinkTransactionCount(lxId);
        for (int t = 0; t < transactionCount; t++) {
            final int transaction = graph.getLinkTransaction(lxId, t);
            final int source = graph.getTransactionSourceVertex(transaction);
            final String sourceId = source == fromVxId ? fromId : toId;
            final String destId = source == fromVxId ? toId : fromId;
            recordStore.add();
            for (Attribute transactionAttribute : transactionAttributes) {
                final String value = graph.getStringValue(transactionAttribute.getId(), transaction);
                recordStore.set(TRANSACTION + transactionAttribute.getName() + "<" + transactionAttribute.getAttributeType() + ">", value);
            }
            if (graph.getTransactionDirection(transaction) == Graph.UNDIRECTED) {
                recordStore.set(TRANSACTION + DIRECTED_KEY, FALSE);
            }
            recordStore.set(TRANSACTION + ID, COPY + String.format(NUMBER_STRING_STRING_FORMAT, transaction, sourceId, destId));
            recordStore.set(SOURCE + ID, sourceId);
            recordStore.set(DESTINATION + ID, destId);
        }
    }
}
Also used : Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute)

Example 22 with GraphAttribute

use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.

the class CopyGraphUtilities method copyGraphToGraph.

/**
 * Adapted from CopySelectedElementsPlugin.makeGraph
 *
 * @param original - the Graph to copy elements from
 * @param graph - the Graph to copy elements to
 * @param copyAll - whether to copy all elements or just the selected ones
 */
public static void copyGraphToGraph(final GraphReadMethods original, final GraphWriteMethods graph, final boolean copyAll) {
    final int vertexSelected = original.getAttribute(GraphElementType.VERTEX, VisualConcept.VertexAttribute.SELECTED.getName());
    final int transactionSelected = original.getAttribute(GraphElementType.TRANSACTION, VisualConcept.TransactionAttribute.SELECTED.getName());
    final int[] attributeTranslation = new int[original.getAttributeCapacity()];
    // Copy the attributes.
    for (final GraphElementType type : GraphElementType.values()) {
        final int attributeCount = original.getAttributeCount(type);
        for (int attributePosition = 0; attributePosition < attributeCount; attributePosition++) {
            int originalAttributeId = original.getAttribute(type, attributePosition);
            final Attribute attribute = new GraphAttribute(original, originalAttributeId);
            int newAttributeId = graph.getAttribute(type, attribute.getName());
            if (newAttributeId == Graph.NOT_FOUND) {
                newAttributeId = graph.addAttribute(type, attribute.getAttributeType(), attribute.getName(), attribute.getDescription(), attribute.getDefaultValue(), null);
            }
            attributeTranslation[originalAttributeId] = newAttributeId;
            if (type == GraphElementType.GRAPH) {
                graph.setObjectValue(newAttributeId, 0, original.getObjectValue(originalAttributeId, 0));
            }
        }
    }
    // Copy the vertices.
    final int[] vertexTranslation = new int[original.getVertexCapacity()];
    for (int position = 0; position < original.getVertexCount(); position++) {
        final int originalVertex = original.getVertex(position);
        if (copyAll || vertexSelected == Graph.NOT_FOUND || original.getBooleanValue(vertexSelected, originalVertex)) {
            final int newVertex = graph.addVertex();
            vertexTranslation[originalVertex] = newVertex;
            for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.VERTEX); attributePosition++) {
                final int originalAttributeId = original.getAttribute(GraphElementType.VERTEX, attributePosition);
                final int newAttributeId = attributeTranslation[originalAttributeId];
                graph.setObjectValue(newAttributeId, newVertex, original.getObjectValue(originalAttributeId, originalVertex));
            }
        }
    }
    // Copy the transactions.
    final int[] edgeTranslation = new int[original.getEdgeCapacity()];
    final int[] linkTranslation = new int[original.getLinkCapacity()];
    for (int position = 0; position < original.getTransactionCount(); position++) {
        final int originalTransaction = original.getTransaction(position);
        if (!copyAll && ((transactionSelected != Graph.NOT_FOUND && !original.getBooleanValue(transactionSelected, originalTransaction)) || (vertexSelected != Graph.NOT_FOUND && (!original.getBooleanValue(vertexSelected, original.getTransactionSourceVertex(originalTransaction)) || !original.getBooleanValue(vertexSelected, original.getTransactionDestinationVertex(originalTransaction)))))) {
            continue;
        }
        final int sourceVertex = vertexTranslation[original.getTransactionSourceVertex(originalTransaction)];
        final int destinationVertex = vertexTranslation[original.getTransactionDestinationVertex(originalTransaction)];
        final boolean directed = original.getTransactionDirection(originalTransaction) < 2;
        final int newTransaction = graph.addTransaction(sourceVertex, destinationVertex, directed);
        // add the edge translations
        final int originalEdge = original.getTransactionEdge(originalTransaction);
        final int newEdge = graph.getTransactionEdge(newTransaction);
        edgeTranslation[originalEdge] = newEdge;
        // add the link translations
        final int originalLink = original.getTransactionLink(originalTransaction);
        final int newLink = graph.getTransactionLink(newTransaction);
        linkTranslation[originalLink] = newLink;
        for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.TRANSACTION); attributePosition++) {
            final int originalAttributeId = original.getAttribute(GraphElementType.TRANSACTION, attributePosition);
            final int newAttributeId = attributeTranslation[originalAttributeId];
            graph.setObjectValue(newAttributeId, newTransaction, original.getObjectValue(originalAttributeId, originalTransaction));
        }
    }
    // Copy the edges
    for (int position = 0; position < original.getEdgeCount(); position++) {
        final int originalEdge = original.getEdge(position);
        if (!copyAll && ((transactionSelected != Graph.NOT_FOUND && !original.getBooleanValue(transactionSelected, originalEdge)) || (vertexSelected != Graph.NOT_FOUND && (!original.getBooleanValue(vertexSelected, original.getEdgeSourceVertex(originalEdge)) || !original.getBooleanValue(vertexSelected, original.getEdgeDestinationVertex(originalEdge)))))) {
            continue;
        }
        for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.EDGE); attributePosition++) {
            final int originalAttributeId = original.getAttribute(GraphElementType.EDGE, attributePosition);
            final int newAttributeId = attributeTranslation[originalAttributeId];
            graph.setObjectValue(newAttributeId, edgeTranslation[originalEdge], original.getObjectValue(originalAttributeId, originalEdge));
        }
    }
    // Copy the links
    for (int position = 0; position < original.getLinkCount(); position++) {
        final int originalLink = original.getLink(position);
        if (!copyAll && ((transactionSelected != Graph.NOT_FOUND && !original.getBooleanValue(transactionSelected, originalLink)) || (vertexSelected != Graph.NOT_FOUND && (!original.getBooleanValue(vertexSelected, original.getEdgeSourceVertex(originalLink)) || !original.getBooleanValue(vertexSelected, original.getEdgeDestinationVertex(originalLink)))))) {
            continue;
        }
        for (int attributePosition = 0; attributePosition < original.getAttributeCount(GraphElementType.LINK); attributePosition++) {
            final int originalAttributeId = original.getAttribute(GraphElementType.LINK, attributePosition);
            final int newAttributeId = attributeTranslation[originalAttributeId];
            graph.setObjectValue(newAttributeId, linkTranslation[originalLink], original.getObjectValue(originalAttributeId, originalLink));
        }
    }
}
Also used : GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType)

Example 23 with GraphAttribute

use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.

the class CopyGraphUtilities method copyGraphTypeElements.

/**
 * Copy a graph attribute and its values to a new graph
 *
 * @param original Original graph
 * @param graph New graph
 */
public static void copyGraphTypeElements(final GraphReadMethods original, final GraphWriteMethods graph) {
    final int attributeCount = original.getAttributeCount(GraphElementType.GRAPH);
    for (int attributePosition = 0; attributePosition < attributeCount; attributePosition++) {
        int originalAttributeId = original.getAttribute(GraphElementType.GRAPH, attributePosition);
        final Attribute attribute = new GraphAttribute(original, originalAttributeId);
        int newAttributeId = graph.getAttribute(GraphElementType.GRAPH, attribute.getName());
        if (newAttributeId == Graph.NOT_FOUND) {
            newAttributeId = graph.addAttribute(GraphElementType.GRAPH, attribute.getAttributeType(), attribute.getName(), attribute.getDescription(), attribute.getDefaultValue(), null);
        }
        graph.setObjectValue(newAttributeId, 0, original.getObjectValue(originalAttributeId, 0));
    }
}
Also used : GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) Attribute(au.gov.asd.tac.constellation.graph.Attribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute)

Example 24 with GraphAttribute

use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.

the class AbstractGeoExportPlugin method read.

@Override
public void read(final GraphReadMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    if (parameters.getStringValue(OUTPUT_PARAMETER_ID) == null) {
        NotifyDisplayer.display("Invalid output file provided, cannot be empty", NotifyDescriptor.ERROR_MESSAGE);
        return;
    }
    if (parameters.getSingleChoice(ELEMENT_TYPE_PARAMETER_ID) == null) {
        NotifyDisplayer.display("Invalid element type provided, cannot be empty", NotifyDescriptor.ERROR_MESSAGE);
        return;
    }
    final File output = new File(parameters.getStringValue(OUTPUT_PARAMETER_ID));
    final GraphElementType elementType = (GraphElementType) ((ElementTypeParameterValue) parameters.getSingleChoice(ELEMENT_TYPE_PARAMETER_ID)).getObjectValue();
    final List<GraphAttribute> graphAttributes = parameters.getMultiChoiceValue(ATTRIBUTES_PARAMETER_ID).getChoicesData().stream().map(attributeChoice -> (GraphAttribute) ((GraphAttributeParameterValue) attributeChoice).getObjectValue()).collect(Collectors.toList());
    final boolean selectedOnly = parameters.getBooleanValue(SELECTED_ONLY_PARAMETER_ID);
    final int vertexIdentifierAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.get(graph);
    final int vertexSelectedAttributeId = VisualConcept.VertexAttribute.SELECTED.get(graph);
    final int vertexLatitudeAttributeId = SpatialConcept.VertexAttribute.LATITUDE.get(graph);
    final int vertexLongitudeAttributeId = SpatialConcept.VertexAttribute.LONGITUDE.get(graph);
    final int vertexShapeAttributeId = SpatialConcept.VertexAttribute.SHAPE.get(graph);
    final int transactionIdentifierAttributeId = VisualConcept.TransactionAttribute.IDENTIFIER.get(graph);
    final int transactionSelectedAttributeId = VisualConcept.TransactionAttribute.SELECTED.get(graph);
    final int transactionLatitudeAttributeId = SpatialConcept.TransactionAttribute.LATITUDE.get(graph);
    final int transactionLongitudeAttributeId = SpatialConcept.TransactionAttribute.LONGITUDE.get(graph);
    final int transactionShapeAttributeId = SpatialConcept.TransactionAttribute.SHAPE.get(graph);
    final Map<String, String> shapes = new HashMap<>();
    final Map<String, Map<String, Object>> attributes = new HashMap<>();
    switch(elementType) {
        case VERTEX:
            final int vertexCount = graph.getVertexCount();
            for (int vertexPosition = 0; vertexPosition < vertexCount; vertexPosition++) {
                final int vertexId = graph.getVertex(vertexPosition);
                final boolean vertexSelected = graph.getBooleanValue(vertexSelectedAttributeId, vertexId);
                final String vertexIdentifier = graph.getStringValue(vertexIdentifierAttributeId, vertexId);
                final Float vertexLatitude = vertexLatitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(vertexLatitudeAttributeId, vertexId);
                final Float vertexLongitude = vertexLongitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(vertexLongitudeAttributeId, vertexId);
                final String vertexShape = vertexShapeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getStringValue(vertexShapeAttributeId, vertexId);
                // if the vertex represents a valid geospatial shape, record it
                boolean shapeFound = false;
                if ((!selectedOnly || vertexSelected) && StringUtils.isNotBlank(vertexShape) && Shape.isValidGeoJson(vertexShape)) {
                    shapes.put(vertexIdentifier, vertexShape);
                    shapeFound = true;
                } else if ((!selectedOnly || vertexSelected) && vertexLatitude != null && vertexLongitude != null) {
                    try {
                        final String vertexPoint = Shape.generateShape(vertexIdentifier, GeometryType.POINT, Arrays.asList(Tuple.create((double) vertexLongitude, (double) vertexLatitude)));
                        shapes.put(vertexIdentifier, vertexPoint);
                        shapeFound = true;
                    } catch (IOException ex) {
                        throw new PluginException(PluginNotificationLevel.ERROR, ex);
                    }
                } else {
                // Do nothing
                }
                // ... and record all its attributes
                if (shapeFound) {
                    final Map<String, Object> attributeMap = new HashMap<>();
                    for (final GraphAttribute graphAttribute : graphAttributes) {
                        final Object attributeValue = graph.getObjectValue(graphAttribute.getId(), vertexId);
                        attributeMap.put(graphAttribute.getName(), attributeValue);
                    }
                    attributes.put(vertexIdentifier, attributeMap);
                }
            }
            break;
        case TRANSACTION:
            final int transactionCount = graph.getTransactionCount();
            for (int transactionPosition = 0; transactionPosition < transactionCount; transactionPosition++) {
                final int transactionId = graph.getTransaction(transactionPosition);
                final boolean transactionSelected = graph.getBooleanValue(transactionSelectedAttributeId, transactionId);
                final String transactionIdentifier = graph.getStringValue(transactionIdentifierAttributeId, transactionId);
                final Float transactionLatitude = transactionLatitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(transactionLatitudeAttributeId, transactionId);
                final Float transactionLongitude = transactionLongitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(transactionLongitudeAttributeId, transactionId);
                final String transactionShape = transactionShapeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getStringValue(transactionShapeAttributeId, transactionId);
                final int sourceVertexId = graph.getTransactionSourceVertex(transactionId);
                final String sourceVertexIdentifier = graph.getStringValue(vertexIdentifierAttributeId, sourceVertexId);
                final Float sourceVertexLatitude = vertexLatitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(vertexLatitudeAttributeId, sourceVertexId);
                final Float sourceVertexLongitude = vertexLongitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(vertexLongitudeAttributeId, sourceVertexId);
                final String sourceVertexShape = vertexShapeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getStringValue(vertexShapeAttributeId, sourceVertexId);
                final int destinationVertexId = graph.getTransactionDestinationVertex(transactionId);
                final String destinationVertexIdentifier = graph.getStringValue(vertexIdentifierAttributeId, destinationVertexId);
                final Float destinationVertexLatitude = vertexLatitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(vertexLatitudeAttributeId, destinationVertexId);
                final Float destinationVertexLongitude = vertexLongitudeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getObjectValue(vertexLongitudeAttributeId, destinationVertexId);
                final String destinationVertexShape = vertexShapeAttributeId == GraphConstants.NOT_FOUND ? null : graph.getStringValue(vertexShapeAttributeId, destinationVertexId);
                // if the transaction represents a valid geospatial shape, record it
                boolean shapeFound = false;
                if ((!selectedOnly || transactionSelected) && StringUtils.isNotBlank(transactionShape) && Shape.isValidGeoJson(transactionShape)) {
                    shapes.put(transactionIdentifier, transactionShape);
                    shapeFound = true;
                } else if ((!selectedOnly || transactionSelected) && transactionLatitude != null && transactionLongitude != null) {
                    try {
                        final String transactionPoint = Shape.generateShape(transactionIdentifier, GeometryType.POINT, Arrays.asList(Tuple.create((double) transactionLongitude, (double) transactionLatitude)));
                        shapes.put(transactionIdentifier, transactionPoint);
                        shapeFound = true;
                    } catch (IOException ex) {
                        throw new PluginException(PluginNotificationLevel.ERROR, ex);
                    }
                } else {
                // Do nothing
                }
                // ... and record all its attributes
                if (shapeFound) {
                    final Map<String, Object> attributeMap = new HashMap<>();
                    final int transactionAttributeCount = graph.getAttributeCount(GraphElementType.TRANSACTION);
                    for (int transactionAttributePosition = 0; transactionAttributePosition < transactionAttributeCount; transactionAttributePosition++) {
                        final int transactionAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, transactionAttributePosition);
                        final String transactionAttributeName = graph.getAttributeName(transactionAttributeId);
                        if (Character.isUpperCase(transactionAttributeName.charAt(0))) {
                            final Object transactionAttributeValue = graph.getObjectValue(transactionAttributeId, transactionId);
                            attributeMap.put(GraphRecordStoreUtilities.TRANSACTION + transactionAttributeName, transactionAttributeValue);
                        }
                    }
                    final int vertexAttributeCount = graph.getAttributeCount(GraphElementType.VERTEX);
                    for (int vertexAttributePosition = 0; vertexAttributePosition < vertexAttributeCount; vertexAttributePosition++) {
                        final int vertexAttributeId = graph.getAttribute(GraphElementType.VERTEX, vertexAttributePosition);
                        final String sourceVertexAttributeName = graph.getAttributeName(vertexAttributeId);
                        if (Character.isUpperCase(sourceVertexAttributeName.charAt(0))) {
                            final Object sourceVertexAttributeValue = graph.getObjectValue(vertexAttributeId, sourceVertexId);
                            attributeMap.put(GraphRecordStoreUtilities.SOURCE + sourceVertexAttributeName, sourceVertexAttributeValue);
                        }
                        final String destinationVertexAttributeName = graph.getAttributeName(vertexAttributeId);
                        if (Character.isUpperCase(destinationVertexAttributeName.charAt(0))) {
                            final Object destinationVertexAttributeValue = graph.getObjectValue(vertexAttributeId, destinationVertexId);
                            attributeMap.put(GraphRecordStoreUtilities.DESTINATION + destinationVertexAttributeName, destinationVertexAttributeValue);
                        }
                    }
                    attributes.put(transactionIdentifier, attributeMap);
                }
                // if the source vertex represents a valid geospatial shape, record it
                shapeFound = false;
                if ((!selectedOnly || transactionSelected) && StringUtils.isNotBlank(sourceVertexShape) && Shape.isValidGeoJson(sourceVertexShape)) {
                    shapes.put(sourceVertexIdentifier, sourceVertexShape);
                    shapeFound = true;
                } else if ((!selectedOnly || transactionSelected) && sourceVertexLatitude != null && sourceVertexLongitude != null) {
                    try {
                        final String vertexPoint = Shape.generateShape(sourceVertexIdentifier, GeometryType.POINT, Arrays.asList(Tuple.create((double) sourceVertexLongitude, (double) sourceVertexLatitude)));
                        shapes.put(sourceVertexIdentifier, vertexPoint);
                        shapeFound = true;
                    } catch (IOException ex) {
                        throw new PluginException(PluginNotificationLevel.ERROR, ex);
                    }
                } else {
                // Do nothing
                }
                // ... and record all its attributes
                if (shapeFound) {
                    final Map<String, Object> attributeMap = new HashMap<>();
                    final int transactionAttributeCount = graph.getAttributeCount(GraphElementType.TRANSACTION);
                    for (int transactionAttributePosition = 0; transactionAttributePosition < transactionAttributeCount; transactionAttributePosition++) {
                        final int transactionAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, transactionAttributePosition);
                        final String transactionAttributeName = graph.getAttributeName(transactionAttributeId);
                        if (Character.isUpperCase(transactionAttributeName.charAt(0))) {
                            final Object transactionAttributeValue = graph.getObjectValue(transactionAttributeId, transactionId);
                            attributeMap.put(GraphRecordStoreUtilities.TRANSACTION + transactionAttributeName, transactionAttributeValue);
                        }
                    }
                    final int vertexAttributeCount = graph.getAttributeCount(GraphElementType.VERTEX);
                    for (int vertexAttributePosition = 0; vertexAttributePosition < vertexAttributeCount; vertexAttributePosition++) {
                        final int vertexAttributeId = graph.getAttribute(GraphElementType.VERTEX, vertexAttributePosition);
                        final String sourceVertexAttributeName = graph.getAttributeName(vertexAttributeId);
                        if (Character.isUpperCase(sourceVertexAttributeName.charAt(0))) {
                            final Object sourceVertexAttributeValue = graph.getObjectValue(vertexAttributeId, sourceVertexId);
                            attributeMap.put(GraphRecordStoreUtilities.SOURCE + sourceVertexAttributeName, sourceVertexAttributeValue);
                        }
                        final String destinationVertexAttributeName = graph.getAttributeName(vertexAttributeId);
                        if (Character.isUpperCase(destinationVertexAttributeName.charAt(0))) {
                            final Object destinationVertexAttributeValue = graph.getObjectValue(vertexAttributeId, destinationVertexId);
                            attributeMap.put(GraphRecordStoreUtilities.DESTINATION + destinationVertexAttributeName, destinationVertexAttributeValue);
                        }
                    }
                    attributes.put(sourceVertexIdentifier, attributeMap);
                }
                // if the destination vertex represents a valid geospatial shape, record it
                shapeFound = false;
                if ((!selectedOnly || transactionSelected) && StringUtils.isNotBlank(destinationVertexShape) && Shape.isValidGeoJson(destinationVertexShape)) {
                    shapes.put(destinationVertexIdentifier, destinationVertexShape);
                    shapeFound = true;
                } else if ((!selectedOnly || transactionSelected) && destinationVertexLatitude != null && destinationVertexLongitude != null) {
                    try {
                        final String vertexPoint = Shape.generateShape(destinationVertexIdentifier, GeometryType.POINT, Arrays.asList(Tuple.create((double) destinationVertexLongitude, (double) destinationVertexLatitude)));
                        shapes.put(destinationVertexIdentifier, vertexPoint);
                        shapeFound = true;
                    } catch (IOException ex) {
                        throw new PluginException(PluginNotificationLevel.ERROR, ex);
                    }
                } else {
                // Do nothing
                }
                // ... and record all its attributes
                if (shapeFound) {
                    final Map<String, Object> attributeMap = new HashMap<>();
                    final int transactionAttributeCount = graph.getAttributeCount(GraphElementType.TRANSACTION);
                    for (int transactionAttributePosition = 0; transactionAttributePosition < transactionAttributeCount; transactionAttributePosition++) {
                        final int transactionAttributeId = graph.getAttribute(GraphElementType.TRANSACTION, transactionAttributePosition);
                        final String transactionAttributeName = graph.getAttributeName(transactionAttributeId);
                        if (Character.isUpperCase(transactionAttributeName.charAt(0))) {
                            final Object transactionAttributeValue = graph.getObjectValue(transactionAttributeId, transactionId);
                            attributeMap.put(GraphRecordStoreUtilities.TRANSACTION + transactionAttributeName, transactionAttributeValue);
                        }
                    }
                    final int vertexAttributeCount = graph.getAttributeCount(GraphElementType.VERTEX);
                    for (int vertexAttributePosition = 0; vertexAttributePosition < vertexAttributeCount; vertexAttributePosition++) {
                        final int vertexAttributeId = graph.getAttribute(GraphElementType.VERTEX, vertexAttributePosition);
                        final String sourceVertexAttributeName = graph.getAttributeName(vertexAttributeId);
                        if (Character.isUpperCase(sourceVertexAttributeName.charAt(0))) {
                            final Object sourceVertexAttributeValue = graph.getObjectValue(vertexAttributeId, sourceVertexId);
                            attributeMap.put(GraphRecordStoreUtilities.SOURCE + sourceVertexAttributeName, sourceVertexAttributeValue);
                        }
                        final String destinationVertexAttributeName = graph.getAttributeName(vertexAttributeId);
                        if (Character.isUpperCase(destinationVertexAttributeName.charAt(0))) {
                            final Object destinationVertexAttributeValue = graph.getObjectValue(vertexAttributeId, destinationVertexId);
                            attributeMap.put(GraphRecordStoreUtilities.DESTINATION + destinationVertexAttributeName, destinationVertexAttributeValue);
                        }
                    }
                    attributes.put(destinationVertexIdentifier, attributeMap);
                }
            }
            break;
        default:
            throw new PluginException(PluginNotificationLevel.ERROR, "Invalid element type");
    }
    try {
        exportGeo(parameters, GraphNode.getGraphNode(graph.getId()).getDisplayName(), shapes, attributes, output);
    } catch (IOException ex) {
        throw new PluginException(PluginNotificationLevel.ERROR, ex);
    }
    ConstellationLoggerHelper.exportPropertyBuilder(this, GraphRecordStoreUtilities.getVertices(graph, false, false, false).getAll(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), output, ConstellationLoggerHelper.SUCCESS);
}
Also used : Arrays(java.util.Arrays) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) GraphAttributeParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.GraphAttributeParameterValue) ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) SingleChoiceParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) SimpleReadPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleReadPlugin) SpatialConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.SpatialConcept) HashMap(java.util.HashMap) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) StringUtils(org.apache.commons.lang3.StringUtils) GraphConstants(au.gov.asd.tac.constellation.graph.GraphConstants) ArrayList(java.util.ArrayList) Graph(au.gov.asd.tac.constellation.graph.Graph) FileParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.FileParameterType.FileParameterValue) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) Shape(au.gov.asd.tac.constellation.utilities.geospatial.Shape) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Map(java.util.Map) GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) OUTPUT_PARAMETER_ID(au.gov.asd.tac.constellation.plugins.importexport.geospatial.AbstractGeoExportPlugin.OUTPUT_PARAMETER_ID) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ELEMENT_TYPE_PARAMETER_ID(au.gov.asd.tac.constellation.plugins.importexport.geospatial.AbstractGeoExportPlugin.ELEMENT_TYPE_PARAMETER_ID) ElementTypeParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ElementTypeParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) FileParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.FileParameterType) MultiChoiceParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) ParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ParameterValue) IOException(java.io.IOException) GraphRecordStoreUtilities(au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) Collectors(java.util.stream.Collectors) File(java.io.File) BooleanParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType) PluginNotificationLevel(au.gov.asd.tac.constellation.plugins.PluginNotificationLevel) List(java.util.List) NotifyDescriptor(org.openide.NotifyDescriptor) NotifyDisplayer(au.gov.asd.tac.constellation.utilities.gui.NotifyDisplayer) ConstellationLoggerHelper(au.gov.asd.tac.constellation.plugins.logging.ConstellationLoggerHelper) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) GeometryType(au.gov.asd.tac.constellation.utilities.geospatial.Shape.GeometryType) ExtensionFilter(javafx.stage.FileChooser.ExtensionFilter) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) Collections(java.util.Collections) HashMap(java.util.HashMap) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) IOException(java.io.IOException) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with GraphAttribute

use of au.gov.asd.tac.constellation.graph.GraphAttribute in project constellation by constellation-app.

the class AbstractGeoExportPlugin method createParameters.

@Override
// the fallthrough at the switch statement is intentional
@SuppressWarnings("fallthrough")
public PluginParameters createParameters() {
    final PluginParameters parameters = new PluginParameters();
    final PluginParameter<FileParameterValue> outputParameter = FileParameterType.build(OUTPUT_PARAMETER_ID);
    outputParameter.setName("Output File");
    outputParameter.setDescription("The name of the output file");
    FileParameterType.setKind(outputParameter, FileParameterType.FileParameterKind.SAVE);
    FileParameterType.setFileFilters(outputParameter, getExportType());
    parameters.addParameter(outputParameter);
    if (includeSpatialReference()) {
        final PluginParameter<SingleChoiceParameterValue> spatialReferenceParameter = SingleChoiceParameterType.build(SPATIAL_REFERENCE_PARAMETER_ID, SpatialReferenceParameterValue.class);
        spatialReferenceParameter.setName("Spatial Reference");
        spatialReferenceParameter.setDescription("The spatial reference to use for the geopackage");
        final List<SpatialReferenceParameterValue> spatialReferences = Arrays.asList(Shape.SpatialReference.values()).stream().map(spatialReference -> new SpatialReferenceParameterValue(spatialReference)).collect(Collectors.toList());
        SingleChoiceParameterType.setOptionsData(spatialReferenceParameter, spatialReferences);
        SingleChoiceParameterType.setChoiceData(spatialReferenceParameter, spatialReferences.get(0));
        parameters.addParameter(spatialReferenceParameter);
    }
    final PluginParameter<SingleChoiceParameterValue> elementTypeParameter = SingleChoiceParameterType.build(ELEMENT_TYPE_PARAMETER_ID, ElementTypeParameterValue.class);
    elementTypeParameter.setName("Element Type");
    elementTypeParameter.setDescription("The graph element type");
    final List<ElementTypeParameterValue> elementTypes = new ArrayList<>();
    elementTypes.add(new ElementTypeParameterValue(GraphElementType.TRANSACTION));
    elementTypes.add(new ElementTypeParameterValue(GraphElementType.VERTEX));
    SingleChoiceParameterType.setOptionsData(elementTypeParameter, elementTypes);
    parameters.addParameter(elementTypeParameter);
    final PluginParameter<MultiChoiceParameterValue> attributesParameter = MultiChoiceParameterType.build(ATTRIBUTES_PARAMETER_ID, GraphAttributeParameterValue.class);
    attributesParameter.setName("Attributes");
    attributesParameter.setDescription("The list of attribute names to include in the export");
    attributesParameter.setEnabled(false);
    parameters.addParameter(attributesParameter);
    final PluginParameter<BooleanParameterValue> selectedOnlyParameter = BooleanParameterType.build(SELECTED_ONLY_PARAMETER_ID);
    selectedOnlyParameter.setName("Selected Only");
    selectedOnlyParameter.setDescription("If True, only export the selected nodes. The default is False.");
    selectedOnlyParameter.setBooleanValue(false);
    parameters.addParameter(selectedOnlyParameter);
    parameters.addController(ELEMENT_TYPE_PARAMETER_ID, (master, params, change) -> {
        if (change == ParameterChange.VALUE) {
            final Graph activeGraph = GraphManager.getDefault().getActiveGraph();
            if (activeGraph != null) {
                // create options by getting attributes for the chosen element type from the graph
                final List<GraphAttributeParameterValue> attributeOptions = new ArrayList<>();
                final ReadableGraph readableGraph = activeGraph.getReadableGraph();
                try {
                    final ParameterValue pv = params.get(master.getId()).getSingleChoice();
                    assert (pv instanceof ElementTypeParameterValue);
                    final GraphElementType elementType = ((ElementTypeParameterValue) pv).getGraphElementType();
                    switch(elementType) {
                        case TRANSACTION:
                            final int transactionAttributeCount = readableGraph.getAttributeCount(GraphElementType.TRANSACTION);
                            for (int attributePosition = 0; attributePosition < transactionAttributeCount; attributePosition++) {
                                final int attributeId = readableGraph.getAttribute(GraphElementType.TRANSACTION, attributePosition);
                                final GraphAttribute graphAttribute = new GraphAttribute(readableGraph, attributeId);
                                attributeOptions.add(new GraphAttributeParameterValue(graphAttribute));
                            }
                        // fall through
                        case VERTEX:
                            final int vertexAttributeCount = readableGraph.getAttributeCount(GraphElementType.VERTEX);
                            for (int attributePosition = 0; attributePosition < vertexAttributeCount; attributePosition++) {
                                final int attributeId = readableGraph.getAttribute(GraphElementType.VERTEX, attributePosition);
                                final GraphAttribute graphAttribute = new GraphAttribute(readableGraph, attributeId);
                                attributeOptions.add(new GraphAttributeParameterValue(graphAttribute));
                            }
                            break;
                        default:
                            return;
                    }
                } finally {
                    readableGraph.release();
                }
                // create choices by deselecting lowercase attributes by default
                final List<GraphAttributeParameterValue> attributeChoices = attributeOptions.stream().filter(attributeOption -> !((GraphAttribute) attributeOption.getObjectValue()).getName().matches("[a-z]{1}.*")).collect(Collectors.toList());
                // sort options and choices lists
                Collections.sort(attributeOptions);
                Collections.sort(attributeChoices);
                // update attributes parameter
                // Attrbutes_Parameter is created as a MultiChoice parameter in this class on line 137.
                @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> updatedAttributesParameter = (PluginParameter<MultiChoiceParameterValue>) params.get(ATTRIBUTES_PARAMETER_ID);
                MultiChoiceParameterType.setOptionsData(updatedAttributesParameter, attributeOptions);
                MultiChoiceParameterType.setChoicesData(updatedAttributesParameter, attributeChoices);
                updatedAttributesParameter.setEnabled(true);
            }
        }
    });
    return parameters;
}
Also used : Arrays(java.util.Arrays) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) GraphAttributeParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.GraphAttributeParameterValue) ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) SingleChoiceParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) SimpleReadPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleReadPlugin) SpatialConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.SpatialConcept) HashMap(java.util.HashMap) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) StringUtils(org.apache.commons.lang3.StringUtils) GraphConstants(au.gov.asd.tac.constellation.graph.GraphConstants) ArrayList(java.util.ArrayList) Graph(au.gov.asd.tac.constellation.graph.Graph) FileParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.FileParameterType.FileParameterValue) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) Shape(au.gov.asd.tac.constellation.utilities.geospatial.Shape) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Map(java.util.Map) GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) GraphManager(au.gov.asd.tac.constellation.graph.manager.GraphManager) OUTPUT_PARAMETER_ID(au.gov.asd.tac.constellation.plugins.importexport.geospatial.AbstractGeoExportPlugin.OUTPUT_PARAMETER_ID) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ELEMENT_TYPE_PARAMETER_ID(au.gov.asd.tac.constellation.plugins.importexport.geospatial.AbstractGeoExportPlugin.ELEMENT_TYPE_PARAMETER_ID) ElementTypeParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ElementTypeParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) FileParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.FileParameterType) MultiChoiceParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) ParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ParameterValue) IOException(java.io.IOException) GraphRecordStoreUtilities(au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) Collectors(java.util.stream.Collectors) File(java.io.File) BooleanParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType) PluginNotificationLevel(au.gov.asd.tac.constellation.plugins.PluginNotificationLevel) List(java.util.List) NotifyDescriptor(org.openide.NotifyDescriptor) NotifyDisplayer(au.gov.asd.tac.constellation.utilities.gui.NotifyDisplayer) ConstellationLoggerHelper(au.gov.asd.tac.constellation.plugins.logging.ConstellationLoggerHelper) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) GeometryType(au.gov.asd.tac.constellation.utilities.geospatial.Shape.GeometryType) ExtensionFilter(javafx.stage.FileChooser.ExtensionFilter) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) Collections(java.util.Collections) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ElementTypeParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ElementTypeParameterValue) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) ArrayList(java.util.ArrayList) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) GraphAttributeParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.GraphAttributeParameterValue) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) FileParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.FileParameterType.FileParameterValue) ElementTypeParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ElementTypeParameterValue) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) ParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ParameterValue) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) GraphAttributeParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.GraphAttributeParameterValue) FileParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.FileParameterType.FileParameterValue) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) Graph(au.gov.asd.tac.constellation.graph.Graph) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Aggregations

GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)65 Attribute (au.gov.asd.tac.constellation.graph.Attribute)45 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)25 ArrayList (java.util.ArrayList)25 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)19 HashMap (java.util.HashMap)16 Test (org.testng.annotations.Test)15 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)10 FindRule (au.gov.asd.tac.constellation.views.find.advanced.FindRule)9 Graph (au.gov.asd.tac.constellation.graph.Graph)8 AdvancedFindPlugin (au.gov.asd.tac.constellation.views.find.advanced.AdvancedFindPlugin)8 FindResult (au.gov.asd.tac.constellation.views.find.advanced.FindResult)8 TopComponent (org.openide.windows.TopComponent)8 TableColumn (javafx.scene.control.TableColumn)6 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)5 List (java.util.List)5 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)4 Column (au.gov.asd.tac.constellation.views.tableview.api.Column)4 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)3 GraphRecordStoreUtilities (au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities)3