use of org.jbei.ice.storage.model.Preference in project ice by JBEI.
the class PreferencesDAO method getPreference.
public Preference getPreference(Account account, String key) {
try {
CriteriaQuery<Preference> query = getBuilder().createQuery(Preference.class);
Root<Preference> from = query.from(Preference.class);
query.where(getBuilder().equal(from.get("account"), account), getBuilder().equal(from.get("key"), key.toUpperCase()));
return currentSession().createQuery(query).uniqueResult();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.model.Preference in project ice by JBEI.
the class PreferencesDAO method retrievePreferenceValues.
public HashMap<String, String> retrievePreferenceValues(Account account, HashSet<String> keys) {
try {
CriteriaQuery<Preference> query = getBuilder().createQuery(Preference.class);
Root<Preference> from = query.from(Preference.class);
query.where(getBuilder().equal(from.get("account"), account), from.get("key").in(keys));
List<Preference> result = currentSession().createQuery(query).list();
Iterator iterator = result.iterator();
HashMap<String, String> results = new HashMap<>();
while (iterator.hasNext()) {
Preference preference = (Preference) iterator.next();
if (keys.contains(preference.getKey().toUpperCase())) {
results.put(preference.getKey().toUpperCase().trim(), preference.getValue().trim());
}
}
return results;
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.model.Preference in project ice by JBEI.
the class PreferencesController method getUserPreferences.
public UserPreferences getUserPreferences(String requester, long userId) {
AccountDAO accountDAO = DAOFactory.getAccountDAO();
Account account = accountDAO.getByEmail(requester);
Account requestedAccount = accountDAO.get(userId);
if (account == null || requestedAccount == null)
return null;
if (account.getType() != AccountType.ADMIN && !requester.equalsIgnoreCase(requestedAccount.getEmail()))
return null;
ArrayList<PreferenceKey> keys = new ArrayList<>();
keys.add(PreferenceKey.PRINCIPAL_INVESTIGATOR);
keys.add(PreferenceKey.FUNDING_SOURCE);
List<Preference> preferences = dao.getAccountPreferences(requestedAccount, keys);
if (preferences == null)
return null;
UserPreferences userPreferences = new UserPreferences();
userPreferences.setUserId(requestedAccount.getEmail());
for (Preference preference : preferences) {
userPreferences.getPreferences().add(preference.toDataTransferObject());
}
return userPreferences;
}
use of org.jbei.ice.storage.model.Preference in project ice by JBEI.
the class PreferencesController method updatePreference.
public PreferenceInfo updatePreference(String requesterEmail, long userId, String key, String value) {
if (value == null)
return null;
// todo : check permissions
Account account = DAOFactory.getAccountDAO().get(userId);
Preference preference = dao.createOrUpdatePreference(account, key, value);
return preference.toDataTransferObject();
}
use of org.jbei.ice.storage.model.Preference in project ice by JBEI.
the class PreferencesController method getPreferenceValue.
public String getPreferenceValue(String userId, String preferenceKey) {
Account account = accountDAO.getByEmail(userId);
if (account == null)
return null;
Preference preference = dao.getPreference(account, preferenceKey);
if (preference == null)
return null;
return preference.getValue();
}
Aggregations