Search in sources :

Example 61 with Group

use of org.jbei.ice.storage.model.Group in project ice by JBEI.

the class Groups method getGroupMembers.

/**
 * Retrieves both local and remote members of the specified group if the user making the request
 * has the appropriate permissions
 *
 * @param groupId unique local identifier of group
 * @return information about specified group including remote and local members
 * @throws PermissionException if the user does not have read permissions
 */
public UserGroup getGroupMembers(long groupId) {
    Group group = dao.get(groupId);
    if (group == null)
        return null;
    if (group.getType() == GroupType.PUBLIC) {
        if (!accountController.isAdministrator(userId))
            throw new PermissionException("Administrative privileges required");
    } else if (!userId.equalsIgnoreCase(group.getOwner().getEmail())) {
        Account account = accountDAO.getByEmail(this.userId);
        if (account.getType() != AccountType.ADMIN)
            throw new PermissionException("Missing required permissions");
    }
    UserGroup userGroup = group.toDataTransferObject();
    for (Account account : group.getMembers()) {
        userGroup.getMembers().add(account.toDataTransferObject());
    }
    // get remote members
    List<RemoteClientModel> clients = remoteClientModelDAO.getClientsForGroup(group);
    for (RemoteClientModel clientModel : clients) {
        userGroup.getRemoteMembers().add(clientModel.toDataTransferObject());
    }
    return userGroup;
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) Group(org.jbei.ice.storage.model.Group) UserGroup(org.jbei.ice.lib.dto.group.UserGroup) Account(org.jbei.ice.storage.model.Account) RemoteClientModel(org.jbei.ice.storage.model.RemoteClientModel) UserGroup(org.jbei.ice.lib.dto.group.UserGroup)

Example 62 with Group

use of org.jbei.ice.storage.model.Group 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

Group (org.jbei.ice.storage.model.Group)62 Account (org.jbei.ice.storage.model.Account)26 UserGroup (org.jbei.ice.lib.dto.group.UserGroup)16 DAOException (org.jbei.ice.storage.DAOException)15 GroupController (org.jbei.ice.lib.group.GroupController)12 ArrayList (java.util.ArrayList)10 HashSet (java.util.HashSet)9 PartData (org.jbei.ice.lib.dto.entry.PartData)9 PermissionException (org.jbei.ice.lib.access.PermissionException)7 HibernateRepositoryTest (org.jbei.ice.storage.hibernate.HibernateRepositoryTest)7 Entry (org.jbei.ice.storage.model.Entry)7 Test (org.junit.Test)7 HibernateException (org.hibernate.HibernateException)5 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)4 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)4 Folder (org.jbei.ice.storage.model.Folder)4 RemoteClientModel (org.jbei.ice.storage.model.RemoteClientModel)4 NativeQuery (org.hibernate.query.NativeQuery)3 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)3 Results (org.jbei.ice.lib.dto.common.Results)3