Search in sources :

Example 11 with Results

use of org.jbei.ice.lib.dto.common.Results in project ice by JBEI.

the class UserApiKeys method getKeys.

/**
 * Retrieves either list of available keys for current user or all keys.
 * If requesting all keys then user must be an administrator
 *
 * @param limit        maximum number of keys to retrieve
 * @param offset       paging parameter start
 * @param sortField    field to sort on
 * @param asc          whether the retrieve order is in ascending order
 * @param getAvailable whether to retrieve all available keys or restrict by current user
 * @return wrapper around list of retrieved keys including number available
 * @throws PermissionException if <code>getAvailable</code> is true but user making the request does not have
 *                             administrative privileges
 */
public Results<AccessKey> getKeys(int limit, int offset, String sortField, boolean asc, boolean getAvailable) {
    Results<AccessKey> accessKeyResults = new Results<>();
    List<ApiKey> results;
    AccountController accountController = new AccountController();
    boolean isAdmin = accountController.isAdministrator(this.userId);
    if (getAvailable) {
        if (!isAdmin)
            throw new PermissionException("Cannot retrieve all api keys without admin privileges");
        results = apiKeyDAO.getAllApiKeys(sortField, limit, offset, asc);
    } else {
        results = apiKeyDAO.getApiKeysForUser(userId, sortField, limit, offset, asc);
    }
    for (ApiKey key : results) {
        AccessKey accessKey = key.toDataTransferObject();
        Account account = accountController.getByEmail(key.getOwnerEmail());
        accessKey.setAccount(account.toDataTransferObject());
        accessKeyResults.getData().add(accessKey);
    }
    // get count
    String user = getAvailable ? null : this.userId;
    long count = apiKeyDAO.getApiKeysCount(user);
    accessKeyResults.setResultCount(count);
    return accessKeyResults;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Account(org.jbei.ice.storage.model.Account) ApiKey(org.jbei.ice.storage.model.ApiKey) Results(org.jbei.ice.lib.dto.common.Results) AccessKey(org.jbei.ice.lib.dto.access.AccessKey)

Example 12 with Results

use of org.jbei.ice.lib.dto.common.Results in project ice by JBEI.

the class PartTraceSequences method getTraces.

public Results<TraceSequenceAnalysis> getTraces(int start, int limit) {
    entryAuthorization.expectRead(userId, entry);
    List<TraceSequence> sequences = dao.getByEntry(entry, start, limit);
    Results<TraceSequenceAnalysis> results = new Results<>();
    if (sequences == null)
        return results;
    for (TraceSequence traceSequence : sequences) {
        TraceSequenceAnalysis analysis = traceSequence.toDataTransferObject();
        AccountTransfer accountTransfer = new AccountTransfer();
        String depositor = traceSequence.getDepositor();
        boolean canEdit = canEdit(userId, depositor, entry);
        analysis.setCanEdit(canEdit);
        Account account = DAOFactory.getAccountDAO().getByEmail(traceSequence.getDepositor());
        if (account != null) {
            accountTransfer.setFirstName(account.getFirstName());
            accountTransfer.setLastName(account.getLastName());
            accountTransfer.setEmail(account.getEmail());
            accountTransfer.setId(account.getId());
        }
        analysis.setDepositor(accountTransfer);
        results.getData().add(analysis);
    }
    // get count
    int count = dao.getCountByEntry(entry);
    results.setResultCount(count);
    return results;
}
Also used : TraceSequenceAnalysis(org.jbei.ice.lib.dto.entry.TraceSequenceAnalysis) Results(org.jbei.ice.lib.dto.common.Results) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 13 with Results

use of org.jbei.ice.lib.dto.common.Results 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.getAuditsForEntryCount(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 14 with Results

use of org.jbei.ice.lib.dto.common.Results in project ice by JBEI.

the class TraceSequences method getTraces.

public Results<TraceSequenceAnalysis> getTraces(int start, int limit) {
    entryAuthorization.expectRead(userId, entry);
    List<TraceSequence> sequences = dao.getByEntry(entry, start, limit);
    Results<TraceSequenceAnalysis> results = new Results<>();
    if (sequences == null)
        return results;
    for (TraceSequence traceSequence : sequences) {
        TraceSequenceAnalysis analysis = traceSequence.toDataTransferObject();
        AccountTransfer accountTransfer = new AccountTransfer();
        String depositor = traceSequence.getDepositor();
        boolean canEdit = canEdit(userId, depositor, entry);
        analysis.setCanEdit(canEdit);
        Account account = DAOFactory.getAccountDAO().getByEmail(traceSequence.getDepositor());
        if (account != null) {
            accountTransfer.setFirstName(account.getFirstName());
            accountTransfer.setLastName(account.getLastName());
            accountTransfer.setEmail(account.getEmail());
            accountTransfer.setId(account.getId());
        }
        analysis.setDepositor(accountTransfer);
        results.getData().add(analysis);
    }
    // get count
    int count = dao.getCountByEntry(entry);
    results.setResultCount(count);
    return results;
}
Also used : TraceSequenceAnalysis(org.jbei.ice.lib.dto.entry.TraceSequenceAnalysis) Results(org.jbei.ice.lib.dto.common.Results) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer)

Example 15 with Results

use of org.jbei.ice.lib.dto.common.Results in project ice by JBEI.

the class CollectionEntries method getPersonalEntries.

/**
     * Retrieves entries owned by user
     *
     * @param field  sort field
     * @param asc    sort order
     * @param offset paging start
     * @param limit  maximum number of entries to retrieve
     * @param filter optional text to filter entries by
     * @return wrapper around list of parts that conform to the parameters and the maximum number
     * of such entries that are available
     * @throws PermissionException on null user id which is required for owner entries
     */
protected Results<PartData> getPersonalEntries(ColumnField field, boolean asc, int offset, int limit, String filter) {
    if (userId == null || userId.isEmpty())
        throw new PermissionException("User id is required to retrieve owner entries");
    OwnerEntries ownerEntries = new OwnerEntries(userId, userId);
    final List<PartData> entries = ownerEntries.retrieveOwnerEntries(field, asc, offset, limit, filter);
    final long count = ownerEntries.getNumberOfOwnerEntries();
    Results<PartData> results = new Results<>();
    results.setResultCount(count);
    results.setData(entries);
    return results;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Results(org.jbei.ice.lib.dto.common.Results) PartData(org.jbei.ice.lib.dto.entry.PartData) OwnerEntries(org.jbei.ice.lib.entry.OwnerEntries)

Aggregations

Results (org.jbei.ice.lib.dto.common.Results)21 PartData (org.jbei.ice.lib.dto.entry.PartData)10 PermissionException (org.jbei.ice.lib.access.PermissionException)5 Account (org.jbei.ice.storage.model.Account)4 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)3 DNAFeature (org.jbei.ice.lib.dto.DNAFeature)3 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)3 Group (org.jbei.ice.storage.model.Group)3 TraceSequenceAnalysis (org.jbei.ice.lib.dto.entry.TraceSequenceAnalysis)2 OwnerEntries (org.jbei.ice.lib.entry.OwnerEntries)2 SharedEntries (org.jbei.ice.lib.entry.SharedEntries)2 VisibleEntries (org.jbei.ice.lib.entry.VisibleEntries)2 Entry (org.jbei.ice.storage.model.Entry)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 AccountController (org.jbei.ice.lib.account.AccountController)1 DNAFeatureLocation (org.jbei.ice.lib.dto.DNAFeatureLocation)1 DNAFeatures (org.jbei.ice.lib.dto.DNAFeatures)1 FeaturedDNASequence (org.jbei.ice.lib.dto.FeaturedDNASequence)1