Search in sources :

Example 16 with PluginException

use of au.gov.asd.tac.constellation.plugins.PluginException in project constellation by constellation-app.

the class ManageTemplatesAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    final Plugin plugin = PluginRegistry.get(GraphNodePluginRegistry.MANAGE_TEMPLATES);
    final PluginParameters params = plugin.createParameters();
    final PluginParametersSwingDialog dialog = new PluginParametersSwingDialog(Bundle.CTL_ManageTemplatesAction(), params);
    dialog.showAndWait();
    if (PluginParametersDialog.OK.equals(dialog.getResult())) {
        Future<?> f = PluginExecution.withPlugin(plugin).withParameters(params).executeLater(null);
        PluginExecution.withPlugin(new SimplePlugin() {

            @Override
            public String getName() {
                return "Update Template Menu";
            }

            @Override
            protected void execute(final PluginGraphs graphs, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
                NewSchemaGraphAction.recreateTemplateMenuItems();
            }
        }).waitingFor(f).executeLater(null);
    }
}
Also used : PluginParametersSwingDialog(au.gov.asd.tac.constellation.plugins.gui.PluginParametersSwingDialog) PluginGraphs(au.gov.asd.tac.constellation.plugins.PluginGraphs) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) SimplePlugin(au.gov.asd.tac.constellation.plugins.templates.SimplePlugin)

Example 17 with PluginException

use of au.gov.asd.tac.constellation.plugins.PluginException in project constellation by constellation-app.

the class PlaceholderUtilities method collapsePlaceholders.

