/** * Create an anonymous DS with a newly minted name and content from request body * * @param pathList * @throws RepositoryException */ @POST public Response create( @PathParam("path") final List<PathSegment> pathList, @QueryParam("checksumType") final String checksumType, @QueryParam("checksum") final String checksum, @HeaderParam("Content-Type") final MediaType requestContentType, final InputStream requestBodyStream) throws IOException, InvalidChecksumException, RepositoryException { final MediaType contentType = requestContentType != null ? requestContentType : APPLICATION_OCTET_STREAM_TYPE; String path = toPath(pathList); if (path.endsWith("/fcr:new")) { logger.debug("Creating a new unnamed object"); final String dsid = pidMinter.mintPid(); path = path.replaceFirst("\\/fcr\\:new$", "/" + dsid); } logger.debug("create Datastream {}", path); final Session session = getAuthenticatedSession(); try { datastreamService.createDatastreamNode( session, path, contentType.toString(), requestBodyStream, checksumType, checksum); } finally { session.save(); } return created(uriInfo.getBaseUriBuilder().path("/rest" + path).build()).build(); }
/** * Get the binary content of a datastream * * @param pid persistent identifier of the digital object * @param dsid datastream identifier * @return Binary blob * @throws RepositoryException */ @GET @Path("/{dsid}/content") public Response getDatastreamContent( @PathParam("pid") final String pid, @PathParam("dsid") final String dsid) throws RepositoryException { final Datastream ds = DatastreamService.getDatastream(pid, dsid); return ok(ds.getContent(), ds.getMimeType()).build(); }
/** * Get the datastream profile of a datastream * * @param pid persistent identifier of the digital object * @param dsid datastream identifier * @return 200 * @throws RepositoryException * @throws IOException * @throws TemplateException */ @GET @Path("/{dsid}") @Produces({TEXT_XML, APPLICATION_JSON}) public DatastreamProfile getDatastream( @PathParam("pid") final String pid, @PathParam("dsid") final String dsId) throws RepositoryException, IOException { logger.trace("Executing getDatastream() with dsId: " + dsId); Datastream ds = DatastreamService.getDatastream(pid, dsId); logger.debug("Retrieved dsNode: " + ds.getNode().getName()); return getDSProfile(ds); }
/** * Get previous version information for this datastream * * @param pid persistent identifier of the digital object * @param dsId datastream identifier * @return 200 * @throws RepositoryException * @throws IOException * @throws TemplateException */ @GET @Path("/{dsid}/versions") @Produces({TEXT_XML, APPLICATION_JSON}) // TODO implement this after deciding on a versioning model public DatastreamHistory getDatastreamHistory( @PathParam("pid") final String pid, @PathParam("dsid") final String dsId) throws RepositoryException, IOException { final Datastream ds = DatastreamService.getDatastream(pid, dsId); final DatastreamHistory dsHistory = new DatastreamHistory(singletonList(getDSProfile(ds))); dsHistory.dsID = dsId; dsHistory.pid = pid; return dsHistory; }
/** * Modify an existing datastream's content * * @param pathList * @param requestContentType Content-Type header * @param requestBodyStream Binary blob * @return 201 Created * @throws RepositoryException * @throws IOException * @throws InvalidChecksumException */ @PUT public Response modifyContent( @PathParam("path") List<PathSegment> pathList, @HeaderParam("Content-Type") final MediaType requestContentType, final InputStream requestBodyStream) throws RepositoryException, IOException, InvalidChecksumException { final Session session = getAuthenticatedSession(); try { String path = toPath(pathList); if (!datastreamService.exists(path)) { return Response.status(404).entity("No datastream to mutate at " + path).build(); } final MediaType contentType = requestContentType != null ? requestContentType : APPLICATION_OCTET_STREAM_TYPE; logger.debug("create Datastream {}", path); datastreamService.createDatastreamNode( session, path, contentType.toString(), requestBodyStream); session.save(); return created(uriInfo.getBaseUriBuilder().path("/rest" + path).build()).build(); } finally { session.logout(); } }
/** * Get the binary content of a datastream * * @param pathList * @return Binary blob * @throws RepositoryException */ @GET public Response getContent( @PathParam("path") List<PathSegment> pathList, @Context final Request request) throws RepositoryException { String path = toPath(pathList); final Datastream ds = datastreamService.getDatastream(path); final EntityTag etag = new EntityTag(ds.getContentDigest().toString()); final Date date = ds.getLastModifiedDate(); final Date roundedDate = new Date(); roundedDate.setTime(date.getTime() - date.getTime() % 1000); ResponseBuilder builder = request.evaluatePreconditions(roundedDate, etag); final CacheControl cc = new CacheControl(); cc.setMaxAge(0); cc.setMustRevalidate(true); if (builder == null) { builder = Response.ok(ds.getContent(), ds.getMimeType()); } return builder.cacheControl(cc).lastModified(date).tag(etag).build(); }