org.gcube.contentmanagement.storagelayer
Class StorageManager

java.lang.Object
  extended by org.gcube.contentmanagement.storagelayer.StorageManager

public class StorageManager
extends java.lang.Object

The library implementation of the storage managment functionality

Author:
michaelspringmann

Field Summary
static boolean initialized
           
static CredentialsProvider provider
           
 
Constructor Summary
StorageManager()
           
 
Method Summary
static void addReference(java.lang.String sourceObjectID, java.lang.String targetObjectID, java.lang.String role, java.lang.String secondaryRole, int position, java.lang.String propagationRule)
          Adds a new reference between two information objects.
static void associateRawContent(java.lang.String objectID, byte[] rawContent, BasicStorageHints hints)
          Gets the file from the defined location and stores it as the raw content of a information object.
static void associateRawContent(java.lang.String objectID, java.lang.String fileLocation, BasicStorageHints hints)
          Gets the file from the defined location and stores it as the raw content of a information object.
static long countReferences(java.lang.String oid, boolean isSource, java.lang.String role, java.lang.String secondaryRole)
          Counts the references of an object
static java.lang.String createInfoObject(java.lang.String name, java.lang.String type, BasicStorageHints hints)
          Creates a new information object.
static void deleteContentLengthInformation(java.lang.String objectID)
           
static void ensureInit()
          Internal method to ensure that the Storage Manager has been initialized.
static boolean existsInfoObject(java.lang.String oid)
          Checks, whether an information object with the given ID exists.
static boolean existsReference(java.lang.String sourceoid, java.lang.String targetoid, java.lang.String role, java.lang.String secondaryRole)
           
static BasicInfoObjectDescription getInfoObject(java.lang.String objectID, java.lang.String targetFileLocation, BasicStorageHints hints)
          Retrieves an existing information object and associated data
static RawFileContentManager getManagerForDataProvider(java.lang.String dataProvider)
           
static boolean hasRawContent(java.lang.String objectID)
          Returns whether there exists raw content associated with an information object
static boolean hasStorageProperty(java.lang.String oid, java.lang.String name)
          Returnes whether an information object has a particular property set
static void init(java.io.File configDir, GCUBEServiceContext ctx)
          Initializes the Storage Manager.
static boolean removeInfoObject(java.lang.String objectID)
          Deletes an information object.
static boolean removeRawContent(java.lang.String objectID, BasicStorageHints hints)
          Removes any raw content associated with the information object
static boolean removeReference(java.lang.String sourceObjectID, java.lang.String targetObjectID, java.lang.String role, java.lang.String secondaryRole)
          Deletes any reference with having the given parameters.
CAUTION: This may delete also referenced information objects and cascade those deletions, depending on the propagation rules.
static java.util.List<java.lang.String> retrieveObjectIDsByStorageProperty(java.lang.String name, java.lang.String value)
          Retrieves all object IDs of information object for which a particular property value has been set
static java.util.Map<java.lang.String,BasicPropertyDescription> retrieveObjectStorageProperties(java.lang.String objectID)
          Retrieves all properties of an information object
static java.util.List<BasicReferenceDescription> retrieveReferences(java.lang.String sourceObjectID, java.lang.String role, java.lang.String secondaryRole)
          Retrieves all references which point from this source object to some other object.
static java.util.List<BasicReferenceDescription> retrieveReferencesOrderedByPosition(java.lang.String sourceObjectID, java.lang.String role, java.lang.String secondaryRole)
          Retrieves all references which point from this source object to some other object.
static java.util.List<BasicReferenceDescription> retrieveReferred(java.lang.String targetObjectID, java.lang.String role, java.lang.String secondaryRole)
          Retrieves all references which point to this target object.
static java.util.List<java.lang.String> retrieveReferredSourceOIDs(java.lang.String targetObjectID, java.lang.String role, java.lang.String secondaryRole)
          Retrieves all object OIDs of information object, which have a reference to this target object.
