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;
|
package org.sleuthkit.autopsy.imagegallery;
|
||||||
|
|
||||||
import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager;
|
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.CategoryManager;
|
||||||
import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB;
|
import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableDB;
|
||||||
import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile;
|
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.HashSetManager;
|
||||||
import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupManager;
|
import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupManager;
|
||||||
import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupViewState;
|
import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupViewState;
|
||||||
|
@ -19,8 +19,10 @@
|
|||||||
package org.sleuthkit.autopsy.imagegallery.actions;
|
package org.sleuthkit.autopsy.imagegallery.actions;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
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.scene.control.Menu;
|
import javafx.scene.control.Menu;
|
||||||
import javafx.scene.control.MenuItem;
|
import javafx.scene.control.MenuItem;
|
||||||
@ -28,12 +30,14 @@ import javafx.scene.input.KeyCode;
|
|||||||
import javafx.scene.input.KeyCodeCombination;
|
import javafx.scene.input.KeyCodeCombination;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager;
|
|
||||||
import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel;
|
import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel;
|
||||||
import org.sleuthkit.autopsy.imagegallery.ImageGalleryController;
|
import org.sleuthkit.autopsy.imagegallery.ImageGalleryController;
|
||||||
import org.sleuthkit.autopsy.imagegallery.datamodel.Category;
|
import org.sleuthkit.autopsy.imagegallery.datamodel.Category;
|
||||||
import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager;
|
import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager;
|
||||||
import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile;
|
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.TagName;
|
||||||
import org.sleuthkit.datamodel.TskCoreException;
|
import org.sleuthkit.datamodel.TskCoreException;
|
||||||
|
|
||||||
@ -127,11 +131,10 @@ public class CategorizeAction extends AddTagAction {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
DrawableFile<?> file = controller.getFileFromId(fileID); //drawable db
|
DrawableFile<?> file = controller.getFileFromId(fileID); //drawable db
|
||||||
|
final List<ContentTag> fileTags = tagsManager.getContentTagsByContent(file);
|
||||||
if (tagName != categoryManager.getTagName(Category.ZERO)) { // no tags for cat-0
|
if (tagName == categoryManager.getTagName(Category.ZERO)) {
|
||||||
tagsManager.addContentTag(file, tagName, comment); //tsk db
|
// delete all cat tags for cat-0
|
||||||
} else {
|
fileTags.stream()
|
||||||
tagsManager.getContentTagsByContent(file).stream()
|
|
||||||
.filter(tag -> CategoryManager.isCategoryTagName(tag.getName()))
|
.filter(tag -> CategoryManager.isCategoryTagName(tag.getName()))
|
||||||
.forEach((ct) -> {
|
.forEach((ct) -> {
|
||||||
try {
|
try {
|
||||||
@ -140,6 +143,14 @@ public class CategorizeAction extends AddTagAction {
|
|||||||
LOGGER.log(Level.SEVERE, "Error removing old categories result", ex);
|
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) {
|
} catch (TskCoreException ex) {
|
||||||
|
@ -233,14 +233,12 @@ public class CategoryManager {
|
|||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void handleTagAdded(ContentTagAddedEvent event) {
|
public void handleTagAdded(ContentTagAddedEvent event) {
|
||||||
ContentTag addedTag = event.getTag();
|
final ContentTag addedTag = event.getTag();
|
||||||
if (isCategoryTagName(addedTag.getName())) {
|
if (isCategoryTagName(addedTag.getName())) {
|
||||||
final DrawableTagsManager tagsManager = controller.getTagsManager();
|
final DrawableTagsManager tagsManager = controller.getTagsManager();
|
||||||
try {
|
try {
|
||||||
//remove old category tag(s) if necessary
|
//remove old category tag(s) if necessary
|
||||||
List<ContentTag> allContentTags = tagsManager.getContentTagsByContent(addedTag.getContent());
|
for (ContentTag ct : tagsManager.getContentTagsByContent(addedTag.getContent())) {
|
||||||
|
|
||||||
for (ContentTag ct : allContentTags) {
|
|
||||||
if (ct.getId() != addedTag.getId()
|
if (ct.getId() != addedTag.getId()
|
||||||
&& CategoryManager.isCategoryTagName(ct.getName())) {
|
&& CategoryManager.isCategoryTagName(ct.getName())) {
|
||||||
try {
|
try {
|
||||||
|
@ -270,7 +270,9 @@ public class GroupManager {
|
|||||||
//get grouping this file would be in
|
//get grouping this file would be in
|
||||||
final DrawableGroup group = getGroupForKey(groupKey);
|
final DrawableGroup group = getGroupForKey(groupKey);
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
|
Platform.runLater(() -> {
|
||||||
group.removeFile(fileID);
|
group.removeFile(fileID);
|
||||||
|
});
|
||||||
|
|
||||||
// If we're grouping by category, we don't want to remove empty groups.
|
// If we're grouping by category, we don't want to remove empty groups.
|
||||||
if (groupKey.getAttribute() != DrawableAttribute.CATEGORY) {
|
if (groupKey.getAttribute() != DrawableAttribute.CATEGORY) {
|
||||||
@ -536,16 +538,21 @@ public class GroupManager {
|
|||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void handleTagAdded(ContentTagAddedEvent evt) {
|
public void handleTagAdded(ContentTagAddedEvent evt) {
|
||||||
GroupKey<?> groupKey = null;
|
GroupKey<?> newGroupKey = null;
|
||||||
if (groupBy == DrawableAttribute.CATEGORY && CategoryManager.isCategoryTagName(evt.getTag().getName())) {
|
|
||||||
groupKey = new GroupKey<Category>(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getTag().getName()));
|
|
||||||
} 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();
|
final long fileID = evt.getTag().getContent().getId();
|
||||||
DrawableGroup g = getGroupForKey(groupKey);
|
if (groupBy == DrawableAttribute.CATEGORY && CategoryManager.isCategoryTagName(evt.getTag().getName())) {
|
||||||
addFileToGroup(g, groupKey, fileID);
|
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())) {
|
||||||
|
newGroupKey = new GroupKey<TagName>(DrawableAttribute.TAGS, evt.getTag().getName());
|
||||||
|
}
|
||||||
|
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
|
//if there wasn't already a group check if there should be one now
|
||||||
g = popuplateIfAnalyzed(groupKey, null);
|
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.
|
//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())) {
|
} else if (groupBy == DrawableAttribute.TAGS && CategoryManager.isNotCategoryTagName(evt.getTag().getName())) {
|
||||||
groupKey = new GroupKey<TagName>(DrawableAttribute.TAGS, evt.getTag().getName());
|
groupKey = new GroupKey<TagName>(DrawableAttribute.TAGS, evt.getTag().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (groupKey != null) {
|
if (groupKey != null) {
|
||||||
final long fileID = evt.getTag().getContent().getId();
|
final long fileID = evt.getTag().getContent().getId();
|
||||||
DrawableGroup g = removeFromGroup(groupKey, fileID);
|
DrawableGroup g = removeFromGroup(groupKey, fileID);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user