From e94f29e16df4357fd5be1b96007c1c84e9cbe1a7 Mon Sep 17 00:00:00 2001 From: jmillman Date: Wed, 17 Jun 2015 15:51:15 -0400 Subject: [PATCH] make sure all code is using the correct TagsManager (DrawableTagsManager) from controller; more cleanup --- .../imagegallery/DrawableTagsManager.java | 49 +++++++++- .../actions/AddDrawableTagAction.java | 1 + .../imagegallery/actions/AddTagAction.java | 1 + .../actions/CategorizeAction.java | 1 + .../actions/DeleteFollowUpTagAction.java | 72 +++++++++----- .../imagegallery/actions/DeleteTagAction.java | 94 ------------------- .../datamodel/grouping/GroupManager.java | 14 +++ .../gui/drawableviews/DrawableTileBase.java | 1 + 8 files changed, 111 insertions(+), 122 deletions(-) delete mode 100644 ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java index 3c1dd42de3..7ba9ceb842 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/DrawableTagsManager.java @@ -28,6 +28,10 @@ import org.sleuthkit.autopsy.casemodule.services.TagsManager; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.autopsy.ingest.IngestServices; +import org.sleuthkit.autopsy.ingest.ModuleDataEvent; +import org.sleuthkit.datamodel.BlackboardArtifact; +import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -45,7 +49,7 @@ public class DrawableTagsManager { /** Used to distribute {@link TagsChangeEvent}s */ private final EventBus tagsEventBus = new EventBus("Tags Event Bus"); - /** The tag name corresponging to the "built-in" tag "Follow Up" */ + /** The tag name corresponding to the "built-in" tag "Follow Up" */ private TagName followUpTagName; public DrawableTagsManager(TagsManager autopsyTagsManager) { @@ -113,7 +117,7 @@ public class DrawableTagsManager { return followUpTagName; } - public Collection getNonCategoryTagNames() { + synchronized public Collection getNonCategoryTagNames() { try { return autopsyTagsManager.getAllTagNames().stream() .filter(Category::isCategoryTagName) @@ -124,6 +128,20 @@ public class DrawableTagsManager { return Collections.emptySet(); } + /** + * Gets content tags count by content. + * + * @param The content of interest. + * + * @return A list, possibly empty, of the tags that have been applied to the + * artifact. + * + * @throws TskCoreException + */ + public synchronized List getContentTagsByContent(Content content) throws TskCoreException { + return autopsyTagsManager.getContentTagsByContent(content); + } + public synchronized TagName getTagName(String displayName) throws TskCoreException { try { for (TagName tn : autopsyTagsManager.getAllTagNames()) { @@ -150,12 +168,35 @@ public class DrawableTagsManager { } } - public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { + synchronized public void addContentTag(DrawableFile file, TagName tagName, String comment) throws TskCoreException { autopsyTagsManager.addContentTag(file, tagName, comment); } - public List getContentTagsByTagName(TagName t) throws TskCoreException { + synchronized public List getContentTagsByTagName(TagName t) throws TskCoreException { return autopsyTagsManager.getContentTagsByTagName(t); } + /** + * Fire the ModuleDataEvent that we use as a place holder for a real Tag + * Event. This is used to refresh the autopsy tag tree and the ui in + * ImageGallery + * + * + * Note: this is a hack. In an ideal world, TagsManager would fire + * events so that the directory tree would refresh. But, we haven't + * had a chance to add that so, we fire these events and the tree + * refreshes based on them. + */ + static public void fireTagsChangedEvent() { + + IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS + } + + public synchronized List getAllTagNames() throws TskCoreException { + return autopsyTagsManager.getAllTagNames(); + } + + public synchronized List getTagNamesInUse() throws TskCoreException { + return autopsyTagsManager.getTagNamesInUse(); + } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java index 3c115d9134..b3a45b3030 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddDrawableTagAction.java @@ -27,6 +27,7 @@ import javax.swing.JOptionPane; import javax.swing.SwingWorker; import org.openide.util.Utilities; import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java index 44bb02f0e0..af42c5ef2c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/AddTagAction.java @@ -26,6 +26,7 @@ import javafx.scene.control.MenuItem; import javax.swing.SwingUtilities; import org.sleuthkit.autopsy.actions.GetTagNameAndCommentDialog; import org.sleuthkit.autopsy.actions.GetTagNameDialog; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java index ff0c939ee3..24e59dda65 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/CategorizeAction.java @@ -30,6 +30,7 @@ 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.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java index fb729807c0..6a1a54c30d 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteFollowUpTagAction.java @@ -18,16 +18,21 @@ */ package org.sleuthkit.autopsy.imagegallery.actions; +import java.util.Collections; import java.util.List; import java.util.logging.Level; import javafx.event.ActionEvent; -import javax.swing.SwingWorker; import org.controlsfx.control.action.Action; import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; +import org.sleuthkit.autopsy.imagegallery.DrawableTagsManager; +import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; +import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; +import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; import org.sleuthkit.datamodel.ContentTag; +import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TskCoreException; @@ -37,31 +42,50 @@ import org.sleuthkit.datamodel.TskCoreException; public class DeleteFollowUpTagAction extends Action { private static final Logger LOGGER = Logger.getLogger(DeleteFollowUpTagAction.class.getName()); + private final long fileID; + private final DrawableFile file; + private final ImageGalleryController controller; - public DeleteFollowUpTagAction(final ImageGalleryController controller, final DrawableFile file) { + public DeleteFollowUpTagAction(ImageGalleryController controller, DrawableFile file) { super("Delete Follow Up Tag"); + this.controller = controller; + this.file = file; + this.fileID = file.getId(); setEventHandler((ActionEvent t) -> { - new SwingWorker() { - - @Override - protected Void doInBackground() throws Exception { - final DrawableTagsManager tagsManager = controller.getTagsManager(); - - try { - final TagName followUpTagName = tagsManager.getFollowUpTagName(); - - List contentTagsByContent = tagsManager.getContentTagsByContent(file); - for (ContentTag ct : contentTagsByContent) { - if (ct.getName().getDisplayName().equals(followUpTagName.getDisplayName())) { - tagsManager.deleteContentTag(ct); - } - } - } catch (TskCoreException ex) { - LOGGER.log(Level.SEVERE, "Failed to delete follow up tag.", ex); - } - return null; - } - }.execute(); + deleteTag(); }); } + + /** + * + * + * + */ + private void deleteTag() { + + final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); + final GroupManager groupManager = controller.getGroupManager(); + final DrawableTagsManager tagsManager = controller.getTagsManager(); + + try { + final TagName followUpTagName = tagsManager.getFollowUpTagName(); + // remove file from old category group + groupManager.removeFromGroup(new GroupKey(DrawableAttribute.TAGS, followUpTagName), fileID); + + List contentTagsByContent = sleuthKitCase.getContentTagsByContent(file); + for (ContentTag ct : contentTagsByContent) { + if (ct.getName().getDisplayName().equals(followUpTagName.getDisplayName())) { + sleuthKitCase.deleteContentTag(ct); + } + } + + DrawableTagsManager.fireTagsChangedEvent(); + + //make sure rest of ui hears category change. + groupManager.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/actions/DeleteTagAction.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java deleted file mode 100644 index 38a8e40256..0000000000 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/actions/DeleteTagAction.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2015 Basis Technology Corp. - * Contact: carrier sleuthkit org - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.sleuthkit.autopsy.imagegallery.actions; - -import java.util.Collections; -import java.util.logging.Level; -import javafx.event.ActionEvent; -import org.controlsfx.control.action.Action; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.imagegallery.FileUpdateEvent; -import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey; -import org.sleuthkit.autopsy.imagegallery.grouping.GroupManager; -import org.sleuthkit.autopsy.ingest.IngestServices; -import org.sleuthkit.autopsy.ingest.ModuleDataEvent; -import org.sleuthkit.datamodel.BlackboardArtifact; -import org.sleuthkit.datamodel.ContentTag; -import org.sleuthkit.datamodel.SleuthkitCase; -import org.sleuthkit.datamodel.TagName; -import org.sleuthkit.datamodel.TskCoreException; - -/** - * Action to delete the follow up tag a - * - * - */ -public class DeleteTagAction extends Action { - - private static final Logger LOGGER = Logger.getLogger(DeleteTagAction.class.getName()); - private final long fileID; - private final DrawableFile file; - private final ImageGalleryController controller; - private final ContentTag tag; - - public DeleteTagAction(ImageGalleryController controller, DrawableFile file, ContentTag tag) { - super("Delete Follow Up Tag"); - this.controller = controller; - this.file = file; - this.fileID = file.getId(); - this.tag = tag; - setEventHandler((ActionEvent t) -> { - deleteTag(); - }); - } - - /** - * - * @param fileID1 the value of fileID1 - * - * @throws IllegalStateException - */ - private void deleteTag() throws IllegalStateException { - - final SleuthkitCase sleuthKitCase = controller.getSleuthKitCase(); - final GroupManager groupManager = controller.getGroupManager(); - - try { - // remove file from old category group - groupManager.removeFromGroup(new GroupKey(DrawableAttribute.TAGS, tag.getName()), fileID); - sleuthKitCase.deleteContentTag(tag); -// -// List contentTagsByContent = sleuthKitCase.getContentTagsByContent(file); -// for (ContentTag ct : contentTagsByContent) { -// if (ct.getName().getDisplayName().equals(tagsManager.getFollowUpTagName().getDisplayName())) { -// sleuthKitCase.deleteContentTag(ct); -// } -// } - IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent("TagAction", BlackboardArtifact.ARTIFACT_TYPE.TSK_TAG_FILE)); //NON-NLS - - //make sure rest of ui hears category change. - groupManager.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/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index 2c0da12044..61281a519c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -199,7 +199,21 @@ public class GroupManager { @Nullable public DrawableGroup getGroupForKey(@Nonnull GroupKey groupKey) { synchronized (groupMap) { + if (groupKey.getAttribute() == DrawableAttribute.TAGS) { + + System.out.println(groupKey); +// @SuppressWarnings("unchecked") +// GroupKey tagKey = (GroupKey) groupKey; +// +// return groupMap.keySet().stream() +// .filter((GroupKey t) -> t.getAttribute() == DrawableAttribute.TAGS) +// .map((GroupKey t) -> (GroupKey) t) +// .filter(t -> tagKey.getValue().getDisplayName().equals(t.getValue().getDisplayName())) +// .findFirst().map(groupMap::get).orElse(null); + + } //else { return groupMap.get(groupKey); +// } } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java index b3bf25ee96..f579a35aed 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/DrawableTileBase.java @@ -258,6 +258,7 @@ public abstract class DrawableTileBase extends DrawableUIBase { try { globalSelectionModel.clearAndSelect(file.getId()); new AddDrawableTagAction(getController()).addTag(getController().getTagsManager().getFollowUpTagName(), ""); + new AddDrawableTagAction(controller).addTag(followUpTagName, ""); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Failed to add Follow Up tag. Could not load TagName.", ex); }