Complete docs/deprecation for FileManager API

This commit is contained in:
Richard Cordovano 2016-05-27 12:53:10 -04:00
parent a855009740
commit f746f455c8
6 changed files with 178 additions and 184 deletions

View File

@ -282,6 +282,7 @@ public class Case implements SleuthkitCase.ErrorObserver {
/** /**
* Constructor for the Case class * Constructor for the Case class
*/ */
@SuppressWarnings("deprecation")
private Case(CaseMetadata caseMetadata, SleuthkitCase db) { private Case(CaseMetadata caseMetadata, SleuthkitCase db) {
this.caseMetadata = caseMetadata; this.caseMetadata = caseMetadata;
this.db = db; this.db = db;
@ -835,6 +836,7 @@ public class Case implements SleuthkitCase.ErrorObserver {
/** /**
* Closes this case. This methods close the xml and clear all the fields. * Closes this case. This methods close the xml and clear all the fields.
*/ */
@SuppressWarnings("deprecation")
public void closeCase() throws CaseActionException { public void closeCase() throws CaseActionException {
changeCase(null); changeCase(null);
try { try {

View File

@ -109,10 +109,13 @@ public final class Blackboard implements Closeable {
} }
/** /**
* Cloese this blackboard and releases any resources associated with it. * Closes the blackboard.
* @throws IOException *
* @throws IOException If there is a problem closing the blackboard.
* @deprecated File manager clients should not close the blackboard.
*/ */
@Override @Override
@Deprecated
public void close() throws IOException { public void close() throws IOException {
} }

View File

@ -26,10 +26,8 @@ import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.datamodel.VirtualDirectoryNode; import org.sleuthkit.autopsy.datamodel.VirtualDirectoryNode;
import org.sleuthkit.autopsy.ingest.IngestServices; import org.sleuthkit.autopsy.ingest.IngestServices;
import org.sleuthkit.autopsy.ingest.ModuleContentEvent; import org.sleuthkit.autopsy.ingest.ModuleContentEvent;
@ -37,7 +35,6 @@ import org.sleuthkit.datamodel.AbstractFile;
import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.Content;
import org.sleuthkit.datamodel.DerivedFile; import org.sleuthkit.datamodel.DerivedFile;
import org.sleuthkit.datamodel.LayoutFile; import org.sleuthkit.datamodel.LayoutFile;
import org.sleuthkit.datamodel.LocalFile;
import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.SleuthkitCase.CaseDbTransaction; import org.sleuthkit.datamodel.SleuthkitCase.CaseDbTransaction;
import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskCoreException;
@ -48,55 +45,19 @@ import org.sleuthkit.datamodel.LocalFilesDataSource;
import org.sleuthkit.datamodel.TskDataException; import org.sleuthkit.datamodel.TskDataException;
/** /**
* A case-level service that provides methods for retrieving files associated * A manager that provides methods for retrieving files from the current case
* with the case and for adding local files, carved files, and derived files to * and for adding local files, carved files, and derived files to the current
* the case. * case.
*/ */
public class FileManager implements Closeable { public class FileManager implements Closeable {
private static final Logger logger = Logger.getLogger(FileManager.class.getName());
private SleuthkitCase caseDb;
/*
* TODO (AUT-1905): Although this counter is guarded by the monitor of the
* FileManager, this does not guarantee unique default file set names for
* multi-user cases where multiple nodes can be running FileManagers for the
* same case.
*/
private int localFileDataSourcesCounter;
/** /**
* Constructs a case-level service that provides methods for retrieving * Constructs a manager that provides methods for retrieving files from the
* files associated with the case and for adding local files, carved files, * current case and for adding local files, carved files, and derived files
* and derived files to the case. * to the current case.
*
*/ */
FileManager(Case currentCase, SleuthkitCase caseDb) throws TskCoreException { FileManager() {
this.caseDb = caseDb;
initializeLocalFileDataSourcesCounter();
}
/**
* Initialize the counter for the number of logical/local file sets that is
* used to generate the default logical/local file data source names.
*/
private void initializeLocalFileDataSourcesCounter() {
/*
* TODO (AUT-1905): Although the counter is guarded by the monitor of
* the FileManager, this does not guarantee unique default file set
* names for multi-user cases where multiple nodes can be running
* FileManagers for the same case.
*/
localFileDataSourcesCounter = 0;
try {
List<VirtualDirectory> localFileDataSources = caseDb.getVirtualDirectoryRoots();
for (VirtualDirectory vd : localFileDataSources) {
if (vd.getName().startsWith(VirtualDirectoryNode.LOGICAL_FILE_SET_PREFIX)) {
++localFileDataSourcesCounter;
}
}
} catch (TskCoreException ex) {
logger.log(Level.SEVERE, "Error initializing logical files counter", ex); //NON-NLS
}
} }
/** /**
@ -111,12 +72,9 @@ public class FileManager implements Closeable {
* @throws TskCoreException if there is a problem querying the case * @throws TskCoreException if there is a problem querying the case
* database. * database.
*/ */
public synchronized List<AbstractFile> findFiles(String fileName) throws TskCoreException { public List<AbstractFile> findFiles(String fileName) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("FileManager closed");
}
List<AbstractFile> result = new ArrayList<>(); List<AbstractFile> result = new ArrayList<>();
List<Content> dataSources = caseDb.getRootObjects(); List<Content> dataSources = Case.getCurrentCase().getSleuthkitCase().getRootObjects();
for (Content dataSource : dataSources) { for (Content dataSource : dataSources) {
result.addAll(findFiles(dataSource, fileName)); result.addAll(findFiles(dataSource, fileName));
} }
@ -137,12 +95,9 @@ public class FileManager implements Closeable {
* @throws TskCoreException if there is a problem querying the case * @throws TskCoreException if there is a problem querying the case
* database. * database.
*/ */
public synchronized List<AbstractFile> findFiles(String fileName, String parentName) throws TskCoreException { public List<AbstractFile> findFiles(String fileName, String parentName) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("FileManager closed");
}
List<AbstractFile> result = new ArrayList<>(); List<AbstractFile> result = new ArrayList<>();
List<Content> dataSources = caseDb.getRootObjects(); List<Content> dataSources = Case.getCurrentCase().getSleuthkitCase().getRootObjects();
for (Content dataSource : dataSources) { for (Content dataSource : dataSources) {
result.addAll(findFiles(dataSource, fileName, parentName)); result.addAll(findFiles(dataSource, fileName, parentName));
} }
@ -163,12 +118,9 @@ public class FileManager implements Closeable {
* @throws TskCoreException if there is a problem querying the case * @throws TskCoreException if there is a problem querying the case
* database. * database.
*/ */
public synchronized List<AbstractFile> findFiles(String fileName, AbstractFile parent) throws TskCoreException { public List<AbstractFile> findFiles(String fileName, AbstractFile parent) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("FileManager closed");
}
List<AbstractFile> result = new ArrayList<>(); List<AbstractFile> result = new ArrayList<>();
List<Content> dataSources = caseDb.getRootObjects(); List<Content> dataSources = Case.getCurrentCase().getSleuthkitCase().getRootObjects();
for (Content dataSource : dataSources) { for (Content dataSource : dataSources) {
result.addAll(findFiles(dataSource, fileName, parent)); result.addAll(findFiles(dataSource, fileName, parent));
} }
@ -189,8 +141,8 @@ public class FileManager implements Closeable {
* @throws TskCoreException if there is a problem querying the case * @throws TskCoreException if there is a problem querying the case
* database. * database.
*/ */
public synchronized List<AbstractFile> findFiles(Content dataSource, String fileName) throws TskCoreException { public List<AbstractFile> findFiles(Content dataSource, String fileName) throws TskCoreException {
return caseDb.findFiles(dataSource, fileName); return Case.getCurrentCase().getSleuthkitCase().findFiles(dataSource, fileName);
} }
/** /**
@ -209,8 +161,8 @@ public class FileManager implements Closeable {
* @throws TskCoreException if there is a problem querying the case * @throws TskCoreException if there is a problem querying the case
* database. * database.
*/ */
public synchronized List<AbstractFile> findFiles(Content dataSource, String fileName, String parentName) throws TskCoreException { public List<AbstractFile> findFiles(Content dataSource, String fileName, String parentName) throws TskCoreException {
return caseDb.findFiles(dataSource, fileName, parentName); return Case.getCurrentCase().getSleuthkitCase().findFiles(dataSource, fileName, parentName);
} }
/** /**
@ -229,7 +181,7 @@ public class FileManager implements Closeable {
* @throws TskCoreException if there is a problem querying the case * @throws TskCoreException if there is a problem querying the case
* database. * database.
*/ */
public synchronized List<AbstractFile> findFiles(Content dataSource, String fileName, AbstractFile parent) throws TskCoreException { public List<AbstractFile> findFiles(Content dataSource, String fileName, AbstractFile parent) throws TskCoreException {
return findFiles(dataSource, fileName, parent.getName()); return findFiles(dataSource, fileName, parent.getName());
} }
@ -258,11 +210,8 @@ public class FileManager implements Closeable {
* @throws TskCoreException if there is a problem querying the case * @throws TskCoreException if there is a problem querying the case
* database. * database.
*/ */
public synchronized List<AbstractFile> openFiles(Content dataSource, String filePath) throws TskCoreException { public List<AbstractFile> openFiles(Content dataSource, String filePath) throws TskCoreException {
if (null == caseDb) { return Case.getCurrentCase().getSleuthkitCase().openFiles(dataSource, filePath);
throw new TskCoreException("FileManager closed");
}
return caseDb.openFiles(dataSource, filePath);
} }
/** /**
@ -293,14 +242,15 @@ public class FileManager implements Closeable {
* @throws TskCoreException if there is a problem adding the file to the * @throws TskCoreException if there is a problem adding the file to the
* case database. * case database.
*/ */
public synchronized DerivedFile addDerivedFile(String fileName, public DerivedFile addDerivedFile(String fileName,
String localPath, String localPath,
long size, long size,
long ctime, long crtime, long atime, long mtime, long ctime, long crtime, long atime, long mtime,
boolean isFile, boolean isFile,
AbstractFile parentFile, AbstractFile parentFile,
String rederiveDetails, String toolName, String toolVersion, String otherDetails) throws TskCoreException { String rederiveDetails, String toolName, String toolVersion, String otherDetails) throws TskCoreException {
return caseDb.addDerivedFile(fileName, localPath, size,
return Case.getCurrentCase().getSleuthkitCase().addDerivedFile(fileName, localPath, size,
ctime, crtime, atime, mtime, ctime, crtime, atime, mtime,
isFile, parentFile, rederiveDetails, toolName, toolVersion, otherDetails); isFile, parentFile, rederiveDetails, toolName, toolVersion, otherDetails);
} }
@ -322,7 +272,7 @@ public class FileManager implements Closeable {
* case database. * case database.
*/ */
public synchronized LayoutFile addCarvedFile(String fileName, long fileSize, long parentObjId, List<TskFileRange> layout) throws TskCoreException { public synchronized LayoutFile addCarvedFile(String fileName, long fileSize, long parentObjId, List<TskFileRange> layout) throws TskCoreException {
return caseDb.addCarvedFile(fileName, fileSize, parentObjId, layout); return Case.getCurrentCase().getSleuthkitCase().addCarvedFile(fileName, fileSize, parentObjId, layout);
} }
/** /**
@ -338,7 +288,7 @@ public class FileManager implements Closeable {
* case database. * case database.
*/ */
public List<LayoutFile> addCarvedFiles(List<CarvedFileContainer> filesToAdd) throws TskCoreException { public List<LayoutFile> addCarvedFiles(List<CarvedFileContainer> filesToAdd) throws TskCoreException {
return caseDb.addCarvedFiles(filesToAdd); return Case.getCurrentCase().getSleuthkitCase().addCarvedFiles(filesToAdd);
} }
/** /**
@ -352,7 +302,7 @@ public class FileManager implements Closeable {
* *
* @param An AbstractFile represeting the added file or directory. * @param An AbstractFile represeting the added file or directory.
*/ */
public void fileAdded(AbstractFile newFile); void fileAdded(AbstractFile newFile);
} }
/** /**
@ -384,27 +334,19 @@ public class FileManager implements Closeable {
* directory that does not exist or cannot be read. * directory that does not exist or cannot be read.
*/ */
public synchronized LocalFilesDataSource addLocalFilesDataSource(String deviceId, String rootVirtualDirectoryName, String timeZone, List<String> localFilePaths, FileAddProgressUpdater progressUpdater) throws TskCoreException, TskDataException { public synchronized LocalFilesDataSource addLocalFilesDataSource(String deviceId, String rootVirtualDirectoryName, String timeZone, List<String> localFilePaths, FileAddProgressUpdater progressUpdater) throws TskCoreException, TskDataException {
/*
* Convert the local/logical file paths into File objects.
*/
List<java.io.File> localFiles = getFilesAndDirectories(localFilePaths); List<java.io.File> localFiles = getFilesAndDirectories(localFilePaths);
CaseDbTransaction trans = null; CaseDbTransaction trans = null;
try { try {
/*
* Generate a name for the root virtual directory for the data
* source, if a name was not supplied, and increment the counter
* used to generate the default names.
*/
int newLocalFilesSetCount = localFileDataSourcesCounter + 1;
String rootDirectoryName = rootVirtualDirectoryName; String rootDirectoryName = rootVirtualDirectoryName;
if (rootVirtualDirectoryName.isEmpty()) { if (rootDirectoryName.isEmpty()) {
rootDirectoryName = VirtualDirectoryNode.LOGICAL_FILE_SET_PREFIX + newLocalFilesSetCount; rootDirectoryName = generateFilesDataSourceName();
} }
/* /*
* Add the root virtual directory and its local/logical file * Add the root virtual directory and its local/logical file
* chioldren to the case database. * children to the case database.
*/ */
SleuthkitCase caseDb = Case.getCurrentCase().getSleuthkitCase();
trans = caseDb.beginTransaction(); trans = caseDb.beginTransaction();
LocalFilesDataSource dataSource = caseDb.addLocalFilesDataSource(deviceId, rootDirectoryName, timeZone, trans); LocalFilesDataSource dataSource = caseDb.addLocalFilesDataSource(deviceId, rootDirectoryName, timeZone, trans);
VirtualDirectory rootDirectory = dataSource.getRootDirectory(); VirtualDirectory rootDirectory = dataSource.getRootDirectory();
@ -419,18 +361,6 @@ public class FileManager implements Closeable {
} }
trans.commit(); trans.commit();
/*
* Update the counter used to generate the default names.
*
* TODO (AUT-1905): Although the counter is guarded by the monitor
* of the FileManager, this does not guarantee unique default file
* set names for multi-user cases where multiple nodes can be
* running FileManagers for the same case.
*/
if (rootVirtualDirectoryName.isEmpty()) {
localFileDataSourcesCounter = newLocalFilesSetCount;
}
/* /*
* Publish content added events for the added files and directories. * Publish content added events for the added files and directories.
*/ */
@ -448,6 +378,34 @@ public class FileManager implements Closeable {
} }
} }
/**
* Generates a name for the root virtual directory for the data source.
*
* NOTE: Although this method is guarded by the file manager's monitor,
* there is currently a minimal chance of default name duplication for
* multi-user cases with multiple FileManagers running on different nodes.
*
* @return A default name for a local/logical files data source of the form:
* LogicalFileSet[N].
*
* @throws TskCoreException If there is a problem querying the case
* database.
*/
private synchronized String generateFilesDataSourceName() throws TskCoreException {
int localFileDataSourcesCounter = 0;
try {
List<VirtualDirectory> localFileDataSources = Case.getCurrentCase().getSleuthkitCase().getVirtualDirectoryRoots();
for (VirtualDirectory vd : localFileDataSources) {
if (vd.getName().startsWith(VirtualDirectoryNode.LOGICAL_FILE_SET_PREFIX)) {
++localFileDataSourcesCounter;
}
}
return VirtualDirectoryNode.LOGICAL_FILE_SET_PREFIX + (localFileDataSourcesCounter + 1);
} catch (TskCoreException ex) {
throw new TskCoreException("Error querying for existing local file data sources with defualt names", ex);
}
}
/** /**
* Converts a list of local/logical file and/or directory paths to a list of * Converts a list of local/logical file and/or directory paths to a list of
* file objects. * file objects.
@ -497,7 +455,7 @@ public class FileManager implements Closeable {
/* /*
* Add the directory as a virtual directory. * Add the directory as a virtual directory.
*/ */
VirtualDirectory virtualDirectory = caseDb.addVirtualDirectory(parentDirectory.getId(), localFile.getName(), trans); VirtualDirectory virtualDirectory = Case.getCurrentCase().getSleuthkitCase().addVirtualDirectory(parentDirectory.getId(), localFile.getName(), trans);
progressUpdater.fileAdded(virtualDirectory); progressUpdater.fileAdded(virtualDirectory);
/* /*
@ -512,32 +470,12 @@ public class FileManager implements Closeable {
return virtualDirectory; return virtualDirectory;
} else { } else {
return caseDb.addLocalFile(localFile.getName(), localFile.getAbsolutePath(), localFile.length(), return Case.getCurrentCase().getSleuthkitCase().addLocalFile(localFile.getName(), localFile.getAbsolutePath(), localFile.length(),
0, 0, 0, 0, 0, 0, 0, 0,
localFile.isFile(), parentDirectory, trans); localFile.isFile(), parentDirectory, trans);
} }
} }
@Override
public synchronized void close() throws IOException {
caseDb = null;
}
/**
* Contructs a case-level service that provides management of files within
* the data sources added to a case and the local files associated with a
* case.
*
* @param tskCase The case database.
*
* @deprecated Use Case.getCurrentCase().getServices().getFileManager()
* instead.
*/
@Deprecated
public FileManager(SleuthkitCase tskCase) {
this();
}
/** /**
* Adds a set of local/logical files and/or directories to the case database * Adds a set of local/logical files and/or directories to the case database
* as data source. * as data source.
@ -557,7 +495,7 @@ public class FileManager implements Closeable {
* @deprecated Use addLocalFilesDataSource instead. * @deprecated Use addLocalFilesDataSource instead.
*/ */
@Deprecated @Deprecated
public synchronized VirtualDirectory addLocalFilesDirs(List<String> localFilePaths, FileAddProgressUpdater progressUpdater) throws TskCoreException { public VirtualDirectory addLocalFilesDirs(List<String> localFilePaths, FileAddProgressUpdater progressUpdater) throws TskCoreException {
try { try {
return addLocalFilesDataSource("", "", "", localFilePaths, progressUpdater).getRootDirectory(); return addLocalFilesDataSource("", "", "", localFilePaths, progressUpdater).getRootDirectory();
} catch (TskDataException ex) { } catch (TskDataException ex) {
@ -565,4 +503,29 @@ public class FileManager implements Closeable {
} }
} }
/**
* Constructs a manager that provides methods for retrieving files from the
* current case and for adding local files, carved files, and derived files
* to the current case.
*
* @param caseDb The case database.
*
* @deprecated Use Case.getCurrentCase().getServices().getFileManager()
* instead.
*/
@Deprecated
public FileManager(SleuthkitCase caseDb) {
}
/**
* Closes the file manager.
*
* @throws IOException If there is a problem closing the file manager.
* @deprecated File manager clients should not close the file manager.
*/
@Override
@Deprecated
public void close() throws IOException {
}
} }

View File

@ -2,11 +2,10 @@
* *
* Autopsy Forensic Browser * Autopsy Forensic Browser
* *
* Copyright 2012-2016 Basis Technology Corp. * Copyright 2011-2016 Basis Technology Corp.
* * Contact: carrier <at> sleuthkit <dot> org
* Copyright 2012 42six Solutions. * Copyright 2012 42six Solutions.
* Contact: aebadirad <at> 42six <dot> com * Contact: aebadirad <at> 42six <dot> com
* Project Contact/Architect: 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");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -29,10 +28,10 @@ import java.util.List;
import org.openide.util.Lookup; import org.openide.util.Lookup;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService;
import org.sleuthkit.datamodel.SleuthkitCase; import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.autopsy.casemodule.Case;
/** /**
* A class to manage various services. * A collection of case-level services (e.g., file manager, tags manager,
* keyword search, blackboard).
*/ */
public class Services implements Closeable { public class Services implements Closeable {
@ -42,25 +41,22 @@ public class Services implements Closeable {
private final KeywordSearchService keywordSearchService; private final KeywordSearchService keywordSearchService;
private final Blackboard blackboard; private final Blackboard blackboard;
Services(Case currentCase, SleuthkitCase caseDb) { /**
fileManager = new FileManager(currentCase, caseDb); * Constructs a collection of case-level services (e.g., file manager, tags
* manager, keyword search, blackboard).
*
* @param caseDb The case database for the current case.
*
* @deprecated Use Case.getCurrentCase().getServices() instead.
*
* TODO (AUT-2158): Prevent public construction of the Services class.
*/
@Deprecated
public Services(SleuthkitCase caseDb) {
fileManager = new FileManager();
services.add(fileManager); services.add(fileManager);
tagsManager = new TagsManager(caseDb); tagsManager = new TagsManager();
services.add(tagsManager);
keywordSearchService = Lookup.getDefault().lookup(KeywordSearchService.class);
services.add(keywordSearchService);
blackboard = new Blackboard();
services.add(blackboard);
}
public Services(SleuthkitCase tskCase) {
fileManager = new FileManager(tskCase);
services.add(fileManager);
tagsManager = new TagsManager(tskCase);
services.add(tagsManager); services.add(tagsManager);
keywordSearchService = Lookup.getDefault().lookup(KeywordSearchService.class); keywordSearchService = Lookup.getDefault().lookup(KeywordSearchService.class);
@ -70,23 +66,51 @@ public class Services implements Closeable {
services.add(blackboard); services.add(blackboard);
} }
/**
* Gets the file manager service for the current case.
*
* @return The file manager service for the current case.
*/
public FileManager getFileManager() { public FileManager getFileManager() {
return fileManager; return fileManager;
} }
/**
* Gets the tags manager service for the current case.
*
* @return The tags manager service for the current case.
*/
public TagsManager getTagsManager() { public TagsManager getTagsManager() {
return tagsManager; return tagsManager;
} }
/**
* Gets the keyword search service for the current case.
*
* @return The keyword search service for the current case.
*/
public KeywordSearchService getKeywordSearchService() { public KeywordSearchService getKeywordSearchService() {
return keywordSearchService; return keywordSearchService;
} }
/**
* Gets the blackboard service for the current case.
*
* @return The blackboard service for the current case.
*/
public Blackboard getBlackboard() { public Blackboard getBlackboard() {
return blackboard; return blackboard;
} }
/**
* Closes the services for the current case.
*
* @throws IOException if there is a problem closing the services.
* @deprecated Services clients other than the case should not close the
* services.
*/
@Override @Override
@Deprecated
public void close() throws IOException { public void close() throws IOException {
for (Closeable service : services) { for (Closeable service : services) {
service.close(); service.close();

View File

@ -32,7 +32,6 @@ import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.BlackboardArtifactTag; import org.sleuthkit.datamodel.BlackboardArtifactTag;
import org.sleuthkit.datamodel.Content; import org.sleuthkit.datamodel.Content;
import org.sleuthkit.datamodel.ContentTag; import org.sleuthkit.datamodel.ContentTag;
import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TagName; import org.sleuthkit.datamodel.TagName;
import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskCoreException;
@ -45,7 +44,6 @@ public class TagsManager implements Closeable {
private static final Logger logger = Logger.getLogger(TagsManager.class.getName()); private static final Logger logger = Logger.getLogger(TagsManager.class.getName());
private static final String TAGS_SETTINGS_NAME = "Tags"; //NON-NLS private static final String TAGS_SETTINGS_NAME = "Tags"; //NON-NLS
private static final String TAG_NAMES_SETTING_KEY = "TagNames"; //NON-NLS private static final String TAG_NAMES_SETTING_KEY = "TagNames"; //NON-NLS
private final SleuthkitCase caseDb;
private final HashMap<String, TagName> uniqueTagNames = new HashMap<>(); private final HashMap<String, TagName> uniqueTagNames = new HashMap<>();
private boolean tagNamesLoaded = false; private boolean tagNamesLoaded = false;
@ -53,11 +51,8 @@ public class TagsManager implements Closeable {
* Constructs a per case Autopsy service that manages the creation, * Constructs a per case Autopsy service that manages the creation,
* updating, and deletion of tags applied to content and blackboard * updating, and deletion of tags applied to content and blackboard
* artifacts by users. * artifacts by users.
*
* @param caseDb The case database for the current case.
*/ */
TagsManager(SleuthkitCase caseDb) { TagsManager() {
this.caseDb = caseDb;
} }
/** /**
@ -71,7 +66,7 @@ public class TagsManager implements Closeable {
*/ */
public synchronized List<TagName> getAllTagNames() throws TskCoreException { public synchronized List<TagName> getAllTagNames() throws TskCoreException {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return caseDb.getAllTagNames(); return Case.getCurrentCase().getSleuthkitCase().getAllTagNames();
} }
/** /**
@ -85,7 +80,7 @@ public class TagsManager implements Closeable {
*/ */
public synchronized List<TagName> getTagNamesInUse() throws TskCoreException { public synchronized List<TagName> getTagNamesInUse() throws TskCoreException {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return caseDb.getTagNamesInUse(); return Case.getCurrentCase().getSleuthkitCase().getTagNamesInUse();
} }
/** /**
@ -159,7 +154,7 @@ public class TagsManager implements Closeable {
/* /*
* Add the tag name to the case. * Add the tag name to the case.
*/ */
TagName newTagName = caseDb.addTagName(displayName, description, color); TagName newTagName = Case.getCurrentCase().getSleuthkitCase().addTagName(displayName, description, color);
/* /*
* Add the tag name to the tags settings. * Add the tag name to the tags settings.
@ -245,7 +240,7 @@ public class TagsManager implements Closeable {
} }
} }
tag = caseDb.addContentTag(content, tagName, comment, beginByteOffset, endByteOffset); tag = Case.getCurrentCase().getSleuthkitCase().addContentTag(content, tagName, comment, beginByteOffset, endByteOffset);
} }
try { try {
@ -267,7 +262,7 @@ public class TagsManager implements Closeable {
public void deleteContentTag(ContentTag tag) throws TskCoreException { public void deleteContentTag(ContentTag tag) throws TskCoreException {
synchronized (this) { synchronized (this) {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
caseDb.deleteContentTag(tag); Case.getCurrentCase().getSleuthkitCase().deleteContentTag(tag);
} }
try { try {
@ -287,7 +282,7 @@ public class TagsManager implements Closeable {
*/ */
public synchronized List<ContentTag> getAllContentTags() throws TskCoreException { public synchronized List<ContentTag> getAllContentTags() throws TskCoreException {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return caseDb.getAllContentTags(); return Case.getCurrentCase().getSleuthkitCase().getAllContentTags();
} }
/** /**
@ -302,7 +297,7 @@ public class TagsManager implements Closeable {
*/ */
public synchronized long getContentTagsCountByTagName(TagName tagName) throws TskCoreException { public synchronized long getContentTagsCountByTagName(TagName tagName) throws TskCoreException {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return caseDb.getContentTagsCountByTagName(tagName); return Case.getCurrentCase().getSleuthkitCase().getContentTagsCountByTagName(tagName);
} }
/** /**
@ -317,7 +312,7 @@ public class TagsManager implements Closeable {
*/ */
public synchronized ContentTag getContentTagByTagID(long tagID) throws TskCoreException { public synchronized ContentTag getContentTagByTagID(long tagID) throws TskCoreException {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return caseDb.getContentTagByID(tagID); return Case.getCurrentCase().getSleuthkitCase().getContentTagByID(tagID);
} }
/** /**
@ -333,7 +328,7 @@ public class TagsManager implements Closeable {
*/ */
public synchronized List<ContentTag> getContentTagsByTagName(TagName tagName) throws TskCoreException { public synchronized List<ContentTag> getContentTagsByTagName(TagName tagName) throws TskCoreException {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return caseDb.getContentTagsByTagName(tagName); return Case.getCurrentCase().getSleuthkitCase().getContentTagsByTagName(tagName);
} }
/** /**
@ -349,7 +344,7 @@ public class TagsManager implements Closeable {
*/ */
public synchronized List<ContentTag> getContentTagsByContent(Content content) throws TskCoreException { public synchronized List<ContentTag> getContentTagsByContent(Content content) throws TskCoreException {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return caseDb.getContentTagsByContent(content); return Case.getCurrentCase().getSleuthkitCase().getContentTagsByContent(content);
} }
/** /**
@ -388,7 +383,7 @@ public class TagsManager implements Closeable {
if (null == comment) { if (null == comment) {
throw new IllegalArgumentException("Passed null comment argument"); throw new IllegalArgumentException("Passed null comment argument");
} }
tag = caseDb.addBlackboardArtifactTag(artifact, tagName, comment); tag = Case.getCurrentCase().getSleuthkitCase().addBlackboardArtifactTag(artifact, tagName, comment);
} }
try { try {
@ -410,7 +405,7 @@ public class TagsManager implements Closeable {
public void deleteBlackboardArtifactTag(BlackboardArtifactTag tag) throws TskCoreException { public void deleteBlackboardArtifactTag(BlackboardArtifactTag tag) throws TskCoreException {
synchronized (this) { synchronized (this) {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
caseDb.deleteBlackboardArtifactTag(tag); Case.getCurrentCase().getSleuthkitCase().deleteBlackboardArtifactTag(tag);
} }
try { try {
@ -430,7 +425,7 @@ public class TagsManager implements Closeable {
*/ */
public synchronized List<BlackboardArtifactTag> getAllBlackboardArtifactTags() throws TskCoreException { public synchronized List<BlackboardArtifactTag> getAllBlackboardArtifactTags() throws TskCoreException {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return caseDb.getAllBlackboardArtifactTags(); return Case.getCurrentCase().getSleuthkitCase().getAllBlackboardArtifactTags();
} }
/** /**
@ -446,7 +441,7 @@ public class TagsManager implements Closeable {
*/ */
public synchronized long getBlackboardArtifactTagsCountByTagName(TagName tagName) throws TskCoreException { public synchronized long getBlackboardArtifactTagsCountByTagName(TagName tagName) throws TskCoreException {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return caseDb.getBlackboardArtifactTagsCountByTagName(tagName); return Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifactTagsCountByTagName(tagName);
} }
/** /**
@ -461,7 +456,7 @@ public class TagsManager implements Closeable {
*/ */
public synchronized BlackboardArtifactTag getBlackboardArtifactTagByTagID(long tagID) throws TskCoreException { public synchronized BlackboardArtifactTag getBlackboardArtifactTagByTagID(long tagID) throws TskCoreException {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return caseDb.getBlackboardArtifactTagByID(tagID); return Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifactTagByID(tagID);
} }
/** /**
@ -477,7 +472,7 @@ public class TagsManager implements Closeable {
*/ */
public synchronized List<BlackboardArtifactTag> getBlackboardArtifactTagsByTagName(TagName tagName) throws TskCoreException { public synchronized List<BlackboardArtifactTag> getBlackboardArtifactTagsByTagName(TagName tagName) throws TskCoreException {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return caseDb.getBlackboardArtifactTagsByTagName(tagName); return Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifactTagsByTagName(tagName);
} }
/** /**
@ -493,13 +488,18 @@ public class TagsManager implements Closeable {
*/ */
public synchronized List<BlackboardArtifactTag> getBlackboardArtifactTagsByArtifact(BlackboardArtifact artifact) throws TskCoreException { public synchronized List<BlackboardArtifactTag> getBlackboardArtifactTagsByArtifact(BlackboardArtifact artifact) throws TskCoreException {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return caseDb.getBlackboardArtifactTagsByArtifact(artifact); return Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifactTagsByArtifact(artifact);
} }
/** /**
* Saves the avaialble tag names to secondary storage. * Closes the tags manager, saving the avaialble tag names to secondary
* storage.
*
* @throws IOException If there is a problem closing the tags manager.
* @deprecated Tags manager clients should not close the tags manager.
*/ */
@Override @Override
@Deprecated
public synchronized void close() throws IOException { public synchronized void close() throws IOException {
saveTagNamesToTagsSettings(); saveTagNamesToTagsSettings();
} }
@ -524,7 +524,7 @@ public class TagsManager implements Closeable {
*/ */
private void addTagNamesFromCurrentCase() { private void addTagNamesFromCurrentCase() {
try { try {
List<TagName> currentTagNames = caseDb.getAllTagNames(); List<TagName> currentTagNames = Case.getCurrentCase().getSleuthkitCase().getAllTagNames();
for (TagName tagName : currentTagNames) { for (TagName tagName : currentTagNames) {
uniqueTagNames.put(tagName.getDisplayName(), tagName); uniqueTagNames.put(tagName.getDisplayName(), tagName);
} }
@ -550,7 +550,7 @@ public class TagsManager implements Closeable {
String[] tagNameAttributes = tagNameTuple.split(","); String[] tagNameAttributes = tagNameTuple.split(",");
if (!uniqueTagNames.containsKey(tagNameAttributes[0])) { if (!uniqueTagNames.containsKey(tagNameAttributes[0])) {
try { try {
TagName tagName = caseDb.addTagName(tagNameAttributes[0], tagNameAttributes[1], TagName.HTML_COLOR.getColorByName(tagNameAttributes[2])); TagName tagName = Case.getCurrentCase().getSleuthkitCase().addTagName(tagNameAttributes[0], tagNameAttributes[1], TagName.HTML_COLOR.getColorByName(tagNameAttributes[2]));
uniqueTagNames.put(tagName.getDisplayName(), tagName); uniqueTagNames.put(tagName.getDisplayName(), tagName);
} catch (TskCoreException ex) { } catch (TskCoreException ex) {
Logger.getLogger(TagsManager.class.getName()).log(Level.SEVERE, "Failed to add saved tag name " + tagNameAttributes[0], ex); //NON-NLS Logger.getLogger(TagsManager.class.getName()).log(Level.SEVERE, "Failed to add saved tag name " + tagNameAttributes[0], ex); //NON-NLS
@ -566,7 +566,7 @@ public class TagsManager implements Closeable {
private void addPredefinedTagNames() { private void addPredefinedTagNames() {
if (!uniqueTagNames.containsKey(NbBundle.getMessage(this.getClass(), "TagsManager.predefTagNames.bookmark.text"))) { if (!uniqueTagNames.containsKey(NbBundle.getMessage(this.getClass(), "TagsManager.predefTagNames.bookmark.text"))) {
try { try {
TagName tagName = caseDb.addTagName( TagName tagName = Case.getCurrentCase().getSleuthkitCase().addTagName(
NbBundle.getMessage(this.getClass(), "TagsManager.predefTagNames.bookmark.text"), "", TagName.HTML_COLOR.NONE); NbBundle.getMessage(this.getClass(), "TagsManager.predefTagNames.bookmark.text"), "", TagName.HTML_COLOR.NONE);
uniqueTagNames.put(tagName.getDisplayName(), tagName); uniqueTagNames.put(tagName.getDisplayName(), tagName);
} catch (TskCoreException ex) { } catch (TskCoreException ex) {

View File

@ -1,7 +1,7 @@
/* /*
* Autopsy Forensic Browser * Autopsy Forensic Browser
* *
* Copyright 2014 Basis Technology Corp. * Copyright 2011-2016 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,9 @@ import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskCoreException;
/** /**
* An implementation of a keyword search service.
* *
* TODO (AUT-2158: This interface should not extend Closeable.
*/ */
public interface KeywordSearchService extends Closeable { public interface KeywordSearchService extends Closeable {