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;
}
Aggregations