19 package org.sleuthkit.autopsy.centralrepository.datamodel;
21 import java.sql.ResultSet;
22 import java.sql.SQLException;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.List;
27 import java.util.Objects;
28 import org.apache.commons.lang.StringUtils;
30 import org.
sleuthkit.datamodel.InvalidAccountIDException;
59 this.accountTypeId = acctTypeID;
81 hash = 29 * hash + Objects.hashCode(this.
acctType);
94 if (getClass() != obj.getClass()) {
146 hash = 43 * hash + (int) (this.accountId ^ (this.accountId >>> 32));
147 hash = 43 * hash + (this.accountType != null ? this.accountType.
hashCode() : 0);
148 hash = 43 * hash + (this.typeSpecificIdentifier != null ? this.typeSpecificIdentifier.hashCode() : 0);
160 if (getClass() != obj.getClass()) {
164 if (this.accountId != other.
getId()) {
167 if (!Objects.equals(
this.typeSpecificIdentifier, other.
getIdentifier())) {
178 Collection<CentralRepoAccount> accountsList =
new ArrayList<>();
186 Account.Type acctType =
new Account.Type(rs.getString(
"type_name"), rs.getString(
"display_name"));
190 rs.getInt(
"account_id"),
192 rs.getString(
"account_unique_identifier"));
194 accountsList.add(account);
198 Collection<CentralRepoAccount> getAccountsList() {
199 return Collections.unmodifiableCollection(accountsList);
204 =
"SELECT accounts.id as account_id, "
205 +
" accounts.account_type_id as account_type_id, accounts.account_unique_identifier as account_unique_identifier,"
206 +
" account_types.id as account_type_id, "
207 +
" account_types.type_name as type_name, account_types.display_name as display_name, account_types.correlation_type_id as correlation_type_id "
209 +
" JOIN account_types as account_types on accounts.account_type_id = account_types.id ";
226 +
" WHERE LOWER(accounts.account_unique_identifier) LIKE LOWER(?)";
228 List<Object> params =
new ArrayList<>();
229 params.add(
"%" + accountIdentifierSubstring +
"%");
234 return queryCallback.getAccountsList();
248 public static Collection<CentralRepoAccount>
getAccountsWithIdentifier(String accountIdentifier)
throws InvalidAccountIDException, CentralRepoException {
252 +
" WHERE LOWER(accounts.account_unique_identifier) = LOWER(?)";
254 List<Object> params =
new ArrayList<>();
255 params.add(normalizedAccountIdentifier);
260 return queryCallback.getAccountsList();
272 public static Collection<CentralRepoAccount>
getAllAccounts() throws CentralRepoException {
276 List<Object> params =
new ArrayList<>();
281 return queryCallback.getAccountsList();
294 if (StringUtils.isEmpty(accountIdentifier)) {
295 throw new InvalidAccountIDException(
"Account id is null or empty.");
298 String normalizedAccountIdentifier;
305 normalizedAccountIdentifier = accountIdentifier.toLowerCase().trim();
308 throw new InvalidAccountIDException(
"Failed to normalize the account idenitier " + accountIdentifier, ex);
310 return normalizedAccountIdentifier;
324 if (StringUtils.isBlank(accountIdentifier)) {
325 throw new InvalidAccountIDException(
"Account identifier is null or empty.");
328 String normalizedAccountIdentifier;
330 if (crAccountType.getAcctType().equals(Account.Type.PHONE)) {
332 }
else if (crAccountType.getAcctType().equals(Account.Type.EMAIL)) {
336 normalizedAccountIdentifier = accountIdentifier.toLowerCase();
339 throw new InvalidAccountIDException(
"Invalid account identifier", ex);
342 return normalizedAccountIdentifier;
static String normalizeAccountIdentifier(CentralRepoAccountType crAccountType, String accountIdentifier)
static Collection< CentralRepoAccount > getAllAccounts()
void executeQuery(String sql, List< Object > params, CentralRepositoryDbQueryCallback queryCallback)
final String typeSpecificIdentifier
boolean equals(Object obj)
boolean equals(Object obj)
static final String ACCOUNTS_QUERY_CLAUSE
CentralRepoAccount(long accountId, CentralRepoAccountType accountType, String typeSpecificIdentifier)
static String normalizeAccountIdentifier(String accountIdentifier)
static Collection< CentralRepoAccount > getAccountsWithIdentifier(String accountIdentifier)
static Collection< CentralRepoAccount > getAccountsWithIdentifierLike(String accountIdentifierSubstring)
final Account.Type acctType
int getCorrelationTypeId()
final int correlationTypeId
CentralRepoAccountType getAccountType()
void process(ResultSet rs)
static CentralRepository getInstance()
final CentralRepoAccountType accountType
Account.Type getAcctType()