Class WorkingFileRepositoryImpl
java.lang.Object
org.opencastproject.workingfilerepository.impl.WorkingFileRepositoryImpl
- All Implemented Interfaces:
StorageUsage,PathMappable,WorkingFileRepository
- Direct Known Subclasses:
WorkingFileRepositoryRestEndpoint
public class WorkingFileRepositoryImpl
extends Object
implements WorkingFileRepository, PathMappable
A very simple (read: inadequate) implementation that stores all files under a root directory using the media package
ID as a subdirectory and the media package element ID as the file name.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe extension we use for the md5 hash calculated from the file contentsprotected ServiceRegistryThe remote service managerprotected StringThe root directory for storing filesprotected SecurityServiceThe security service to get current organization fromprotected StringThe Base URL for this serverprotected StringThe URL path for the services provided by the working file repositorystatic final StringConfiguration key for garbage collection max age.static final StringConfiguration key for garbage collection period.Fields inherited from interface org.opencastproject.workingfilerepository.api.WorkingFileRepository
CHAR_ENCODING, COLLECTION_PATH_PREFIX, MEDIAPACKAGE_PATH_PREFIX, SERVICE_TYPE, URI_PREFIX -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate(org.osgi.service.component.ComponentContext cc) Activate the componentprotected voidcheckPathSafe(String id) booleancleanupOldFilesFromCollection(String collectionId, long days) Cleans up collection files older than the number of days passed.booleancleanupOldFilesFromMediaPackage(long days) Cleans up media files older than the number of days passed.copyTo(String fromCollection, String fromFileName, String toMediaPackage, String toMediaPackageElement, String toFileName) protected FileCreates a file containing the md5 hash for the contents of a source file.voidCallback from OSGi on service deactivation.booleanDelete the file stored at the given media package and element IDs.booleandeleteFromCollection(String collectionId, String fileName) Removes a file from a collectionbooleandeleteFromCollection(String collectionId, String fileName, boolean removeCollection) Removes a file from a collection, and the parent folder if emptyStream the file stored under the given media package and element IDs.Gets the base URI for this service.URI[]getCollectionContents(String collectionId) Gets the URIs of the members of this collectionlonggetCollectionURI(String collectionID, String fileName) Get the URL for a file stored under the given collection.A textual representation of available and total storageprotected FileReturns the file to the media package element.getFileFromCollection(String collectionId, String fileName) Returns the file from the given collection.getFromCollection(String collectionId, String fileName) Returns the prefix to the working file repository file system root directory.protected FilegetSourceFile(File md5File) Gets the file handle for a source file from its md5 file.Gets the total space of storage in BytesGet the URL for a file stored under the given media package and element IDs.Get the URL for a file stored under the given media package and element IDs.Returns the repository's base url.Gets the available space of storage in Bytes This is free storage that is not reservedGets the used space of storage in BytesmoveTo(String fromCollection, String fromFileName, String toMediaPackage, String toMediaPackageElement, String toFileName) Moves a file from a collection into a mediapackageput(String mediaPackageID, String mediaPackageElementID, String filename, InputStream in) Store the data stream under the given media package and element IDs with filename as name of the file.putInCollection(String collectionId, String fileName, InputStream in) Puts a file into a collection, overwriting the existing file if present.voidsetRemoteServiceManager(ServiceRegistry remoteServiceManager) Sets the remote service manager.voidsetSecurityService(SecurityService securityService) toSafeName(String fileName) Returns the filename translated into a version that can safely be used as part of a file system path.
-
Field Details
-
MD5_EXTENSION
The extension we use for the md5 hash calculated from the file contents- See Also:
-
WORKING_FILE_REPOSITORY_CLEANUP_PERIOD_KEY
Configuration key for garbage collection period.- See Also:
-
WORKING_FILE_REPOSITORY_CLEANUP_MAX_AGE_KEY
Configuration key for garbage collection max age.- See Also:
-
remoteServiceManager
The remote service manager -
rootDirectory
The root directory for storing files -
serverUrl
The Base URL for this server -
servicePath
The URL path for the services provided by the working file repository -
securityService
The security service to get current organization from
-
-
Constructor Details
-
WorkingFileRepositoryImpl
public WorkingFileRepositoryImpl()
-
-
Method Details
-
activate
Activate the component- Throws:
IOException
-
deactivate
public void deactivate()Callback from OSGi on service deactivation. -
toSafeName
Returns the filename translated into a version that can safely be used as part of a file system path. The method shortens both the base file name and the extension to a maximum of 255 characters each, and replaces unsafe characters with <doce>_</doce>.- Specified by:
toSafeNamein interfaceWorkingFileRepository- Parameters:
fileName- The file name- Returns:
- the safe version
-
delete
Delete the file stored at the given media package and element IDs.- Specified by:
deletein interfaceWorkingFileRepository- Parameters:
mediaPackageID- the media package identifiermediaPackageElementID- the media package element identifier- Throws:
IOException- if the element cannot be deleted- See Also:
-
get
public InputStream get(String mediaPackageID, String mediaPackageElementID) throws NotFoundException, IOException Stream the file stored under the given media package and element IDs.- Specified by:
getin interfaceWorkingFileRepository- Parameters:
mediaPackageID- the media package identifiermediaPackageElementID- the media package element identifier- Returns:
- the media package element contents
- Throws:
NotFoundException- if the media package element can't be foundIOException- if there is a problem reading the data- See Also:
-
getCollectionURI
Get the URL for a file stored under the given collection.- Specified by:
getCollectionURIin interfaceWorkingFileRepository- Parameters:
collectionID- the collection identifierfileName- the file name- Returns:
- the file's uri
- See Also:
-
getURI
Get the URL for a file stored under the given media package and element IDs. This may be called for mediapackages, elements, or files that have not yet been stored in the repository.- Specified by:
getURIin interfaceWorkingFileRepository- Parameters:
mediaPackageID- the media package identifiermediaPackageElementID- the media package element identifier- Returns:
- the URI to this resource
- See Also:
-
getURI
Get the URL for a file stored under the given media package and element IDs. This may be called for mediapackages, elements, or files that have not yet been stored in the repository.- Specified by:
getURIin interfaceWorkingFileRepository- Parameters:
mediaPackageID- the media package identifiermediaPackageElementID- the media package element identifierfileName- the file name- Returns:
- the URI to this resource
- See Also:
-
put
public URI put(String mediaPackageID, String mediaPackageElementID, String filename, InputStream in) throws IOException Store the data stream under the given media package and element IDs with filename as name of the file.- Specified by:
putin interfaceWorkingFileRepository- Parameters:
mediaPackageID- the media package identifiermediaPackageElementID- the media package element identifierfilename- the file name to usein- the input stream- Returns:
- The URL to access this file
- Throws:
IOException- if the input stream cannot be accessed or the element cannot be written to the repository- See Also:
-
createMd5
Creates a file containing the md5 hash for the contents of a source file.- Parameters:
f- the source file containing the data to hash- Throws:
IOException- if the hash cannot be created
-
getSourceFile
Gets the file handle for a source file from its md5 file.- Parameters:
md5File- The md5 file- Returns:
- The source file
-
checkPathSafe
-
getFile
protected File getFile(String mediaPackageID, String mediaPackageElementID) throws IllegalStateException, NotFoundException Returns the file to the media package element.- Parameters:
mediaPackageID- the media package identifiermediaPackageElementID- the media package element identifier- Returns:
- the file or
nullif no such element exists - Throws:
IllegalStateException- if more than one matching elements were foundNotFoundException- if the file cannot be found in the Working File Repository
-
getFileFromCollection
public File getFileFromCollection(String collectionId, String fileName) throws NotFoundException, IllegalArgumentException Returns the file from the given collection.- Parameters:
collectionId- the collection identifierfileName- the file name- Returns:
- the file
- Throws:
NotFoundException- if either the collection or the file don't existIllegalArgumentException
-
getCollectionSize
- Throws:
NotFoundException
-
getFromCollection
public InputStream getFromCollection(String collectionId, String fileName) throws NotFoundException, IOException - Throws:
NotFoundExceptionIOException
-
putInCollection
Puts a file into a collection, overwriting the existing file if present.- Specified by:
putInCollectionin interfaceWorkingFileRepository- Parameters:
collectionId- The collection identifierfileName- The filename to use in storing the input streamin- the data to store- Returns:
- The URI identifying the file
- Throws:
IOException- if the hash can't be created- See Also:
-
copyTo
public URI copyTo(String fromCollection, String fromFileName, String toMediaPackage, String toMediaPackageElement, String toFileName) throws NotFoundException, IOException - Throws:
NotFoundExceptionIOException
-
moveTo
public URI moveTo(String fromCollection, String fromFileName, String toMediaPackage, String toMediaPackageElement, String toFileName) throws NotFoundException, IOException Moves a file from a collection into a mediapackage- Specified by:
moveToin interfaceWorkingFileRepository- Parameters:
fromCollection- The collection holding the filefromFileName- The filenametoMediaPackage- 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:
NotFoundExceptionIOException- See Also:
-
deleteFromCollection
public boolean deleteFromCollection(String collectionId, String fileName, boolean removeCollection) throws IOException Removes a file from a collection, and the parent folder if empty- Specified by:
deleteFromCollectionin interfaceWorkingFileRepository- Parameters:
collectionId- the collection identifierfileName- the filename to removeremoveCollection- remove the parent collection folder if empty- Returns:
trueif the file existed and was removed- Throws:
IOException- See Also:
-
deleteFromCollection
Removes a file from a collection- Specified by:
deleteFromCollectionin interfaceWorkingFileRepository- Parameters:
collectionId- the collection identifierfileName- the filename to remove- Returns:
trueif the file existed and was removed- Throws:
IOException- See Also:
-
getCollectionContents
Gets the URIs of the members of this collection- Specified by:
getCollectionContentsin interfaceWorkingFileRepository- Parameters:
collectionId- the collection identifier- Returns:
- the URIs for each member of the collection
- Throws:
NotFoundException- if the collectionId does not exist- See Also:
-
getTotalSpace
Gets the total space of storage in Bytes- Specified by:
getTotalSpacein interfaceStorageUsage- Returns:
- Number of all bytes in storage
- See Also:
-
getUsableSpace
Gets the available space of storage in Bytes This is free storage that is not reserved- Specified by:
getUsableSpacein interfaceStorageUsage- Returns:
- Number of available bytes in storage
- See Also:
-
getUsedSpace
Gets the used space of storage in Bytes- Specified by:
getUsedSpacein interfaceStorageUsage- Returns:
- Number of used bytes in storage
- See Also:
-
getDiskSpace
A textual representation of available and total storage- Specified by:
getDiskSpacein interfaceWorkingFileRepository- Returns:
- Percentage and numeric values of used storage space
- See Also:
-
cleanupOldFilesFromCollection
Cleans up collection files older than the number of days passed.- Specified by:
cleanupOldFilesFromCollectionin interfaceWorkingFileRepository- Parameters:
collectionId- the collection identifierdays- files older than that will be deleted- Throws:
IOException- See Also:
-
cleanupOldFilesFromMediaPackage
Description copied from interface:WorkingFileRepositoryCleans up media files older than the number of days passed.- Specified by:
cleanupOldFilesFromMediaPackagein interfaceWorkingFileRepository- Parameters:
days- files older than that will be deleted- Throws:
IOException
-
getPathPrefix
Returns the prefix to the working file repository file system root directory.- Specified by:
getPathPrefixin interfacePathMappable- Returns:
- the root path on the file system
- See Also:
-
getUrlPrefix
Returns the repository's base url.- Specified by:
getUrlPrefixin interfacePathMappable- Returns:
- the base url
- See Also:
-
getBaseUri
Gets the base URI for this service.- Specified by:
getBaseUriin interfaceWorkingFileRepository- Returns:
- The base URI
- See Also:
-
setRemoteServiceManager
Sets the remote service manager.- Parameters:
remoteServiceManager-
-
setSecurityService
-