Merge pull request #6026 from rcordovano/6567-tag-name-serialization-fix

6567 tag name serialization fix
This commit is contained in:
Richard Cordovano 2020-06-29 18:58:54 -04:00 committed by GitHub
commit a5f99d5e7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 34 deletions

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2019 Basis Technology Corp.
* Copyright 2013-2020 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -139,7 +139,7 @@ abstract class AddTagAction extends AbstractAction implements Presenter.Popup {
if (!tagNamesMap.isEmpty()) {
for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
TagName tagName = entry.getValue();
TagSet tagSet = tagName.getTagSet();
TagSet tagSet = tagsManager.getTagSet(tagName);
// Show custom tags before predefined tags in the menu
if (tagSet != null) {

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2018 Basis Technology Corp.
* Copyright 2013-2020 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -23,7 +23,6 @@ import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.List;
import java.util.Map;
@ -36,7 +35,6 @@ import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.KeyStroke;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.casemodule.Case;
@ -150,7 +148,7 @@ public class GetTagNameAndCommentDialog extends JDialog {
}
);
try {
try {
TagsManager tagsManager = Case.getCurrentCaseThrows().getServices().getTagsManager();
List<String> standardTagNames = TagsManager.getStandardTagNames();
Map<String, TagName> tagNamesMap = new TreeMap<>(tagsManager.getDisplayNamesToTagNamesMap());
@ -161,7 +159,7 @@ public class GetTagNameAndCommentDialog extends JDialog {
tagNamesMap.entrySet().stream().map((entry) -> entry.getValue()).forEachOrdered((tagName) -> {
TagSet tagSet = null;
try {
tagSet = tagName.getTagSet();
tagSet = tagsManager.getTagSet(tagName);
} catch (TskCoreException ex) {
Logger.getLogger(GetTagNameAndCommentDialog.class
.getName()).log(Level.SEVERE, "Failed to get tag set", ex); //NON-NLS

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2018 Basis Technology Corp.
* Copyright 2018-2020 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -131,7 +131,7 @@ abstract class ReplaceTagAction<T extends Tag> extends AbstractAction implements
if (!tagNamesMap.isEmpty()) {
for (Map.Entry<String, TagName> entry : tagNamesMap.entrySet()) {
TagName tagName = entry.getValue();
TagSet tagSet = tagName.getTagSet();
TagSet tagSet = tagsManager.getTagSet(tagName);
// Show custom tags before predefined tags in the menu
if (tagSet != null) {

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2020 Basis Technology Corp.
* Copyright 2013-2020 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -56,7 +56,7 @@ public class TagsManager implements Closeable {
private final SleuthkitCase caseDb;
private static String DEFAULT_TAG_SET_NAME = "Project VIC";
private static final Object lock = new Object();
static {
@ -235,16 +235,16 @@ public class TagsManager implements Closeable {
public static String getNotableTagDisplayName() {
return TagNameDefinition.getNotableTagDisplayName();
}
/**
* Creates a new TagSetDefinition file.
*
*
* @param tagSetDef The tag set definition.
*
* @throws IOException
*
* @throws IOException
*/
public static void addTagSetDefinition(TagSetDefinition tagSetDef) throws IOException {
synchronized(lock) {
synchronized (lock) {
TagSetDefinition.writeTagSetDefinition(tagSetDef);
}
}
@ -267,20 +267,20 @@ public class TagsManager implements Closeable {
caseDb.addOrUpdateTagName(def.getDisplayName(), def.getDescription(), def.getColor(), def.getKnownStatus());
}
//Assume new case and add tag sets
for(TagSetDefinition setDef: TagSetDefinition.readTagSetDefinitions()) {
for (TagSetDefinition setDef : TagSetDefinition.readTagSetDefinitions()) {
List<TagName> tagNameList = new ArrayList<>();
for(TagNameDefinition tagNameDef: setDef.getTagNameDefinitions()) {
for (TagNameDefinition tagNameDef : setDef.getTagNameDefinitions()) {
tagNameList.add(caseDb.addOrUpdateTagName(tagNameDef.getDisplayName(), tagNameDef.getDescription(), tagNameDef.getColor(), tagNameDef.getKnownStatus()));
}
if(!tagNameList.isEmpty()) {
if (!tagNameList.isEmpty()) {
taggingMgr.addTagSet(setDef.getName(), tagNameList);
}
}
}
} catch (TskCoreException ex) {
LOGGER.log(Level.SEVERE, "Error updating standard tag name and tag set definitions", ex);
} catch(IOException ex) {
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, "Error loading tag set JSON files", ex);
}
@ -288,28 +288,41 @@ public class TagsManager implements Closeable {
tagName.saveToCase(caseDb);
}
}
/**
* Get a list of all tag sets currently in the case database.
*
*
* @return A list, possibly empty, of TagSet objects.
*
*
* @throws TskCoreException
*/
public List<TagSet> getAllTagSets() throws TskCoreException {
return caseDb.getTaggingManager().getTagSets();
}
/**
* Gets the tag set a tag name (tag definition) belongs to, if any.
*
* @param tagName The tag name.
*
* @return A TagSet object or null.
*
* @throws TskCoreException If there is an error querying the case database.
*/
public TagSet getTagSet(TagName tagName) throws TskCoreException {
return caseDb.getTaggingManager().getTagSet(tagName);
}
/**
* Add a new TagSet to the case database. Tags will be ranked in the order
* which they are passed to this method.
*
* @param name Tag set name.
*
* @param name Tag set name.
* @param tagNameList List of TagName in rank order.
*
*
* @return A new TagSet object.
*
* @throws TskCoreException
*
* @throws TskCoreException
*/
public TagSet addTagSet(String name, List<TagName> tagNameList) throws TskCoreException {
return caseDb.getTaggingManager().addTagSet(name, tagNameList);
@ -501,7 +514,7 @@ public class TagsManager implements Closeable {
* name to the case database.
*/
public TagName addTagName(String displayName, String description, TagName.HTML_COLOR color, TskData.FileKnown knownStatus) throws TagNameAlreadyExistsException, TskCoreException {
synchronized(lock) {
synchronized (lock) {
try {
TagName tagName = caseDb.addOrUpdateTagName(displayName, description, color, knownStatus);
Set<TagNameDefinition> customTypes = TagNameDefinition.getTagNameDefinitions();

View File

@ -19,6 +19,9 @@
package org.sleuthkit.autopsy.tags;
import java.util.logging.Level;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.casemodule.services.TagsManager;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.datamodel.TagName;
import org.sleuthkit.datamodel.TagSet;
@ -52,12 +55,13 @@ public final class TagUtils {
public static String getDecoratedTagDisplayName(TagName tagName) {
String displayName = tagName.getDisplayName();
try {
TagSet tagSet = tagName.getTagSet();
TagsManager tagsManager = Case.getCurrentCaseThrows().getServices().getTagsManager();
TagSet tagSet = tagsManager.getTagSet(tagName);
if (tagSet != null) {
displayName = tagSet.getName() + ": " + displayName;
}
} catch (TskCoreException ex) {
logger.log(Level.WARNING, String.format("Failed to get TagSet for TagName (%d)", tagName.getId()));
} catch (NoCurrentCaseException | TskCoreException ex) {
logger.log(Level.SEVERE, String.format("Failed to get TagSet for TagName '%s' (ID=%d)", tagName.getDisplayName(), tagName.getId()));
}
if (tagName.getKnownStatus() == TskData.FileKnown.BAD) {