public static StoreGraph collapsePlaceholders(final StoreGraphRecordStore graph, final Record record, final DatumProcessor<Record, ?> rowProcessor, final Comparator<GraphVertex> dominanceComparator, final boolean cleanupGraph, final boolean debug) throws PluginException, InterruptedException {
    graph.complete();
    graph.validateKeys();
    GraphWrapper g = new GraphWrapper(graph);
    // remove all transactions with type 'unknown' and all nodes with identifier 'unknown'
    if (cleanupGraph) {
        g.streamTransactions().filter(transaction -> transaction.getTypeValue().equals(SchemaTransactionTypeUtilities.getDefaultType())).forEach(GraphTransaction::deferRemove);
        g.streamVertices().filter(vertex -> "unknown".equals(vertex.getStringValue(VisualConcept.VertexAttribute.IDENTIFIER))).forEach(GraphVertex::deferRemove);
        g.completeDeferred();
    }
    if (debug) {
        GraphOpener.getDefault().openGraph(new DualGraph(graph, true), rowProcessor.getClass().getSimpleName() + "-debug-stage1");
    }
    // connect all nodes with type 'placeholder'
    g.streamVertices().filter(v -> v.getTypeValue().equals(AnalyticConcept.VertexType.PLACEHOLDER)).map(v -> v.walkNeighbours(s -> s.getTransaction().getTypeValue().isSubTypeOf(AnalyticConcept.TransactionType.CORRELATION) && s.getDestinationVertex().getTypeValue().equals(AnalyticConcept.VertexType.PLACEHOLDER), true).map(GraphStep::getDestinationVertex).collect(Collectors.toSet())).distinct().forEach(c -> {
        String newIdentifier = c.stream().map(v -> v.getStringValue(VisualConcept.VertexAttribute.IDENTIFIER)).collect(Collectors.joining(SeparatorConstants.HYPHEN));
        c.stream().forEach(v -> {
            v.setStringValue(VisualConcept.VertexAttribute.IDENTIFIER, newIdentifier);
            v.completeWithSchema();
        });
    });
    g.validateKeys();
    if (debug) {
        GraphOpener.getDefault().openGraph(new DualGraph(graph, true), rowProcessor.getClass().getSimpleName() + "-debug-stage2");
    }
    // replace nodes with type 'placeholder' with the dominant correlated node
    g.streamVertices().filter(v -> v.getTypeValue().equals(AnalyticConcept.VertexType.PLACEHOLDER)).forEach(v -> {
        Optional<GraphVertex> dominant = v.streamNeighbours().filter(n -> n.getDirection() != GraphDirection.LOOPBACK).filter(n -> n.getTransaction().getTypeValue().isSubTypeOf(AnalyticConcept.TransactionType.CORRELATION)).map(n -> n.getDestinationVertex()).distinct().sorted(dominanceComparator).findFirst();
        // TODO: needed to create a special case for 'unknown' type vertices, but not sure why...
        if (dominant.isPresent() && !dominant.get().getTypeValue().equals(SchemaVertexTypeUtilities.getDefaultType())) {
            v.setStringValue(VisualConcept.VertexAttribute.IDENTIFIER, dominant.get().getStringValue(VisualConcept.VertexAttribute.IDENTIFIER));
            v.setTypeValue(dominant.get().getTypeValue());
            v.setRawValue(dominant.get().getRawValue());
            v.completeWithSchema();
        } else {
            v.deferRemove();
        }
    });
    g.completeDeferred();
    g.validateKeys();
    if (debug) {
        GraphOpener.getDefault().openGraph(new DualGraph(graph, true), rowProcessor.getClass().getSimpleName() + "-debug-stage3");
    }
    // remove transactions that correlate nodes with themselves
    g.streamTransactions().filter(t -> t.getTypeValue().isSubTypeOf(AnalyticConcept.TransactionType.CORRELATION)).filter(t -> t.getSourceVertex().equals(t.getDestinationVertex())).forEach(GraphTransaction::deferRemove);
    g.completeDeferred();
    return graph;
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) SchemaVertexTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities) DatumProcessor(au.gov.asd.tac.constellation.graph.processing.DatumProcessor) ProcessingException(au.gov.asd.tac.constellation.graph.processing.ProcessingException) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) SchemaTransactionTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities) GraphOpener(au.gov.asd.tac.constellation.graph.file.opener.GraphOpener) GraphVertex(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphVertex) HashMap(java.util.HashMap) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) ArrayList(java.util.ArrayList) Map(java.util.Map) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) GraphDirection(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphDirection) SeparatorConstants(au.gov.asd.tac.constellation.utilities.text.SeparatorConstants) GraphWrapper(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphWrapper) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) GraphRecordStoreUtilities(au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) Collectors(java.util.stream.Collectors) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphTransaction(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphTransaction) PluginNotificationLevel(au.gov.asd.tac.constellation.plugins.PluginNotificationLevel) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) GraphStep(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphStep) List(java.util.List) AnalyticConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept) Record(au.gov.asd.tac.constellation.graph.processing.Record) Optional(java.util.Optional) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) Comparator(java.util.Comparator) GraphVertex(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphVertex) GraphStep(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphStep) GraphWrapper(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphWrapper) GraphTransaction(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphTransaction) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph)

Example 18 with PluginException

use of au.gov.asd.tac.constellation.plugins.PluginException in project constellation by constellation-app.

the class PlaceholderUtilities method collapsePlaceholders.

