use of au.gov.asd.tac.constellation.views.dataaccess.plugins.clean.MergeNodeType.MergeException in project constellation by constellation-app.
the class MergeNodesPlugin method edit.
@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
int mergedCount = 0;
interaction.setProgress(0, 0, "Merging nodes...", true);
final String mergeNodeTypeName = parameters.getParameters().get(MERGE_TYPE_PARAMETER_ID).getStringValue();
if (mergeNodeTypeName == null) {
throw new PluginException(PluginNotificationLevel.ERROR, "Select a Merge By option.");
}
if (!MERGE_TYPES.containsKey(mergeNodeTypeName)) {
throw new PluginException(PluginNotificationLevel.FATAL, String.format("Merge node type %s not found.", mergeNodeTypeName));
}
final int threshold = parameters.getParameters().get(THRESHOLD_PARAMETER_ID).getIntegerValue();
final GraphElementMerger merger = MERGERS.get(parameters.getParameters().get(MERGER_PARAMETER_ID).getStringValue());
final Comparator<String> leadNodeChooser = VERTEX_CHOOSER.get(parameters.getParameters().get(LEAD_PARAMETER_ID).getStringValue());
final boolean selectedOnly = parameters.getParameters().get(SELECTED_PARAMETER_ID).getBooleanValue();
final MergeNodeType mergeNodeType = MERGE_TYPES.get(mergeNodeTypeName);
final Map<Integer, Set<Integer>> nodesToMerge;
try {
nodesToMerge = mergeNodeType.getNodesToMerge(graph, leadNodeChooser, threshold, selectedOnly);
} catch (MergeException ex) {
throw new PluginException(PluginNotificationLevel.ERROR, ex);
}
// perform the merge
for (final Map.Entry<Integer, Set<Integer>> entry : nodesToMerge.entrySet()) {
mergedCount += mergeVertices(graph, entry.getValue(), entry.getKey(), merger);
}
interaction.setProgress(1, 0, "Merged " + mergedCount + " nodes.", true);
PluginExecution.withPlugin(VisualSchemaPluginRegistry.COMPLETE_SCHEMA).executeNow(graph);
}
Aggregations