Search in sources :

Example 1 with AccountDAO

use of org.jbei.ice.storage.hibernate.dao.AccountDAO in project ice by JBEI.

the class EntryHistory method get.

public Results<History> get(int limit, int offset, boolean asc, String sort) {
    entryAuthorization.expectWrite(userId, entry);
    List<Audit> list = dao.getAuditsForEntry(entry, limit, offset, asc, sort);
    Results<History> results = new Results<>();
    AccountDAO accountDAO = DAOFactory.getAccountDAO();
    for (Audit audit : list) {
        History history = audit.toDataTransferObject();
        if (history.getPartner() == null) {
            Account account = accountDAO.getByEmail(history.getUserId());
            if (account != null)
                history.setAccount(account.toDataTransferObject());
        }
        results.getData().add(history);
    }
    long count = dao.getHistoryCount(this.entry);
    results.setResultCount(count);
    return results;
}
Also used : Audit(org.jbei.ice.storage.model.Audit) Account(org.jbei.ice.storage.model.Account) Results(org.jbei.ice.lib.dto.common.Results) AccountDAO(org.jbei.ice.storage.hibernate.dao.AccountDAO) History(org.jbei.ice.lib.dto.History)

Example 2 with AccountDAO

use of org.jbei.ice.storage.hibernate.dao.AccountDAO in project ice by JBEI.

the class AccountCreator method createTestAccount.

public static Account createTestAccount(String testName, boolean admin) throws Exception {
    String email = testName + "@TESTER";
    AccountDAO dao = DAOFactory.getAccountDAO();
    Account account = dao.getByEmail(email);
    if (account != null)
        throw new Exception("duplicate account");
    AccountTransfer accountTransfer = new AccountTransfer();
    accountTransfer.setFirstName("TEST_FNAME");
    accountTransfer.setLastName("TEST");
    accountTransfer.setEmail(email);
    accountTransfer = new AccountController().createNewAccount(accountTransfer, false);
    Assert.assertNotNull(accountTransfer.getPassword());
    account = dao.getByEmail(email);
    Assert.assertNotNull(account);
    if (admin) {
        account.setType(AccountType.ADMIN);
        dao.update(account);
    }
    return account;
}
Also used : Account(org.jbei.ice.storage.model.Account) AccountDAO(org.jbei.ice.storage.hibernate.dao.AccountDAO) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer) AccountController(org.jbei.ice.lib.account.AccountController)

Example 3 with AccountDAO

use of org.jbei.ice.storage.hibernate.dao.AccountDAO in project ice by JBEI.

the class TokenVerification method verifyAPIKey.

public String verifyAPIKey(String token, String clientId, String userId) {
    // hash = (token, client + salt + client)
    Optional<ApiKey> optionalKey = DAOFactory.getApiKeyDAO().getByClientId(clientId);
    if (!optionalKey.isPresent())
        throw new PermissionException("Invalid client Id " + clientId);
    ApiKey key = optionalKey.get();
    String hash_token = tokenHash.encrypt(token, clientId + key.getSecret() + clientId);
    if (!hash_token.equalsIgnoreCase(key.getHashedToken()))
        throw new PermissionException("Invalid token");
    // if the api belongs to an admin, accept whatever user id they present
    AccountDAO accountDAO = DAOFactory.getAccountDAO();
    Account account = accountDAO.getByEmail(key.getOwnerEmail());
    if (userId == null)
        userId = account.getEmail();
    if (account.getType() == AccountType.ADMIN) {
        if (account.getEmail().equalsIgnoreCase(userId))
            return userId;
        if (accountDAO.getByEmail(userId) == null)
            throw new PermissionException("Invalid user id");
        return userId;
    }
    return key.getOwnerEmail();
}
Also used : Account(org.jbei.ice.storage.model.Account) ApiKey(org.jbei.ice.storage.model.ApiKey) AccountDAO(org.jbei.ice.storage.hibernate.dao.AccountDAO)

Example 4 with AccountDAO

use of org.jbei.ice.storage.hibernate.dao.AccountDAO 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

AccountDAO (org.jbei.ice.storage.hibernate.dao.AccountDAO)4 Account (org.jbei.ice.storage.model.Account)4 ArrayList (java.util.ArrayList)1 AccountController (org.jbei.ice.lib.account.AccountController)1 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)1 History (org.jbei.ice.lib.dto.History)1 Results (org.jbei.ice.lib.dto.common.Results)1 PreferenceKey (org.jbei.ice.lib.dto.user.PreferenceKey)1 UserPreferences (org.jbei.ice.lib.dto.user.UserPreferences)1 ApiKey (org.jbei.ice.storage.model.ApiKey)1 Audit (org.jbei.ice.storage.model.Audit)1 Preference (org.jbei.ice.storage.model.Preference)1