use of org.jbei.ice.lib.dto.AccountResults in project ice by JBEI.
the class Accounts method getAvailableAccounts.
/**
* Retrieves the user records available.
*
* @param userId requesting userid
* @param offset start
* @param limit account count upper limit
* @param asc sort order
* @param sort account sort type
* @return wrapper around list of retrieved requested records and number available for retrieval
*/
public AccountResults getAvailableAccounts(String userId, int offset, int limit, boolean asc, String sort, String filter) {
Account account = accountDAO.getByEmail(userId);
if (!isAdministrator(account))
throw new PermissionException(userId + " does not have the privilege to access all accounts");
AccountResults results = new AccountResults();
List<Account> accounts = accountDAO.getAccounts(offset, limit, sort, asc, filter);
for (Account userAccount : accounts) {
AccountTransfer info = userAccount.toDataTransferObject();
long entryCount = getNumberOfOwnerEntries(account, userAccount.getEmail());
info.setUserEntryCount(entryCount);
info.setAdmin(isAdministrator(userAccount));
results.getResults().add(info);
}
long count = accountDAO.getAccountsCount(filter);
results.setResultCount(count);
return results;
}
use of org.jbei.ice.lib.dto.AccountResults in project ice by JBEI.
the class UserResource method get.
/**
* Retrieves list of users that are available to user making request. Availability is defined by
* being in the same group if the user does not have admin privileges.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response get(@DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("15") @QueryParam("limit") int limit, @DefaultValue("lastName") @QueryParam("sort") String sort, @DefaultValue("true") @QueryParam("asc") boolean asc, @QueryParam("filter") String filter) {
String userId = getUserId();
log(userId, "retrieving available accounts");
try {
Accounts accounts = new Accounts();
AccountResults result = accounts.getAvailableAccounts(userId, offset, limit, asc, sort, filter);
return super.respond(result);
} catch (PermissionException pe) {
return super.respond(Response.Status.UNAUTHORIZED);
}
}
Aggregations