public static void collapsePlaceholders(final GraphWriteMethods graph, final Comparator<SchemaVertexType> dominanceComparator, final boolean debug) throws PluginException, InterruptedException {
    final List<Integer> placeholderIds = new ArrayList<>();
    final Map<Integer, List<Integer>> placeholderCorrelations = new HashMap<>();
    final Map<Integer, List<Integer>> placeholderActivity = new HashMap<>();
    final Map<Integer, Integer> placeholderNeighbours = new HashMap<>();
    final int vertexTypeAttributeId = AnalyticConcept.VertexAttribute.TYPE.get(graph);
    final int transactionTypeAttributeId = AnalyticConcept.TransactionAttribute.TYPE.get(graph);
    // collect placeholders, their transactions and their neighbours
    final int vertexCount = graph.getVertexCount();
    for (int vertexPosition = 0; vertexPosition < vertexCount; vertexPosition++) {
        final int vertexId = graph.getVertex(vertexPosition);
        final SchemaVertexType vertexType = graph.getObjectValue(vertexTypeAttributeId, vertexId);
        if (vertexType.isSubTypeOf(AnalyticConcept.VertexType.PLACEHOLDER)) {
            placeholderIds.add(vertexId);
            final List<Integer> placeholderCorrelationList = new ArrayList<>();
            final List<Integer> placeholderActivityList = new ArrayList<>();
            final int transactionCount = graph.getVertexTransactionCount(vertexId);
            for (int transactionPosition = 0; transactionPosition < transactionCount; transactionPosition++) {
                final int transactionId = graph.getVertexTransaction(vertexId, transactionPosition);
                final SchemaTransactionType transactionType = graph.getObjectValue(transactionTypeAttributeId, transactionId);
                if (transactionType.isSubTypeOf(AnalyticConcept.TransactionType.CORRELATION)) {
                    placeholderCorrelationList.add(transactionId);
                } else {
                    placeholderActivityList.add(transactionId);
                }
                final int neighbourId = graph.getTransactionSourceVertex(transactionId) == vertexId ? graph.getTransactionDestinationVertex(transactionId) : graph.getTransactionSourceVertex(transactionId);
                placeholderNeighbours.put(transactionId, neighbourId);
            }
            placeholderCorrelations.put(vertexId, placeholderCorrelationList);
            placeholderActivity.put(vertexId, placeholderActivityList);
        }
    }
    if (debug) {
        GraphOpener.getDefault().openGraph(new DualGraph((StoreGraph) graph.copy(), true), GraphNode.getGraphNode(graph.getId()).getName() + "-debug-stage1");
    }
    // choose lead vertices to replace placeholders
    placeholderIds.forEach(placeholderId -> {
        final int leadVertex;
        final List<Integer> placeholderCorrelationList = placeholderCorrelations.get(placeholderId);
        if (!placeholderCorrelationList.isEmpty()) {
            // calculate lead vertex
            final SchemaVertexType leadVertexType = placeholderCorrelationList.stream().map(placeholderNeighbours::get).map(neighbourId -> (SchemaVertexType) graph.getObjectValue(vertexTypeAttributeId, neighbourId)).sorted(dominanceComparator).findFirst().get();
            leadVertex = placeholderCorrelationList.stream().map(placeholderNeighbours::get).filter(neighbourId -> graph.getObjectValue(vertexTypeAttributeId, neighbourId).equals(leadVertexType)).findFirst().get();
            // move correlations from the placeholder to the lead vertex of the entity
            placeholderCorrelationList.forEach(correlationId -> {
                if (graph.getTransactionSourceVertex(correlationId) == placeholderId && graph.getTransactionDestinationVertex(correlationId) != leadVertex) {
                    graph.setTransactionSourceVertex(correlationId, leadVertex);
                } else if (graph.getTransactionDestinationVertex(correlationId) == placeholderId && graph.getTransactionSourceVertex(correlationId) != leadVertex) {
                    graph.setTransactionDestinationVertex(correlationId, leadVertex);
                } else {
                // Do nothing
                }
            });
            // move activity from the placeholder to the lead vertex of the entity
            final List<Integer> placeholderActivityList = placeholderActivity.get(placeholderId);
            placeholderActivityList.forEach(activityId -> {
                if (graph.getTransactionSourceVertex(activityId) == placeholderId) {
                    graph.setTransactionSourceVertex(activityId, leadVertex);
                } else {
                    graph.setTransactionDestinationVertex(activityId, leadVertex);
                }
            });
        }
    });
    if (debug) {
        GraphOpener.getDefault().openGraph(new DualGraph((StoreGraph) graph.copy(), true), GraphNode.getGraphNode(graph.getId()).getName() + "-debug-stage2");
    }
    // remove all placeholders
    placeholderIds.forEach(graph::removeVertex);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) SchemaVertexTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities) DatumProcessor(au.gov.asd.tac.constellation.graph.processing.DatumProcessor) ProcessingException(au.gov.asd.tac.constellation.graph.processing.ProcessingException) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) SchemaTransactionTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities) GraphOpener(au.gov.asd.tac.constellation.graph.file.opener.GraphOpener) GraphVertex(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphVertex) HashMap(java.util.HashMap) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) ArrayList(java.util.ArrayList) Map(java.util.Map) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) GraphDirection(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphDirection) SeparatorConstants(au.gov.asd.tac.constellation.utilities.text.SeparatorConstants) GraphWrapper(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphWrapper) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) GraphRecordStoreUtilities(au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) Collectors(java.util.stream.Collectors) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphTransaction(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphTransaction) PluginNotificationLevel(au.gov.asd.tac.constellation.plugins.PluginNotificationLevel) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) GraphStep(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphStep) List(java.util.List) AnalyticConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept) Record(au.gov.asd.tac.constellation.graph.processing.Record) Optional(java.util.Optional) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) Comparator(java.util.Comparator) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) ArrayList(java.util.ArrayList) List(java.util.List) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph)

