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");
}
}
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;
}
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();
}
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;
}
Aggregations