use of org.jbei.ice.lib.dto.user.UserPreferences 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