* resource already exists.
*/
@POST
@Consumes("multipart/form")
public Response postContent(MultiPartBody form) {
FormFile formFile = form.getFormFileParameterValues("content")[0];
String uri = form.getTextParameterValues("uri")[0];
byte[] content = formFile.getContent();
if (content == null || uri == null) {
return Response.status(400).entity("Required form field is missing").
type(MediaType.TEXT_PLAIN_TYPE).build();
}
LockableMGraph contentGraph = cgProvider.getContentGraph();
Lock readLock = contentGraph.getLock().readLock();
readLock.lock();
try {
if (contentGraph.filter(new UriRef(uri), RDF.type, null).hasNext()) {
return Response.status(Response.Status.CONFLICT).
entity("A resource with the specified URI already exists").
type(MediaType.TEXT_PLAIN_TYPE).build();
}
} finally {
readLock.unlock();
}
handler.put(new UriRef(uri), formFile.getMediaType(), content);
return Response.created(URI.create(uri)).build();
}