cleanup Follow Up tag and Category TagNames (prevent short name version from being added, by removing commas)

This commit is contained in:
jmillman 2015-06-16 12:51:06 -04:00
parent e1e5e78bd0
commit edfe858dd8
5 changed files with 35 additions and 20 deletions

View File

@ -371,6 +371,7 @@ public final class ImageGalleryController {
historyManager.clear(); historyManager.clear();
}); });
Category.clearTagNames(); Category.clearTagNames();
TagUtils.clearFollowUpTagName();
Toolbar.getDefault().reset(); Toolbar.getDefault().reset();
groupManager.clear(); groupManager.clear();

View File

@ -20,10 +20,12 @@ package org.sleuthkit.autopsy.imagegallery;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.scene.control.MenuItem; import javafx.scene.control.MenuItem;
@ -43,34 +45,36 @@ import org.sleuthkit.datamodel.TskCoreException;
*/ */
public class TagUtils { public class TagUtils {
private static final String follow_Up = "Follow Up"; private static final String FOLLOW_UP = "Follow Up";
private static TagName followUpTagName; 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<TagListener> listeners = new ArrayList<>(); private final static List<TagListener> listeners = new ArrayList<>();
synchronized public static TagName getFollowUpTagName() throws TskCoreException { synchronized public static TagName getFollowUpTagName() throws TskCoreException {
if (followUpTagName == null) { if (followUpTagName == null) {
followUpTagName = getTagName(follow_Up); followUpTagName = getTagName(FOLLOW_UP);
} }
return followUpTagName; return followUpTagName;
} }
static public Collection<TagName> getNonCategoryTagNames() { static public Collection<TagName> getNonCategoryTagNames() {
List<TagName> nonCatTagNames = new ArrayList<>();
List<TagName> allTagNames;
try { try {
allTagNames = Case.getCurrentCase().getServices().getTagsManager().getAllTagNames(); return Case.getCurrentCase().getServices().getTagsManager().getAllTagNames().stream()
for (TagName tn : allTagNames) { .filter(Category::isCategoryTagName)
if (tn.getDisplayName().startsWith(Category.CATEGORY_PREFIX) == false) { .collect(Collectors.toSet());
nonCatTagNames.add(tn);
}
}
} catch (TskCoreException | IllegalStateException ex) { } catch (TskCoreException | IllegalStateException ex) {
Logger.getLogger(TagUtils.class.getName()).log(Level.WARNING, "couldn't access case", ex); Logger.getLogger(TagUtils.class.getName()).log(Level.WARNING, "couldn't access case", ex);
} }
return Collections.emptySet();
return nonCatTagNames;
} }
synchronized static public TagName getTagName(String displayName) throws TskCoreException { synchronized static public TagName getTagName(String displayName) throws TskCoreException {
@ -94,7 +98,7 @@ public class TagUtils {
} }
public static void fireChange(Collection<Long> ids) { public static void fireChange(Collection<Long> ids) {
Set<TagUtils.TagListener> listenersCopy = new HashSet<TagUtils.TagListener>(listeners); Set<TagUtils.TagListener> listenersCopy = new HashSet<>(listeners);
synchronized (listeners) { synchronized (listeners) {
listenersCopy.addAll(listeners); listenersCopy.addAll(listeners);
} }
@ -132,6 +136,7 @@ public class TagUtils {
} }
public static interface TagListener { public static interface TagListener {
public void handleTagsChanged(Collection<Long> ids); public void handleTagsChanged(Collection<Long> ids);
} }
} }

View File

@ -78,6 +78,8 @@ public class DeleteFollowUpTag extends Action {
} }
} }
IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS 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)); controller.getGroupManager().handleFileUpdate(FileUpdateEvent.newUpdateEvent(Collections.singleton(fileID), DrawableAttribute.TAGS));
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex);

View File

@ -34,16 +34,17 @@ import org.sleuthkit.datamodel.TskCoreException;
*/ */
public enum Category implements Comparable<Category> { public enum Category implements Comparable<Category> {
ZERO(Color.LIGHTGREY, 0, "CAT-0, Uncategorized"), ZERO(Color.LIGHTGREY, 0, "CAT-0: Uncategorized"),
ONE(Color.RED, 1, "CAT-1, Child Exploitation (Illegal)"), ONE(Color.RED, 1, "CAT-1: Child Exploitation (Illegal)"),
TWO(Color.ORANGE, 2, "CAT-2, Child Exploitation (Non-Illegal/Age Difficult)"), TWO(Color.ORANGE, 2, "CAT-2: Child Exploitation (Non-Illegal/Age Difficult)"),
THREE(Color.YELLOW, 3, "CAT-3, CGI/Animation (Child Exploitive)"), THREE(Color.YELLOW, 3, "CAT-3: CGI/Animation (Child Exploitive)"),
FOUR(Color.BISQUE, 4, "CAT-4, Exemplar/Comparison (Internal Use Only)"), FOUR(Color.BISQUE, 4, "CAT-4: Exemplar/Comparison (Internal Use Only)"),
FIVE(Color.GREEN, 5, "CAT-5, Non-pertinent"); FIVE(Color.GREEN, 5, "CAT-5: Non-pertinent");
/** map from displayName to enum value */ /** map from displayName to enum value */
private static final Map<String, Category> nameMap private static final Map<String, Category> nameMap
= Stream.of(values()).collect(Collectors.toMap(Category::getDisplayName, = Stream.of(values()).collect(Collectors.toMap(
Category::getDisplayName,
Function.identity())); Function.identity()));
public static final String CATEGORY_PREFIX = "CAT-"; public static final String CATEGORY_PREFIX = "CAT-";
@ -65,6 +66,10 @@ public enum Category implements Comparable<Category> {
Category.FIVE.tagName = null; Category.FIVE.tagName = null;
} }
public static boolean isCategoryTagName(TagName tName) {
return nameMap.containsKey(tName.getDisplayName());
}
private TagName tagName; private TagName tagName;
private final Color color; private final Color color;

View File

@ -26,6 +26,7 @@ import java.util.Collection;
import java.util.concurrent.atomic.LongAdder; import java.util.concurrent.atomic.LongAdder;
import java.util.logging.Level; import java.util.logging.Level;
import org.sleuthkit.autopsy.coreutils.Logger; 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 * Provides a cached view of the number of files per category, and fires
@ -75,6 +76,7 @@ public class CategoryManager {
this.db = db; this.db = db;
categoryCounts.invalidateAll(); categoryCounts.invalidateAll();
Category.clearTagNames(); Category.clearTagNames();
TagUtils.clearFollowUpTagName();
} }
/** /**