mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-12 07:56:16 +00:00
only add new cat tag if there is no existing cat tag. put adding and removing fileids to/from group on jfx thread; remove file from groups when adding to new catagory based on new tag
This commit is contained in:
parent
ad39755fe4
commit
7dba4be3cc
@ -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;
|
||||
|
@ -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<ContentTag> 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) {
|
||||
|
@ -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<ContentTag> 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 {
|
||||
|
@ -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<Category>(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName()));
|
||||
newGroupKey = new GroupKey<Category>(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<TagName>(DrawableAttribute.TAGS, evt.getTag().getName());
|
||||
newGroupKey = new GroupKey<TagName>(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<TagName>(DrawableAttribute.TAGS, evt.getTag().getName());
|
||||
}
|
||||
|
||||
if (groupKey != null) {
|
||||
final long fileID = evt.getTag().getContent().getId();
|
||||
DrawableGroup g = removeFromGroup(groupKey, fileID);
|
||||
|
Loading…
x
Reference in New Issue
Block a user