Ejemplo n.º 1
0
  /**
   * Modify an existing datastream's content
   *
   * @param pathList
   * @param requestContentType Content-Type header
   * @param requestBodyStream Binary blob
   * @return 201 Created
   * @throws RepositoryException
   * @throws InvalidChecksumException
   */
  @PUT
  @Timed
  public Response modifyContent(
      @PathParam("path") final List<PathSegment> pathList,
      @QueryParam("checksum") final String checksum,
      @HeaderParam("Content-Disposition") final String contentDisposition,
      @HeaderParam("Content-Type") final MediaType requestContentType,
      @ContentLocation final InputStream requestBodyStream,
      @Context final Request request,
      @Context final HttpServletResponse servletResponse)
      throws RepositoryException, InvalidChecksumException, URISyntaxException, ParseException {

    try {
      final String path = toPath(pathList);
      final MediaType contentType = getSimpleContentType(requestContentType);

      if (nodeService.exists(session, path)) {

        final Datastream ds = datastreamService.getDatastream(session, path);

        evaluateRequestPreconditions(request, ds);
      }

      LOGGER.debug("create Datastream {}", path);

      final URI checksumURI = checksumURI(checksum);
      final String originalFileName = originalFileName(contentDisposition);

      final Datastream datastream =
          datastreamService.createDatastream(
              session,
              path,
              contentType.toString(),
              originalFileName,
              requestBodyStream,
              checksumURI);

      final boolean isNew = datastream.isNew();
      session.save();
      versionService.nodeUpdated(datastream.getNode());

      ResponseBuilder builder;
      if (isNew) {
        final HttpIdentifierTranslator subjects =
            new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo);

        builder =
            created(new URI(subjects.getSubject(datastream.getContentNode().getPath()).getURI()));
      } else {
        builder = noContent();
      }

      addCacheControlHeaders(servletResponse, datastream);

      return builder.build();
    } finally {
      session.logout();
    }
  }
Ejemplo n.º 2
0
  /**
   * Create an anonymous DS with a newly minted name and content from request body
   *
   * @param pathList
   * @throws RepositoryException
   */
  @POST
  @Timed
  public Response create(
      @PathParam("path") final List<PathSegment> pathList,
      @HeaderParam("Slug") final String slug,
      @HeaderParam("Content-Disposition") final String contentDisposition,
      @QueryParam("checksum") final String checksum,
      @HeaderParam("Content-Type") final MediaType requestContentType,
      @ContentLocation final InputStream requestBodyStream,
      @Context final HttpServletResponse servletResponse)
      throws InvalidChecksumException, RepositoryException, URISyntaxException, ParseException {
    final MediaType contentType = getSimpleContentType(requestContentType);

    final String newDatastreamPath;
    final String path = toPath(pathList);

    if (nodeService.exists(session, path)) {
      if (nodeService.getObject(session, path).hasContent()) {
        return status(SC_CONFLICT).entity(path + " is an existing resource!").build();
      }

      final String pid;

      if (slug != null) {
        pid = slug;
      } else {
        pid = pidMinter.mintPid();
      }

      newDatastreamPath = path + "/" + pid;
    } else {
      newDatastreamPath = path;
    }

    LOGGER.trace("Attempting to ingest fcr:content with path: {}", newDatastreamPath);

    try {

      if (nodeService.exists(session, newDatastreamPath)) {
        return status(SC_CONFLICT).entity(path + " is an existing resource!").build();
      }

      final URI checksumURI = checksumURI(checksum);
      final String originalFileName = originalFileName(contentDisposition);

      final Datastream datastream =
          datastreamService.createDatastream(
              session,
              newDatastreamPath,
              contentType.toString(),
              originalFileName,
              requestBodyStream,
              checksumURI);

      final HttpIdentifierTranslator subjects =
          new HttpIdentifierTranslator(session, FedoraNodes.class, uriInfo);

      session.save();
      versionService.nodeUpdated(datastream.getNode());

      final ResponseBuilder builder =
          created(new URI(subjects.getSubject(datastream.getContentNode().getPath()).getURI()));

      addCacheControlHeaders(servletResponse, datastream);

      return builder.build();

    } finally {
      session.logout();
    }
  }