static java.util.List<java.lang.String> retrieveReferredTargetOIDs(java.lang.String sourceObjectID, java.lang.String role, java.lang.String secondaryRole)
          Retrieves all object OIDs of information object, which have a reference from this source object.
static BasicPropertyDescription retrieveStorageProperty(java.lang.String objectID, java.lang.String name)
          Retrieves a particular property of an information object
static void setStorageProperty(java.lang.String objectID, java.lang.String name, java.lang.String type, java.lang.String value)
          Sets the property of a given name for a particular information object.
static void unassociateAndDeleteRawContent(java.lang.String objectID, BasicStorageHints hints)
          Deletes all raw content of an information object.
static boolean unsetStorageProperty(java.lang.String objectID, java.lang.String name)
          Removes a property of an information object
static void updateContentLengthInformation(java.lang.String objectID, long newLengthInformation, boolean appended)
          Updates the information about the length of the raw content, which is stored as a storage property.
static void updateRawContent(java.lang.String objectID, byte[] rawContent, BasicStorageHints hints)
          Stores new raw content of a information object.
static void updateRawContent(java.lang.String objectID, java.lang.String fileLocation, BasicStorageHints hints)
          Gets the file from the defined location and stores it as the raw content of a information object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

provider

public static CredentialsProvider provider

initialized

public static boolean initialized
Constructor Detail

StorageManager

public StorageManager()
Method Detail

init

public static void init(java.io.File configDir,
                        GCUBEServiceContext ctx)
Initializes the Storage Manager. The ServiceContext can be null, to allow invoking the libraries from outside a service. In this case, however, appropriate actions should be considerer whenever the serviceContext is used...


createInfoObject

public static java.lang.String createInfoObject(java.lang.String name,
                                                java.lang.String type,
                                                BasicStorageHints hints)
                                         throws StorageLayerException
Creates a new information object.

Parameters:
name - a human readable name (does not need to be unique, can also be null)
type - the type of the information object
hints - hints that should be taken into account
Returns:
the object ID of the new information object
Throws:
StorageLayerException - if something goes wrong

removeInfoObject

public static boolean removeInfoObject(java.lang.String objectID)
                                throws StorageLayerException
Deletes an information object. This will trigger propagation of deletions if corresponding relations exist.

Parameters:
objectID - the object ID of the object that should be deleted
Returns:
true, if object has been deleted successfully;false if the object did not exist and therefore the operation had no effect.
Throws:
StorageLayerException - if something goes wrong

hasRawContent

public static boolean hasRawContent(java.lang.String objectID)
                             throws StorageLayerException
Returns whether there exists raw content associated with an information object

Parameters:
objectID - the object ID of the information object
Returns:
true, if there is raw content; false otherwise
Throws:
StorageLayerException - if something goes wrong

getInfoObject

public static BasicInfoObjectDescription getInfoObject(java.lang.String objectID,
                                                       java.lang.String targetFileLocation,
                                                       BasicStorageHints hints)
                                                throws StorageLayerException
Retrieves an existing information object and associated data

Parameters:
objectID - the object ID of the object that should be deleted
targetFileLocation - a URI where raw content should be transferred (if present), use DO_NOT_TRANFER_RAW_CONTENT if raw content is not wanted
hints - recommendation, how a source should be selected (if several are availble)
Throws:
StorageLayerException - if something goes wrong

existsInfoObject

public static boolean existsInfoObject(java.lang.String oid)
                                throws StorageLayerException
Checks, whether an information object with the given ID exists. Since the ID is supposed to be UUID, the main purpose is to ensure that some other operation, e.g. removal of an object finished correctly.

Parameters:
oid - the object ID of the object
Throws:
StorageLayerException - if something goes wrong

existsReference

public static boolean existsReference(java.lang.String sourceoid,
                                      java.lang.String targetoid,
                                      java.lang.String role,
                                      java.lang.String secondaryRole)
                               throws StorageLayerException
Throws:
StorageLayerException

