diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/CasePropertiesPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/CasePropertiesPanel.java index 23e9d0b1c8..101f8688dd 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/CasePropertiesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/CasePropertiesPanel.java @@ -78,10 +78,9 @@ final class CasePropertiesPanel extends javax.swing.JPanel { try { EamDb dbManager = EamDb.getInstance(); if (dbManager != null) { - CorrelationCase correlationCase = dbManager.getCaseByUUID(Case.getCurrentCase().getName()); + CorrelationCase correlationCase = dbManager.getCase(Case.getCurrentCase()); if (null == correlationCase) { - dbManager.newCase(Case.getCurrentCase()); - correlationCase = dbManager.getCaseByUUID(Case.getCurrentCase().getName()); + correlationCase = dbManager.newCase(Case.getCurrentCase()); } currentOrg = correlationCase.getOrg(); } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java index 7a4a1f7bf4..89d527fcc1 100755 --- a/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/NewCaseWizardAction.java @@ -91,7 +91,7 @@ final class NewCaseWizardAction extends CallableSystemAction { if (EamDb.isEnabled()) { //if the eam is enabled we need to save the case organization information now EamDb dbManager = EamDb.getInstance(); if (dbManager != null) { - CorrelationCase cRCase = dbManager.getCaseByUUID(Case.getCurrentCase().getName()); + CorrelationCase cRCase = dbManager.getCase(Case.getCurrentCase()); if (cRCase == null) { cRCase = dbManager.newCase(Case.getCurrentCase()); } diff --git a/Core/src/org/sleuthkit/autopsy/casemodule/OptionalCasePropertiesPanel.java b/Core/src/org/sleuthkit/autopsy/casemodule/OptionalCasePropertiesPanel.java index a2793ec295..0a9649c45d 100644 --- a/Core/src/org/sleuthkit/autopsy/casemodule/OptionalCasePropertiesPanel.java +++ b/Core/src/org/sleuthkit/autopsy/casemodule/OptionalCasePropertiesPanel.java @@ -89,7 +89,7 @@ final class OptionalCasePropertiesPanel extends javax.swing.JPanel { if (currentCase != null) { try { EamDb dbManager = EamDb.getInstance(); - selectedOrg = dbManager.getCaseByUUID(currentCase.getName()).getOrg(); + selectedOrg = dbManager.getCase(currentCase).getOrg(); } catch (EamDbException ex) { LOGGER.log(Level.SEVERE, "Unable to get Organization associated with the case from Central Repo", ex); } @@ -561,7 +561,7 @@ final class OptionalCasePropertiesPanel extends javax.swing.JPanel { if (EamDb.isEnabled()) { try { EamDb dbManager = EamDb.getInstance(); - CorrelationCase correlationCase = dbManager.getCaseByUUID(Case.getCurrentCase().getName()); + CorrelationCase correlationCase = dbManager.getCase(Case.getCurrentCase()); if (caseDisplayNameTextField.isVisible()) { correlationCase.setDisplayName(caseDisplayNameTextField.getText()); } diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java b/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java index 2a7fcf168b..fbc955ca72 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/contentviewer/DataContentViewerOtherCases.java @@ -177,7 +177,7 @@ public class DataContentViewerOtherCases extends javax.swing.JPanel implements D } caseDisplayName = eamCasePartial.getDisplayName(); // query case details - CorrelationCase eamCase = dbManager.getCaseByUUID(eamCasePartial.getCaseUUID()); + CorrelationCase eamCase = dbManager.getCase(Case.getCurrentCase()); if (eamCase == null) { JOptionPane.showConfirmDialog(showCaseDetailsMenuItem, Bundle.DataContentViewerOtherCases_caseDetailsDialog_noDetails(), diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index f9c2435472..9560d635c4 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -170,9 +170,10 @@ public abstract class AbstractSqlEamDb implements EamDb { * Expects the Organization for this case to already exist in the database. * * @param eamCase The case to add + * @returns New Case class with populated database ID */ @Override - public void newCase(CorrelationCase eamCase) throws EamDbException { + public CorrelationCase newCase(CorrelationCase eamCase) throws EamDbException { Connection conn = connect(); PreparedStatement preparedStatement = null; @@ -225,6 +226,9 @@ public abstract class AbstractSqlEamDb implements EamDb { EamDbUtil.closePreparedStatement(preparedStatement); EamDbUtil.closeConnection(conn); } + + // get a new version with the updated ID + return getCaseByUUID(eamCase.getCaseUUID()); } /** @@ -249,9 +253,14 @@ public abstract class AbstractSqlEamDb implements EamDb { autopsyCase.getExaminerEmail(), autopsyCase.getExaminerPhone(), autopsyCase.getCaseNotes()); - newCase(curCeCase); - return curCeCase; + return newCase(curCeCase); } + + @Override + public CorrelationCase getCase(Case autopsyCase) throws EamDbException { + return getCaseByUUID(autopsyCase.getName()); + } + /** * Updates an existing Case in the database @@ -432,7 +441,7 @@ public abstract class AbstractSqlEamDb implements EamDb { * @return The data source */ @Override - public CorrelationDataSource getDataSourceDetails(CorrelationCase correlationCase, String dataSourceDeviceId) throws EamDbException { + public CorrelationDataSource getDataSource(CorrelationCase correlationCase, String dataSourceDeviceId) throws EamDbException { Connection conn = connect(); CorrelationDataSource eamDataSourceResult = null; @@ -450,7 +459,7 @@ public abstract class AbstractSqlEamDb implements EamDb { eamDataSourceResult = getEamDataSourceFromResultSet(resultSet); } } catch (SQLException ex) { - throw new EamDbException("Error getting case details.", ex); // NON-NLS + throw new EamDbException("Error getting data source.", ex); // NON-NLS } finally { EamDbUtil.closePreparedStatement(preparedStatement); EamDbUtil.closeResultSet(resultSet); @@ -1057,12 +1066,12 @@ public abstract class AbstractSqlEamDb implements EamDb { // We could improve effiency by keeping a list of all datasources and cases // in the database, but we don't expect the user to be tagging large numbers // of items (that didn't have the CE ingest module run on them) at once. - CorrelationCase correlationCase = getCaseByUUID(eamInstance.getCorrelationCase().getCaseUUID()); - if (null == correlationCase) { - newCase(eamInstance.getCorrelationCase()); - correlationCase = getCaseByUUID(eamInstance.getCorrelationCase().getCaseUUID()); + CorrelationCase correlationCaseWithId = getCaseByUUID(eamInstance.getCorrelationCase().getCaseUUID()); + if (null == correlationCaseWithId) { + correlationCaseWithId = newCase(eamInstance.getCorrelationCase()); } - if (null == getDataSourceDetails(correlationCase, eamInstance.getCorrelationDataSource().getDeviceID())) { + + if (null == getDataSource(correlationCaseWithId, eamInstance.getCorrelationDataSource().getDeviceID())) { newDataSource(eamInstance.getCorrelationDataSource()); } eamArtifact.getInstances().get(0).setKnownStatus(knownStatus); @@ -2146,7 +2155,7 @@ public abstract class AbstractSqlEamDb implements EamDb { return null; } CorrelationAttributeInstance eamArtifactInstance = new CorrelationAttributeInstance( - new CorrelationCase(resultSet.getString("case_uid"), resultSet.getString("case_name")), + new CorrelationCase(resultSet.getInt("case_id"), resultSet.getString("case_uid"), resultSet.getString("case_name")), new CorrelationDataSource(-1, resultSet.getInt("case_id"), resultSet.getString("device_id"), resultSet.getString("name")), resultSet.getString("file_path"), resultSet.getString("comment"), diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationCase.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationCase.java index 466c73a7ee..79d94837ee 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationCase.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CorrelationCase.java @@ -49,16 +49,12 @@ public class CorrelationCase implements Serializable { * * @param caseUUID Globally unique identifier * @param displayName - */ - public CorrelationCase(String caseUUID, String displayName) { - this(-1, caseUUID, null, displayName, DATE_FORMAT.format(new Date()), null, null, null, null, null); - } - + */ CorrelationCase(int ID, String caseUUID, String displayName) { this(ID, caseUUID, null, displayName, DATE_FORMAT.format(new Date()), null, null, null, null, null); } - public CorrelationCase(int ID, + CorrelationCase(int ID, String caseUUID, EamOrganization org, String displayName, diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamArtifactUtil.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamArtifactUtil.java index b3194e4b7f..c2bb0e0016 100755 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamArtifactUtil.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamArtifactUtil.java @@ -96,10 +96,9 @@ public class EamArtifactUtil { } // make an instance for the BB source file - CorrelationCase correlationCase = EamDb.getInstance().getCaseByUUID(Case.getCurrentCase().getName()); + CorrelationCase correlationCase = EamDb.getInstance().getCase(Case.getCurrentCase()); if (null == correlationCase) { - EamDb.getInstance().newCase(Case.getCurrentCase()); - correlationCase = EamDb.getInstance().getCaseByUUID(Case.getCurrentCase().getName()); + correlationCase = EamDb.getInstance().newCase(Case.getCurrentCase()); } CorrelationAttributeInstance eamInstance = new CorrelationAttributeInstance( correlationCase, @@ -250,10 +249,9 @@ public class EamArtifactUtil { try { CorrelationAttribute.Type filesType = EamDb.getInstance().getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); eamArtifact = new CorrelationAttribute(filesType, af.getMd5Hash()); - CorrelationCase correlationCase = EamDb.getInstance().getCaseByUUID(Case.getCurrentCase().getName()); + CorrelationCase correlationCase = EamDb.getInstance().getCase(Case.getCurrentCase()); if (null == correlationCase) { - EamDb.getInstance().newCase(Case.getCurrentCase()); - correlationCase = EamDb.getInstance().getCaseByUUID(Case.getCurrentCase().getName()); + correlationCase = EamDb.getInstance().newCase(Case.getCurrentCase()); } CorrelationAttributeInstance cei = new CorrelationAttributeInstance( correlationCase, diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java index b021a1fcfc..b9ce4320de 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java @@ -133,7 +133,7 @@ public interface EamDb { * * @param eamCase The case to add */ - void newCase(CorrelationCase eamCase) throws EamDbException; + CorrelationCase newCase(CorrelationCase eamCase) throws EamDbException; /** * Creates new Case in the database from the given case @@ -141,6 +141,8 @@ public interface EamDb { * @param autopsyCase The case to add */ CorrelationCase newCase(Case autopsyCase) throws EamDbException; + + /** * Updates an existing Case in the database @@ -149,6 +151,15 @@ public interface EamDb { */ void updateCase(CorrelationCase eamCase) throws EamDbException; + /** + * Retrieves Central Repo case based on an Autopsy Case + * + * @param autopsyCase Autopsy case to find corresponding CR case for + * @return CR Case + * @throws EamDbException + */ + CorrelationCase getCase(Case autopsyCase) throws EamDbException; + /** * Retrieves Case details based on Case UUID * @@ -181,7 +192,7 @@ public interface EamDb { * * @return The data source */ - CorrelationDataSource getDataSourceDetails(CorrelationCase correlationCase, String dataSourceDeviceId) throws EamDbException; + CorrelationDataSource getDataSource(CorrelationCase correlationCase, String dataSourceDeviceId) throws EamDbException; /** * Retrieves data sources that are in DB diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java index 3e79f5abca..85fda8d4a1 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java @@ -149,16 +149,14 @@ public class SqliteEamDb extends AbstractSqlEamDb { * */ private void setupConnectionPool() throws EamDbException { + + if (dbSettings.dbFileExists() == false) { + throw new EamDbException("Central repository database missing"); + } + connectionPool = new BasicDataSource(); connectionPool.setDriverClassName(dbSettings.getDriver()); - - StringBuilder connectionURL = new StringBuilder(); - connectionURL.append(dbSettings.getJDBCBaseURI()); - connectionURL.append(dbSettings.getDbDirectory()); - connectionURL.append(File.separator); - connectionURL.append(dbSettings.getDbName()); - - connectionPool.setUrl(connectionURL.toString()); + connectionPool.setUrl(dbSettings.getConnectionURL()); // tweak pool configuration connectionPool.setInitialSize(50); @@ -279,10 +277,10 @@ public class SqliteEamDb extends AbstractSqlEamDb { * @param eamCase The case to add */ @Override - public void newCase(CorrelationCase eamCase) throws EamDbException { + public CorrelationCase newCase(CorrelationCase eamCase) throws EamDbException { try{ acquireExclusiveLock(); - super.newCase(eamCase); + return super.newCase(eamCase); } finally { releaseExclusiveLock(); } @@ -359,10 +357,10 @@ public class SqliteEamDb extends AbstractSqlEamDb { * @return The data source */ @Override - public CorrelationDataSource getDataSourceDetails(CorrelationCase correlationCase, String dataSourceDeviceId) throws EamDbException { + public CorrelationDataSource getDataSource(CorrelationCase correlationCase, String dataSourceDeviceId) throws EamDbException { try{ acquireSharedLock(); - return super.getDataSourceDetails(correlationCase, dataSourceDeviceId); + return super.getDataSource(correlationCase, dataSourceDeviceId); } finally { releaseSharedLock(); } diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CaseEventListener.java b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CaseEventListener.java index 7252ca53cc..88cf1ed59e 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CaseEventListener.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/eventlisteners/CaseEventListener.java @@ -430,12 +430,11 @@ final class CaseEventListener implements PropertyChangeListener { try { String deviceId = Case.getCurrentCase().getSleuthkitCase().getDataSource(newDataSource.getId()).getDeviceId(); - CorrelationCase correlationCase = dbManager.getCaseByUUID(Case.getCurrentCase().getName()); + CorrelationCase correlationCase = dbManager.getCase(Case.getCurrentCase()); if (null == correlationCase) { - dbManager.newCase(Case.getCurrentCase()); - correlationCase = dbManager.getCaseByUUID(Case.getCurrentCase().getName()); + correlationCase = dbManager.newCase(Case.getCurrentCase()); } - if (null == dbManager.getDataSourceDetails(correlationCase, deviceId)) { + if (null == dbManager.getDataSource(correlationCase, deviceId)) { dbManager.newDataSource(CorrelationDataSource.fromTSKDataSource(correlationCase, newDataSource)); } } catch (EamDbException ex) { @@ -466,18 +465,6 @@ final class CaseEventListener implements PropertyChangeListener { Case curCase = (Case) event.getNewValue(); IngestEventsListener.resetCeModuleInstanceCount(); - CorrelationCase curCeCase = new CorrelationCase( - -1, - curCase.getName(), // unique case ID - EamOrganization.getDefault(), - curCase.getDisplayName(), - curCase.getCreatedDate(), - curCase.getNumber(), - curCase.getExaminer(), - curCase.getExaminerEmail(), - curCase.getExaminerPhone(), - curCase.getCaseNotes()); - if (!EamDb.isEnabled()) { return; } @@ -485,10 +472,8 @@ final class CaseEventListener implements PropertyChangeListener { try { // NOTE: Cannot determine if the opened case is a new case or a reopened case, // so check for existing name in DB and insert if missing. - CorrelationCase existingCase = dbManager.getCaseByUUID(curCeCase.getCaseUUID()); - - if (null == existingCase) { - dbManager.newCase(curCeCase); + if (dbManager.getCase(curCase) == null) { + dbManager.newCase(curCase); } } catch (EamDbException ex) { LOGGER.log(Level.SEVERE, "Error connecting to Central Repository database.", ex); //NON-NLS diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/ingestmodule/IngestModule.java b/Core/src/org/sleuthkit/autopsy/centralrepository/ingestmodule/IngestModule.java index 30d374f133..9e1e36cb8a 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/ingestmodule/IngestModule.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/ingestmodule/IngestModule.java @@ -201,47 +201,36 @@ class IngestModule implements FileIngestModule { } jobId = context.getJobId(); - EamDb dbManager; + EamDb centralRepoDb; try { - dbManager = EamDb.getInstance(); + centralRepoDb = EamDb.getInstance(); } catch (EamDbException ex) { LOGGER.log(Level.SEVERE, "Error connecting to central repository database.", ex); // NON-NLS throw new IngestModuleException("Error connecting to central repository database.", ex); // NON-NLS } try { - filesType = dbManager.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); + filesType = centralRepoDb.getCorrelationTypeById(CorrelationAttribute.FILES_TYPE_ID); } catch (EamDbException ex) { LOGGER.log(Level.SEVERE, "Error getting correlation type FILES in ingest module start up.", ex); // NON-NLS throw new IngestModuleException("Error getting correlation type FILES in ingest module start up.", ex); // NON-NLS } - Case curCase = Case.getCurrentCase(); + Case autopsyCase = Case.getCurrentCase(); try { - eamCase = dbManager.getCaseByUUID(curCase.getName()); + eamCase = centralRepoDb.getCase(autopsyCase); } catch (EamDbException ex) { throw new IngestModuleException("Unable to get case from central repository database ", ex); } if (eamCase == null) { // ensure we have this case defined in the EAM DB - CorrelationCase curCeCase = new CorrelationCase( - -1, - curCase.getName(), // unique case ID - EamOrganization.getDefault(), - curCase.getDisplayName(), - curCase.getCreatedDate(), - curCase.getNumber(), - curCase.getExaminer(), - curCase.getExaminerEmail(), - curCase.getExaminerPhone(), - curCase.getCaseNotes()); try { - dbManager.newCase(curCeCase); - eamCase = dbManager.getCaseByUUID(curCase.getName()); + eamCase = centralRepoDb.newCase(autopsyCase); } catch (EamDbException ex) { LOGGER.log(Level.SEVERE, "Error creating new case in ingest module start up.", ex); // NON-NLS throw new IngestModuleException("Error creating new case in ingest module start up.", ex); // NON-NLS } } + try { eamDataSource = CorrelationDataSource.fromTSKDataSource(eamCase, context.getDataSource()); } catch (EamDbException ex) { @@ -255,12 +244,12 @@ class IngestModule implements FileIngestModule { == 1) { // ensure we have this data source in the EAM DB try { - if (null == dbManager.getDataSourceDetails(eamCase, eamDataSource.getDeviceID())) { - dbManager.newDataSource(eamDataSource); + if (null == centralRepoDb.getDataSource(eamCase, eamDataSource.getDeviceID())) { + centralRepoDb.newDataSource(eamDataSource); } } catch (EamDbException ex) { - LOGGER.log(Level.SEVERE, "Error creating new data source in ingest module start up.", ex); // NON-NLS - throw new IngestModuleException("Error creating new data source in ingest module start up.", ex); // NON-NLS + LOGGER.log(Level.SEVERE, "Error adding data source to Central Repository.", ex); // NON-NLS + throw new IngestModuleException("Error adding data source to Central Repository.", ex); // NON-NLS } }