Class BitstreamResource


  • @Path("/bitstreams")
    public class BitstreamResource
    extends Resource
    Author:
    Rostislav Novak (Computing and Information Centre, CTU in Prague)
    • Constructor Detail

      • BitstreamResource

        public BitstreamResource()
    • Method Detail

      • getBitstream

        @GET
        @Path("/{bitstream_id}")
        @Produces({"application/json","application/xml"})
        public Bitstream getBitstream​(@PathParam("bitstream_id")
                                      String bitstreamId,
                                      @QueryParam("expand")
                                      String expand,
                                      @QueryParam("userIP")
                                      String user_ip,
                                      @QueryParam("userAgent")
                                      String user_agent,
                                      @QueryParam("xforwardedfor")
                                      String xforwardedfor,
                                      @Context
                                      javax.ws.rs.core.HttpHeaders headers,
                                      @Context
                                      javax.servlet.http.HttpServletRequest request)
                               throws javax.ws.rs.WebApplicationException
        Return bitstream properties without file data. It can throw WebApplicationException with three response codes. Response code NOT_FOUND(404) or UNAUTHORIZED(401) or INTERNAL_SERVER_ERROR(500). Bad request is when the bitstream id does not exist. UNAUTHORIZED if the user logged into the DSpace context does not have the permission to access the bitstream. Server error when something went wrong.
        Parameters:
        bitstreamId - Id of bitstream in DSpace.
        expand - This string defines which additional optional fields will be added to bitstream response. Individual options are separated by commas without spaces. The options are: "all", "parent".
        user_ip - User's IP address.
        user_agent - User agent string (specifies browser used and its version).
        xforwardedfor - When accessed via a reverse proxy, the application sees the proxy's IP as the source of the request. The proxy may be configured to add the "X-Forwarded-For" HTTP header containing the original IP of the client so that the reverse-proxied application can get the client's IP.
        headers - If you want to access the item as the user logged into the context. The value of the "rest-dspace-token" header must be set to the token received from the login method response.
        request - Servlet's HTTP request object.
        Returns:
        If user is allowed to read bitstream, it returns instance of bitstream. Otherwise, it throws WebApplicationException with response code UNAUTHORIZED.
        Throws:
        javax.ws.rs.WebApplicationException - It can happen on: Bad request, unauthorized, SQL exception and context exception(could not create context).
      • getBitstreamPolicies

        @GET
        @Path("/{bitstream_id}/policy")
        @Produces({"application/json","application/xml"})
        public ResourcePolicy[] getBitstreamPolicies​(@PathParam("bitstream_id")
                                                     String bitstreamId,
                                                     @Context
                                                     javax.ws.rs.core.HttpHeaders headers)
        Return all bitstream resource policies from all bundles, in which the bitstream is present.
        Parameters:
        bitstreamId - Id of bitstream in DSpace.
        headers - If you want to access the item as the user logged into the context. The header "rest-dspace-token" with the token passed from the login method must be set.
        Returns:
        Returns an array of ResourcePolicy objects.
      • getBitstreams

        @GET
        @Produces({"application/json","application/xml"})
        public Bitstream[] getBitstreams​(@QueryParam("expand")
                                         String expand,
                                         @QueryParam("limit") @DefaultValue("100")
                                         Integer limit,
                                         @QueryParam("offset") @DefaultValue("0")
                                         Integer offset,
                                         @QueryParam("userIP")
                                         String user_ip,
                                         @QueryParam("userAgent")
                                         String user_agent,
                                         @QueryParam("xforwardedfor")
                                         String xforwardedfor,
                                         @Context
                                         javax.ws.rs.core.HttpHeaders headers,
                                         @Context
                                         javax.servlet.http.HttpServletRequest request)
                                  throws javax.ws.rs.WebApplicationException
        Read list of bitstreams. It throws WebApplicationException with response code INTERNAL_SERVER_ERROR(500), if there was problem while reading bitstreams from database.
        Parameters:
        expand - This string defines which additional optional fields will be added to bitstream response. Individual options are separated by commas without spaces. The options are: "all", "parent".
        limit - How many bitstreams will be in the list. Default value is 100.
        offset - On which offset (item) the list starts. Default value is 0.
        user_ip - User's IP address.
        user_agent - User agent string (specifies browser used and its version).
        xforwardedfor - When accessed via a reverse proxy, the application sees the proxy's IP as the source of the request. The proxy may be configured to add the "X-Forwarded-For" HTTP header containing the original IP of the client so that the reverse-proxied application can get the client's IP.
        headers - If you want to access the item as the user logged into the context. The header "rest-dspace-token" with the token passed from the login method must be set.
        request - Servlet's HTTP request object.
        Returns:
        Returns an array of bistreams. Array doesn't contain bitstreams for which the user doesn't have read permission.
        Throws:
        javax.ws.rs.WebApplicationException - Thrown in case of a problem with reading the database or with creating a context.
      • getBitstreamData

        @GET
        @Path("/{bitstream_id}/retrieve")
        public javax.ws.rs.core.Response getBitstreamData​(@PathParam("bitstream_id")
                                                          String bitstreamId,
                                                          @QueryParam("userIP")
                                                          String user_ip,
                                                          @QueryParam("userAgent")
                                                          String user_agent,
                                                          @QueryParam("xforwardedfor")
                                                          String xforwardedfor,
                                                          @Context
                                                          javax.ws.rs.core.HttpHeaders headers,
                                                          @Context
                                                          javax.servlet.http.HttpServletRequest request)
                                                   throws javax.ws.rs.WebApplicationException
        Read bitstream data. May throw WebApplicationException with the INTERNAL_SERVER_ERROR(500) code. Caused by three exceptions: IOException if there was a problem with reading bitstream file. SQLException if there was a problem while reading from database. And AuthorizeException if there was a problem with authorization of user logged to DSpace context.
        Parameters:
        bitstreamId - Id of the bitstream, whose data will be read.
        user_ip - User's IP address.
        user_agent - User agent string (specifies browser used and its version).
        xforwardedfor - When accessed via a reverse proxy, the application sees the proxy's IP as the source of the request. The proxy may be configured to add the "X-Forwarded-For" HTTP header containing the original IP of the client so that the reverse-proxied application can get the client's IP.
        headers - If you want to access the item as the user logged into the context. The header "rest-dspace-token" with the token passed from the login method must be set.
        request - Servlet's HTTP request object.
        Returns:
        Returns response with data with file content type. It can return the NOT_FOUND(404) response code in case of wrong bitstream id. Or response code UNAUTHORIZED(401) if user is not allowed to read bitstream.
        Throws:
        javax.ws.rs.WebApplicationException - Thrown if there was a problem: reading the file data; or reading the database; or creating the context; or with authorization.
      • addBitstreamPolicy

        @POST
        @Path("/{bitstream_id}/policy")
        @Consumes({"application/json","application/xml"})
        public javax.ws.rs.core.Response addBitstreamPolicy​(@PathParam("bitstream_id")
                                                            String bitstreamId,
                                                            ResourcePolicy policy,
                                                            @QueryParam("userIP")
                                                            String user_ip,
                                                            @QueryParam("userAgent")
                                                            String user_agent,
                                                            @QueryParam("xforwardedfor")
                                                            String xforwardedfor,
                                                            @Context
                                                            javax.ws.rs.core.HttpHeaders headers,
                                                            @Context
                                                            javax.servlet.http.HttpServletRequest request)
                                                     throws javax.ws.rs.WebApplicationException
        Add bitstream policy to all bundles containing the bitstream.
        Parameters:
        bitstreamId - Id of bitstream in DSpace.
        policy - Policy to be added. The following attributes are not applied: epersonId,
        user_ip - User's IP address.
        user_agent - User agent string (specifies browser used and its version).
        xforwardedfor - When accessed via a reverse proxy, the application sees the proxy's IP as the source of the request. The proxy may be configured to add the "X-Forwarded-For" HTTP header containing the original IP of the client so that the reverse-proxied application can get the client's IP.
        headers - If you want to access the item as the user logged into the context. The header "rest-dspace-token" with the token passed from the login method must be set.
        request - Servlet's HTTP request object.
        Returns:
        Returns ok, if all was ok. Otherwise status code 500.
        Throws:
        javax.ws.rs.WebApplicationException
      • updateBitstream

        @PUT
        @Path("/{bitstream_id}")
        @Consumes({"application/json","application/xml"})
        public javax.ws.rs.core.Response updateBitstream​(@PathParam("bitstream_id")
                                                         String bitstreamId,
                                                         Bitstream bitstream,
                                                         @QueryParam("userIP")
                                                         String user_ip,
                                                         @QueryParam("userAgent")
                                                         String user_agent,
                                                         @QueryParam("xforwardedfor")
                                                         String xforwardedfor,
                                                         @Context
                                                         javax.ws.rs.core.HttpHeaders headers,
                                                         @Context
                                                         javax.servlet.http.HttpServletRequest request)
                                                  throws javax.ws.rs.WebApplicationException
        Update bitstream metadata. Replaces everything on targeted bitstream. May throw WebApplicationException caused by two exceptions: SQLException, if there was a problem with the database. AuthorizeException if there was a problem with the authorization to edit bitstream metadata.
        Parameters:
        bitstreamId - Id of bistream to be updated.
        bitstream - Bitstream with will be placed. It must have filled user credentials.
        user_ip - User's IP address.
        user_agent - User agent string (specifies browser used and its version).
        xforwardedfor - When accessed via a reverse proxy, the application sees the proxy's IP as the source of the request. The proxy may be configured to add the "X-Forwarded-For" HTTP header containing the original IP of the client so that the reverse-proxied application can get the client's IP.
        headers - If you want to access the item as the user logged into the context. The header "rest-dspace-token" with the token passed from the login method must be set.
        request - Servlet's HTTP request object.
        Returns:
        Return response codes: OK(200), NOT_FOUND(404) if bitstream does not exist and UNAUTHORIZED(401) if user is not allowed to write to bitstream.
        Throws:
        javax.ws.rs.WebApplicationException - Thrown when: Error reading from database; or error creating context; or error regarding bitstream authorization.
      • updateBitstreamData

        @PUT
        @Path("/{bitstream_id}/data")
        public javax.ws.rs.core.Response updateBitstreamData​(@PathParam("bitstream_id")
                                                             String bitstreamId,
                                                             InputStream is,
                                                             @QueryParam("userIP")
                                                             String user_ip,
                                                             @QueryParam("userAgent")
                                                             String user_agent,
                                                             @QueryParam("xforwardedfor")
                                                             String xforwardedfor,
                                                             @Context
                                                             javax.ws.rs.core.HttpHeaders headers,
                                                             @Context
                                                             javax.servlet.http.HttpServletRequest request)
                                                      throws javax.ws.rs.WebApplicationException
        Update bitstream data. Changes bitstream data by editing database rows. May throw WebApplicationException caused by: SQLException if there was a problem editing or reading the database, IOException if there was a problem with reading from InputStream, Exception if there was another problem.
        Parameters:
        bitstreamId - Id of bistream to be updated.
        is - InputStream filled with new data.
        user_ip - User's IP address.
        user_agent - User agent string (specifies browser used and its version).
        xforwardedfor - When accessed via a reverse proxy, the application sees the proxy's IP as the source of the request. The proxy may be configured to add the "X-Forwarded-For" HTTP header containing the original IP of the client so that the reverse-proxied application can get the client's IP.
        headers - If you want to access the item as the user logged into the context. The header "rest-dspace-token" with the token passed from the login method must be set.
        request - Servlet's HTTP request object.
        Returns:
        Return response if bitstream was updated. Response codes: OK(200), NOT_FOUND(404) if id of bitstream was bad. And UNAUTHORIZED(401) if user is not allowed to update bitstream.
        Throws:
        javax.ws.rs.WebApplicationException - This exception can be thrown in this cases: Problem with reading or writing to database. Or problem with reading from InputStream.
      • deleteBitstream

        @DELETE
        @Path("/{bitstream_id}")
        public javax.ws.rs.core.Response deleteBitstream​(@PathParam("bitstream_id")
                                                         String bitstreamId,
                                                         @QueryParam("userIP")
                                                         String user_ip,
                                                         @QueryParam("userAgent")
                                                         String user_agent,
                                                         @QueryParam("xforwardedfor")
                                                         String xforwardedfor,
                                                         @Context
                                                         javax.ws.rs.core.HttpHeaders headers,
                                                         @Context
                                                         javax.servlet.http.HttpServletRequest request)
                                                  throws javax.ws.rs.WebApplicationException
        Delete bitstream from all bundles in DSpace. May throw WebApplicationException, which can be caused by three exceptions. SQLException if there was a problem reading from database or removing from database. AuthorizeException, if user doesn't have permission to delete the bitstream or file. IOException, if there was a problem deleting the file.
        Parameters:
        bitstreamId - Id of bitstream to be deleted.
        user_ip - User's IP address.
        user_agent - User agent string (specifies browser used and its version).
        xforwardedfor - When accessed via a reverse proxy, the application sees the proxy's IP as the source of the request. The proxy may be configured to add the "X-Forwarded-For" HTTP header containing the original IP of the client so that the reverse-proxied application can get the client's IP.
        headers - If you want to access the item as the user logged into the context. The header "rest-dspace-token" with the token passed from the login method must be set.
        request - Servlet's HTTP request object.
        Returns:
        Return response codes: OK(200), NOT_FOUND(404) if bitstream of that id does not exist and UNAUTHORIZED(401) if user is not allowed to delete bitstream.
        Throws:
        javax.ws.rs.WebApplicationException - Can be thrown if there was a problem reading or editing the database. Or problem deleting the file. Or problem with authorization to bitstream and bundles. Or problem with creating context.
      • deleteBitstreamPolicy

        @DELETE
        @Path("/{bitstream_id}/policy/{policy_id}")
        public javax.ws.rs.core.Response deleteBitstreamPolicy​(@PathParam("bitstream_id")
                                                               String bitstreamId,
                                                               @PathParam("policy_id")
                                                               Integer policyId,
                                                               @QueryParam("userIP")
                                                               String user_ip,
                                                               @QueryParam("userAgent")
                                                               String user_agent,
                                                               @QueryParam("xforwardedfor")
                                                               String xforwardedfor,
                                                               @Context
                                                               javax.ws.rs.core.HttpHeaders headers,
                                                               @Context
                                                               javax.servlet.http.HttpServletRequest request)
                                                        throws javax.ws.rs.WebApplicationException
        Delete policy.
        Parameters:
        bitstreamId - Id of the DSpace bitstream whose policy will be deleted.
        policyId - Id of the policy to delete.
        user_ip - User's IP address.
        user_agent - User agent string (specifies browser used and its version).
        xforwardedfor - When accessed via a reverse proxy, the application sees the proxy's IP as the source of the request. The proxy may be configured to add the "X-Forwarded-For" HTTP header containing the original IP of the client so that the reverse-proxied application can get the client's IP.
        headers - If you want to access the item as the user logged into the context. The header "rest-dspace-token" with the token passed from the login method must be set.
        request - Servlet's HTTP request object.
        Returns:
        It returns Ok, if all was ok. Otherwise status code 500.
        Throws:
        javax.ws.rs.WebApplicationException