Search in sources :

Example 1 with Item

use of com.sun.jersey.samples.storageservice.Item in project enunciate by stoicflame.

the class ItemResource method deleteItem.

@DELETE
public void deleteItem() {
    System.out.println("DELETE ITEM " + container + " " + item);
    Item i = MemoryStore.MS.deleteItem(container, item);
    if (i == null) {
        throw new NotFoundException("Item not found");
    }
}
Also used : Item(com.sun.jersey.samples.storageservice.Item) NotFoundException(javax.ws.rs.NotFoundException) DELETE(javax.ws.rs.DELETE)

Example 2 with Item

use of com.sun.jersey.samples.storageservice.Item in project enunciate by stoicflame.

the class ItemResource method putItem.

@PUT
public Response putItem(@Context HttpHeaders headers, byte[] data) {
    System.out.println("PUT ITEM " + container + " " + item);
    URI uri = uriInfo.getAbsolutePath();
    MediaType mimeType = headers.getMediaType();
    GregorianCalendar gc = new GregorianCalendar();
    gc.set(GregorianCalendar.MILLISECOND, 0);
    Item i = new Item(item, uri.toString(), mimeType.toString(), gc);
    String digest = computeDigest(data);
    i.setDigest(digest);
    Response r;
    if (!MemoryStore.MS.hasItem(container, item)) {
        r = Response.created(uri).build();
    } else {
        r = Response.noContent().build();
    }
    Item ii = MemoryStore.MS.createOrUpdateItem(container, i, data);
    if (ii == null) {
        // Create the container if one has not been created
        URI containerUri = uriInfo.getAbsolutePathBuilder().path("..").build().normalize();
        Container c = new Container(container, containerUri.toString());
        MemoryStore.MS.createContainer(c);
        i = MemoryStore.MS.createOrUpdateItem(container, i, data);
        if (i == null)
            throw new NotFoundException("Container not found");
    }
    return r;
}
Also used : Response(javax.ws.rs.core.Response) Item(com.sun.jersey.samples.storageservice.Item) Container(com.sun.jersey.samples.storageservice.Container) GregorianCalendar(java.util.GregorianCalendar) MediaType(javax.ws.rs.core.MediaType) NotFoundException(javax.ws.rs.NotFoundException) URI(java.net.URI) PUT(javax.ws.rs.PUT)

Example 3 with Item

use of com.sun.jersey.samples.storageservice.Item in project enunciate by stoicflame.

the class ItemResource method getItem.

@GET
public Response getItem() {
    System.out.println("GET ITEM " + container + " " + item);
    Item i = MemoryStore.MS.getItem(container, item);
    if (i == null)
        throw new NotFoundException("Item not found");
    Date lastModified = i.getLastModified().getTime();
    EntityTag et = new EntityTag(i.getDigest());
    ResponseBuilder rb = request.evaluatePreconditions(lastModified, et);
    if (rb != null)
        return rb.build();
    byte[] b = MemoryStore.MS.getItemData(container, item);
    return Response.ok(b, i.getMimeType()).lastModified(lastModified).tag(et).build();
}
Also used : Item(com.sun.jersey.samples.storageservice.Item) NotFoundException(javax.ws.rs.NotFoundException) EntityTag(javax.ws.rs.core.EntityTag) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Date(java.util.Date) GET(javax.ws.rs.GET)

Example 4 with Item

use of com.sun.jersey.samples.storageservice.Item in project enunciate by stoicflame.

the class ContainerResource method getContainer.

@GET
public Container getContainer(@QueryParam("search") String search) {
    System.out.println("GET CONTAINER " + container + ", search = " + search);
    Container c = MemoryStore.MS.getContainer(container);
    if (c == null)
        throw new NotFoundException("Container not found");
    if (search != null) {
        c = c.clone();
        Iterator<Item> i = c.getItem().iterator();
        byte[] searchBytes = search.getBytes();
        while (i.hasNext()) {
            if (!match(searchBytes, container, i.next().getName()))
                i.remove();
        }
    }
    return c;
}
Also used : Item(com.sun.jersey.samples.storageservice.Item) Container(com.sun.jersey.samples.storageservice.Container)

Aggregations

Item (com.sun.jersey.samples.storageservice.Item)4 NotFoundException (javax.ws.rs.NotFoundException)3 Container (com.sun.jersey.samples.storageservice.Container)2 URI (java.net.URI)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1 EntityTag (javax.ws.rs.core.EntityTag)1 MediaType (javax.ws.rs.core.MediaType)1 Response (javax.ws.rs.core.Response)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1