Search in sources :

Example 1 with VertexListInclusionGraph

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

the class RecordStoreQueryPlugin method edit.

@Override
protected void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    for (final RecordStoreValidator validator : getValidators()) {
        validator.validatePreEdit(this, result, wg, interaction, parameters);
    }
    if (result != null) {
        // TODO: try to see if its worth setting this to init with schema to true - it did cause issues with it sometimes generating vertex # nodes
        final List<Integer> newVertices = GraphRecordStoreUtilities.addRecordStoreToGraph(wg, result, false, true, null);
        wg.validateKey(GraphElementType.VERTEX, true);
        wg.validateKey(GraphElementType.TRANSACTION, true);
        // Only arrange if there are new vertices, otherwise everything will be arranged.
        if (!newVertices.isEmpty()) {
            final PluginExecutor arrangement = completionArrangement();
            if (arrangement != null) {
                final float[] xOriginal = new float[wg.getVertexCount()];
                final float[] yOriginal = new float[wg.getVertexCount()];
                final float[] zOriginal = new float[wg.getVertexCount()];
                // save original positions
                if (wg.isRecordingEdit()) {
                    saveOriginalPositionCoordinates(wg, xOriginal, yOriginal, zOriginal);
                }
                // run the arrangement
                final VertexListInclusionGraph vlGraph = new VertexListInclusionGraph(wg, Connections.NONE, newVertices);
                arrangement.executeNow(vlGraph.getInclusionGraph());
                vlGraph.retrieveCoords();
                // restore the original positions
                if (wg.isRecordingEdit()) {
                    restoreOriginalPositionCoordinates(wg, xOriginal, yOriginal, zOriginal);
                }
            }
        }
        // Reset the view
        PluginExecutor.startWith(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(wg);
    }
}
Also used : PluginExecutor(au.gov.asd.tac.constellation.plugins.PluginExecutor) VertexListInclusionGraph(au.gov.asd.tac.constellation.plugins.arrangements.VertexListInclusionGraph)

Example 2 with VertexListInclusionGraph

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

the class SplitNodesPlugin method edit.