associateRawContent

public static void associateRawContent(java.lang.String objectID,
                                       byte[] rawContent,
                                       BasicStorageHints hints)
                                throws StorageLayerException
Gets the file from the defined location and stores it as the raw content of a information object.

Parameters:
objectID - the id of the information object, to which the file should be associated
rawContent - the content of the file
hints - recommendation, how the this file should be stored
Throws:
StorageLayerException - if something goes wrong

associateRawContent

public static void associateRawContent(java.lang.String objectID,
                                       java.lang.String fileLocation,
                                       BasicStorageHints hints)
                                throws StorageLayerException
Gets the file from the defined location and stores it as the raw content of a information object.

Parameters:
objectID - the id of the information object, to which the file should be associated
fileLocation - the location from which the file can be retrieved
hints - recommendation, how the this file should be stored
Throws:
StorageLayerException - if something goes wrong

updateRawContent

public static void updateRawContent(java.lang.String objectID,
                                    byte[] rawContent,
                                    BasicStorageHints hints)
                             throws StorageLayerException
Stores new raw content of a information object. Any possibly pre-existing content associated with the object will be invalidated.

Parameters:
objectID - the id of the information object, to which the file should be associated
rawContent - the content of the file
hints - recommendation, how the this file should be stored
Throws:
StorageLayerException - if something goes wrong

updateRawContent

public static void updateRawContent(java.lang.String objectID,
                                    java.lang.String fileLocation,
                                    BasicStorageHints hints)
                             throws StorageLayerException
Gets the file from the defined location and stores it as the raw content of a information object. Any possibly pre-existing content associated with the object will be invalidated.

Parameters:
objectID - the id of the information object, to which the file should be associated
fileLocation - the location from which the file can be retrieved, if this is set to BasicInfoObjectDescription.RAW_CONTENT_DO_NOT_TRANFER, any previously associated content will be removed.
hints - recommendation, how the this file should be stored
Throws:
StorageLayerException - if something goes wrong

unassociateAndDeleteRawContent

public static void unassociateAndDeleteRawContent(java.lang.String objectID,
                                                  BasicStorageHints hints)
                                           throws StorageLayerException
Deletes all raw content of an information object. This method does NOT delete the information object itself.

Parameters:
objectID - the object id of the information object, of which the content should be deleted
hints - storage hints (if any)
Throws:
StorageLayerException - in case of a failure

removeRawContent

public static boolean removeRawContent(java.lang.String objectID,
                                       BasicStorageHints hints)
                                throws StorageLayerException
Removes any raw content associated with the information object

Parameters:
objectID - the id of the information object
Throws:
StorageLayerException - if something goes wrong

addReference

public static void addReference(java.lang.String sourceObjectID,
                                java.lang.String targetObjectID,
                                java.lang.String role,
                                java.lang.String secondaryRole,
                                int position,
                                java.lang.String propagationRule)
                         throws StorageLayerException
Adds a new reference between two information objects. A reference is always directed and can define propagation rules for deletion of items.

Parameters:
sourceObjectID - the object ID of the starting information object of the relation
targetObjectID - the object Id of the referenced information object
role - the role of the information object (sourceObject) with respect to this reference
secondaryRole - similar to role, but for the secondary role used by Metadata Catalog
position - an attribute to allow for position preserving representation, set to ReferenceDescription.UNDEFINED_POSITION if not in use.
propagationRule - rule for propagation of deletion.
Throws:
StorageLayerException - if something goes wrong
See Also:
org.gcube.contentmanagement.layerindependent.descriptions.BasicReferenceDescription

removeReference

public static boolean removeReference(java.lang.String sourceObjectID,
                                      java.lang.String targetObjectID,
                                      java.lang.String role,
                                      java.lang.String secondaryRole)
                               throws StorageLayerException
Deletes any reference with having the given parameters.
CAUTION: This may delete also referenced information objects and cascade those deletions, depending on the propagation rules.

