diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java index ba0066c412..2e28dfccfa 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/AbstractSqlEamDb.java @@ -133,6 +133,24 @@ abstract class AbstractSqlEamDb implements EamDb { } + @Override + public void addDataSourceObjectId(int rowId, long dataSourceObjectId) throws EamDbException{ + Connection conn = connect(); + PreparedStatement preparedStatement = null; + String sql = "UPDATE data_sources SET datasource_id=? WHERE id=?"; + try { + preparedStatement = conn.prepareStatement(sql); + preparedStatement.setLong(1, dataSourceObjectId); + preparedStatement.setInt(2, rowId); + preparedStatement.executeUpdate(); + } catch (SQLException ex) { + throw new EamDbException("Error updating data source object id for data_sources row " + rowId, ex); + } finally { + EamDbUtil.closeStatement(preparedStatement); + EamDbUtil.closeConnection(conn); + } + } + /** * Get the value for the given name from the name/value db_info table. * diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CaseUpdateAutopsyService.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CaseUpdateAutopsyService.java new file mode 100644 index 0000000000..c2f6575acf --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/CaseUpdateAutopsyService.java @@ -0,0 +1,59 @@ +/* + * Central Repository + * + * Copyright 2018 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.centralrepository.datamodel; + +import org.openide.util.lookup.ServiceProvider; +import org.sleuthkit.autopsy.appservices.AutopsyService +import org.sleuthkit.datamodel.Content; +import org.sleuthkit.datamodel.DataSource; +import org.sleuthkit.datamodel.TskCoreException; + + +@ServiceProvider(service = AutopsyService.class) +public class CaseUpdateAutopsyService implements AutopsyService{ + + @Override + public String getServiceName() { + return "UpdateCR"; + } + + @Override + public void openCaseResources(CaseContext context) throws AutopsyServiceException { + if (EamDb.isEnabled()){ + try { + EamDb centralRepository = EamDb.getInstance(); + CorrelationCase correlationCase = centralRepository.getCase(context.getCase()); + for (CorrelationDataSource correlationDataSource : centralRepository.getDataSources()) { + if (correlationDataSource.getCaseID() == correlationCase.getID() && correlationDataSource.getCaseDataSourceID() == null){ + for (Content dataSource : context.getCase().getDataSources()){ + if (((DataSource)dataSource).getDeviceId().equals(correlationDataSource.getDeviceID())){ + centralRepository.addDataSourceObjectId(correlationDataSource.getID(), dataSource.getId()); + break; + } + } + + } + } + } catch (EamDbException | TskCoreException ex) { + throw new AutopsyServiceException("Unabe to update datasources in central repository", ex); + } + } + } + +} diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java index 358fe93b0d..92cf9aea4e 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/EamDb.java @@ -110,6 +110,16 @@ public interface EamDb { */ public void newDbInfo(String name, String value) throws EamDbException; + /** + * Set the data source object id for a specific entry in the data_sources + * table + * + * @param rowId - the row id for the data_sources table entry + * @param dataSourceObjectId - the object id for the data source from the + * caseDb + */ + void addDataSourceObjectId(int rowId, long dataSourceObjectId) throws EamDbException; + /** * Get the value for the given name from the name/value db_info table. * @@ -345,9 +355,9 @@ public interface EamDb { /** * Find a correlation attribute in the Central Repository database given the * instance type, case, data source, value, and file path. - * - * Method exists to support instances added using Central Repository version 1,1 and - * older + * + * Method exists to support instances added using Central Repository version + * 1,1 and older * * @param type The type of instance. * @param correlationCase The case tied to the instance. @@ -356,7 +366,7 @@ public interface EamDb { * @param filePath The file path tied to the instance. * * @return The correlation attribute if it exists; otherwise null. - * + * * @throws EamDbException */ CorrelationAttributeInstance getCorrelationAttributeInstance(CorrelationAttributeInstance.Type type, CorrelationCase correlationCase, @@ -369,7 +379,8 @@ public interface EamDb { * @param type The type of instance. * @param correlationCase The case tied to the instance. * @param correlationDataSource The data source tied to the instance. - * @param objectID The object id of the file tied to the instance. + * @param objectID The object id of the file tied to the + * instance. * * @return The correlation attribute if it exists; otherwise null. * diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java index d702bde5b1..36484d2f2d 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/SqliteEamDb.java @@ -274,6 +274,16 @@ final class SqliteEamDb extends AbstractSqlEamDb { } } + @Override + public void addDataSourceObjectId(int rowId, long dataSourceObjectId) throws EamDbException{ + try { + acquireExclusiveLock(); + super.addDataSourceObjectId(rowId, dataSourceObjectId); + } finally { + releaseExclusiveLock(); + } + } + /** * Creates new Case in the database *