diff --git a/bindings/java/src/org/sleuthkit/datamodel/CommunicationsManager.java b/bindings/java/src/org/sleuthkit/datamodel/CommunicationsManager.java index 1deb422b987bf8cd8e123e756d3136c5c4f5acde..54f63e8c8d76518784ef9ec609e7bfdfedf06e4e 100644 --- a/bindings/java/src/org/sleuthkit/datamodel/CommunicationsManager.java +++ b/bindings/java/src/org/sleuthkit/datamodel/CommunicationsManager.java @@ -1248,6 +1248,48 @@ public List<AccountFileInstance> getAccountFileInstances(Account account) throws return null; } } + + /** + * Gets a list of the distinct account types that can currently be found in + * the case db. + * + * @return A list of distinct accounts or an empty list. + * + * @throws TskCoreException + */ + public List<Account.Type> getAccountTypesInUse() throws TskCoreException{ + CaseDbConnection connection = db.getConnection(); + db.acquireSingleUserCaseReadLock(); + Statement s = null; + ResultSet rs = null; + List<Account.Type> inUseAccounts = new ArrayList<>(); + + try { + String query = "SELECT DISTINCT accounts.account_type_id, type_name, display_name FROM accounts JOIN account_types ON accounts.account_type_id = account_types.account_type_id"; + s = connection.createStatement(); + rs = connection.executeQuery(s, query); //NON-NLS + Account.Type accountType = null; + while (rs.next()) { + String accountTypeName = rs.getString("type_name"); + accountType = this.typeNameToAccountTypeMap.get(accountTypeName); + + if(accountType == null) { + accountType = new Account.Type(accountTypeName, rs.getString("display_name")); + this.accountTypeToTypeIdMap.put(accountType, rs.getInt("account_type_id")); + } + + inUseAccounts.add(accountType); + } + return inUseAccounts; + } catch (SQLException ex) { + throw new TskCoreException("Error getting account type id", ex); + } finally { + closeResultSet(rs); + closeStatement(s); + connection.close(); + db.releaseSingleUserCaseReadLock(); + } + } /** * Get account_type_id for the given account type.