diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java index 178c9dd725..d021dfcc40 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/ImageGalleryController.java @@ -18,7 +18,6 @@ */ package org.sleuthkit.autopsy.imagegallery; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import java.beans.PropertyChangeEvent; import java.util.ArrayList; import java.util.List; @@ -63,6 +62,7 @@ import org.sleuthkit.autopsy.events.ContentTagDeletedEvent; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.datamodel.HashSetManager; import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupManager; import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupViewState; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index 518a49b87a..f7c20ab56b 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -19,8 +19,10 @@ package org.sleuthkit.autopsy.imagegallery.actions; 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.scene.control.Menu; import javafx.scene.control.MenuItem; @@ -28,12 +30,14 @@ import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; import javax.swing.JOptionPane; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; +import org.sleuthkit.datamodel.ContentTag; +import org.sleuthkit.datamodel.Tag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -127,11 +131,10 @@ public class CategorizeAction extends AddTagAction { try { DrawableFile file = controller.getFileFromId(fileID); //drawable db - - if (tagName != categoryManager.getTagName(Category.ZERO)) { // no tags for cat-0 - tagsManager.addContentTag(file, tagName, comment); //tsk db - } else { - tagsManager.getContentTagsByContent(file).stream() + final List fileTags = tagsManager.getContentTagsByContent(file); + if (tagName == categoryManager.getTagName(Category.ZERO)) { + // delete all cat tags for cat-0 + fileTags.stream() .filter(tag -> CategoryManager.isCategoryTagName(tag.getName())) .forEach((ct) -> { try { @@ -140,6 +143,14 @@ public class CategorizeAction extends AddTagAction { LOGGER.log(Level.SEVERE, "Error removing old categories result", ex); } }); + } else { + //add cat tag if no existing cat tag for that cat + if (fileTags.stream() + .map(Tag::getName) + .filter(tagName::equals) + .collect(Collectors.toList()).isEmpty()) { + tagsManager.addContentTag(file, tagName, comment); + } } } catch (TskCoreException ex) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 31be08e71a..3377fdce6e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -233,14 +233,12 @@ public class CategoryManager { @Subscribe public void handleTagAdded(ContentTagAddedEvent event) { - ContentTag addedTag = event.getTag(); + final ContentTag addedTag = event.getTag(); if (isCategoryTagName(addedTag.getName())) { final DrawableTagsManager tagsManager = controller.getTagsManager(); try { //remove old category tag(s) if necessary - List allContentTags = tagsManager.getContentTagsByContent(addedTag.getContent()); - - for (ContentTag ct : allContentTags) { + for (ContentTag ct : tagsManager.getContentTagsByContent(addedTag.getContent())) { if (ct.getId() != addedTag.getId() && CategoryManager.isCategoryTagName(ct.getName())) { try { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index dc27ac136b..8b7844d9c4 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -270,7 +270,9 @@ public class GroupManager { //get grouping this file would be in final DrawableGroup group = getGroupForKey(groupKey); if (group != null) { - group.removeFile(fileID); + Platform.runLater(() -> { + group.removeFile(fileID); + }); // If we're grouping by category, we don't want to remove empty groups. if (groupKey.getAttribute() != DrawableAttribute.CATEGORY) { @@ -536,16 +538,21 @@ public class GroupManager { @Subscribe public void handleTagAdded(ContentTagAddedEvent evt) { - GroupKey groupKey = null; + GroupKey newGroupKey = null; + final long fileID = evt.getTag().getContent().getId(); if (groupBy == DrawableAttribute.CATEGORY && CategoryManager.isCategoryTagName(evt.getTag().getName())) { - groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName())); + newGroupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName())); + for (GroupKey oldGroupKey : groupMap.keySet()) { + if (oldGroupKey.equals(newGroupKey) == false) { + removeFromGroup(oldGroupKey, fileID); + } + } } else if (groupBy == DrawableAttribute.TAGS && CategoryManager.isNotCategoryTagName(evt.getTag().getName())) { - groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); + newGroupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); } - if (groupKey != null) { - final long fileID = evt.getTag().getContent().getId(); - DrawableGroup g = getGroupForKey(groupKey); - addFileToGroup(g, groupKey, fileID); + if (newGroupKey != null) { + DrawableGroup g = getGroupForKey(newGroupKey); + addFileToGroup(g, newGroupKey, fileID); } } @@ -555,9 +562,13 @@ public class GroupManager { //if there wasn't already a group check if there should be one now g = popuplateIfAnalyzed(groupKey, null); } - if (g != null) { + DrawableGroup group = g; + if (group != null) { //if there is aleady a group that was previously deemed fully analyzed, then add this newly analyzed file to it. - g.addFile(fileID); + Platform.runLater(() -> { + group.addFile(fileID); + }); + } } @@ -569,7 +580,6 @@ public class GroupManager { } else if (groupBy == DrawableAttribute.TAGS && CategoryManager.isNotCategoryTagName(evt.getTag().getName())) { groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getTag().getName()); } - if (groupKey != null) { final long fileID = evt.getTag().getContent().getId(); DrawableGroup g = removeFromGroup(groupKey, fileID);