mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-14 17:06:16 +00:00
make sure all code is using the correct TagsManager (DrawableTagsManager) from controller; more cleanup
This commit is contained in:
parent
1be231107d
commit
e94f29e16d
@ -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<TagName> getNonCategoryTagNames() {
|
||||
synchronized public Collection<TagName> 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<ContentTag> 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<ContentTag> getContentTagsByTagName(TagName t) throws TskCoreException {
|
||||
synchronized public List<ContentTag> 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<TagName> getAllTagNames() throws TskCoreException {
|
||||
return autopsyTagsManager.getAllTagNames();
|
||||
}
|
||||
|
||||
public synchronized List<TagName> getTagNamesInUse() throws TskCoreException {
|
||||
return autopsyTagsManager.getTagNamesInUse();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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<Void, Void>() {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground() throws Exception {
|
||||
final DrawableTagsManager tagsManager = controller.getTagsManager();
|
||||
|
||||
try {
|
||||
final TagName followUpTagName = tagsManager.getFollowUpTagName();
|
||||
|
||||
List<ContentTag> 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<TagName>(DrawableAttribute.TAGS, followUpTagName), fileID);
|
||||
|
||||
List<ContentTag> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Autopsy Forensic Browser
|
||||
*
|
||||
* Copyright 2015 Basis Technology Corp.
|
||||
* Contact: carrier <at> sleuthkit <dot> 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<TagName>(DrawableAttribute.TAGS, tag.getName()), fileID);
|
||||
sleuthKitCase.deleteContentTag(tag);
|
||||
//
|
||||
// List<ContentTag> 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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<TagName> tagKey = (GroupKey<TagName>) groupKey;
|
||||
//
|
||||
// return groupMap.keySet().stream()
|
||||
// .filter((GroupKey<?> t) -> t.getAttribute() == DrawableAttribute.TAGS)
|
||||
// .map((GroupKey<?> t) -> (GroupKey<TagName>) t)
|
||||
// .filter(t -> tagKey.getValue().getDisplayName().equals(t.getValue().getDisplayName()))
|
||||
// .findFirst().map(groupMap::get).orElse(null);
|
||||
|
||||
} //else {
|
||||
return groupMap.get(groupKey);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user