Interface Workspace

All Superinterfaces:
StorageUsage
All Known Implementing Classes:
WorkspaceImpl

public interface Workspace extends StorageUsage
Provides efficient access java.io.File objects from potentially remote URIs. This helper service prevents different service implementations running in the same osgi container from downloading remote files multiple times. Additionally, when the system is configured to use shared storage, this performance gain is also achieved across distributed osgi containers. The methods from WorkingFileRepository are also available as a convenience to clients.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    cleanup(int maxAge)
    Cleans up files not belonging to a mediapackage or a collection.
    void
    cleanup(Id mediaPackageId)
    Clean up all elements of one media package from the local workspace, not touching the working file repository.
    void
    cleanup(Id mediaPackageId, boolean filesOnly)
    Clean up elements of one media package from the local workspace, not touching the working file repository.
    void
    delete(String mediaPackageID, String mediaPackageElementID)
    Delete the file stored at the given media package and element IDs.
    void
    delete(URI uri)
    Delete the file stored at the given uri.
    void
    deleteFromCollection(String collectionId, String fileName)
    Removes a file from a collection
    get(URI uri)
    Gets a locally cached File for the given URI.
    get(URI uri, boolean uniqueFilename)
    Get a locally cached File for a given URI, optionally ensuring that the file is cached in a unique path so that it can safely be removed afterwards.
    Gets the base URI for files stored using this service.
    URI[]
    Gets the URIs of the members of this collection
    getCollectionURI(String collectionID, String fileName)
    Get the URL for a file stored under the given collection.
    getURI(String mediaPackageID, String mediaPackageElementID)
    Get the URL for a file stored under the given media package and element IDs.
    moveTo(URI collectionURI, String toMediaPackage, String toMediaPackageElement, String toFileName)
    Moves a file from a collection into a mediapackage
    put(String mediaPackageID, String mediaPackageElementID, String fileName, InputStream in)
    Store the data stream under the given media package and element IDs, specifying a filename.
    putInCollection(String collectionId, String fileName, InputStream in)
    Stores the data stream in the given collection, overwriting any data with the same collection id and file name.
    read(URI uri)
    Get the File for the given URI directly from the working file repository.
    Returns the workspace's root directory
    toSafeName(String fileName)
     

    Methods inherited from interface org.opencastproject.storage.StorageUsage

    getTotalSpace, getUsableSpace, getUsedSpace
  • Method Details

    • toSafeName

      String toSafeName(String fileName)
    • get

      Gets a locally cached File for the given URI.
      Parameters:
      uri -
      Returns:
      The locally cached file
      Throws:
      NotFoundException - if the file does not exist
      IOException - if reading the file from the workspace fails
    • get

      File get(URI uri, boolean uniqueFilename) throws NotFoundException, IOException
      Get a locally cached File for a given URI, optionally ensuring that the file is cached in a unique path so that it can safely be removed afterwards.
      Parameters:
      uri - URI to the resource to get
      uniqueFilename - If a unique path should be used
      Returns:
      The locally cached file
      Throws:
      NotFoundException - if the file does not exist
      IOException - if reading the file from the workspace fails
    • read

      Get the File for the given URI directly from the working file repository. If shared storage is not available, then fall back to get(uri).
      Parameters:
      uri - URI identifying the resource to load
      Returns:
      The file
      Throws:
      NotFoundException - if the file does not exist
      IOException - if reading the file from the working file repository fails
    • getBaseUri

      URI getBaseUri()
      Gets the base URI for files stored using this service.
      Returns:
      The base URI
    • put

      URI put(String mediaPackageID, String mediaPackageElementID, String fileName, InputStream in) throws IOException, IllegalArgumentException
      Store the data stream under the given media package and element IDs, specifying a filename.
      Parameters:
      mediaPackageID -
      mediaPackageElementID -
      fileName -
      in -
      Throws:
      IOException - if writing the data to the workspace fails
      IllegalArgumentException - if a URI cannot be created using the arguments provided
    • putInCollection

      URI putInCollection(String collectionId, String fileName, InputStream in) throws IOException, IllegalArgumentException
      Stores the data stream in the given collection, overwriting any data with the same collection id and file name.
      Parameters:
      collectionId - The collection to use for storing this data
      fileName - the filename to use in the collection.
      in - the inputstream
      Returns:
      the URI of the stored data
      Throws:
      IOException - if writing the data to the workspace fails
      IllegalArgumentException - if a URI cannot be created using the arguments provided
    • getCollectionContents

      URI[] getCollectionContents(String collectionId) throws NotFoundException, IllegalArgumentException
      Gets the URIs of the members of this collection
      Parameters:
      collectionId - the collection identifier
      Returns:
      the URIs for each member of the collection
      Throws:
      NotFoundException - if the collection cannot be found
      IllegalArgumentException - if a URI cannot be created using the arguments provided
    • delete

      void delete(URI uri) throws NotFoundException, IOException
      Delete the file stored at the given uri.
      Parameters:
      uri - the uri
      Throws:
      NotFoundException - if there was not file stored under this combination of mediapackage and element IDs.
      IOException - if deleting the data from the workspace fails
    • delete

      void delete(String mediaPackageID, String mediaPackageElementID) throws NotFoundException, IOException
      Delete the file stored at the given media package and element IDs.
      Parameters:
      mediaPackageID -
      mediaPackageElementID -
      Throws:
      NotFoundException - if there was not file stored under this combination of mediapackage and element IDs.
      IOException - if deleting the data from the workspace fails
    • deleteFromCollection

      void deleteFromCollection(String collectionId, String fileName) throws NotFoundException, IOException
      Removes a file from a collection
      Parameters:
      collectionId - the collection identifier
      fileName - the filename to remove
      Throws:
      NotFoundException - if there was no file with the provided name stored under this collection.
      IOException - if deleting the data from the workspace fails
    • getURI

      URI getURI(String mediaPackageID, String mediaPackageElementID) throws IllegalArgumentException
      Get the URL for a file stored under the given media package and element IDs. MediaPackages may reference elements that are not yet stored in the working file repository, so this method will return a URI even if the file is not yet stored.
      Parameters:
      mediaPackageID - the mediapackage identifier
      mediaPackageElementID - the element identifier
      Returns:
      the URI to the file
      Throws:
      IllegalArgumentException - if a URI cannot be created using the arguments provided
    • getCollectionURI

      URI getCollectionURI(String collectionID, String fileName) throws IllegalArgumentException
      Get the URL for a file stored under the given collection.
      Parameters:
      collectionID - the collection id
      fileName - the file name
      Returns:
      the file's uri
      Throws:
      IllegalArgumentException - if a URI cannot be created using the arguments provided
    • moveTo

      URI moveTo(URI collectionURI, String toMediaPackage, String toMediaPackageElement, String toFileName) throws NotFoundException, IOException, IllegalArgumentException
      Moves a file from a collection into a mediapackage
      Parameters:
      collectionURI - the uri pointing to a workspace collection
      toMediaPackage - The media package ID to move the file into
      toMediaPackageElement - the media package element ID of the file
      toFileName - the name of the resulting file
      Returns:
      the URI pointing to the file's new location
      Throws:
      NotFoundException - if the element identified by collectionURI cannot be found
      IOException - if either the original element cannot be read or it cannot be moved to the new location
      IllegalArgumentException - if a URI cannot be created using the arguments provided
    • cleanup

      void cleanup(int maxAge)
      Cleans up files not belonging to a mediapackage or a collection. If the optional maxAge parameter is set, only files older than the maxAge are deleted.
      Parameters:
      maxAge - the maximal age in seconds of a file before deletion is performed
    • cleanup

      void cleanup(Id mediaPackageId) throws IOException
      Clean up all elements of one media package from the local workspace, not touching the working file repository.
      Parameters:
      mediaPackageId - Id specifying the media package to remove files for.
      Throws:
      IOException
    • cleanup

      void cleanup(Id mediaPackageId, boolean filesOnly) throws IOException
      Clean up elements of one media package from the local workspace, not touching the working file repository.
      Parameters:
      mediaPackageId - Id specifying the media package to remove files for.
      filesOnly - Boolean specifying whether only files or also directories (including the root directory) are deleted.
      Throws:
      IOException
    • rootDirectory

      String rootDirectory()
      Returns the workspace's root directory
      Returns:
      Path to the workspace root directory