From 8b487ca56da8e7bd369dc660afe1abe1c9bb445c Mon Sep 17 00:00:00 2001 From: Richard Cordovano Date: Tue, 22 Oct 2013 17:21:44 -0400 Subject: [PATCH] Removed prematuer merge of some new tags api files --- .../autopsy/casemodule/services/Services.java | 8 - .../casemodule/services/TagsManager.java | 247 ------------------ .../directorytree/TagAbstractFileAction.java | 169 ++++++------ .../TagBlackboardArtifactAction.java | 171 ++++++------ 4 files changed, 151 insertions(+), 444 deletions(-) delete mode 100755 Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java b/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java index 069b13ef2e..10663c173b 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/services/Services.java @@ -41,26 +41,18 @@ public class Services implements Closeable { // services private FileManager fileManager; - private TagsManager tagsManager; public Services(SleuthkitCase tskCase) { this.tskCase = tskCase; //create and initialize FileManager as early as possibly in the new/opened Case fileManager = new FileManager(tskCase); services.add(fileManager); - - tagsManager = new TagsManager(tskCase); - services.add(tagsManager); } public FileManager getFileManager() { return fileManager; } - public TagsManager getTagsManager() { - return tagsManager; - } - @Override public void close() throws IOException { // close all services diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java b/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java deleted file mode 100755 index 2ae7426655..0000000000 --- a/Core/src/org/sleuthkit/autopsy/casemodule/services/TagsManager.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2013 Basis Technology Corp. - * Contact: carrier sleuthkit 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.casemodule.services; - -import java.io.Closeable; -import java.io.IOException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.sleuthkit.autopsy.coreutils.ModuleSettings; -import org.sleuthkit.datamodel.BlackboardArtifact; -import org.sleuthkit.datamodel.BlackboardArtifactTag; -import org.sleuthkit.datamodel.Content; -import org.sleuthkit.datamodel.ContentTag; -import org.sleuthkit.datamodel.SleuthkitCase; -import org.sleuthkit.datamodel.TagType; -import org.sleuthkit.datamodel.TskCoreException; - -/** - * A singleton instance of this class functions as an Autopsy service that - * manages the creation, updating, and deletion of tags applied to Content and - * BlackboardArtifacts objects by users. - */ -public class TagsManager implements Closeable { - private static final String TAGS_SETTINGS_FILE_NAME = "tags"; - private static final String TAG_TYPES_SETTING_KEY = "tagTypes"; - private final SleuthkitCase tskCase; - private final HashMap tagTypes = new HashMap<>(); - - TagsManager(SleuthkitCase tskCase) { - this.tskCase = tskCase; - loadTagTypesFromTagSettings(); - } - - private void loadTagTypesFromTagSettings() { - // Get any tag types already added to the current case. - try { - List currentTagTypes = tskCase.getTagTypes(); - for (TagType tagType : currentTagTypes) { - tagTypes.put(tagType.getDisplayName(), tagType); - } - } - catch (TskCoreException ex) { - Logger.getLogger(TagsManager.class.getName()).log(Level.SEVERE, "Failed to get tag types from the current case", ex); - } - - // Read the saved tag types, if any, from the tags settings file and - // add them to the current case if they haven't already been added, e.g, - // when the case was last opened. - String setting = ModuleSettings.getConfigSetting(TAGS_SETTINGS_FILE_NAME, TAG_TYPES_SETTING_KEY); - if (null != setting && !setting.isEmpty()) { - // Read the tag types setting and break in into tag type tuples. - List tagTypeTuples = Arrays.asList(setting.split(";")); - - // Parse each tuple and add the tag types to the current case, one - // at a time to gracefully discard any duplicates or corrupt tuples. - for (String tagTypeTuple : tagTypeTuples) { - String[] tagTypeAttributes = tagTypeTuple.split(","); - if (!tagTypes.containsKey(tagTypeAttributes[0])) { - TagType tagType = new TagType(tagTypeAttributes[0], tagTypeAttributes[1], TagType.HTML_COLOR.getColorByName(tagTypeAttributes[2])); - try { - tskCase.addTagType(tagType); - tagTypes.put(tagType.getDisplayName(),tagType); - } - catch(TskCoreException ex) { - Logger.getLogger(TagsManager.class.getName()).log(Level.WARNING, "Failed to add saved " + tagType.getDisplayName() + " tag type to the current case", ex); - } - } - } - - saveTagTypesToTagsSettings(); - } - } - - private void saveTagTypesToTagsSettings() { - if (!tagTypes.isEmpty()) { - StringBuilder setting = new StringBuilder(); - for (TagType tagType : tagTypes.values()) { - if (setting.length() != 0) { - setting.append(";"); - } - setting.append(tagType.getDisplayName()).append(","); - setting.append(tagType.getDescription()).append(","); - setting.append(tagType.getColor().name()); - } - - ModuleSettings.setConfigSetting(TAGS_SETTINGS_FILE_NAME, TAG_TYPES_SETTING_KEY, setting.toString()); - } - } - - /** - * Gets a list of all tag types currently available for tagging content or - * blackboard artifacts. - * @return A list, possibly empty, of TagType data transfer objects (DTOs). - * @throws TskCoreException - */ - public List getTagTypes() throws TskCoreException { - return tskCase.getTagTypes(); - } - - /** - * Adds a new tag type to the current case and to the tags settings file. - * @param displayName The display name for the new tag type. - * @return A TagType object representing the new type on success, null on failure. - * @throws TskCoreException - */ - public TagType addTagType(String displayName) throws TagTypeAlreadyExistsException, TskCoreException { - return addTagType(displayName, "", TagType.HTML_COLOR.NONE); - } - - /** - * Adds a new tag type to the current case and to the tags settings file. - * @param displayName The display name for the new tag type. - * @param description The description for the new tag type. - * @return A TagType object representing the new type on success, null on failure. - * @throws TskCoreException - */ - public TagType addTagType(String displayName, String description) throws TagTypeAlreadyExistsException, TskCoreException { - return addTagType(displayName, description, TagType.HTML_COLOR.NONE); - } - - /** - * Adds a new tag type to the current case and to the tags settings file. - * @param displayName The display name for the new tag type. - * @param description The description for the new tag type. - * @param color The HTML color to associate with the new tag type. - * @return A TagType object representing the new type. - * @throws TskCoreException - */ - public synchronized TagType addTagType(String displayName, String description, TagType.HTML_COLOR color) throws TagTypeAlreadyExistsException, TskCoreException { - if (tagTypes.containsKey(displayName)) { - throw new TagTypeAlreadyExistsException(); - } - - TagType newTagType = new TagType(displayName, description, color); - tskCase.addTagType(newTagType); - tagTypes.put(newTagType.getDisplayName(), newTagType); - saveTagTypesToTagsSettings(); - return newTagType; - } - - public class TagTypeAlreadyExistsException extends Exception { - } - - /** - * Tags a Content object. - * @param content The Content to tag. - * @param tagType The type of tag to add. - * @throws TskCoreException - */ - public void addContentTag(Content content, TagType tagType) throws TskCoreException { - addContentTag(content, tagType, "", 0, content.getSize() - 1); - } - - /** - * Tags a Content object. - * @param content The Content to tag. - * @param tagType The type of tag to add. - * @param comment A comment to store with the tag. - * @throws TskCoreException - */ - public void addContentTag(Content content, TagType tagType, String comment) throws TskCoreException { - addContentTag(content, tagType, comment, 0, content.getSize() - 1); - } - - /** - * Tags a Content object or a portion of a content object. - * @param content The Content to tag. - * @param tagType The type of tag to add. - * @param comment A comment to store with the tag. - * @param beginByteOffset Designates the beginning of a tagged extent. - * @param endByteOffset Designates the end of a tagged extent. - * @throws TskCoreException - */ - public void addContentTag(Content content, TagType tagType, String comment, long beginByteOffset, long endByteOffset) throws IllegalArgumentException, TskCoreException { - if (beginByteOffset < 0) { - throw new IllegalArgumentException("Content extent incorrect: beginByteOffset < 0"); - } - - if (endByteOffset <= beginByteOffset) { - throw new IllegalArgumentException("Content extent incorrect: endByteOffset <= beginByteOffset"); - } - - if (endByteOffset > content.getSize() - 1) { - throw new IllegalArgumentException("Content extent incorrect: endByteOffset exceeds content size"); - } - - tskCase.addContentTag(new ContentTag(content, tagType, comment, beginByteOffset, endByteOffset)); - } - - /** - * Deletes a content tag. - * @param tag The tag to delete. - * @throws TskCoreException - */ - public void deleteContentTag(ContentTag tag) throws TskCoreException { - tskCase.deleteContentTag(tag); - } - - /** - * Tags a BlackboardArtifact object. - * @param artifact The BlackboardArtifact to tag. - * @param tagType The type of tag to add. - * @throws TskCoreException - */ - public void addBlackboardArtifactTag(BlackboardArtifact artifact, TagType tagType) throws TskCoreException { - addBlackboardArtifactTag(artifact, tagType, ""); - } - - /** - * Tags a BlackboardArtifact object. - * @param artifact The BlackboardArtifact to tag. - * @param tagType The type of tag to add. - * @param comment A comment to store with the tag. - * @throws TskCoreException - */ - public void addBlackboardArtifactTag(BlackboardArtifact artifact, TagType tagType, String comment) throws TskCoreException { - tskCase.addBlackboardArtifactTag(new BlackboardArtifactTag(artifact, tagType, comment)); - } - - void deleteBlackboardArtifactTag(BlackboardArtifactTag tag) throws TskCoreException { - tskCase.deleteBlackboardArtifactTag(tag); - } - - @Override - public void close() throws IOException { - saveTagTypesToTagsSettings(); - } -} diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/TagAbstractFileAction.java b/Core/src/org/sleuthkit/autopsy/directorytree/TagAbstractFileAction.java index 5afbf89fef..f174e79121 100755 --- a/Core/src/org/sleuthkit/autopsy/directorytree/TagAbstractFileAction.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/TagAbstractFileAction.java @@ -1,94 +1,75 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2013 Basis Technology Corp. - * Contact: carrier sleuthkit 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.directorytree; - -import java.awt.event.ActionEvent; -import java.util.Collection; -import java.util.logging.Level; -import javax.swing.AbstractAction; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import org.openide.util.Utilities; -import org.openide.util.actions.Presenter; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.casemodule.services.TagsManager; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.datamodel.Tags; -import org.sleuthkit.datamodel.AbstractFile; -import org.sleuthkit.datamodel.TagType; -import org.sleuthkit.datamodel.TskCoreException; - -public class TagAbstractFileAction extends AbstractAction implements Presenter.Popup { - // This class is a singleton to support multi-selection of nodes, since - // org.openide.nodes.NodeOp.findActions(Node[] nodes) will only pick up an Action if every - // node in the array returns a reference to the same action object from Node.getActions(boolean). - private static TagAbstractFileAction instance; - - public static synchronized TagAbstractFileAction getInstance() { - if (null == instance) { - instance = new TagAbstractFileAction(); - } - return instance; - } - - private TagAbstractFileAction() { - } - - @Override - public JMenuItem getPopupPresenter() { - return new TagAbstractFileMenu(); - } - - @Override - public void actionPerformed(ActionEvent e) { - // Do nothing - this action should never be performed. - // Submenu actions are invoked instead. - } - - private static class TagAbstractFileMenu extends TagMenu { - public TagAbstractFileMenu() { - super(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class).size() > 1 ? "Tag Files" : "Tag File"); - } - - @Override - protected void applyTag(String tagDisplayName, String comment) { - try { - TagsManager tagsManager = Case.getCurrentCase().getServices().getTagsManager(); - TagType tagType = tagsManager.addTagType(tagDisplayName); - - Collection selectedFiles = Utilities.actionsGlobalContext().lookupAll(AbstractFile.class); - for (AbstractFile file : selectedFiles) { - Tags.createTag(file, tagDisplayName, comment); -// try { -// tagsManager.addContentTag(file, tagType); -// } -// catch (TskCoreException ex) { -// Logger.getLogger(TagAbstractFileMenu.class.getName()).log(Level.SEVERE, "Error tagging content", ex); -// } - } - } - catch (TagsManager.TagTypeAlreadyExistsException ex) { - JOptionPane.showMessageDialog(null, "A " + tagDisplayName + " tag type has already been defined.", "Duplicate Tag Type", JOptionPane.ERROR_MESSAGE); - } - catch (TskCoreException ex) { - Logger.getLogger(TagAbstractFileMenu.class.getName()).log(Level.SEVERE, "Error adding " + tagDisplayName + " tag type", ex); - } - } - } -} +/* + * Autopsy Forensic Browser + * + * Copyright 2013 Basis Technology Corp. + * Contact: carrier sleuthkit 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.directorytree; + +import java.awt.event.ActionEvent; +import java.util.Collection; +import java.util.logging.Level; +import javax.swing.AbstractAction; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import org.openide.util.Utilities; +import org.openide.util.actions.Presenter; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.datamodel.Tags; +import org.sleuthkit.datamodel.AbstractFile; +import org.sleuthkit.datamodel.TskCoreException; + +public class TagAbstractFileAction extends AbstractAction implements Presenter.Popup { + // This class is a singleton to support multi-selection of nodes, since + // org.openide.nodes.NodeOp.findActions(Node[] nodes) will only pick up an Action if every + // node in the array returns a reference to the same action object from Node.getActions(boolean). + private static TagAbstractFileAction instance; + + public static synchronized TagAbstractFileAction getInstance() { + if (null == instance) { + instance = new TagAbstractFileAction(); + } + return instance; + } + + private TagAbstractFileAction() { + } + + @Override + public JMenuItem getPopupPresenter() { + return new TagAbstractFileMenu(); + } + + @Override + public void actionPerformed(ActionEvent e) { + // Do nothing - this action should never be performed. + // Submenu actions are invoked instead. + } + + private static class TagAbstractFileMenu extends TagMenu { + public TagAbstractFileMenu() { + super(Utilities.actionsGlobalContext().lookupAll(AbstractFile.class).size() > 1 ? "Tag Files" : "Tag File"); + } + + @Override + protected void applyTag(String tagDisplayName, String comment) { + Collection selectedFiles = Utilities.actionsGlobalContext().lookupAll(AbstractFile.class); + for (AbstractFile file : selectedFiles) { + Tags.createTag(file, tagDisplayName, comment); + } + } + } +} diff --git a/Core/src/org/sleuthkit/autopsy/directorytree/TagBlackboardArtifactAction.java b/Core/src/org/sleuthkit/autopsy/directorytree/TagBlackboardArtifactAction.java index 3f2c8fd407..460c5b1a90 100755 --- a/Core/src/org/sleuthkit/autopsy/directorytree/TagBlackboardArtifactAction.java +++ b/Core/src/org/sleuthkit/autopsy/directorytree/TagBlackboardArtifactAction.java @@ -1,95 +1,76 @@ -/* - * Autopsy Forensic Browser - * - * Copyright 2013 Basis Technology Corp. - * Contact: carrier sleuthkit 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.directorytree; - -import java.awt.event.ActionEvent; -import java.util.Collection; -import java.util.logging.Level; -import javax.swing.AbstractAction; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import org.openide.util.Utilities; -import org.openide.util.actions.Presenter; -import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.casemodule.services.TagsManager; -import org.sleuthkit.autopsy.coreutils.Logger; -import org.sleuthkit.autopsy.datamodel.Tags; -import org.sleuthkit.datamodel.BlackboardArtifact; -import org.sleuthkit.datamodel.TagType; -import org.sleuthkit.datamodel.TskCoreException; - -public class TagBlackboardArtifactAction extends AbstractAction implements Presenter.Popup { - // This class is a singleton to support multi-selection of nodes, since - // org.openide.nodes.NodeOp.findActions(Node[] nodes) will only pick up an Action if every - // node in the array returns a reference to the same action object from Node.getActions(boolean). - private static TagBlackboardArtifactAction instance; - - public static synchronized TagBlackboardArtifactAction getInstance() { - if (null == instance) { - instance = new TagBlackboardArtifactAction(); - } - return instance; - } - - private TagBlackboardArtifactAction() { - } - - @Override - public JMenuItem getPopupPresenter() { - return new TagBlackboardArtifactMenu(); - } - - @Override - public void actionPerformed(ActionEvent e) { - // Do nothing - this action should never be performed. - // Submenu actions are invoked instead. - } - - - private static class TagBlackboardArtifactMenu extends TagMenu { - public TagBlackboardArtifactMenu() { - super(Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class).size() > 1 ? "Tag Results" : "Tag Result"); - } - - @Override - protected void applyTag(String tagDisplayName, String comment) { - try { - TagsManager tagsManager = Case.getCurrentCase().getServices().getTagsManager(); - TagType tagType = tagsManager.addTagType(tagDisplayName); - - Collection selectedArtifacts = Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class); - for (BlackboardArtifact artifact : selectedArtifacts) { - Tags.createTag(artifact, tagDisplayName, comment); - try { - tagsManager.addBlackboardArtifactTag(artifact, tagType); - } - catch (TskCoreException ex) { - Logger.getLogger(TagBlackboardArtifactMenu.class.getName()).log(Level.SEVERE, "Error tagging result", ex); - } - } - } - catch (TagsManager.TagTypeAlreadyExistsException ex) { - JOptionPane.showMessageDialog(null, "A " + tagDisplayName + " tag type has already been defined.", "Duplicate Tag Type", JOptionPane.ERROR_MESSAGE); - } - catch (TskCoreException ex) { - Logger.getLogger(TagBlackboardArtifactMenu.class.getName()).log(Level.SEVERE, "Error adding " + tagDisplayName + " tag type", ex); - } - } - } -} +/* + * Autopsy Forensic Browser + * + * Copyright 2013 Basis Technology Corp. + * Contact: carrier sleuthkit 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.directorytree; + +import java.awt.event.ActionEvent; +import java.util.Collection; +import java.util.logging.Level; +import javax.swing.AbstractAction; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import org.openide.util.Utilities; +import org.openide.util.actions.Presenter; +import org.sleuthkit.autopsy.casemodule.Case; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.datamodel.Tags; +import org.sleuthkit.datamodel.BlackboardArtifact; +import org.sleuthkit.datamodel.TskCoreException; + +public class TagBlackboardArtifactAction extends AbstractAction implements Presenter.Popup { + // This class is a singleton to support multi-selection of nodes, since + // org.openide.nodes.NodeOp.findActions(Node[] nodes) will only pick up an Action if every + // node in the array returns a reference to the same action object from Node.getActions(boolean). + private static TagBlackboardArtifactAction instance; + + public static synchronized TagBlackboardArtifactAction getInstance() { + if (null == instance) { + instance = new TagBlackboardArtifactAction(); + } + return instance; + } + + private TagBlackboardArtifactAction() { + } + + @Override + public JMenuItem getPopupPresenter() { + return new TagBlackboardArtifactMenu(); + } + + @Override + public void actionPerformed(ActionEvent e) { + // Do nothing - this action should never be performed. + // Submenu actions are invoked instead. + } + + + private static class TagBlackboardArtifactMenu extends TagMenu { + public TagBlackboardArtifactMenu() { + super(Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class).size() > 1 ? "Tag Results" : "Tag Result"); + } + + @Override + protected void applyTag(String tagDisplayName, String comment) { + Collection selectedArtifacts = Utilities.actionsGlobalContext().lookupAll(BlackboardArtifact.class); + for (BlackboardArtifact artifact : selectedArtifacts) { + Tags.createTag(artifact, tagDisplayName, comment); + } + } + } +}