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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
/* /*
* Autopsy Forensic Browser * Autopsy Forensic Browser
* *
* Copyright 2011-2020 Basis Technology Corp. * Copyright 2013-2020 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org * Contact: carrier <at> sleuthkit <dot> org
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -244,7 +244,7 @@ public class TagsManager implements Closeable {
* @throws IOException * @throws IOException
*/ */
public static void addTagSetDefinition(TagSetDefinition tagSetDef) throws IOException { public static void addTagSetDefinition(TagSetDefinition tagSetDef) throws IOException {
synchronized(lock) { synchronized (lock) {
TagSetDefinition.writeTagSetDefinition(tagSetDef); TagSetDefinition.writeTagSetDefinition(tagSetDef);
} }
} }
@ -267,20 +267,20 @@ public class TagsManager implements Closeable {
caseDb.addOrUpdateTagName(def.getDisplayName(), def.getDescription(), def.getColor(), def.getKnownStatus()); caseDb.addOrUpdateTagName(def.getDisplayName(), def.getDescription(), def.getColor(), def.getKnownStatus());
} }
//Assume new case and add tag sets //Assume new case and add tag sets
for(TagSetDefinition setDef: TagSetDefinition.readTagSetDefinitions()) { for (TagSetDefinition setDef : TagSetDefinition.readTagSetDefinitions()) {
List<TagName> tagNameList = new ArrayList<>(); 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())); tagNameList.add(caseDb.addOrUpdateTagName(tagNameDef.getDisplayName(), tagNameDef.getDescription(), tagNameDef.getColor(), tagNameDef.getKnownStatus()));
} }
if(!tagNameList.isEmpty()) { if (!tagNameList.isEmpty()) {
taggingMgr.addTagSet(setDef.getName(), tagNameList); taggingMgr.addTagSet(setDef.getName(), tagNameList);
} }
} }
} }
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
LOGGER.log(Level.SEVERE, "Error updating standard tag name and tag set definitions", 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); LOGGER.log(Level.SEVERE, "Error loading tag set JSON files", ex);
} }
@ -300,11 +300,24 @@ public class TagsManager implements Closeable {
return caseDb.getTaggingManager().getTagSets(); 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 * Add a new TagSet to the case database. Tags will be ranked in the order
* which they are passed to this method. * 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. * @param tagNameList List of TagName in rank order.
* *
* @return A new TagSet object. * @return A new TagSet object.
@ -501,7 +514,7 @@ public class TagsManager implements Closeable {
* name to the case database. * name to the case database.
*/ */
public TagName addTagName(String displayName, String description, TagName.HTML_COLOR color, TskData.FileKnown knownStatus) throws TagNameAlreadyExistsException, TskCoreException { public TagName addTagName(String displayName, String description, TagName.HTML_COLOR color, TskData.FileKnown knownStatus) throws TagNameAlreadyExistsException, TskCoreException {
synchronized(lock) { synchronized (lock) {
try { try {
TagName tagName = caseDb.addOrUpdateTagName(displayName, description, color, knownStatus); TagName tagName = caseDb.addOrUpdateTagName(displayName, description, color, knownStatus);
Set<TagNameDefinition> customTypes = TagNameDefinition.getTagNameDefinitions(); Set<TagNameDefinition> customTypes = TagNameDefinition.getTagNameDefinitions();

View File

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