Example 19 with PluginException

use of au.gov.asd.tac.constellation.plugins.PluginException 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 20 with PluginException

use of au.gov.asd.tac.constellation.plugins.PluginException in project constellation by constellation-app.

the class CutToClipboardPlugin method edit.

@Override
protected void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    // Do a copy to the clipboard.
    final String text = GraphCopyUtilities.copyGraphTextToSystemClipboard(wg);
    ConstellationLoggerHelper.copyPropertyBuilder(this, text.length(), ConstellationLoggerHelper.SUCCESS);
    final BitSet[] selectedElements = GraphCopyUtilities.copySelectedGraphElementsToClipboard(wg);
    final BitSet vxCopied = selectedElements[0];
    final BitSet txCopied = selectedElements[1];
    if (vxCopied != null && txCopied != null) {
        // Delete the elements that were copied.
        for (int id = vxCopied.nextSetBit(0); id >= 0; id = vxCopied.nextSetBit(id + 1)) {
            wg.removeVertex(id);
        }
        for (int id = txCopied.nextSetBit(0); id >= 0; id = txCopied.nextSetBit(id + 1)) {
            if (wg.transactionExists(id)) {
                wg.removeTransaction(id);
            }
        }
        final String msg = Bundle.MSG_Cut(vxCopied.cardinality(), txCopied.cardinality());
        final StatusDisplayer statusDisplayer = StatusDisplayer.getDefault();
        if (statusDisplayer != null) {
            statusDisplayer.setStatusText(msg);
        }
    } else {
        throw new PluginException(PluginNotificationLevel.ERROR, "Failed to copy selection to the clipboard");
    }
}
Also used : StatusDisplayer(org.openide.awt.StatusDisplayer) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) BitSet(java.util.BitSet)

Aggregations

PluginException (au.gov.asd.tac.constellation.plugins.PluginException)60 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)28 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)23 Graph (au.gov.asd.tac.constellation.graph.Graph)21 ArrayList (java.util.ArrayList)20 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)19 Test (org.testng.annotations.Test)16 GraphRecordStore (au.gov.asd.tac.constellation.graph.processing.GraphRecordStore)14 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)12 IOException (java.io.IOException)12 List (java.util.List)12 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)10 WritableGraph (au.gov.asd.tac.constellation.graph.WritableGraph)10 File (java.io.File)10 PluginNotificationLevel (au.gov.asd.tac.constellation.plugins.PluginNotificationLevel)9 Map (java.util.Map)9 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)8 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)8 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)8 PluginGraphs (au.gov.asd.tac.constellation.plugins.PluginGraphs)8