use of au.gov.asd.tac.constellation.views.dataaccess.plugins.clean.MergeTransactionType.MergeException in project constellation by constellation-app.
the class MergeTransactionsPlugin 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 transactions...", true);
final String mergeTransactionTypeName = parameters.getParameters().get(MERGE_TYPE_PARAMETER_ID).getStringValue();
if (mergeTransactionTypeName == null) {
throw new PluginException(PluginNotificationLevel.ERROR, "Select a Merge By option.");
}
if (!MERGE_TYPES.containsKey(mergeTransactionTypeName)) {
throw new PluginException(PluginNotificationLevel.FATAL, String.format("Merge node type %s not found.", mergeTransactionTypeName));
}
final int threshold = parameters.getParameters().get(THRESHOLD_PARAMETER_ID).getIntegerValue();
final GraphElementMerger merger = MERGERS.get(parameters.getParameters().get(MERGER_PARAMETER_ID).getStringValue());
String leadTransactionChooserName = parameters.getParameters().get(LEAD_PARAMETER_ID).getStringValue();
final Comparator<Long> leadTransactionChooser = LEAD_TRANSACTION_CHOOSERS.get(leadTransactionChooserName);
final boolean selectedOnly = parameters.getParameters().get(SELECTED_PARAMETER_ID).getBooleanValue();
final MergeTransactionType mergeTransactionType = MERGE_TYPES.get(mergeTransactionTypeName);
final Map<Integer, Set<Integer>> transactionsToMerge;
try {
transactionsToMerge = mergeTransactionType.getTransactionsToMerge(graph, leadTransactionChooser, threshold, selectedOnly);
} catch (MergeException ex) {
throw new PluginException(PluginNotificationLevel.ERROR, ex);
}
for (final Map.Entry<Integer, Set<Integer>> entry : transactionsToMerge.entrySet()) {
mergedCount += mergeTransactions(graph, entry.getValue(), entry.getKey(), merger);
}
interaction.setProgress(1, 0, "Merged " + mergedCount + " transactions.", true);
PluginExecution.withPlugin(VisualSchemaPluginRegistry.COMPLETE_SCHEMA).executeNow(graph);
}
Aggregations