Search in sources :

Example 21 with Results

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

the class Groups method get.

/**
 * Retrieves groups that user is either a member of. Users are implicit members of the groups
 * that they create so call also returns those groups
 *
 * @param userId id of account whose groups are being requested
 * @return list of groups that user is a member of
 */
public Results<UserGroup> get(long userId) {
    AccountController accountController = new AccountController();
    Account userIdAccount = accountDAO.get(userId);
    Account account = accountDAO.getByEmail(this.userId);
    // TODO : account authorization
    if (!accountController.isAdministrator(account.getEmail()) && account.getId() != userIdAccount.getId())
        return null;
    List<Group> result = dao.retrieveMemberGroups(account);
    Results<UserGroup> groupResults = new Results<>();
    for (Group group : result) {
        UserGroup user = group.toDataTransferObject();
        long count = dao.getMemberCount(group.getUuid());
        // get clients
        count += DAOFactory.getRemoteClientModelDAO().getClientCount(group);
        user.setMemberCount(count);
        groupResults.getData().add(user);
    }
    return groupResults;
}
Also used : Account(org.jbei.ice.storage.model.Account) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) Results(org.jbei.ice.lib.dto.common.Results) AccountController(org.jbei.ice.lib.account.AccountController) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

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