Interface Workspace
-
- All Superinterfaces:
org.opencastproject.storage.StorageUsage
public interface Workspace extends org.opencastproject.storage.StorageUsageProvides 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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcleanup(int maxAge)Cleans up files not belonging to a mediapackage or a collection.voidcleanup(org.opencastproject.mediapackage.identifier.Id mediaPackageId)Clean up all elements of one media package from the local workspace, not touching the working file repository.voidcleanup(org.opencastproject.mediapackage.identifier.Id mediaPackageId, boolean filesOnly)Clean up elements of one media package from the local workspace, not touching the working file repository.voiddelete(String mediaPackageID, String mediaPackageElementID)Delete the file stored at the given media package and element IDs.voiddelete(URI uri)Delete the file stored at the given uri.voiddeleteFromCollection(String collectionId, String fileName)Removes a file from a collectionFileget(URI uri)Gets a locally cachedFilefor the given URI.Fileget(URI uri, boolean uniqueFilename)Get a locally cachedFilefor a given URI, optionally ensuring that the file is cached in a unique path so that it can safely be removed afterwards.URIgetBaseUri()Gets the base URI for files stored using this service.URI[]getCollectionContents(String collectionId)Gets the URIs of the members of this collectionURIgetCollectionURI(String collectionID, String fileName)Get the URL for a file stored under the given collection.URIgetURI(String mediaPackageID, String mediaPackageElementID)Get the URL for a file stored under the given media package and element IDs.URImoveTo(URI collectionURI, String toMediaPackage, String toMediaPackageElement, String toFileName)Moves a file from a collection into a mediapackageURIput(String mediaPackageID, String mediaPackageElementID, String fileName, InputStream in)Store the data stream under the given media package and element IDs, specifying a filename.URIputInCollection(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.InputStreamread(URI uri)Get theFilefor the given URI directly from the working file repository.StringrootDirectory()Returns the workspace's root directoryStringtoSafeName(String fileName)
-
-
-
Method Detail
-
get
File get(URI uri) throws org.opencastproject.util.NotFoundException, IOException
Gets a locally cachedFilefor the given URI.- Parameters:
uri-- Returns:
- The locally cached file
- Throws:
org.opencastproject.util.NotFoundException- if the file does not existIOException- if reading the file from the workspace fails
-
get
File get(URI uri, boolean uniqueFilename) throws org.opencastproject.util.NotFoundException, IOException
Get a locally cachedFilefor 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 getuniqueFilename- If a unique path should be used- Returns:
- The locally cached file
- Throws:
org.opencastproject.util.NotFoundException- if the file does not existIOException- if reading the file from the workspace fails
-
read
InputStream read(URI uri) throws org.opencastproject.util.NotFoundException, IOException
Get theFilefor 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:
org.opencastproject.util.NotFoundException- if the file does not existIOException- 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 failsIllegalArgumentException- 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 datafileName- 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 failsIllegalArgumentException- if a URI cannot be created using the arguments provided
-
getCollectionContents
URI[] getCollectionContents(String collectionId) throws org.opencastproject.util.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:
org.opencastproject.util.NotFoundException- if the collection cannot be foundIllegalArgumentException- if a URI cannot be created using the arguments provided
-
delete
void delete(URI uri) throws org.opencastproject.util.NotFoundException, IOException
Delete the file stored at the given uri.- Parameters:
uri- the uri- Throws:
org.opencastproject.util.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 org.opencastproject.util.NotFoundException, IOException
Delete the file stored at the given media package and element IDs.- Parameters:
mediaPackageID-mediaPackageElementID-- Throws:
org.opencastproject.util.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 org.opencastproject.util.NotFoundException, IOException
Removes a file from a collection- Parameters:
collectionId- the collection identifierfileName- the filename to remove- Throws:
org.opencastproject.util.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 identifiermediaPackageElementID- 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 idfileName- 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 org.opencastproject.util.NotFoundException, IOException, IllegalArgumentException
Moves a file from a collection into a mediapackage- Parameters:
collectionURI- the uri pointing to a workspace collectiontoMediaPackage- The media package ID to move the file intotoMediaPackageElement- the media package element ID of the filetoFileName- the name of the resulting file- Returns:
- the URI pointing to the file's new location
- Throws:
org.opencastproject.util.NotFoundException- if the element identified bycollectionURIcannot be foundIOException- if either the original element cannot be read or it cannot be moved to the new locationIllegalArgumentException- 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(org.opencastproject.mediapackage.identifier.Id mediaPackageId) throws IOExceptionClean 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(org.opencastproject.mediapackage.identifier.Id mediaPackageId, boolean filesOnly) throws IOExceptionClean 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
-
-