Parameters:
sourceObjectID - the object ID of the starting information object of the relation
targetObjectID - the object Id of the referenced information object
role - the role of the information object (sourceoid) with respect this reference. Can be set to ReferenceDescription.ANY_ROLE to match all possible values of role.
secondaryRole - similar to role, but for the secondary role used by Metadata Catalog
Throws:
StorageLayerException - if something goes wrong

retrieveReferences

public static java.util.List<BasicReferenceDescription> retrieveReferences(java.lang.String sourceObjectID,
                                                                           java.lang.String role,
                                                                           java.lang.String secondaryRole)
                                                                    throws StorageLayerException
Retrieves all references which point from this source object to some other object.

Parameters:
sourceObjectID - the object ID of the starting information object of the relation
role - the role of the information object (sourceoid) with respect this reference. Can be set to ReferenceDescription.ANY_ROLE to match all possible values of role.
secondaryRole - similar to role, but for the secondary role used by Metadata Catalog
Returns:
a list of ReferenceDescriptionrepresenting all references
Throws:
StorageLayerException - if something goes wrong

retrieveReferencesOrderedByPosition

public static java.util.List<BasicReferenceDescription> retrieveReferencesOrderedByPosition(java.lang.String sourceObjectID,
                                                                                            java.lang.String role,
                                                                                            java.lang.String secondaryRole)
                                                                                     throws StorageLayerException
Retrieves all references which point from this source object to some other object.

Parameters:
sourceObjectID - the object ID of the starting information object of the relation
role - the role of the information object (sourceoid) with respect this reference. Can be set to ReferenceDescription.ANY_ROLE to match all possible values of role.
secondaryRole - similar to role, but for the secondary role used by Metadata Catalog
Returns:
the list of retrieved references
Throws:
StorageLayerException - if something goes wrong

retrieveReferred

public static java.util.List<BasicReferenceDescription> retrieveReferred(java.lang.String targetObjectID,
                                                                         java.lang.String role,
                                                                         java.lang.String secondaryRole)
                                                                  throws StorageLayerException
Retrieves all references which point to this target object.

Parameters:
targetObjectID - the object Id of the referenced information object
role - the role of the information object (sourceoid) with respect this reference. Can be set to ReferenceDescription.ANY_ROLE to match all possible values of role.
secondaryRole - similar to role, but for the secondary role used by Metadata Catalog
references - a collection to which ReferenceDescription representing all references shall be added
Throws:
StorageLayerException - if something goes wrong

retrieveReferredSourceOIDs

public static java.util.List<java.lang.String> retrieveReferredSourceOIDs(java.lang.String targetObjectID,
                                                                          java.lang.String role,
                                                                          java.lang.String secondaryRole)
                                                                   throws StorageLayerException
Retrieves all object OIDs of information object, which have a reference to this target object.

Parameters:
targetObjectID - the object Id of the referenced information object
role - the role of the information object (sourceoid) with respect this reference. Can be set to ReferenceDescription.ANY_ROLE to match all possible values of role.
secondaryRole - similar to role, but for the secondary role used by Metadata Catalog
oids - a collection to which the OIDs shall be added
Throws:
StorageLayerException - if something goes wrong

retrieveReferredTargetOIDs

public static java.util.List<java.lang.String> retrieveReferredTargetOIDs(java.lang.String sourceObjectID,
                                                                          java.lang.String role,
                                                                          java.lang.String secondaryRole)
                                                                   throws StorageLayerException
Retrieves all object OIDs of information object, which have a reference from this source object.

Parameters:
sourceObjectID - the object Id of the reference source information object
role - the role of the information object (sourceoid) with respect this reference. Can be set to ReferenceDescription.ANY_ROLE to match all possible values of role.
secondaryRole - similar to role, but for the secondary role used by Metadata Catalog
oids - a collection to which the OIDs shall be added
Throws:
StorageLayerException - if something goes wrong

countReferences

