CentralRepository getInstance will throw exception when CR is disabled

This commit is contained in:
Kelly Kelly 2020-06-19 11:21:25 -04:00
parent 6c39a709b7
commit 715e4718fd
2 changed files with 39 additions and 79 deletions

View File

@ -53,7 +53,7 @@ public interface CentralRepository {
case SQLITE: case SQLITE:
return SqliteCentralRepo.getInstance(); return SqliteCentralRepo.getInstance();
default: default:
return null; throw new CentralRepoException("Failed to get CentralRepository instance, Central Repositiory is not enabled.");
} }
} }

View File

@ -127,16 +127,12 @@ public class PersonaAccount {
* @param confidence Confidence level. * @param confidence Confidence level.
* *
* @return PersonaAccount * @return PersonaAccount
*
* @throws CentralRepoException If there is an error in creating the * @throws CentralRepoException If there is an error in creating the
* account. * account.
*/ */
static PersonaAccount addPersonaAccount(Persona persona, CentralRepoAccount account, String justification, Persona.Confidence confidence) throws CentralRepoException { static PersonaAccount addPersonaAccount(Persona persona, CentralRepoAccount account, String justification, Persona.Confidence confidence) throws CentralRepoException {
CentralRepository cr = CentralRepository.getInstance(); CentralRepository cr = CentralRepository.getInstance();
if(cr == null) {
throw new CentralRepoException("Failed to add Persona, Central Repository is not enable");
}
CentralRepoExaminer currentExaminer = cr.getOrInsertExaminer(System.getProperty("user.name")); CentralRepoExaminer currentExaminer = cr.getOrInsertExaminer(System.getProperty("user.name"));
Instant instant = Instant.now(); Instant instant = Instant.now();
@ -151,7 +147,7 @@ public class PersonaAccount {
+ currentExaminer.getId() + currentExaminer.getId()
+ ")"; + ")";
CentralRepository.getInstance().executeInsertSQL(insertClause); cr.executeInsertSQL(insertClause);
String queryClause = PERSONA_ACCOUNTS_QUERY_CLAUSE String queryClause = PERSONA_ACCOUNTS_QUERY_CLAUSE
+ "WHERE persona_id = " + persona.getId() + "WHERE persona_id = " + persona.getId()
@ -249,21 +245,15 @@ public class PersonaAccount {
* persona_account. * persona_account.
*/ */
static Collection<PersonaAccount> getPersonaAccountsForPersona(long personaId) throws CentralRepoException { static Collection<PersonaAccount> getPersonaAccountsForPersona(long personaId) throws CentralRepoException {
CentralRepository cr = CentralRepository.getInstance();
if (cr != null) {
String queryClause = PERSONA_ACCOUNTS_QUERY_CLAUSE String queryClause = PERSONA_ACCOUNTS_QUERY_CLAUSE
+ " WHERE persona_accounts.persona_id = " + personaId; + " WHERE persona_accounts.persona_id = " + personaId;
PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback(); PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback();
cr.executeSelectSQL(queryClause, queryCallback); CentralRepository.getInstance().executeSelectSQL(queryClause, queryCallback);
return queryCallback.getPersonaAccountsList(); return queryCallback.getPersonaAccountsList();
} }
return new ArrayList<>();
}
/** /**
* Gets all the Persona for the specified Account. * Gets all the Persona for the specified Account.
* *
@ -279,18 +269,12 @@ public class PersonaAccount {
+ " WHERE persona_accounts.account_id = " + accountId + " WHERE persona_accounts.account_id = " + accountId
+ " AND personas.status_id != " + Persona.PersonaStatus.DELETED.getStatusId(); + " AND personas.status_id != " + Persona.PersonaStatus.DELETED.getStatusId();
CentralRepository cr = CentralRepository.getInstance();
if (cr != null) {
PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback(); PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback();
cr.executeSelectSQL(queryClause, queryCallback); CentralRepository.getInstance().executeSelectSQL(queryClause, queryCallback);
return queryCallback.getPersonaAccountsList(); return queryCallback.getPersonaAccountsList();
} }
return new ArrayList<>();
}
/** /**
* Gets all the Persona associated with all the accounts matching the given * Gets all the Persona associated with all the accounts matching the given
* account identifier substring. * account identifier substring.
@ -308,17 +292,12 @@ public class PersonaAccount {
+ " WHERE LOWER(accounts.account_unique_identifier) LIKE LOWER('%" + accountIdentifierSubstring + "%')" + " WHERE LOWER(accounts.account_unique_identifier) LIKE LOWER('%" + accountIdentifierSubstring + "%')"
+ " AND personas.status_id != " + Persona.PersonaStatus.DELETED.getStatusId(); + " AND personas.status_id != " + Persona.PersonaStatus.DELETED.getStatusId();
CentralRepository cr = CentralRepository.getInstance();
if (cr != null) {
PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback(); PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback();
cr.executeSelectSQL(queryClause, queryCallback); CentralRepository.getInstance().executeSelectSQL(queryClause, queryCallback);
return queryCallback.getPersonaAccountsList(); return queryCallback.getPersonaAccountsList();
} }
return new ArrayList<>();
}
/** /**
* Gets all the Persona associated with the given account. * Gets all the Persona associated with the given account.
* *
@ -335,14 +314,10 @@ public class PersonaAccount {
+ " AND type_name = '" + account.getAccountType().getTypeName() + "' " + " AND type_name = '" + account.getAccountType().getTypeName() + "' "
+ " AND personas.status_id != " + Persona.PersonaStatus.DELETED.getStatusId(); + " AND personas.status_id != " + Persona.PersonaStatus.DELETED.getStatusId();
CentralRepository cr = CentralRepository.getInstance();
if (cr != null) {
PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback(); PersonaAccountsQueryCallback queryCallback = new PersonaAccountsQueryCallback();
cr.executeSelectSQL(queryClause, queryCallback); CentralRepository.getInstance().executeSelectSQL(queryClause, queryCallback);
return queryCallback.getPersonaAccountsList(); return queryCallback.getPersonaAccountsList();
}
return new ArrayList<>();
} }
/** /**
@ -354,14 +329,8 @@ public class PersonaAccount {
* account. * account.
*/ */
static void removePersonaAccount(long id) throws CentralRepoException { static void removePersonaAccount(long id) throws CentralRepoException {
CentralRepository cr = CentralRepository.getInstance();
if(cr == null) {
throw new CentralRepoException("Failed to remove persona account, Central Repo is not enabled");
}
String deleteClause = " DELETE FROM persona_accounts WHERE id = " + id; String deleteClause = " DELETE FROM persona_accounts WHERE id = " + id;
cr.executeDeleteSQL(deleteClause); CentralRepository.getInstance().executeDeleteSQL(deleteClause);
} }
/** /**
@ -373,14 +342,8 @@ public class PersonaAccount {
* account. * account.
*/ */
static void modifyPersonaAccount(long id, Persona.Confidence confidence, String justification) throws CentralRepoException { static void modifyPersonaAccount(long id, Persona.Confidence confidence, String justification) throws CentralRepoException {
CentralRepository cr = CentralRepository.getInstance();
if (cr == null) {
throw new CentralRepoException("Failed to modify persona account, Central Repo is not enabled");
}
String updateClause = "UPDATE persona_accounts SET confidence_id = " + confidence.getLevelId() + ", justification = \"" + justification + "\" WHERE id = " + id; String updateClause = "UPDATE persona_accounts SET confidence_id = " + confidence.getLevelId() + ", justification = \"" + justification + "\" WHERE id = " + id;
cr.executeUpdateSQL(updateClause); CentralRepository.getInstance().executeUpdateSQL(updateClause);
} }
/** /**
@ -419,13 +382,12 @@ public class PersonaAccount {
* *
* @return Collection of all accounts associated with the given persona, may * @return Collection of all accounts associated with the given persona, may
* be empty. * be empty.
*
* @throws CentralRepoException If there is an error in getting the * @throws CentralRepoException If there is an error in getting the
* accounts. * accounts.
*/ */
static Collection<CentralRepoAccount> getAccountsForPersona(long personaId) throws CentralRepoException { static Collection<CentralRepoAccount> getAccountsForPersona(long personaId) throws CentralRepoException {
CentralRepository cr = CentralRepository.getInstance();
if (cr != null) {
String queryClause = "SELECT account_id, " String queryClause = "SELECT account_id, "
+ " accounts.account_type_id as account_type_id, accounts.account_unique_identifier as account_unique_identifier," + " accounts.account_type_id as account_type_id, accounts.account_unique_identifier as account_unique_identifier,"
+ " account_types.type_name as type_name " + " account_types.type_name as type_name "
@ -435,11 +397,9 @@ public class PersonaAccount {
+ " WHERE persona_accounts.persona_id = " + personaId; + " WHERE persona_accounts.persona_id = " + personaId;
AccountsForPersonaQueryCallback queryCallback = new AccountsForPersonaQueryCallback(); AccountsForPersonaQueryCallback queryCallback = new AccountsForPersonaQueryCallback();
cr.executeSelectSQL(queryClause, queryCallback); CentralRepository.getInstance().executeSelectSQL(queryClause, queryCallback);
return queryCallback.getAccountsList(); return queryCallback.getAccountsList();
}
return new ArrayList<>();
} }
} }