use of org.jbei.ice.lib.shared.ColumnField in project ice by JBEI.
the class CollectionResource method read.
/**
* Retrieve entries by collection type using paging parameters, including a filter
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{type}/entries")
public Response read(@PathParam("type") String collectionType, @DefaultValue("0") @QueryParam("offset") final int offset, @DefaultValue("15") @QueryParam("limit") final int limit, @DefaultValue("created") @QueryParam("sort") final String sort, @DefaultValue("false") @QueryParam("asc") final boolean asc, @DefaultValue("") @QueryParam("filter") String filter, @QueryParam("fields") List<String> queryParam) {
String userId = requireUserId();
try {
CollectionType type = CollectionType.valueOf(collectionType.toUpperCase());
ColumnField sortField = ColumnField.valueOf(sort.toUpperCase());
log(userId, "retrieving entries for collection " + type);
CollectionEntries entries = new CollectionEntries(userId, type);
return super.respond(entries.getEntries(sortField, asc, offset, limit, filter));
} catch (PermissionException pe) {
return super.respond(Response.Status.FORBIDDEN);
} catch (IllegalArgumentException ie) {
throw new WebApplicationException(Response.Status.BAD_REQUEST);
} catch (Exception e) {
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of org.jbei.ice.lib.shared.ColumnField in project ice by JBEI.
the class FolderResource method read.
/**
* Retrieves the entries for specified folder. Handles request
* from a local client (ui) or from a remote ice instance
*
* @return list of retrieved entries wrapped in folder object
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/entries")
public FolderDetails read(@PathParam("id") final String folderId, @DefaultValue("0") @QueryParam("offset") final int offset, @DefaultValue("15") @QueryParam("limit") final int limit, @DefaultValue("created") @QueryParam("sort") final String sort, @DefaultValue("false") @QueryParam("asc") final boolean asc, @DefaultValue("") @QueryParam("filter") String filter, // todo: move to headers
@QueryParam("token") String token, // todo : ditto
@QueryParam("userId") String remoteUserId, @QueryParam("fields") List<String> queryParam) {
try {
final ColumnField field = ColumnField.valueOf(sort.toUpperCase());
if (folderId.equalsIgnoreCase("public")) {
// todo : move to separate rest resource path
RegistryPartner registryPartner = requireWebPartner();
// return public entries
log(registryPartner.getUrl(), "requesting public entries");
return this.controller.getPublicEntries(field, offset, limit, asc);
}
// userId can be empty for public folders
String userId = super.getUserId();
try {
final long id = Long.decode(folderId);
String message = "retrieving folder " + id + " entries";
if (filter.length() > 0)
message += " filtered by \"" + filter + "\"";
FolderContents folderContents = new FolderContents();
PageParameters pageParameters = new PageParameters(offset, limit, field, asc, filter);
if (StringUtils.isEmpty(userId)) {
if (// todo :verify partner?
StringUtils.isEmpty(token))
return folderContents.getContents(userId, id, pageParameters);
// get registry partner
RegistryPartner partner = requireWebPartner();
log(partner.getUrl(), message);
return folderContents.getRemotelySharedContents(remoteUserId, token, partner, id, pageParameters);
} else {
log(userId, message);
return folderContents.getContents(userId, id, pageParameters);
}
} catch (final NumberFormatException nfe) {
Logger.error("Passed folder id " + folderId + " is not a number");
return null;
}
} catch (PermissionException e) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
}
use of org.jbei.ice.lib.shared.ColumnField in project ice by JBEI.
the class UserResource method getProfileEntries.
/**
* @return collection for user's part entries
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{id}/entries")
public FolderDetails getProfileEntries(@PathParam("id") long userId, @DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("15") @QueryParam("limit") int limit, @DefaultValue("created") @QueryParam("sort") String sort, @DefaultValue("false") @QueryParam("asc") boolean asc, @DefaultValue("") @QueryParam("filter") String filter) {
String userIdString = getUserId();
ColumnField field = ColumnField.valueOf(sort.toUpperCase());
OwnerEntries ownerEntries = new OwnerEntries(userIdString, userId);
List<PartData> entries = ownerEntries.retrieveOwnerEntries(field, asc, offset, limit, filter);
long count = ownerEntries.getNumberOfOwnerEntries();
FolderDetails details = new FolderDetails();
details.getEntries().addAll(entries);
details.setCount(count);
return details;
}
Aggregations