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);
}
}
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);
}
}
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();
}
}
}
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();
}
}
Aggregations