Search in sources :

Example 1 with UserPreferences

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;
}
Also used : UserPreferences(org.jbei.ice.lib.dto.user.UserPreferences) Account(org.jbei.ice.storage.model.Account) Preference(org.jbei.ice.storage.model.Preference) ArrayList(java.util.ArrayList) PreferenceKey(org.jbei.ice.lib.dto.user.PreferenceKey) AccountDAO(org.jbei.ice.storage.hibernate.dao.AccountDAO)

Aggregations

ArrayList (java.util.ArrayList)1 PreferenceKey (org.jbei.ice.lib.dto.user.PreferenceKey)1 UserPreferences (org.jbei.ice.lib.dto.user.UserPreferences)1 AccountDAO (org.jbei.ice.storage.hibernate.dao.AccountDAO)1 Account (org.jbei.ice.storage.model.Account)1 Preference (org.jbei.ice.storage.model.Preference)1