private URI addDatastreamNode(
      final String pid,
      final String dsPath,
      final MediaType contentType,
      final InputStream requestBodyStream,
      final Session session)
      throws RepositoryException, IOException {

    Long oldObjectSize = getObjectSize(session.getNode(getObjectJcrNodePath(pid)));
    logger.debug("Attempting to add datastream node at path: " + dsPath);
    try {
      boolean created = session.nodeExists(dsPath);
      createDatastreamNode(session, dsPath, contentType.toString(), requestBodyStream);
      session.save();
      if (created) {
        /*
         * we save before updating the repo size because the act of
         * persisting session state creates new system-curated nodes and
         * properties which contribute to the footprint of this resource
         */
        updateRepositorySize(
            getObjectSize(session.getNode(getObjectJcrNodePath(pid))) - oldObjectSize, session);
        // now we save again to persist the repo size
        session.save();
      }
    } finally {
      session.logout();
    }
    logger.debug("Finished adding datastream node at path: " + dsPath);
    return uriInfo.getAbsolutePath();
  }
Exemple #2
0
  /**
   * 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();
  }
  @POST
  @Path("/")
  public Response addDatastreams(
      @PathParam("pid") final String pid, final List<Attachment> attachmentList)
      throws RepositoryException, IOException {

    final Session session = repo.login();
    try {
      Long oldObjectSize = getObjectSize(session.getNode(getObjectJcrNodePath(pid)));

      for (final Attachment a : attachmentList) {
        final String dsid = a.getContentDisposition().getParameter("name");
        final String dsPath = getDatastreamJcrNodePath(pid, dsid);
        createDatastreamNode(
            session,
            dsPath,
            a.getDataHandler().getContentType(),
            a.getDataHandler().getInputStream());
      }
      session.save();

      /*
       * we save before updating the repo size because the act of
       * persisting session state creates new system-curated nodes and
       * properties which contribute to the footprint of this resource
       */
      updateRepositorySize(
          getObjectSize(session.getNode(getObjectJcrNodePath(pid))) - oldObjectSize, session);
      // now we save again to persist the repo size
      session.save();
    } finally {
      session.logout();
    }

    return created(uriInfo.getAbsolutePath()).build();
  }
Exemple #4
0
  /**
   * 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();
    }
  }