Search in sources :

Example 1 with MergeException

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);
}
Also used : Set(java.util.Set) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) MergeException(au.gov.asd.tac.constellation.views.dataaccess.plugins.clean.MergeTransactionType.MergeException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IgnoreSurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.IgnoreSurvivingGraphElementMerger) PriorityMergedGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PriorityMergedGraphElementMerger) GraphElementMerger(au.gov.asd.tac.constellation.graph.GraphElementMerger) PrioritySurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger) IgnoreMergedGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.IgnoreMergedGraphElementMerger)

Aggregations

GraphElementMerger (au.gov.asd.tac.constellation.graph.GraphElementMerger)1 IgnoreMergedGraphElementMerger (au.gov.asd.tac.constellation.graph.mergers.IgnoreMergedGraphElementMerger)1 IgnoreSurvivingGraphElementMerger (au.gov.asd.tac.constellation.graph.mergers.IgnoreSurvivingGraphElementMerger)1 PriorityMergedGraphElementMerger (au.gov.asd.tac.constellation.graph.mergers.PriorityMergedGraphElementMerger)1 PrioritySurvivingGraphElementMerger (au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger)1 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)1 MergeException (au.gov.asd.tac.constellation.views.dataaccess.plugins.clean.MergeTransactionType.MergeException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Set (java.util.Set)1