Merge pull request #3510 from zhhl/2229-Part19UsegetOpenCaseInsteadOfgetCurrentCase

2229 Part 19 use getOpenCase() instead of getCurrentCase()
This commit is contained in:
Richard Cordovano 2018-03-09 17:44:26 -05:00 committed by GitHub
commit 528689f8cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 26 deletions

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2017 Basis Technology Corp.
* Copyright 2011-2018 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -19,7 +19,6 @@
package org.sleuthkit.autopsy.experimental.autoingest;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@ -101,7 +100,7 @@ class AddArchiveTask implements Runnable {
// extract the archive and pass the extracted folder as input
try {
Case currentCase = Case.getCurrentCase();
Case currentCase = Case.getOpenCase();
// create folder to extract archive to
Path destinationFolder = createDirectoryForFile(archivePath, currentCase.getModuleDirectory());

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2017 Basis Technology Corp.
* Copyright 2011-2018 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -29,6 +29,7 @@ import javax.swing.filechooser.FileFilter;
import org.apache.commons.lang3.StringUtils;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import static org.sleuthkit.autopsy.experimental.autoingest.Bundle.*;
import org.sleuthkit.autopsy.corecomponentinterfaces.DataSourceProcessor;
import org.sleuthkit.autopsy.coreutils.DriveUtils;
@ -204,7 +205,9 @@ class ArchiveFilePanel extends JPanel implements DocumentListener {
*
* @return true if a proper archive has been selected, false otherwise
*/
@NbBundle.Messages("DataSourceOnCDriveError.text=Warning: Path to multi-user data source is on \"C:\" drive")
@NbBundle.Messages({"DataSourceOnCDriveError.text=Warning: Path to multi-user data source is on \"C:\" drive",
"DataSourceOnCDriveError.noOpenCase.errMsg=Warning: Exception while getting open case."
})
public boolean validatePanel() {
errorLabel.setVisible(false);
String path = getContentPaths();
@ -213,9 +216,14 @@ class ArchiveFilePanel extends JPanel implements DocumentListener {
}
// display warning if there is one (but don't disable "next" button)
if (false == PathValidator.isValid(path, Case.getCurrentCase().getCaseType())) {
try {
if (false == PathValidator.isValid(path, Case.getOpenCase().getCaseType())) {
errorLabel.setVisible(true);
errorLabel.setText(Bundle.DataSourceOnCDriveError_text());
}
} catch (NoCurrentCaseException ex) {
errorLabel.setVisible(true);
errorLabel.setText(Bundle.DataSourceOnCDriveError_text());
errorLabel.setText(Bundle.DataSourceOnCDriveError_noOpenCase_errMsg());
}
return new File(path).isFile()

View File

@ -63,6 +63,7 @@ import org.sleuthkit.autopsy.casemodule.Case.CaseType;
import org.sleuthkit.autopsy.casemodule.CaseActionException;
import org.sleuthkit.autopsy.casemodule.CaseDetails;
import org.sleuthkit.autopsy.casemodule.CaseMetadata;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.coordinationservice.CaseNodeData;
import org.sleuthkit.autopsy.coordinationservice.CoordinationService;
import org.sleuthkit.autopsy.coordinationservice.CoordinationService.CoordinationServiceException;
@ -2269,7 +2270,7 @@ final class AutoIngestManager extends Observable implements PropertyChangeListen
Thread.sleep(AutoIngestUserPreferences.getSecondsToSleepBetweenCases() * 1000);
}
currentJob.setCaseDirectoryPath(caseDirectoryPath);
Case caseForJob = Case.getCurrentCase();
Case caseForJob = Case.getOpenCase();
SYS_LOGGER.log(Level.INFO, "Opened case {0} for {1}", new Object[]{caseForJob.getName(), manifest.getFilePath()});
return caseForJob;
@ -2277,10 +2278,10 @@ final class AutoIngestManager extends Observable implements PropertyChangeListen
throw new CaseManagementException(String.format("Error creating solr settings file for case %s for %s", caseName, manifest.getFilePath()), ex);
} catch (CaseActionException ex) {
throw new CaseManagementException(String.format("Error creating or opening case %s for %s", caseName, manifest.getFilePath()), ex);
} catch (IllegalStateException ex) {
} catch (NoCurrentCaseException ex) {
/*
* Deal with the unfortunate fact that
* Case.getCurrentCase throws IllegalStateException.
* Case.getOpenCase throws NoCurrentCaseException.
*/
throw new CaseManagementException(String.format("Error getting current case %s for %s", caseName, manifest.getFilePath()), ex);
}

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2015 Basis Technology Corp.
* Copyright 2015-2018 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -39,6 +39,7 @@ import org.sleuthkit.datamodel.BlackboardAttribute;
import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException;
import org.apache.commons.codec.binary.Hex;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
/**
* Uniquely named file export rules organized into uniquely named rule sets.
@ -374,7 +375,7 @@ final class FileExportRuleSet implements Serializable, Comparable<FileExportRule
*/
List<Long> evaluate(long dataSourceId) throws ExportRulesException {
try {
SleuthkitCase db = Case.getCurrentCase().getSleuthkitCase();
SleuthkitCase db = Case.getOpenCase().getSleuthkitCase();
try (SleuthkitCase.CaseDbQuery queryResult = db.executeQuery(getQuery(dataSourceId))) {
ResultSet resultSet = queryResult.getResultSet();
List<Long> fileIds = new ArrayList<>();
@ -383,7 +384,7 @@ final class FileExportRuleSet implements Serializable, Comparable<FileExportRule
}
return fileIds;
}
} catch (IllegalStateException ex) {
} catch (NoCurrentCaseException ex) {
throw new ExportRulesException("No current case", ex);
} catch (TskCoreException ex) {
throw new ExportRulesException("Error querying case database", ex);
@ -1060,7 +1061,12 @@ final class FileExportRuleSet implements Serializable, Comparable<FileExportRule
* exist.
*/
private String getConditionClause(int index) throws ExportRulesException {
Case currentCase = Case.getCurrentCase();
Case currentCase;
try {
currentCase = Case.getOpenCase();
} catch (NoCurrentCaseException ex) {
throw new ExportRulesException("Exception while getting open case.", ex);
}
SleuthkitCase caseDb = currentCase.getSleuthkitCase();
BlackboardArtifact.Type artifactType;
BlackboardAttribute.Type attributeType;

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2015 Basis Technology Corp.
* Copyright 2015-2018 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -34,6 +34,7 @@ import java.util.Map;
import java.util.TreeMap;
import java.util.function.Supplier;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.coreutils.FileUtil;
import org.sleuthkit.autopsy.datamodel.ContentUtils;
import org.sleuthkit.datamodel.AbstractFile;
@ -111,7 +112,7 @@ final class FileExporter {
}
closeCatalogs();
writeFlagFiles();
} catch (FileExportSettings.PersistenceException | FileExportRuleSet.ExportRulesException | TskCoreException | IOException ex) {
} catch (FileExportSettings.PersistenceException | FileExportRuleSet.ExportRulesException | TskCoreException | IOException | NoCurrentCaseException ex) {
throw new FileExportException("Error occurred during file export", ex);
}
}
@ -128,7 +129,12 @@ final class FileExporter {
* @throws org.sleuthkit.autopsy.autoingest.FileExporter.FileExportException
*/
private boolean verifyPrerequisites(List<Content> dataSources) throws FileExportException {
SleuthkitCase skCase = Case.getCurrentCase().getSleuthkitCase();
SleuthkitCase skCase;
try {
skCase = Case.getOpenCase().getSleuthkitCase();
} catch (NoCurrentCaseException ex) {
throw new FileExportException("Exception while getting open case.", ex);
}
List<IngestJobInfo> ingestJobs = new ArrayList<>();
try {
// all ingest jobs that were processed as part of this case
@ -310,7 +316,7 @@ final class FileExporter {
* @throws IOException If there is a problem writing a file to
* secondary storage.
*/
private void exportFiles(Map<Long, List<String>> fileIdsToRuleNames, Supplier<Boolean> cancelCheck) throws TskCoreException, IOException {
private void exportFiles(Map<Long, List<String>> fileIdsToRuleNames, Supplier<Boolean> cancelCheck) throws TskCoreException, IOException, NoCurrentCaseException {
for (Map.Entry<Long, List<String>> entry : fileIdsToRuleNames.entrySet()) {
if (cancelCheck.get()) {
return;
@ -334,8 +340,8 @@ final class FileExporter {
* @throws IOException If there is a problem writing the file to
* storage.
*/
private void exportFile(Long fileId, List<String> ruleNames, Supplier<Boolean> cancelCheck) throws TskCoreException, IOException {
AbstractFile file = Case.getCurrentCase().getSleuthkitCase().getAbstractFileById(fileId);
private void exportFile(Long fileId, List<String> ruleNames, Supplier<Boolean> cancelCheck) throws TskCoreException, IOException, NoCurrentCaseException {
AbstractFile file = Case.getOpenCase().getSleuthkitCase().getAbstractFileById(fileId);
if (!shouldExportFile(file)) {
return;
}

View File

@ -82,6 +82,7 @@ import java.time.ZoneId;
import javax.swing.DefaultListModel;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
/**
* Global settings panel for data-source-level ingest modules that export and
@ -528,11 +529,11 @@ public final class FileExporterSettingsPanel extends JPanel {
void populateArtifacts() {
Set<String> artifactTypes = scanRulesForArtifacts();
try {
SleuthkitCase currentCase = Case.getCurrentCase().getSleuthkitCase();
SleuthkitCase currentCase = Case.getOpenCase().getSleuthkitCase();
for (BlackboardArtifact.Type type : currentCase.getArtifactTypes()) {
artifactTypes.add(type.getTypeName());
}
} catch (IllegalStateException | TskCoreException ex) {
} catch (NoCurrentCaseException | TskCoreException ex) {
// Unable to find and open case or cannot read the database. Use enum.
for (BlackboardArtifact.ARTIFACT_TYPE artifact : BlackboardArtifact.ARTIFACT_TYPE.values()) {
artifactTypes.add(artifact.toString());
@ -602,12 +603,12 @@ public final class FileExporterSettingsPanel extends JPanel {
Set<String> attributeTypes = scanRulesForAttributes();
try {
SleuthkitCase currentCase = Case.getCurrentCase().getSleuthkitCase();
SleuthkitCase currentCase = Case.getOpenCase().getSleuthkitCase();
for (BlackboardAttribute.Type type : currentCase.getAttributeTypes()) {
attributeTypes.add(type.getTypeName());
attributeTypeMap.put(type.getTypeName(), type.getValueType());
}
} catch (IllegalStateException | TskCoreException ex) {
} catch (NoCurrentCaseException | TskCoreException ex) {
// Unable to find and open case or cannot read the database. Use enum.
for (BlackboardAttribute.ATTRIBUTE_TYPE type : BlackboardAttribute.ATTRIBUTE_TYPE.values()) {
attributeTypes.add(type.getLabel());

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2015-17 Basis Technology Corp.
* Copyright 2015-2018 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -45,6 +45,7 @@ import org.openide.util.NbBundle.Messages;
import org.openide.util.actions.CallableSystemAction;
import org.openide.windows.WindowManager;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
import org.sleuthkit.autopsy.core.Installer;
import org.sleuthkit.autopsy.core.RuntimeProperties;
import org.sleuthkit.autopsy.coreutils.Logger;
@ -106,7 +107,13 @@ public final class OpenAction extends CallableSystemAction {
@Override
public boolean isEnabled() {
return super.isEnabled() && Case.isCaseOpen() && Installer.isJavaFxInited() && Case.getCurrentCase().hasData();
Case openCase;
try {
openCase = Case.getOpenCase();
} catch (NoCurrentCaseException ex) {
return false;
}
return super.isEnabled() && Installer.isJavaFxInited() && openCase.hasData();
}
/**