@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final Map<String, PluginParameter<?>> splitParameters = parameters.getParameters();
    final String character = splitParameters.get(SPLIT_PARAMETER_ID) != null && splitParameters.get(SPLIT_PARAMETER_ID).getStringValue() != null ? splitParameters.get(SPLIT_PARAMETER_ID).getStringValue() : "";
    final ParameterValue transactionTypeChoice = splitParameters.get(TRANSACTION_TYPE_PARAMETER_ID).getSingleChoice();
    final String linkType = transactionTypeChoice != null ? transactionTypeChoice.toString() : AnalyticConcept.TransactionType.CORRELATION.getName();
    final boolean allOccurrences = splitParameters.get(ALL_OCCURRENCES_PARAMETER_ID).getBooleanValue();
    final boolean splitIntoSameLevel = splitParameters.get(DUPLICATE_TRANSACTIONS_PARAMETER_ID).getBooleanValue();
    final int vertexSelectedAttributeId = VisualConcept.VertexAttribute.SELECTED.ensure(graph);
    final int vertexIdentifierAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
    final List<Integer> newVertices = new ArrayList<>();
    final int graphVertexCount = graph.getVertexCount();
    for (int position = 0; position < graphVertexCount; position++) {
        final int currentVertexId = graph.getVertex(position);
        if (graph.getBooleanValue(vertexSelectedAttributeId, currentVertexId)) {
            final String identifier = graph.getStringValue(vertexIdentifierAttributeId, currentVertexId);
            if (identifier != null && identifier.contains(character) && identifier.indexOf(character) < identifier.length() - character.length()) {
                String leftNodeIdentifier = "";
                if (allOccurrences) {
                    final String[] substrings = Arrays.stream(identifier.split(character)).filter(value -> value != null && value.length() > 0).toArray(size -> new String[size]);
                    if (substrings.length <= 0) {
                        continue;
                    }
                    leftNodeIdentifier = substrings[0];
                    for (int i = 1; i < substrings.length; i++) {
                        newVertices.add(createNewNode(graph, position, substrings[i], linkType, splitIntoSameLevel));
                    }
                } else {
                    final int i = identifier.indexOf(character);
                    leftNodeIdentifier = identifier.substring(0, i);
                    if (StringUtils.isNotBlank(leftNodeIdentifier)) {
                        newVertices.add(createNewNode(graph, position, identifier.substring(i + 1), linkType, splitIntoSameLevel));
                    } else {
                        leftNodeIdentifier = identifier.substring(i + 1);
                    }
                }
                // Rename the selected node
                if (StringUtils.isNotBlank(leftNodeIdentifier)) {
                    graph.setStringValue(vertexIdentifierAttributeId, currentVertexId, leftNodeIdentifier);
                    newVertices.add(currentVertexId);
                }
            }
        }
    }
    if (!newVertices.isEmpty()) {
        // Reset the view
        graph.validateKey(GraphElementType.VERTEX, true);
        graph.validateKey(GraphElementType.TRANSACTION, true);
        final PluginExecutor arrangement = completionArrangement();
        if (arrangement != null) {
            // run the arrangement
            final VertexListInclusionGraph vlGraph = new VertexListInclusionGraph(graph, AbstractInclusionGraph.Connections.NONE, newVertices);
            arrangement.executeNow(vlGraph.getInclusionGraph());
            vlGraph.retrieveCoords();
        }
        if (splitParameters.get(COMPLETE_WITH_SCHEMA_OPTION_ID).getBooleanValue()) {
            PluginExecution.withPlugin(VisualSchemaPluginRegistry.COMPLETE_SCHEMA).executeNow(graph);
        }
        PluginExecutor.startWith(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(graph);
    }
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) Arrays(java.util.Arrays) StringParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterType) SchemaTransactionTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities) ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) SingleChoiceParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType) SimpleEditPlugin(au.gov.asd.tac.constellation.plugins.templates.SimpleEditPlugin) PluginType(au.gov.asd.tac.constellation.plugins.PluginType) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Graph(au.gov.asd.tac.constellation.graph.Graph) ArrangementPluginRegistry(au.gov.asd.tac.constellation.plugins.arrangements.ArrangementPluginRegistry) DataAccessPlugin(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPlugin) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) ServiceProviders(org.openide.util.lookup.ServiceProviders) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Map(java.util.Map) ServiceProvider(org.openide.util.lookup.ServiceProvider) PluginExecutor(au.gov.asd.tac.constellation.plugins.PluginExecutor) PluginTags(au.gov.asd.tac.constellation.plugins.templates.PluginTags) StringParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) AbstractInclusionGraph(au.gov.asd.tac.constellation.plugins.arrangements.AbstractInclusionGraph) VertexListInclusionGraph(au.gov.asd.tac.constellation.plugins.arrangements.VertexListInclusionGraph) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) InteractiveGraphPluginRegistry(au.gov.asd.tac.constellation.graph.interaction.InteractiveGraphPluginRegistry) 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) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) BooleanParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType) PluginInfo(au.gov.asd.tac.constellation.plugins.PluginInfo) List(java.util.List) AnalyticConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept) VisualSchemaPluginRegistry(au.gov.asd.tac.constellation.graph.schema.visual.VisualSchemaPluginRegistry) DataAccessPluginCoreType(au.gov.asd.tac.constellation.views.dataaccess.plugins.DataAccessPluginCoreType) NbBundle(org.openide.util.NbBundle) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) StringParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue) 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) ArrayList(java.util.ArrayList) PluginExecutor(au.gov.asd.tac.constellation.plugins.PluginExecutor) VertexListInclusionGraph(au.gov.asd.tac.constellation.plugins.arrangements.VertexListInclusionGraph) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)

