4791 use name of first image in multi-image data sources

This commit is contained in:
William Schaefer 2019-03-04 16:24:43 -05:00
parent ba0010f626
commit 90c75d635e

View File

@ -1,16 +1,16 @@
/* /*
* *
* Autopsy Forensic Browser * Autopsy Forensic Browser
* *
* Copyright 2018 Basis Technology Corp. * Copyright 2018 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");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -30,10 +30,10 @@ import org.sleuthkit.datamodel.SleuthkitCase;
import org.sleuthkit.datamodel.TskCoreException; import org.sleuthkit.datamodel.TskCoreException;
/** /**
* Encapsulates logic required to create a mapping of data sources in the * Encapsulates logic required to create a mapping of data sources in the
* current case to their data source IDs. * current case to their data source IDs.
* *
* Intended to be used within the context of a SwingWorker or other background * Intended to be used within the context of a SwingWorker or other background
* thread. * thread.
*/ */
public class DataSourceLoader { public class DataSourceLoader {
@ -46,8 +46,7 @@ public class DataSourceLoader {
//try block releases resources - exceptions are handled in done() //try block releases resources - exceptions are handled in done()
try ( try (
SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_LOGICAL); SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_LOGICAL);
ResultSet resultSet = query.getResultSet() ResultSet resultSet = query.getResultSet()) {
) {
while (resultSet.next()) { while (resultSet.next()) {
Long objectId = resultSet.getLong(1); Long objectId = resultSet.getLong(1);
String dataSourceName = resultSet.getString(2); String dataSourceName = resultSet.getString(2);
@ -56,7 +55,7 @@ public class DataSourceLoader {
} }
} }
private void loadImageSources(SleuthkitCase tskDb, Map<Long, String> dataSouceMap) throws SQLException, TskCoreException { private void loadImageSources(SleuthkitCase tskDb, Map<Long, String> dataSourceMap) throws SQLException, TskCoreException {
//try block releases resources - exceptions are handled in done() //try block releases resources - exceptions are handled in done()
try ( try (
SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_IMAGE); SleuthkitCase.CaseDbQuery query = tskDb.executeQuery(SELECT_DATA_SOURCES_IMAGE);
@ -64,21 +63,24 @@ public class DataSourceLoader {
while (resultSet.next()) { while (resultSet.next()) {
Long objectId = resultSet.getLong(1); Long objectId = resultSet.getLong(1);
String dataSourceName = resultSet.getString(2); if (!dataSourceMap.containsKey(objectId)) {
File image = new File(dataSourceName); String dataSourceName = resultSet.getString(2);
String dataSourceNameTrimmed = image.getName(); File image = new File(dataSourceName);
dataSouceMap.put(objectId, dataSourceNameTrimmed); String dataSourceNameTrimmed = image.getName();
dataSourceMap.put(objectId, dataSourceNameTrimmed);
}
} }
} }
} }
/** /**
* Get a map of data source Ids to their string names for the current case. * Get a map of data source Ids to their string names for the current case.
* *
* @return Map of Long (id) to String (name) * @return Map of Long (id) to String (name)
*
* @throws NoCurrentCaseException * @throws NoCurrentCaseException
* @throws TskCoreException * @throws TskCoreException
* @throws SQLException * @throws SQLException
*/ */
public Map<Long, String> getDataSourceMap() throws NoCurrentCaseException, TskCoreException, SQLException { public Map<Long, String> getDataSourceMap() throws NoCurrentCaseException, TskCoreException, SQLException {
Map<Long, String> dataSouceMap = new HashMap<>(); Map<Long, String> dataSouceMap = new HashMap<>();