use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class AccountPreferencesDAO method getAccountPreferences.
/**
* Retrieve the {@link AccountPreferences} of the given {@link Account}.
*
* @param account account whose preferences are being retrieved
* @return retrieved AccountPreferences
* @throws DAOException
*/
public AccountPreferences getAccountPreferences(Account account) {
try {
CriteriaQuery<AccountPreferences> query = getBuilder().createQuery(AccountPreferences.class);
Root<AccountPreferences> from = query.from(AccountPreferences.class);
query.where(getBuilder().equal(from.get("account"), account));
return currentSession().createQuery(query).uniqueResult();
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException("Failed to get AccountPreferences by Account: " + account.getFullName(), e);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class AccountDAO method getByEmail.
/**
* Retrieve an {@link Account} by the email field.
*
* @param email unique email identifier for account
* @return Account record referenced by email
*/
public Account getByEmail(String email) {
if (email == null)
return null;
try {
CriteriaQuery<Account> query = getBuilder().createQuery(Account.class);
Root<Account> from = query.from(Account.class);
query.where(getBuilder().equal(getBuilder().lower(from.get("email")), email.trim().toLowerCase()));
return currentSession().createQuery(query).uniqueResult();
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException("Failed to retrieve Account by email: " + email, e);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class AccountDAO method getMatchingAccounts.
/**
* Retrieves accounts whose firstName, lastName, or email fields match the specified
* token up to the specified limit.
*
* @param token filter for the account fields
* @param limit maximum number of matching accounts to return; 0 to return all
* @return list of matching accounts
*/
public List<Account> getMatchingAccounts(String token, int limit) {
try {
CriteriaQuery<Account> query = getBuilder().createQuery(Account.class);
Root<Account> from = query.from(Account.class);
String[] tokens = token.split("\\s+");
List<Predicate> predicates = new ArrayList<>();
for (String tok : tokens) {
tok = tok.toLowerCase();
predicates.add(getBuilder().or(getBuilder().like(getBuilder().lower(from.get("firstName")), "%" + tok + "%"), getBuilder().like(getBuilder().lower(from.get("lastName")), "%" + tok + "%"), getBuilder().like(getBuilder().lower(from.get("email")), "%" + tok + "%")));
}
query.where(predicates.toArray(new Predicate[predicates.size()])).distinct(true);
return currentSession().createQuery(query).setMaxResults(limit).list();
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException(e);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class ApiKeyDAO method getByClientId.
/**
* Retrieves an api key by client id.
* If one exists it is expected that the client id + the creator id uniquely retrieves it. In other words,
* the same user cannot have two api keys for the same client
*
* @param clientId client identifier for api key
* @return container that may or may not contain the found key
* @throws DAOException if more that one api key is found or there is a problem accessing the database
*/
public Optional<ApiKey> getByClientId(String clientId) {
try {
CriteriaQuery<ApiKey> query = getBuilder().createQuery(ApiKey.class);
Root<ApiKey> from = query.from(ApiKey.class);
query.where(getBuilder().equal(from.get("clientId"), clientId));
return currentSession().createQuery(query).uniqueResultOptional();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class ApiKeyDAO method getAllApiKeys.
public List<ApiKey> getAllApiKeys(String sort, int limit, int start, boolean asc) {
try {
CriteriaQuery<ApiKey> query = getBuilder().createQuery(ApiKey.class);
Root<ApiKey> from = query.from(ApiKey.class);
query.orderBy(asc ? getBuilder().asc(from.get(sort)) : getBuilder().desc(from.get(sort)));
return currentSession().createQuery(query).setFirstResult(start).setMaxResults(limit).list();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
Aggregations