Class CMSMediaResource

java.lang.Object
io.goobi.viewer.api.rest.v2.cms.CMSMediaResource

@Path("/cms/media") public class CMSMediaResource extends Object
REST resource for accessing CMS media files in the v2 API with category and type filtering.
Author:
Florian Alpers
  • Field Details

  • Constructor Details

    • CMSMediaResource

      public CMSMediaResource()
  • Method Details

    • getMediaOfCategories

      @GET @Produces("application/json") @Path("/category/{tags}") public CMSMediaResource.MediaList getMediaOfCategories(@PathParam("tags") String tags, @QueryParam("max") Integer maxItems, @QueryParam("prioritySlots") Integer prioritySlots, @QueryParam("random") Boolean random) throws DAOException
      getMediaByTag.
      Parameters:
      tags - a String object.
      maxItems - maximum number of items to return
      prioritySlots - number of high-priority items guaranteed in result
      random - if true, return items in random order
      Returns:
      a MediaList containing the CMS media items matching the given category tags
      Throws:
      DAOException - if any.
    • getAllMedia

      @GET @Produces("application/json") public CMSMediaResource.MediaList getAllMedia(@QueryParam("tags") String tags, @QueryParam("max") Integer maxItems, @QueryParam("prioritySlots") Integer prioritySlots, @QueryParam("random") Boolean random) throws DAOException
      getMediaByTag.
      Parameters:
      tags - comma-separated list of category tags to filter by
      maxItems - maximum number of items to return
      prioritySlots - number of high-priority items guaranteed in result
      random - if true, return items in random order
      Returns:
      a MediaList containing all CMS media items optionally filtered by the given tags
      Throws:
      DAOException - if any.
    • getMediaItem

      @GET @Path("/{id: \\d+}") @Produces("application/json") public MediaItem getMediaItem(@PathParam("id") Long id) throws DAOException
      Throws:
      DAOException
    • getPDFMediaItemContent

      @GET @Path("/files/{filename: (?i)[^\\/]*\\.(pdf)}") @Produces("application/pdf") public static StreamingOutput getPDFMediaItemContent(@PathParam("filename") String filename, @Context HttpServletResponse response) throws de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException
      getPDFMediaItemContent.
      Parameters:
      filename - name of the PDF file to serve
      response - a HttpServletResponse object.
      Returns:
      File contents as HTML
      Throws:
      de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException - if any.
      DAOException - if any.
    • getSvgContent

      @GET @Path("/files/{filename: (?i)[^\\/]*\\.(svg)}") @Produces("image/svg+xml") public static StreamingOutput getSvgContent(@PathParam("filename") String filename, @Context HttpServletResponse response) throws de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException
      Throws:
      de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException
    • getIcoContent

      @GET @Path("/files/{filename: (?i)[^\\/]*\\.(ico)}") @Produces("image/x-icon") public static StreamingOutput getIcoContent(@PathParam("filename") String filename, @Context HttpServletResponse response) throws de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException
      Throws:
      de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException
    • serveVideoContent

      @GET @Path("/files/{filename: (?i).*\\.(mp4|mpeg4|avi|mov|wmv)}") public String serveVideoContent(@PathParam("filename") String filename) throws PresentationException, WebApplicationException
      Throws:
      PresentationException
      WebApplicationException
    • serveAudioContent

      @GET @Path("/files/{filename: (?i).*\\.(mp3|mpeg|wav|ogg|wma)}") public String serveAudioContent(@PathParam("filename") String filename) throws PresentationException, WebApplicationException
      Throws:
      PresentationException
      WebApplicationException
    • getMediaItemContent

      @GET @Path("/files/{filename: (?i)[^\\/]*\\.(html)}") @Produces("text/html") public static String getMediaItemContent(@PathParam("filename") String filename) throws de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException
      getMediaItemContent.
      Parameters:
      filename - name of the HTML file to serve
      Returns:
      File contents as HTML
      Throws:
      de.unigoettingen.sub.commons.contentlib.exceptions.ContentNotFoundException - if any.
      DAOException - if any.
    • validateUploadMediaFiles

      @GET @Path("/{filename: [^\\/]*\\.\\w{1,4}}") @Produces("application/json") public Response validateUploadMediaFiles(@PathParam("filename") String filename) throws DAOException
      Return the media item for the given filename. If no matching media item exists, return a not-found status code
      Parameters:
      filename - URL-encoded filename to look up in the database
      Returns:
      an HTTP response containing the CMS media item metadata as JSON, or a 404 response if no item was found for the given filename
      Throws:
      DAOException - if any.
    • getAllFiles

      @GET @Path("/files") @Produces("application/json") public List<String> getAllFiles() throws PresentationException
      List all uploaded media files.
      Returns:
      All CMS media files
      Throws:
      PresentationException
    • deleteAllFiles

      @DELETE @Path("/files") @Produces("application/json") public void deleteAllFiles() throws de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException
      Throws:
      de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException
    • deleteFile

      @DELETE @Path("/files/{filename}") @Produces("application/json") public void deleteFile() throws de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException
      Throws:
      de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException
    • getInvalidFilename

      @GET @Path("/files/{filename}") @Produces("application/json") public Response getInvalidFilename(@PathParam("filename") String filename) throws de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException
      Fallback GET handler for filenames that do NOT match any of the specific extension patterns handled by CMSMediaImageResource3 and the other typed handlers.

      Returns 400 so that schemathesis receives the correct error code instead of 405 Method Not Allowed (which JAX-RS would return if no GET handler existed for this path).

      Parameters:
      filename - the requested filename
      Returns:
      never returns normally; always throws IllegalRequestException
      Throws:
      de.unigoettingen.sub.commons.contentlib.exceptions.IllegalRequestException
    • uploadMediaFiles

      @POST @Path("/files") @Consumes("multipart/form-data") @Produces("application/json") public Response uploadMediaFiles(@DefaultValue("true") boolean enabled, String filename, InputStream uploadedInputStream, org.glassfish.jersey.media.multipart.FormDataContentDisposition fileDetail) throws DAOException
      May receive a file from a multipart form and saves the file in the cms media folder.
      Parameters:
      enabled - whether the uploaded media item should be enabled; defaults to true
      filename - target filename for the uploaded file in the CMS media folder
      uploadedInputStream - byte stream of the uploaded file content
      fileDetail - multipart content-disposition metadata for the uploaded file
      Returns:
      an ACCEPTED response if the upload was successful, a FORBIDDEN response if no user is registered in the html session or the user does not have rights to upload media, or a CONFLICT response if a file of the same name already exists in the cms media foler
      Throws:
      DAOException - if any.
    • removeFromImageCache

      public static void removeFromImageCache(CMSMediaItem item)
      Parameters:
      item - the CMS media item to evict from cache
    • createMediaItem

      public CMSMediaItem createMediaItem(Path filePath)
      createMediaItem.
      Parameters:
      filePath - path to the newly uploaded file on disk
      Returns:
      a new CMSMediaItem initialized with the filename and empty metadata for all configured locales