use of org.jbei.ice.lib.dto.user.PreferenceKey in project ice by JBEI.
the class PreferencesDAO method getAccountPreferences.
public List<Preference> getAccountPreferences(Account account, List<PreferenceKey> keys) {
ArrayList<String> keyString = new ArrayList<>();
for (PreferenceKey key : keys) keyString.add(key.name());
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(keyString));
return currentSession().createQuery(query).list();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.lib.dto.user.PreferenceKey in project ice by JBEI.
the class PreferencesController method retrieveAccountPreferences.
public HashMap<PreferenceKey, String> retrieveAccountPreferences(Account account, ArrayList<PreferenceKey> keys) {
HashMap<PreferenceKey, String> preferences = new HashMap<>();
List<Preference> results = dao.getAccountPreferences(account, keys);
for (Preference preference : results) {
PreferenceKey key = PreferenceKey.fromString(preference.getKey());
// bulk uploads do not.
if (key == null) {
continue;
}
preferences.put(key, preference.getValue());
}
return preferences;
}
use of org.jbei.ice.lib.dto.user.PreferenceKey in project ice by JBEI.
the class PreferencesControllerTest method testRetrieveAccountPreferences.
@Test
public void testRetrieveAccountPreferences() throws Exception {
Account account = AccountCreator.createTestAccount("testRetrieveAccountPreferences", false);
ArrayList<PreferenceKey> keys = new ArrayList<>(Arrays.asList(PreferenceKey.values()));
HashMap<PreferenceKey, String> preferences = controller.retrieveAccountPreferences(account, keys);
Assert.assertNotNull(preferences);
Assert.assertEquals(0, preferences.size());
Preference preference = controller.createPreference(account, PreferenceKey.FUNDING_SOURCE.name(), "JBEI");
Assert.assertNotNull(preference);
preferences = controller.retrieveAccountPreferences(account, keys);
Assert.assertNotNull(preference);
Assert.assertEquals(1, preferences.size());
Assert.assertTrue(preferences.containsKey(PreferenceKey.FUNDING_SOURCE));
Assert.assertTrue(preferences.get(PreferenceKey.FUNDING_SOURCE).equals("JBEI"));
preference = controller.createPreference(account, PreferenceKey.PRINCIPAL_INVESTIGATOR.name(), "PI");
Assert.assertNotNull(preference);
preferences = controller.retrieveAccountPreferences(account, keys);
Assert.assertNotNull(preference);
Assert.assertEquals(2, preferences.size());
Assert.assertTrue(preferences.containsKey(PreferenceKey.FUNDING_SOURCE));
Assert.assertTrue(preferences.get(PreferenceKey.FUNDING_SOURCE).equals("JBEI"));
Assert.assertTrue(preferences.containsKey(PreferenceKey.PRINCIPAL_INVESTIGATOR));
Assert.assertTrue(preferences.get(PreferenceKey.PRINCIPAL_INVESTIGATOR).equals("PI"));
}
use of org.jbei.ice.lib.dto.user.PreferenceKey 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;
}
Aggregations