From edfe858dd869e7ab4ed17abf91de25a6a9725c93 Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 16 Jun 2015 12:51:06 -0400 Subject: [PATCH] cleanup Follow Up tag and Category TagNames (prevent short name version from being added, by removing commas) --- .../imagegallery/ImageGalleryController.java | 1 + .../autopsy/imagegallery/TagUtils.java | 31 +++++++++++-------- .../actions/DeleteFollowUpTag.java | 2 ++ .../imagegallery/datamodel/Category.java | 19 +++++++----- .../datamodel/CategoryManager.java | 2 ++ 5 files changed, 35 insertions(+), 20 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index b93f362dae..8864ddc264 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -371,6 +371,7 @@ public final class ImageGalleryController { historyManager.clear(); }); Category.clearTagNames(); + TagUtils.clearFollowUpTagName(); Toolbar.getDefault().reset(); groupManager.clear(); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java index b5eb4cfc25..8e9e8cfc98 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/TagUtils.java @@ -20,10 +20,12 @@ package org.sleuthkit.autopsy.imagegallery; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.logging.Level; +import java.util.stream.Collectors; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.control.MenuItem; @@ -43,34 +45,36 @@ import org.sleuthkit.datamodel.TskCoreException; */ public class TagUtils { - private static final String follow_Up = "Follow Up"; + private static final String FOLLOW_UP = "Follow Up"; private static TagName followUpTagName; + /** + * Use when closing a case to make sure everything is re-initialized in the + * next case. + */ + public static void clearFollowUpTagName() { + followUpTagName = null; + } + private final static List listeners = new ArrayList<>(); synchronized public static TagName getFollowUpTagName() throws TskCoreException { if (followUpTagName == null) { - followUpTagName = getTagName(follow_Up); + followUpTagName = getTagName(FOLLOW_UP); } return followUpTagName; } static public Collection getNonCategoryTagNames() { - List nonCatTagNames = new ArrayList<>(); - List allTagNames; try { - allTagNames = Case.getCurrentCase().getServices().getTagsManager().getAllTagNames(); - for (TagName tn : allTagNames) { - if (tn.getDisplayName().startsWith(Category.CATEGORY_PREFIX) == false) { - nonCatTagNames.add(tn); - } - } + return Case.getCurrentCase().getServices().getTagsManager().getAllTagNames().stream() + .filter(Category::isCategoryTagName) + .collect(Collectors.toSet()); } catch (TskCoreException | IllegalStateException ex) { Logger.getLogger(TagUtils.class.getName()).log(Level.WARNING, "couldn't access case", ex); } - - return nonCatTagNames; + return Collections.emptySet(); } synchronized static public TagName getTagName(String displayName) throws TskCoreException { @@ -94,7 +98,7 @@ public class TagUtils { } public static void fireChange(Collection ids) { - Set listenersCopy = new HashSet(listeners); + Set listenersCopy = new HashSet<>(listeners); synchronized (listeners) { listenersCopy.addAll(listeners); } @@ -132,6 +136,7 @@ public class TagUtils { } public static interface TagListener { + public void handleTagsChanged(Collection ids); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java index 0399b545ed..0fe88de953 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTag.java @@ -78,6 +78,8 @@ public class DeleteFollowUpTag extends Action { } } IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS + + //make sure rest of ui hears category change. controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS)); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java index 780e851876..4839537731 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/Category.java @@ -34,16 +34,17 @@ import org.sleuthkit.datamodel.TskCoreException; */ public enum Category implements Comparable { - ZERO(Color.LIGHTGREY, 0, "CAT-0, Uncategorized"), - ONE(Color.RED, 1, "CAT-1, Child Exploitation (Illegal)"), - TWO(Color.ORANGE, 2, "CAT-2, Child Exploitation (Non-Illegal/Age Difficult)"), - THREE(Color.YELLOW, 3, "CAT-3, CGI/Animation (Child Exploitive)"), - FOUR(Color.BISQUE, 4, "CAT-4, Exemplar/Comparison (Internal Use Only)"), - FIVE(Color.GREEN, 5, "CAT-5, Non-pertinent"); + ZERO(Color.LIGHTGREY, 0, "CAT-0: Uncategorized"), + ONE(Color.RED, 1, "CAT-1: Child Exploitation (Illegal)"), + TWO(Color.ORANGE, 2, "CAT-2: Child Exploitation (Non-Illegal/Age Difficult)"), + THREE(Color.YELLOW, 3, "CAT-3: CGI/Animation (Child Exploitive)"), + FOUR(Color.BISQUE, 4, "CAT-4: Exemplar/Comparison (Internal Use Only)"), + FIVE(Color.GREEN, 5, "CAT-5: Non-pertinent"); /** map from displayName to enum value */ private static final Map nameMap - = Stream.of(values()).collect(Collectors.toMap(Category::getDisplayName, + = Stream.of(values()).collect(Collectors.toMap( + Category::getDisplayName, Function.identity())); public static final String CATEGORY_PREFIX = "CAT-"; @@ -65,6 +66,10 @@ public enum Category implements Comparable { Category.FIVE.tagName = null; } + public static boolean isCategoryTagName(TagName tName) { + return nameMap.containsKey(tName.getDisplayName()); + } + private TagName tagName; private final Color color; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 699af41bbb..f6e0404c6e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -26,6 +26,7 @@ import java.util.Collection; import java.util.concurrent.atomic.LongAdder; import java.util.logging.Level; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.TagUtils; /** * Provides a cached view of the number of files per category, and fires @@ -75,6 +76,7 @@ public class CategoryManager { this.db = db; categoryCounts.invalidateAll(); Category.clearTagNames(); + TagUtils.clearFollowUpTagName(); } /**