public static long countReferences(java.lang.String oid,
                                   boolean isSource,
                                   java.lang.String role,
                                   java.lang.String secondaryRole)
                            throws StorageLayerException
Counts the references of an object

Parameters:
oid - the oid of the known object
isSource - true, if oid is the object ID of the source object, false if oid is the target oid
role - the role, or ReferenceDescription.ANY_ROLE
secondaryRole - similar to role, but for the secondary role used by Metadata Catalog
Throws:
StorageLayerException - if something goes wrong

setStorageProperty

public static void setStorageProperty(java.lang.String objectID,
                                      java.lang.String name,
                                      java.lang.String type,
                                      java.lang.String value)
                               throws StorageLayerException
Sets the property of a given name for a particular information object.

If this property already exists, it will be updated. If not, it will be added with the given values.

Parameters:
objectID - the object ID of the information object
name - the name of the property (use prefixes, e.g. namespace prefixes to disambiguate)
value - the value of the property
Throws:
StorageLayerException - if something goes wrong

unsetStorageProperty

public static boolean unsetStorageProperty(java.lang.String objectID,
                                           java.lang.String name)
                                    throws StorageLayerException
Removes a property of an information object

Parameters:
objectID - the object ID of the information object
name - the name of the property
Throws:
StorageLayerException - if something goes wrong

retrieveObjectStorageProperties

public static java.util.Map<java.lang.String,BasicPropertyDescription> retrieveObjectStorageProperties(java.lang.String objectID)
                                                                                                throws StorageLayerException
Retrieves all properties of an information object

Parameters:
objectID - the object ID of the information object
Returns:
the retrieved properties in a map to which PropertyDescription shall be added, key is the property name
Throws:
StorageLayerException - if something goes wrong

retrieveStorageProperty

public static BasicPropertyDescription retrieveStorageProperty(java.lang.String objectID,
                                                               java.lang.String name)
                                                        throws StorageLayerException
Retrieves a particular property of an information object

Parameters:
objectID - the object ID of the information object
name - the name of the property
Returns:
a PropertyDescription of the defined property
Throws:
StorageLayerException - if something goes wrong

hasStorageProperty

public static boolean hasStorageProperty(java.lang.String oid,
                                         java.lang.String name)
                                  throws StorageLayerException
Returnes whether an information object has a particular property set

Parameters:
oid - the object ID of the information object
name - the name of the property
Returns:
true, if the property is set
Throws:
ObjectNotFoundException - if the OID is invalid
StorageLayerException - if something goes wrong

retrieveObjectIDsByStorageProperty

public static java.util.List<java.lang.String> retrieveObjectIDsByStorageProperty(java.lang.String name,
                                                                                  java.lang.String value)
                                                                           throws StorageLayerException
Retrieves all object IDs of information object for which a particular property value has been set

Parameters:
name - the name of the property
value - the value of the property
oids - a collection to which the OIDs shall be added
Throws:
StorageLayerException - if something goes wrong

updateContentLengthInformation

public static void updateContentLengthInformation(java.lang.String objectID,
                                                  long newLengthInformation,
                                                  boolean appended)
                                           throws StorageLayerException
Updates the information about the length of the raw content, which is stored as a storage property.

Parameters:
objectID - OID of the information object, to which raw content is associated
newLengthInformation - the number of bytes, negativ values imply that length information should be deleted instead of updated
appended - if true, content has been appended and therefore new length information should be added to the old value; if false, old information willl simply be overwritten
Throws:
StorageLayerException - if something goes wrong

deleteContentLengthInformation

public static void deleteContentLengthInformation(java.lang.String objectID)
                                           throws StorageLayerException
Throws:
StorageLayerException

ensureInit

public static void ensureInit()
Internal method to ensure that the Storage Manager has been initialized. Since Storage Manager has only static methods and no construtor, this is basically an empty body to enforce Java to load the class and so on.


getManagerForDataProvider

public static RawFileContentManager getManagerForDataProvider(java.lang.String dataProvider)