Search in sources :

Example 1 with ColumnField

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);
    }
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) CollectionEntries(org.jbei.ice.lib.folder.collection.CollectionEntries) CollectionType(org.jbei.ice.lib.folder.collection.CollectionType) ColumnField(org.jbei.ice.lib.shared.ColumnField) PermissionException(org.jbei.ice.lib.access.PermissionException)

Example 2 with ColumnField

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);
    }
}
Also used : PermissionException(org.jbei.ice.lib.access.PermissionException) RegistryPartner(org.jbei.ice.lib.dto.web.RegistryPartner) ColumnField(org.jbei.ice.lib.shared.ColumnField) PageParameters(org.jbei.ice.lib.dto.common.PageParameters)

Example 3 with ColumnField

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;
}
Also used : ColumnField(org.jbei.ice.lib.shared.ColumnField) PartData(org.jbei.ice.lib.dto.entry.PartData) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) OwnerEntries(org.jbei.ice.lib.entry.OwnerEntries)

Aggregations

ColumnField (org.jbei.ice.lib.shared.ColumnField)3 PermissionException (org.jbei.ice.lib.access.PermissionException)2 PageParameters (org.jbei.ice.lib.dto.common.PageParameters)1 PartData (org.jbei.ice.lib.dto.entry.PartData)1 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)1 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)1 OwnerEntries (org.jbei.ice.lib.entry.OwnerEntries)1 CollectionEntries (org.jbei.ice.lib.folder.collection.CollectionEntries)1 CollectionType (org.jbei.ice.lib.folder.collection.CollectionType)1