Example 3 with VertexListInclusionGraph

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

the class ImportJDBCPlugin method edit.

@Override
protected void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final JDBCConnection connection = (JDBCConnection) parameters.getParameters().get(CONNECTION_PARAMETER_ID).getObjectValue();
    final String query = parameters.getParameters().get(QUERY_PARAMETER_ID).getStringValue();
    final List<ImportDefinition> definitions = (List<ImportDefinition>) parameters.getParameters().get(DEFINITIONS_PARAMETER_ID).getObjectValue();
    final Boolean initialiseWithSchema = parameters.getParameters().get(SCHEMA_PARAMETER_ID).getBooleanValue();
    boolean positionalAtrributesExist = false;
    int totalImportedRows = 0;
    final String username = parameters.getParameters().get(USERNAME_PARAMETER_ID).getStringValue();
    final String password = parameters.getParameters().get(PASSWORD_PARAMETER_ID).getStringValue();
    if (connection != null && query != null && !query.isBlank()) {
        final List<String[]> data = new ArrayList<>();
        try {
            try (final Connection dbConnection = connection.getConnection(username, password)) {
                try (final PreparedStatement ps = dbConnection.prepareStatement(query)) {
                    try (final ResultSet rs = ps.executeQuery()) {
                        while (rs.next()) {
                            final String[] d = new String[ps.getMetaData().getColumnCount()];
                            for (int i = 0; i < ps.getMetaData().getColumnCount(); i++) {
                                d[i] = rs.getString(i + 1);
                            }
                            data.add(d);
                        }
                    }
                }
            }
        } catch (final MalformedURLException | ClassNotFoundException | SQLException | NoSuchMethodException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
            return;
        }
        for (final ImportDefinition definition : definitions) {
            if (definition.getDefinitions(AttributeType.SOURCE_VERTEX).isEmpty()) {
                if (!definition.getDefinitions(AttributeType.DESTINATION_VERTEX).isEmpty()) {
                    totalImportedRows += processVertices(definition, graph, data, AttributeType.DESTINATION_VERTEX, initialiseWithSchema, interaction);
                }
            } else if (definition.getDefinitions(AttributeType.DESTINATION_VERTEX).isEmpty()) {
                totalImportedRows += processVertices(definition, graph, data, AttributeType.SOURCE_VERTEX, initialiseWithSchema, interaction);
            } else {
                totalImportedRows += processTransactions(definition, graph, data, initialiseWithSchema, interaction);
            }
            // Determine if a positional attribute has been defined, if so update the overall flag
            final boolean isPositional = attributeDefintionIsPositional(definition.getDefinitions(AttributeType.SOURCE_VERTEX), definition.getDefinitions(AttributeType.DESTINATION_VERTEX));
            positionalAtrributesExist = (positionalAtrributesExist || isPositional);
        }
        displaySummaryAlert(totalImportedRows, data.size(), connection.getConnectionName());
        // the graph. This does mean some nodes could sit on top of each other if multiple nodes have the same coordinates.
        if (!positionalAtrributesExist) {
            interaction.setProgress(1, 1, "Arranging", true);
            graph.validateKey(GraphElementType.VERTEX, true);
            graph.validateKey(GraphElementType.TRANSACTION, true);
            // unfortunately need to arrange with pendants and uncollide because grid arranger works based on selection
            final VertexListInclusionGraph vlGraph = new VertexListInclusionGraph(graph, AbstractInclusionGraph.Connections.NONE, new ArrayList<>());
            PluginExecutor.startWith(ArrangementPluginRegistry.GRID_COMPOSITE).followedBy(ArrangementPluginRegistry.PENDANTS).followedBy(ArrangementPluginRegistry.UNCOLLIDE).followedBy(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(vlGraph.getInclusionGraph());
            vlGraph.retrieveCoords();
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ImportDefinition(au.gov.asd.tac.constellation.plugins.importexport.ImportDefinition) VertexListInclusionGraph(au.gov.asd.tac.constellation.plugins.arrangements.VertexListInclusionGraph) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with VertexListInclusionGraph

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

the class ImportDelimitedPlugin method edit.

@Override
protected void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    final ImportFileParser parser = (ImportFileParser) parameters.getParameters().get(PARSER_PARAMETER_ID).getObjectValue();
    // files will be a list of file which extends from object type
    @SuppressWarnings("unchecked") final List<File> files = (List<File>) parameters.getParameters().get(FILES_PARAMETER_ID).getObjectValue();
    // definitions will be a list of import defintions which extends from object type
    @SuppressWarnings("unchecked") final List<ImportDefinition> definitions = (List<ImportDefinition>) parameters.getParameters().get(DEFINITIONS_PARAMETER_ID).getObjectValue();
    final boolean initialiseWithSchema = parameters.getParameters().get(SCHEMA_PARAMETER_ID).getBooleanValue();
    final PluginParameters parserParameters = (PluginParameters) parameters.getParameters().get(PARSER_PARAMETER_IDS_PARAMETER_ID).getObjectValue();
    final boolean filesIncludeHeaders = parameters.getParameters().get(FILES_INCLUDE_HEADERS_PARAMETER_ID).getBooleanValue();
    boolean positionalAtrributesExist = false;
    final List<String> validFiles = new ArrayList<>();
    final List<String> emptyFiles = new ArrayList<>();
    final List<String> invalidFiles = new ArrayList<>();
    final List<String> emptyRunConfigs = new ArrayList<>();
    int totalRows = 0;
    int totalImportedRows = 0;
    int dataSize = 0;
    // a minimum) defined
    for (final ImportDefinition definition : definitions) {
        if (definition.getDefinitions(AttributeType.SOURCE_VERTEX).isEmpty() && definition.getDefinitions(AttributeType.DESTINATION_VERTEX).isEmpty()) {
            emptyRunConfigs.add(definition.getDefinitionName());
        }
    }
    for (final File file : files) {
        interaction.setProgress(0, 0, "Reading File: " + file.getName(), true);
        List<String[]> data = null;
        int importedRowsPerFile = 0;
        try {
            data = parser.parse(new InputSource(file), parserParameters);
            dataSize = filesIncludeHeaders ? data.size() - 1 : data.size();
            totalRows = totalRows + Integer.max(0, dataSize);
            if (dataSize > 0) {
                if (validFiles.isEmpty()) {
                    validFiles.add(file.getName().concat(" (").concat(Integer.toString(dataSize)).concat(" rows)"));
                } else {
                    validFiles.add(file.getName().concat(" (").concat(Integer.toString(dataSize)).concat(")"));
                }
            } else {
                emptyFiles.add(file.getName());
            }
        } catch (FileNotFoundException ex) {
            final String errorMsg = file.getPath() + " could not be found. Ignoring file during import.";
            LOGGER.log(Level.INFO, errorMsg);
            invalidFiles.add(file.getName());
        } catch (IOException ex) {
            final String errorMsg = file.getPath() + " could not be parsed. Removing file during import.";
            LOGGER.log(Level.INFO, errorMsg);
            invalidFiles.add(file.getName());
        }
        if (data != null) {
            for (final ImportDefinition definition : definitions) {
                if (definition.getDefinitions(AttributeType.SOURCE_VERTEX).isEmpty()) {
                    // Process destination vertexes if defintions are defined, otherwise there is nothing to do.
                    if (!definition.getDefinitions(AttributeType.DESTINATION_VERTEX).isEmpty()) {
                        importedRowsPerFile += processVertices(definition, graph, data, AttributeType.DESTINATION_VERTEX, initialiseWithSchema, interaction, file.getName());
                    }
                } else if (definition.getDefinitions(AttributeType.DESTINATION_VERTEX).isEmpty()) {
                    // Source defintions exist, but no destination definitions exist. Process the source definitions.
                    importedRowsPerFile += processVertices(definition, graph, data, AttributeType.SOURCE_VERTEX, initialiseWithSchema, interaction, file.getName());
                } else {
                    // Both source and destination defintions exist, process them.
                    importedRowsPerFile += processTransactions(definition, graph, data, initialiseWithSchema, interaction, file.getName());
                }
                // Determine if a positional attribute has been defined, if so update the overall flag
                final boolean isPositional = attributeDefintionIsPositional(definition.getDefinitions(AttributeType.SOURCE_VERTEX), definition.getDefinitions(AttributeType.DESTINATION_VERTEX));
                positionalAtrributesExist = (positionalAtrributesExist || isPositional);
            }
        }
        totalImportedRows += importedRowsPerFile;
        LOGGER.log(Level.INFO, "Imported {0} rows of data from file {1} containing {2} total rows", new Object[] { importedRowsPerFile, file.getPath(), dataSize });
    }
    displaySummaryAlert(graph.getVertexCount() + graph.getTransactionCount(), totalImportedRows, validFiles, emptyFiles, invalidFiles, emptyRunConfigs);
    ConstellationLoggerHelper.importPropertyBuilder(this, GraphRecordStoreUtilities.getVertices(graph, false, false, false).getAll(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), files, ConstellationLoggerHelper.SUCCESS);
    LOGGER.log(Level.INFO, "Auto arrangement use={0}", (!positionalAtrributesExist));
    // the graph. This does mean some nodes could sit on top of each other if multiple nodes have the same coordinates.
    if (!positionalAtrributesExist) {
        interaction.setProgress(1, 1, "Arranging", true);
        graph.validateKey(GraphElementType.VERTEX, true);
        graph.validateKey(GraphElementType.TRANSACTION, true);
        // unfortunately need to arrange with pendants and uncollide because grid arranger works based on selection
        final VertexListInclusionGraph vlGraph = new VertexListInclusionGraph(graph, AbstractInclusionGraph.Connections.NONE, new ArrayList<>());
        PluginExecutor.startWith(ArrangementPluginRegistry.GRID_COMPOSITE).followedBy(ArrangementPluginRegistry.PENDANTS).followedBy(ArrangementPluginRegistry.UNCOLLIDE).followedBy(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(vlGraph.getInclusionGraph());
        vlGraph.retrieveCoords();
    }
}
Also used : InputSource(au.gov.asd.tac.constellation.plugins.importexport.delimited.parser.InputSource) ImportFileParser(au.gov.asd.tac.constellation.plugins.importexport.delimited.parser.ImportFileParser) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ImportDefinition(au.gov.asd.tac.constellation.plugins.importexport.ImportDefinition) VertexListInclusionGraph(au.gov.asd.tac.constellation.plugins.arrangements.VertexListInclusionGraph) ArrayList(java.util.ArrayList) List(java.util.List) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) File(java.io.File)

Aggregations

VertexListInclusionGraph (au.gov.asd.tac.constellation.plugins.arrangements.VertexListInclusionGraph)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 PluginExecutor (au.gov.asd.tac.constellation.plugins.PluginExecutor)2 ImportDefinition (au.gov.asd.tac.constellation.plugins.importexport.ImportDefinition)2 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)1 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)1 InteractiveGraphPluginRegistry (au.gov.asd.tac.constellation.graph.interaction.InteractiveGraphPluginRegistry)1 AnalyticConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept)1 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)1 SchemaTransactionTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities)1 VisualSchemaPluginRegistry (au.gov.asd.tac.constellation.graph.schema.visual.VisualSchemaPluginRegistry)1 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)1 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)1 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)1 PluginExecution (au.gov.asd.tac.constellation.plugins.PluginExecution)1 PluginInfo (au.gov.asd.tac.constellation.plugins.PluginInfo)1 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)1