org.gcube.contentmanagement.baselayer.filesystemImpl
Class LocalFilesystemHandler

java.lang.Object
  extended by org.gcube.contentmanagement.baselayer.filesystemImpl.LocalFilesystemHandler
All Implemented Interfaces:
InstantiableManager, RawFileContentManager

public class LocalFilesystemHandler
extends java.lang.Object
implements RawFileContentManager, InstantiableManager

Manager for fies stored on local file system. Access can and should get restricted to particular directory trees, otherwise it is able to read all configuration files of the user under whichs permissions the manager is running.

Author:
michaelspringmann

Field Summary
 
Fields inherited from interface org.gcube.contentmanagement.baselayer.InstantiableManager
MANAGER_INSTANTIATION_METHOD_NAME
 
Constructor Summary
LocalFilesystemHandler()
           
 
Method Summary
 boolean deleteBinaryContent(RawContentLocation rcl, BasicStorageHints hints)
          Removes the binary content from storage
 boolean existsBinaryContent(RawContentLocation rcl, BasicStorageHints hints)
          Checks whether there is content at this location
 BaseLayerStream getBinaryContent(java.io.File file, BasicStorageHints hints)
          Opens the content for reading and passes the input stream to the caller
 BaseLayerStream getBinaryContent(RawContentLocation rcl, BasicStorageHints hints)
          Opens the content for reading and passes the input stream to the caller
 java.lang.String getDataProvider()
          
static java.lang.String getDataProviderPrefix()
          Returns the prefix that is used by the manager for identying responsibility for a data source
static LocalFilesystemHandler getInstance()
           
static LocalFilesystemHandler getManagerFor(RawContentLocation rcl)
          Factory method that returns the instance of a manager for a particular location.
static LocalFilesystemHandler getManagerFor(java.lang.String directory)
          Deprecated. use getManagerInstance() instead;
static LocalFilesystemHandler getManagerInstance(java.lang.String[] params, java.lang.String managerName)
          Generic factory method that returns an instance responsible for a particular directory
 java.lang.String getUniqueStorageLocationIDFor(java.lang.String objectID)
           
 boolean handles(java.lang.String dataProvider)
          Checks whether the RawFileContentManager can handle this data.
 RawContentLocation makePermanentLocation(RawContentLocation currentLocation, BasicStorageHints hints)
          Returns a raw location, which can be stored and retrieved later without the need to pass again all the hints.
 RawContentLocation saveBinaryContent(java.io.File outputFile, BaseLayerStream binaryFileContent, BasicStorageHints hints)
          Saves the passed binary content in the managed resource.
 RawContentLocation saveBinaryContent(java.lang.String uniqueStorageID, BaseLayerStream binaryFileContent, BasicStorageHints hints)
          Saves the passed binary content in the managed resource.
 boolean supportsAppending()
          Tells whether this content manager supports appending content in addition to overwriting the content when storing
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalFilesystemHandler

public LocalFilesystemHandler()
Method Detail

getInstance

public static LocalFilesystemHandler getInstance()

getManagerInstance

public static LocalFilesystemHandler getManagerInstance(java.lang.String[] params,
                                                        java.lang.String managerName)
                                                 throws BaseLayerException
Generic factory method that returns an instance responsible for a particular directory

Parameters:
params - the first String contains the directory that will be managed. If array is empty, the manager will be able to manage any directory
managerName - the name of the manager (currently not in use)
Returns:
the manager
Throws:
BaseLayerException - if location is not manageable by this kind of manager, e.g. because directory does not exist

getDataProvider

public java.lang.String getDataProvider()

Specified by:
getDataProvider in interface RawFileContentManager
Returns:
a string identifying this data source

getDataProviderPrefix

public static java.lang.String getDataProviderPrefix()
Returns the prefix that is used by the manager for identying responsibility for a data source

Returns:
the prefix

getManagerFor

public static LocalFilesystemHandler getManagerFor(java.lang.String directory)
                                            throws BaseLayerException
Deprecated. use getManagerInstance() instead;

Factory method that returns the instance of a manager for a particular directory. Reuses an existing manager, if it already exists; otherwise creates a new instance.

Parameters:
directory - the directory to manage
Returns:
the manager
Throws:
BaseLayerException - if location is not manageable by this kind of manager, e.g. because directory does not exist

getManagerFor

public static LocalFilesystemHandler getManagerFor(RawContentLocation rcl)
                                            throws BaseLayerException
Factory method that returns the instance of a manager for a particular location. Reuses an existing manager, if it already exists; otherwise creates a new instance.

Parameters:
rcl - the raw content location under responsibility of the manager
Returns:
the manager
Throws:
BaseLayerException - if location is not manageable by this kind of manager, e.g. because directory does not exist

supportsAppending

