Revert AUT-2158 changes

This commit is contained in:
Richard Cordovano 2016-05-27 15:13:59 -04:00
parent 02233f5ce2
commit 0ebfb0d7da
5 changed files with 220 additions and 64 deletions

View File

@ -282,7 +282,6 @@ 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;
@ -836,7 +835,6 @@ 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

@ -25,17 +25,30 @@ import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService; import org.sleuthkit.autopsy.keywordsearchservice.KeywordSearchService;
import org.sleuthkit.datamodel.BlackboardArtifact; import org.sleuthkit.datamodel.BlackboardArtifact;
import org.sleuthkit.datamodel.BlackboardAttribute; import org.sleuthkit.datamodel.BlackboardAttribute;
import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskCoreException;
import org.sleuthkit.datamodel.TskDataException; import org.sleuthkit.datamodel.TskDataException;
/** /**
* Represents the blackboard, a place where artifacts and their attributes are * A representation of the blackboard, a place where artifacts and their
* posted. * attributes are posted.
* *
* NOTE: This API of this class is under development. * NOTE: This API of this class is under development.
*/ */
public final class Blackboard implements Closeable { public final class Blackboard implements Closeable {
private SleuthkitCase caseDb;
/**
* Constructs a representation of the blackboard, a place where artifacts
* and their attributes are posted.
*
* @param casedb The case database.
*/
Blackboard(SleuthkitCase casedb) {
this.caseDb = casedb;
}
/** /**
* Indexes the text associated with the an artifact. * Indexes the text associated with the an artifact.
* *
@ -44,6 +57,9 @@ public final class Blackboard implements Closeable {
* @throws BlackboardException If there is a problem indexing the artifact. * @throws BlackboardException If there is a problem indexing the artifact.
*/ */
public void indexArtifact(BlackboardArtifact artifact) throws BlackboardException { public void indexArtifact(BlackboardArtifact artifact) throws BlackboardException {
if (null == caseDb) {
throw new BlackboardException("Blackboard has been closed");
}
KeywordSearchService searchService = Lookup.getDefault().lookup(KeywordSearchService.class); KeywordSearchService searchService = Lookup.getDefault().lookup(KeywordSearchService.class);
if (null == searchService) { if (null == searchService) {
throw new BlackboardException("Keyword search service not found"); throw new BlackboardException("Keyword search service not found");
@ -68,6 +84,9 @@ public final class Blackboard implements Closeable {
* adding the artifact type. * adding the artifact type.
*/ */
public BlackboardArtifact.Type getOrAddArtifactType(String typeName, String displayName) throws BlackboardException { public BlackboardArtifact.Type getOrAddArtifactType(String typeName, String displayName) throws BlackboardException {
if (null == caseDb) {
throw new BlackboardException("Blackboard has been closed");
}
try { try {
return Case.getCurrentCase().getSleuthkitCase().addBlackboardArtifactType(typeName, displayName); return Case.getCurrentCase().getSleuthkitCase().addBlackboardArtifactType(typeName, displayName);
} catch (TskDataException typeExistsEx) { } catch (TskDataException typeExistsEx) {
@ -95,6 +114,9 @@ public final class Blackboard implements Closeable {
* adding the attribute type. * adding the attribute type.
*/ */
public BlackboardAttribute.Type getOrAddAttributeType(String typeName, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE valueType, String displayName) throws BlackboardException { public BlackboardAttribute.Type getOrAddAttributeType(String typeName, BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE valueType, String displayName) throws BlackboardException {
if (null == caseDb) {
throw new BlackboardException("Blackboard has been closed");
}
try { try {
return Case.getCurrentCase().getSleuthkitCase().addArtifactAttributeType(typeName, valueType, displayName); return Case.getCurrentCase().getSleuthkitCase().addArtifactAttributeType(typeName, valueType, displayName);
} catch (TskDataException typeExistsEx) { } catch (TskDataException typeExistsEx) {
@ -112,13 +134,13 @@ public final class Blackboard implements Closeable {
* Closes the blackboard. * Closes the blackboard.
* *
* @throws IOException If there is a problem closing the blackboard. * @throws IOException If there is a problem closing the blackboard.
* @deprecated blackboard clients should not close the blackboard.
*/ */
@Override @Override
@Deprecated public synchronized void close() throws IOException {
public void close() throws IOException { caseDb = null;
} }
/** /**
* A blackboard exception. * A blackboard exception.
*/ */

View File

@ -25,9 +25,9 @@ package org.sleuthkit.autopsy.casemodule.services;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case;
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;
@ -43,6 +43,7 @@ import org.sleuthkit.datamodel.VirtualDirectory;
import org.sleuthkit.datamodel.CarvedFileContainer; import org.sleuthkit.datamodel.CarvedFileContainer;
import org.sleuthkit.datamodel.LocalFilesDataSource; import org.sleuthkit.datamodel.LocalFilesDataSource;
import org.sleuthkit.datamodel.TskDataException; import org.sleuthkit.datamodel.TskDataException;
import org.apache.commons.lang3.StringUtils;
/** /**
* A manager that provides methods for retrieving files from the current case * A manager that provides methods for retrieving files from the current case
@ -51,13 +52,65 @@ import org.sleuthkit.datamodel.TskDataException;
*/ */
public class FileManager implements Closeable { public class FileManager implements Closeable {
private SleuthkitCase caseDb;
/** /**
* Constructs a manager that provides methods for retrieving files from the * Constructs a manager that provides methods for retrieving files from the
* current case and for adding local files, carved files, and derived files * current case and for adding local files, carved files, and derived files
* to the current case. * to the current case.
* *
* @param caseDb The case database.
*/ */
FileManager() { public FileManager(SleuthkitCase caseDb) {
this.caseDb = caseDb;
}
/**
* Finds all files with types that match one of a collection of MIME types.
*
* @param mimeTypes The MIME types.
*
* @return The files.
*
* @throws TskCoreException If there is a problem querying the case
* database.
*/
public synchronized List<AbstractFile> findFilesByMimeType(Collection<String> mimeTypes) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("File manager has been closed");
}
return caseDb.findAllFilesWhere(createFileTypeInCondition(mimeTypes));
}
/**
* Finds all files in a given data source (image, local/logical files set,
* etc.) with types that match one of a collection of MIME types.
*
* @param dataSource The data source.
* @param mimeTypes The MIME types.
*
* @return The files.
*
* @throws TskCoreException If there is a problem querying the case
* database.
*/
public synchronized List<AbstractFile> findFilesByMimeType(Content dataSource, Collection<String> mimeTypes) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("File manager has been closed");
}
return caseDb.findAllFilesWhere("data_source_obj_id = " + dataSource.getId() + " AND " + createFileTypeInCondition(mimeTypes));
}
/**
* Converts a list of MIME types into an SQL "mime_type IN" condition.
*
* @param mimeTypes The MIIME types.
*
* @return The condition string.
*/
private static String createFileTypeInCondition(Collection<String> mimeTypes) {
String types = StringUtils.join(mimeTypes, "',");
return "mime_type IN ('" + types + "')";
} }
/** /**
@ -72,9 +125,12 @@ 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 List<AbstractFile> findFiles(String fileName) throws TskCoreException { public synchronized List<AbstractFile> findFiles(String fileName) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("File manager has been closed");
}
List<AbstractFile> result = new ArrayList<>(); List<AbstractFile> result = new ArrayList<>();
List<Content> dataSources = Case.getCurrentCase().getSleuthkitCase().getRootObjects(); List<Content> dataSources = caseDb.getRootObjects();
for (Content dataSource : dataSources) { for (Content dataSource : dataSources) {
result.addAll(findFiles(dataSource, fileName)); result.addAll(findFiles(dataSource, fileName));
} }
@ -95,9 +151,12 @@ 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 List<AbstractFile> findFiles(String fileName, String parentName) throws TskCoreException { public synchronized List<AbstractFile> findFiles(String fileName, String parentName) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("File manager has been closed");
}
List<AbstractFile> result = new ArrayList<>(); List<AbstractFile> result = new ArrayList<>();
List<Content> dataSources = Case.getCurrentCase().getSleuthkitCase().getRootObjects(); List<Content> dataSources = caseDb.getRootObjects();
for (Content dataSource : dataSources) { for (Content dataSource : dataSources) {
result.addAll(findFiles(dataSource, fileName, parentName)); result.addAll(findFiles(dataSource, fileName, parentName));
} }
@ -118,9 +177,12 @@ 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 List<AbstractFile> findFiles(String fileName, AbstractFile parent) throws TskCoreException { public synchronized List<AbstractFile> findFiles(String fileName, AbstractFile parent) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("File manager has been closed");
}
List<AbstractFile> result = new ArrayList<>(); List<AbstractFile> result = new ArrayList<>();
List<Content> dataSources = Case.getCurrentCase().getSleuthkitCase().getRootObjects(); List<Content> dataSources = caseDb.getRootObjects();
for (Content dataSource : dataSources) { for (Content dataSource : dataSources) {
result.addAll(findFiles(dataSource, fileName, parent)); result.addAll(findFiles(dataSource, fileName, parent));
} }
@ -141,8 +203,11 @@ 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 List<AbstractFile> findFiles(Content dataSource, String fileName) throws TskCoreException { public synchronized List<AbstractFile> findFiles(Content dataSource, String fileName) throws TskCoreException {
return Case.getCurrentCase().getSleuthkitCase().findFiles(dataSource, fileName); if (null == caseDb) {
throw new TskCoreException("File manager has been closed");
}
return caseDb.findFiles(dataSource, fileName);
} }
/** /**
@ -161,8 +226,11 @@ 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 List<AbstractFile> findFiles(Content dataSource, String fileName, String parentName) throws TskCoreException { public synchronized List<AbstractFile> findFiles(Content dataSource, String fileName, String parentName) throws TskCoreException {
return Case.getCurrentCase().getSleuthkitCase().findFiles(dataSource, fileName, parentName); if (null == caseDb) {
throw new TskCoreException("File manager has been closed");
}
return caseDb.findFiles(dataSource, fileName, parentName);
} }
/** /**
@ -181,7 +249,10 @@ 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 List<AbstractFile> findFiles(Content dataSource, String fileName, AbstractFile parent) throws TskCoreException { public synchronized List<AbstractFile> findFiles(Content dataSource, String fileName, AbstractFile parent) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("File manager has been closed");
}
return findFiles(dataSource, fileName, parent.getName()); return findFiles(dataSource, fileName, parent.getName());
} }
@ -210,8 +281,11 @@ 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 List<AbstractFile> openFiles(Content dataSource, String filePath) throws TskCoreException { public synchronized List<AbstractFile> openFiles(Content dataSource, String filePath) throws TskCoreException {
return Case.getCurrentCase().getSleuthkitCase().openFiles(dataSource, filePath); if (null == caseDb) {
throw new TskCoreException("File manager has been closed");
}
return caseDb.openFiles(dataSource, filePath);
} }
/** /**
@ -242,15 +316,17 @@ 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 DerivedFile addDerivedFile(String fileName, public synchronized 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 {
if (null == caseDb) {
return Case.getCurrentCase().getSleuthkitCase().addDerivedFile(fileName, localPath, size, throw new TskCoreException("File manager has been closed");
}
return caseDb.addDerivedFile(fileName, localPath, size,
ctime, crtime, atime, mtime, ctime, crtime, atime, mtime,
isFile, parentFile, rederiveDetails, toolName, toolVersion, otherDetails); isFile, parentFile, rederiveDetails, toolName, toolVersion, otherDetails);
} }
@ -272,7 +348,10 @@ 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 Case.getCurrentCase().getSleuthkitCase().addCarvedFile(fileName, fileSize, parentObjId, layout); if (null == caseDb) {
throw new TskCoreException("File manager has been closed");
}
return caseDb.addCarvedFile(fileName, fileSize, parentObjId, layout);
} }
/** /**
@ -287,8 +366,11 @@ public class FileManager implements Closeable {
* @throws TskCoreException if there is a problem adding the files to the * @throws TskCoreException if there is a problem adding the files to the
* case database. * case database.
*/ */
public List<LayoutFile> addCarvedFiles(List<CarvedFileContainer> filesToAdd) throws TskCoreException { public synchronized List<LayoutFile> addCarvedFiles(List<CarvedFileContainer> filesToAdd) throws TskCoreException {
return Case.getCurrentCase().getSleuthkitCase().addCarvedFiles(filesToAdd); if (null == caseDb) {
throw new TskCoreException("File manager has been closed");
}
return caseDb.addCarvedFiles(filesToAdd);
} }
/** /**
@ -334,19 +416,21 @@ 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 {
if (null == caseDb) {
throw new TskCoreException("File manager has been closed");
}
List<java.io.File> localFiles = getFilesAndDirectories(localFilePaths); List<java.io.File> localFiles = getFilesAndDirectories(localFilePaths);
CaseDbTransaction trans = null; CaseDbTransaction trans = null;
try { try {
String rootDirectoryName = rootVirtualDirectoryName; String rootDirectoryName = rootVirtualDirectoryName;
if (rootDirectoryName.isEmpty()) { if (rootDirectoryName.isEmpty()) {
rootDirectoryName = generateFilesDataSourceName(); rootDirectoryName = generateFilesDataSourceName(caseDb);
} }
/* /*
* Add the root virtual directory and its local/logical file * Add the root virtual directory and its local/logical file
* children 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();
@ -391,10 +475,10 @@ 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.
*/ */
private synchronized String generateFilesDataSourceName() throws TskCoreException { private static synchronized String generateFilesDataSourceName(SleuthkitCase caseDb) throws TskCoreException {
int localFileDataSourcesCounter = 0; int localFileDataSourcesCounter = 0;
try { try {
List<VirtualDirectory> localFileDataSources = Case.getCurrentCase().getSleuthkitCase().getVirtualDirectoryRoots(); List<VirtualDirectory> localFileDataSources = caseDb.getVirtualDirectoryRoots();
for (VirtualDirectory vd : localFileDataSources) { for (VirtualDirectory vd : localFileDataSources) {
if (vd.getName().startsWith(VirtualDirectoryNode.LOGICAL_FILE_SET_PREFIX)) { if (vd.getName().startsWith(VirtualDirectoryNode.LOGICAL_FILE_SET_PREFIX)) {
++localFileDataSourcesCounter; ++localFileDataSourcesCounter;
@ -455,7 +539,7 @@ public class FileManager implements Closeable {
/* /*
* Add the directory as a virtual directory. * Add the directory as a virtual directory.
*/ */
VirtualDirectory virtualDirectory = Case.getCurrentCase().getSleuthkitCase().addVirtualDirectory(parentDirectory.getId(), localFile.getName(), trans); VirtualDirectory virtualDirectory = caseDb.addVirtualDirectory(parentDirectory.getId(), localFile.getName(), trans);
progressUpdater.fileAdded(virtualDirectory); progressUpdater.fileAdded(virtualDirectory);
/* /*
@ -470,7 +554,7 @@ public class FileManager implements Closeable {
return virtualDirectory; return virtualDirectory;
} else { } else {
return Case.getCurrentCase().getSleuthkitCase().addLocalFile(localFile.getName(), localFile.getAbsolutePath(), localFile.length(), return caseDb.addLocalFile(localFile.getName(), localFile.getAbsolutePath(), localFile.length(),
0, 0, 0, 0, 0, 0, 0, 0,
localFile.isFile(), parentDirectory, trans); localFile.isFile(), parentDirectory, trans);
} }
@ -495,7 +579,10 @@ public class FileManager implements Closeable {
* @deprecated Use addLocalFilesDataSource instead. * @deprecated Use addLocalFilesDataSource instead.
*/ */
@Deprecated @Deprecated
public VirtualDirectory addLocalFilesDirs(List<String> localFilePaths, FileAddProgressUpdater progressUpdater) throws TskCoreException { public synchronized VirtualDirectory addLocalFilesDirs(List<String> localFilePaths, FileAddProgressUpdater progressUpdater) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("File manager has been closed");
}
try { try {
return addLocalFilesDataSource("", "", "", localFilePaths, progressUpdater).getRootDirectory(); return addLocalFilesDataSource("", "", "", localFilePaths, progressUpdater).getRootDirectory();
} catch (TskDataException ex) { } catch (TskDataException ex) {
@ -503,29 +590,14 @@ 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. * Closes the file manager.
* *
* @throws IOException If there is a problem closing 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 @Override
@Deprecated public synchronized void close() throws IOException {
public void close() throws IOException { caseDb = null;
} }
} }

View File

@ -46,23 +46,18 @@ public class Services implements Closeable {
* manager, keyword search, blackboard). * manager, keyword search, blackboard).
* *
* @param caseDb The case database for the current case. * @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) { public Services(SleuthkitCase caseDb) {
fileManager = new FileManager(); fileManager = new FileManager(caseDb);
services.add(fileManager); services.add(fileManager);
tagsManager = new TagsManager(); tagsManager = new TagsManager(caseDb);
services.add(tagsManager); services.add(tagsManager);
keywordSearchService = Lookup.getDefault().lookup(KeywordSearchService.class); keywordSearchService = Lookup.getDefault().lookup(KeywordSearchService.class);
services.add(keywordSearchService); services.add(keywordSearchService);
blackboard = new Blackboard(); blackboard = new Blackboard(caseDb);
services.add(blackboard); services.add(blackboard);
} }
@ -106,11 +101,8 @@ public class Services implements Closeable {
* Closes the services for the current case. * Closes the services for the current case.
* *
* @throws IOException if there is a problem closing the services. * @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,6 +32,7 @@ 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;
@ -44,6 +45,7 @@ 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 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;
@ -51,8 +53,11 @@ 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.
*/ */
TagsManager() { TagsManager(SleuthkitCase caseDb) {
this.caseDb = caseDb;
} }
/** /**
@ -65,6 +70,9 @@ public class TagsManager implements Closeable {
* database. * database.
*/ */
public synchronized List<TagName> getAllTagNames() throws TskCoreException { public synchronized List<TagName> getAllTagNames() throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return Case.getCurrentCase().getSleuthkitCase().getAllTagNames(); return Case.getCurrentCase().getSleuthkitCase().getAllTagNames();
} }
@ -79,6 +87,9 @@ public class TagsManager implements Closeable {
* database. * database.
*/ */
public synchronized List<TagName> getTagNamesInUse() throws TskCoreException { public synchronized List<TagName> getTagNamesInUse() throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return Case.getCurrentCase().getSleuthkitCase().getTagNamesInUse(); return Case.getCurrentCase().getSleuthkitCase().getTagNamesInUse();
} }
@ -109,6 +120,9 @@ public class TagsManager implements Closeable {
* to the case database. * to the case database.
*/ */
public TagName addTagName(String displayName) throws TagNameAlreadyExistsException, TskCoreException { public TagName addTagName(String displayName) throws TagNameAlreadyExistsException, TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
return addTagName(displayName, "", TagName.HTML_COLOR.NONE); return addTagName(displayName, "", TagName.HTML_COLOR.NONE);
} }
@ -127,6 +141,9 @@ public class TagsManager implements Closeable {
* to the case database. * to the case database.
*/ */
public TagName addTagName(String displayName, String description) throws TagNameAlreadyExistsException, TskCoreException { public TagName addTagName(String displayName, String description) throws TagNameAlreadyExistsException, TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
return addTagName(displayName, description, TagName.HTML_COLOR.NONE); return addTagName(displayName, description, TagName.HTML_COLOR.NONE);
} }
@ -146,6 +163,9 @@ public class TagsManager implements Closeable {
* to the case database. * to the case database.
*/ */
public synchronized TagName addTagName(String displayName, String description, TagName.HTML_COLOR color) throws TagNameAlreadyExistsException, TskCoreException { public synchronized TagName addTagName(String displayName, String description, TagName.HTML_COLOR color) throws TagNameAlreadyExistsException, TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
if (uniqueTagNames.containsKey(displayName)) { if (uniqueTagNames.containsKey(displayName)) {
throw new TagNameAlreadyExistsException(); throw new TagNameAlreadyExistsException();
@ -177,6 +197,9 @@ public class TagsManager implements Closeable {
* database. * database.
*/ */
public ContentTag addContentTag(Content content, TagName tagName) throws TskCoreException { public ContentTag addContentTag(Content content, TagName tagName) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
return addContentTag(content, tagName, "", -1, -1); return addContentTag(content, tagName, "", -1, -1);
} }
@ -193,6 +216,9 @@ public class TagsManager implements Closeable {
* database. * database.
*/ */
public ContentTag addContentTag(Content content, TagName tagName, String comment) throws TskCoreException { public ContentTag addContentTag(Content content, TagName tagName, String comment) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
return addContentTag(content, tagName, comment, -1, -1); return addContentTag(content, tagName, comment, -1, -1);
} }
@ -213,6 +239,9 @@ public class TagsManager implements Closeable {
* the case database. * the case database.
*/ */
public ContentTag addContentTag(Content content, TagName tagName, String comment, long beginByteOffset, long endByteOffset) throws IllegalArgumentException, TskCoreException { public ContentTag addContentTag(Content content, TagName tagName, String comment, long beginByteOffset, long endByteOffset) throws IllegalArgumentException, TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
ContentTag tag; ContentTag tag;
synchronized (this) { synchronized (this) {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
@ -260,6 +289,9 @@ public class TagsManager implements Closeable {
* case database. * case database.
*/ */
public void deleteContentTag(ContentTag tag) throws TskCoreException { public void deleteContentTag(ContentTag tag) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
synchronized (this) { synchronized (this) {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
Case.getCurrentCase().getSleuthkitCase().deleteContentTag(tag); Case.getCurrentCase().getSleuthkitCase().deleteContentTag(tag);
@ -281,6 +313,9 @@ public class TagsManager implements Closeable {
* case database. * case database.
*/ */
public synchronized List<ContentTag> getAllContentTags() throws TskCoreException { public synchronized List<ContentTag> getAllContentTags() throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return Case.getCurrentCase().getSleuthkitCase().getAllContentTags(); return Case.getCurrentCase().getSleuthkitCase().getAllContentTags();
} }
@ -296,6 +331,9 @@ public class TagsManager implements Closeable {
* the case database. * the case database.
*/ */
public synchronized long getContentTagsCountByTagName(TagName tagName) throws TskCoreException { public synchronized long getContentTagsCountByTagName(TagName tagName) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return Case.getCurrentCase().getSleuthkitCase().getContentTagsCountByTagName(tagName); return Case.getCurrentCase().getSleuthkitCase().getContentTagsCountByTagName(tagName);
} }
@ -311,6 +349,9 @@ public class TagsManager implements Closeable {
* case database. * case database.
*/ */
public synchronized ContentTag getContentTagByTagID(long tagID) throws TskCoreException { public synchronized ContentTag getContentTagByTagID(long tagID) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return Case.getCurrentCase().getSleuthkitCase().getContentTagByID(tagID); return Case.getCurrentCase().getSleuthkitCase().getContentTagByID(tagID);
} }
@ -327,6 +368,9 @@ public class TagsManager implements Closeable {
* case database. * case database.
*/ */
public synchronized List<ContentTag> getContentTagsByTagName(TagName tagName) throws TskCoreException { public synchronized List<ContentTag> getContentTagsByTagName(TagName tagName) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return Case.getCurrentCase().getSleuthkitCase().getContentTagsByTagName(tagName); return Case.getCurrentCase().getSleuthkitCase().getContentTagsByTagName(tagName);
} }
@ -343,6 +387,9 @@ public class TagsManager implements Closeable {
* case database. * case database.
*/ */
public synchronized List<ContentTag> getContentTagsByContent(Content content) throws TskCoreException { public synchronized List<ContentTag> getContentTagsByContent(Content content) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return Case.getCurrentCase().getSleuthkitCase().getContentTagsByContent(content); return Case.getCurrentCase().getSleuthkitCase().getContentTagsByContent(content);
} }
@ -360,6 +407,9 @@ public class TagsManager implements Closeable {
* database. * database.
*/ */
public BlackboardArtifactTag addBlackboardArtifactTag(BlackboardArtifact artifact, TagName tagName) throws TskCoreException { public BlackboardArtifactTag addBlackboardArtifactTag(BlackboardArtifact artifact, TagName tagName) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
return addBlackboardArtifactTag(artifact, tagName, ""); return addBlackboardArtifactTag(artifact, tagName, "");
} }
@ -377,6 +427,9 @@ public class TagsManager implements Closeable {
* database. * database.
*/ */
public BlackboardArtifactTag addBlackboardArtifactTag(BlackboardArtifact artifact, TagName tagName, String comment) throws TskCoreException { public BlackboardArtifactTag addBlackboardArtifactTag(BlackboardArtifact artifact, TagName tagName, String comment) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
BlackboardArtifactTag tag; BlackboardArtifactTag tag;
synchronized (this) { synchronized (this) {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
@ -403,6 +456,9 @@ public class TagsManager implements Closeable {
* case database. * case database.
*/ */
public void deleteBlackboardArtifactTag(BlackboardArtifactTag tag) throws TskCoreException { public void deleteBlackboardArtifactTag(BlackboardArtifactTag tag) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
synchronized (this) { synchronized (this) {
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
Case.getCurrentCase().getSleuthkitCase().deleteBlackboardArtifactTag(tag); Case.getCurrentCase().getSleuthkitCase().deleteBlackboardArtifactTag(tag);
@ -424,6 +480,9 @@ public class TagsManager implements Closeable {
* case database. * case database.
*/ */
public synchronized List<BlackboardArtifactTag> getAllBlackboardArtifactTags() throws TskCoreException { public synchronized List<BlackboardArtifactTag> getAllBlackboardArtifactTags() throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return Case.getCurrentCase().getSleuthkitCase().getAllBlackboardArtifactTags(); return Case.getCurrentCase().getSleuthkitCase().getAllBlackboardArtifactTags();
} }
@ -440,6 +499,9 @@ public class TagsManager implements Closeable {
* the case database. * the case database.
*/ */
public synchronized long getBlackboardArtifactTagsCountByTagName(TagName tagName) throws TskCoreException { public synchronized long getBlackboardArtifactTagsCountByTagName(TagName tagName) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifactTagsCountByTagName(tagName); return Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifactTagsCountByTagName(tagName);
} }
@ -455,6 +517,9 @@ public class TagsManager implements Closeable {
* case database. * case database.
*/ */
public synchronized BlackboardArtifactTag getBlackboardArtifactTagByTagID(long tagID) throws TskCoreException { public synchronized BlackboardArtifactTag getBlackboardArtifactTagByTagID(long tagID) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifactTagByID(tagID); return Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifactTagByID(tagID);
} }
@ -471,6 +536,9 @@ public class TagsManager implements Closeable {
* case database. * case database.
*/ */
public synchronized List<BlackboardArtifactTag> getBlackboardArtifactTagsByTagName(TagName tagName) throws TskCoreException { public synchronized List<BlackboardArtifactTag> getBlackboardArtifactTagsByTagName(TagName tagName) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifactTagsByTagName(tagName); return Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifactTagsByTagName(tagName);
} }
@ -487,6 +555,9 @@ public class TagsManager implements Closeable {
* case database. * case database.
*/ */
public synchronized List<BlackboardArtifactTag> getBlackboardArtifactTagsByArtifact(BlackboardArtifact artifact) throws TskCoreException { public synchronized List<BlackboardArtifactTag> getBlackboardArtifactTagsByArtifact(BlackboardArtifact artifact) throws TskCoreException {
if (null == caseDb) {
throw new TskCoreException("Tags manager has been closed");
}
lazyLoadExistingTagNames(); lazyLoadExistingTagNames();
return Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifactTagsByArtifact(artifact); return Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifactTagsByArtifact(artifact);
} }
@ -502,6 +573,7 @@ public class TagsManager implements Closeable {
@Deprecated @Deprecated
public synchronized void close() throws IOException { public synchronized void close() throws IOException {
saveTagNamesToTagsSettings(); saveTagNamesToTagsSettings();
caseDb = null;
} }
/** /**