1
0
mirror of https://github.com/elisspace/autopsy.git synced 2026-09-05 18:14:30 +00:00

fix findValuesForAttribute and getFileIDsWithMimeType

This commit is contained in:
millmanorama
2016-01-21 21:57:16 -05:00
committed by jmillman
parent 76c2aa2f4d
commit 3146010d76
2 changed files with 27 additions and 6 deletions

View File

@@ -830,6 +830,7 @@ public final class DrawableDB {
*
* @throws TskCoreException
*/
@Deprecated
public long countFiles() throws TskCoreException {
Statement statement = null;
ResultSet rs = null;

View File

@@ -345,16 +345,19 @@ public class GroupManager {
values = new ArrayList<>(names);
break;
case MIME_TYPE:
try (SleuthkitCase.CaseDbQuery executeQuery = controller.getSleuthKitCase().executeQuery("select distinct mime_type from tsk_files");
HashSet<String> types = new HashSet<>();
try (SleuthkitCase.CaseDbQuery executeQuery = controller.getSleuthKitCase().executeQuery("select obj_id, mime_type from tsk_files");
ResultSet resultSet = executeQuery.getResultSet();) {
values = new ArrayList<>();
while (resultSet.next()) {
values.add((A) resultSet.getString("mime_type"));
if (db.isInDB(resultSet.getLong("obj_id"))) {
types.add(resultSet.getString("mime_type"));
}
}
} catch (SQLException | TskCoreException ex) {
Exceptions.printStackTrace(ex);
}
values = new ArrayList<A>((Collection<? extends A>) types);
break;
default:
//otherwise do straight db query
return db.findValuesForAttribute(groupBy, sortBy, sortOrder);
@@ -375,6 +378,8 @@ public class GroupManager {
return getFileIDsWithCategory((Category) groupKey.getValue());
case TAGS:
return getFileIDsWithTag((TagName) groupKey.getValue());
case MIME_TYPE:
return getFileIDsWithMimeType((String) groupKey.getValue());
// case HASHSET: //comment out this case to use db functionality for hashsets
// return getFileIDsWithHashSetName((String) groupKey.getValue());
default:
@@ -679,8 +684,23 @@ public class GroupManager {
return null;
}
public Set<Long> getFileIDsWithMimeType(String string) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
public Set<Long> getFileIDsWithMimeType(String mimeType) throws TskCoreException {
HashSet<Long> hashSet = new HashSet<>();
try (SleuthkitCase.CaseDbQuery executeQuery = controller.getSleuthKitCase().executeQuery("select obj_id from tsk_files where mime_type = '" + mimeType + "'");) {
ResultSet resultSet = executeQuery.getResultSet();
while (resultSet.next()) {
final long fileID = resultSet.getLong("obj_id");
if (db.isInDB(fileID)) {
hashSet.add(fileID);
}
}
return hashSet;
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
throw new TskCoreException("Failed to get file ids with mime type " + mimeType, ex);
}
}
/**