public boolean supportsAppending()
Tells whether this content manager supports appending content in addition to overwriting the content when storing

Specified by:
supportsAppending in interface RawFileContentManager
Returns:
true, if appending is supported
See Also:
BasicStorageHints#HINT_NAME_APPEND_CONTENT

handles

public boolean handles(java.lang.String dataProvider)
Checks whether the RawFileContentManager can handle this data.

This means that it can handle the requests for content stored at this dataprovider. In the ideal case, this also checks if it has all required access rights. But this cannot be enforced as a strong requirement before the actual calls take place.

Specified by:
handles in interface RawFileContentManager
Parameters:
dataprovider -
Returns:
true, if it can do, false otherwise

saveBinaryContent

public RawContentLocation saveBinaryContent(java.lang.String uniqueStorageID,
                                            BaseLayerStream binaryFileContent,
                                            BasicStorageHints hints)
                                     throws BaseLayerException
Saves the passed binary content in the managed resource. If the resource did previously exist, it is updated and the old content is lost. If the resource did not exist, it will be newly created.

Specified by:
saveBinaryContent in interface RawFileContentManager
Parameters:
binaryFileContent - the content to store
uniqueStorageID - a unique ID to access the content
hints - the hints that should be used
Returns:
the RawContentLocation where the content is now accessible
Throws:
java.io.IOException - in case of failure of underlying storage system
BaseLayerException - in case of failure of underlying storage system

getUniqueStorageLocationIDFor

public java.lang.String getUniqueStorageLocationIDFor(java.lang.String objectID)
Specified by:
getUniqueStorageLocationIDFor in interface RawFileContentManager

saveBinaryContent

public RawContentLocation saveBinaryContent(java.io.File outputFile,
                                            BaseLayerStream binaryFileContent,
                                            BasicStorageHints hints)
                                     throws BaseLayerException
Saves the passed binary content in the managed resource. If the resource did previously exist, it is updated and the old content is lost. If the resource did not exist, it will be newly created.

Parameters:
binaryFileContent - the content to store
outputFile - a local file to store the content
Throws:
java.io.IOException - in case of failure of underlying storage system
BaseLayerException

getBinaryContent

public BaseLayerStream getBinaryContent(RawContentLocation rcl,
                                        BasicStorageHints hints)
                                 throws BaseLayerException
Opens the content for reading and passes the input stream to the caller

Specified by:
getBinaryContent in interface RawFileContentManager
Parameters:
rcl - the RawContentLocation where the content is accessible
hints - the hints that should be used
Returns:
the content stored in the managed resource
Throws:
BaseLayerException - in case of failure of underlying storage system

getBinaryContent

public BaseLayerStream getBinaryContent(java.io.File file,
                                        BasicStorageHints hints)
                                 throws ObjectNotFoundException,
                                        ValueNotValidException,
                                        BaseLayerException
Opens the content for reading and passes the input stream to the caller

Parameters:
file - the file that should be read
hints - the hints that should be used
Returns:
the content stored in the managed resource
Throws:
ObjectNotFoundException - if file does not exist
ValueNotValidException - if some value, e.g. a hint has an invalid value
BaseLayerException - in case of failure of underlying storage system

deleteBinaryContent

public boolean deleteBinaryContent(RawContentLocation rcl,
                                   BasicStorageHints hints)
                            throws BaseLayerException
Removes the binary content from storage

Specified by:
deleteBinaryContent in interface RawFileContentManager
Parameters:
rcl - the RawContentLocation where the content is accessible
hints - the hints that should be used
Returns:
true, if content has been deleted successfully; false if the content did not exist and therefore the operation had no effect.
Throws:
BaseLayerException - in case of failure of underlying storage system

existsBinaryContent

public boolean existsBinaryContent(RawContentLocation rcl,
                                   BasicStorageHints hints)
                            throws ValueNotValidException
Checks whether there is content at this location

Specified by:
existsBinaryContent in interface RawFileContentManager
Parameters:
rcl - the RawContentLocation where the content is accessible
Returns:
true, if there is content at this location; false otherwise
Throws:
ValueNotValidException

makePermanentLocation

public RawContentLocation makePermanentLocation(RawContentLocation currentLocation,
                                                BasicStorageHints hints)
                                         throws ValueNotValidException
Returns a raw location, which can be stored and retrieved later without the need to pass again all the hints.

This is of particular interest for username / password combinations.

Specified by:
makePermanentLocation in interface RawFileContentManager
Parameters:
currentLocation - the location, where content can be accessed currently (may require information from the hints)
hints - hints, that may be needed to request the content
Returns:
a location which can be accessed without providing again the hints. This may not always be possible.
Throws:
ValueNotValidException - If some hints was not defined correctly or there is no possibility to include that in the permanent location.