GridFileManager Class Reference

GridFileManager provides utility functions for working with files in Mongo GridFS and links to them stored in entity attributes (s. More...

#include <MemoryX/core/GridFileManager.h>

+ Inheritance diagram for GridFileManager:

Public Member Functions

std::string addFileToAttr (const std::string &filesDBName, const std::string &localFileName, EntityAttributeBasePtr &fileAttr, const std::string &gridFSName="")
 Stores a file in GridFS and puts a reference to it into entity attribute.
 
bool ensureFileInCache (const EntityAttributeBasePtr &fileAttr, std::string &cacheFileName, bool preserveOriginalName=false)
 Caches the file locally and returns the filename.
 
bool ensureFileInCache (GridFileInterfacePrx &filePrx, std::string &cacheFileName, bool preserveOriginalName=false)
 Caches the file locally and returns the filename.
 
bool ensureFilesInCache (const EntityAttributeBasePtr &fileAttr, bool preserveOriginalNames=false)
 Caches multiple files locally.
 
bool ensureFilesInCache (const EntityAttributeBasePtr &fileAttr, std::vector< std::string > &cacheFileNames, bool preserveOriginalNames=false)
 Caches multiple files locally.
 
CommonStorageInterfacePrx getDBPrx () const
 
std::string getFileCachePath () const
 Retrieves a local path where files will be cached.
 
bool getFileStream (const EntityAttributeBasePtr &fileAttr, std::ifstream &fs)
 Caches the file locally and opens a filestream for it.
 
bool getFileStream (GridFileInterfacePrx &filePrx, std::ifstream &fs)
 Caches the file locally and opens a filestream for it.
 
 GridFileManager (const CommonStorageInterfacePrx &databasePrx)
 Constructs new GridFileManager.
 
 GridFileManager (const CommonStorageInterfacePrx &databasePrx, const std::string &cachePath)
 Constructs new GridFileManager.
 
bool removeAttrDirectory (const EntityAttributeBasePtr &fileAttr)
 Removes GridFS directory referenced by entity attribute.
 
bool removeAttrFile (const EntityAttributeBasePtr &fileAttr, unsigned int fileIndex)
 
bool removeAttrFiles (const EntityAttributeBasePtr &fileAttr)
 Removes all GridFS files referenced by entity attribute.
 
bool storeDirectoryToAttr (const std::string &filesDBName, const std::string &localDirectoryName, EntityAttributeBasePtr &fileAttr, std::string excludeFilter=".svn")
 Stores a complete directory tree in GridFS and puts a reference to it into entity attribute Overwrites any previously stored attribute.
 
bool storeFilesToAttr (const std::string &filesDBName, const std::string &localBaseDirectoryName, const std::vector< std::string > &localFiles, EntityAttributeBasePtr &fileAttr)
 Stores a set of files with in GridFS and puts a reference to it into entity attribute.
 
std::string storeFileToAttr (const std::string &filesDBName, const std::string &localFileName, EntityAttributeBasePtr &fileAttr, const std::string &gridFSName="")
 Stores a file in GridFS and puts a reference to it into entity attribute.
 
 ~GridFileManager () override
 
- Public Member Functions inherited from Logging
SpamFilterDataPtr deactivateSpam (float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
 disables the logging for the current line for the given amount of seconds.
 
MessageTypeT getEffectiveLoggingLevel () const
 
 Logging ()
 
void setLocalMinimumLoggingLevel (MessageTypeT level)
 With setLocalMinimumLoggingLevel the minimum verbosity-level of log-messages can be set.
 
void setTag (const LogTag &tag)
 
void setTag (const std::string &tagName)
 
virtual ~Logging ()
 

Protected Member Functions

void init (std::string cachePath)
 
- Protected Member Functions inherited from Logging
bool checkLogLevel (MessageTypeT level) const
 
const LogSenderPtr & getLogSender () const
 Retrieve log sender.
 
LogSenderPtr loghelper (const char *file, int line, const char *function) const
 

Additional Inherited Members

- Protected Attributes inherited from Logging
MessageTypeT minimumLoggingLevel
 
SpamFilterDataPtr spamFilter
 
LogTag tag
 

Detailed Description

GridFileManager provides utility functions for working with files in Mongo GridFS and links to them stored in entity attributes (s.

memoryx::MongoDBRef)

Constructor & Destructor Documentation

◆ GridFileManager() [1/2]

GridFileManager ( const CommonStorageInterfacePrx & databasePrx)

Constructs new GridFileManager.

GridFileManager needs a MongoDB connection, so CommonStorage proxy needs to be specified. Cache path for files is retrived from the Application properties.

Parameters
databasePrxCommonStorage proxy. It can be obtained either directly or via getCommonStorage() method of WorkingMemory and PriorKnowledge.

◆ GridFileManager() [2/2]

GridFileManager ( const CommonStorageInterfacePrx & databasePrx,
const std::string & cachePath )

Constructs new GridFileManager.

GridFileManager needs a MongoDB connection, so CommonStorage proxy needs to be specified. Use this constructor, if you want to provide an own cache path.

Parameters
databasePrxCommonStorage proxy. It can be obtained either directly or via getCommonStorage() method of WorkingMemory and PriorKnowledge.
cachePathPath where to store cache files. Path may contain environmenta variables, which get replaced by their value.

◆ ~GridFileManager()

~GridFileManager ( )
override

Member Function Documentation

◆ addFileToAttr()

std::string addFileToAttr ( const std::string & filesDBName,
const std::string & localFileName,
EntityAttributeBasePtr & fileAttr,
const std::string & gridFSName = "" )

Stores a file in GridFS and puts a reference to it into entity attribute.

Allows to add multiple files to an attribdatabasePrxute.

Parameters
filesDBNameMongo database name to store file into
localFileNamename of a file to store (gets turned into an absolute path)
fileAttrentity attribute to store file reference into
gridFSNamename of the file in GridFS. Default: localFileName WITHOUT path
Returns
MongoDB id of the file object as returned by GridFS

◆ ensureFileInCache() [1/2]

bool ensureFileInCache ( const EntityAttributeBasePtr & fileAttr,
std::string & cacheFileName,
bool preserveOriginalName = false )

Caches the file locally and returns the filename.

Parameters
fileAttrentity attribute containing a file reference
cacheFileNamename of local file
preserveOriginalNamewhether file should be saved under its original GridFS name (true) or or it could be given a special name to simplify modification check (false). Even though the latter option is preferred, sometimes original names must be preserved because of links between files (e.g. textures in .iv file)
Returns
true on succcess, false otherwise

◆ ensureFileInCache() [2/2]

bool ensureFileInCache ( GridFileInterfacePrx & filePrx,
std::string & cacheFileName,
bool preserveOriginalName = false )

Caches the file locally and returns the filename.

Parameters
filePrxfile proxy
cacheFileNamename of local file
preserveOriginalNamewhether file should be saved under its original GridFS name (true) or or it could be given a special name to simplify modification check (false). Even though the latter option is preferred, sometimes original names must be preserved because of links between files (e.g. textures in .iv file)
Returns
true on succcess, false otherwise

◆ ensureFilesInCache() [1/2]

bool ensureFilesInCache ( const EntityAttributeBasePtr & fileAttr,
bool preserveOriginalNames = false )

Caches multiple files locally.

Version without returning the cache file names

Parameters
fileAttrentity attribute containing file references
preserveOriginalNamewhether file should be saved under its original GridFS name (true) or or it could be given a special name to simplify modification check (false). Even though the latter option is preferred, sometimes original names must be preserved because of links between files (e.g. textures in .iv file)
Returns
true on succcess, false otherwise

◆ ensureFilesInCache() [2/2]

bool ensureFilesInCache ( const EntityAttributeBasePtr & fileAttr,
std::vector< std::string > & cacheFileNames,
bool preserveOriginalNames = false )

Caches multiple files locally.

Parameters
fileAttrentity attribute containing file references
cacheFileNamesnames of caches files
preserveOriginalNamewhether file should be saved under its original GridFS name (true) or or it could be given a special name to simplify modification check (false). Even though the latter option is preferred, sometimes original names must be preserved because of links between files (e.g. textures in .iv file)
Returns
true on succcess, false otherwise

◆ getDBPrx()

CommonStorageInterfacePrx getDBPrx ( ) const
inline

◆ getFileCachePath()

std::string getFileCachePath ( ) const

Retrieves a local path where files will be cached.

◆ getFileStream() [1/2]

bool getFileStream ( const EntityAttributeBasePtr & fileAttr,
std::ifstream & fs )

Caches the file locally and opens a filestream for it.

Parameters
fileAttrentity attribute containing a file reference
fsfile stream to open.
Returns
true on succcess, false otherwise

◆ getFileStream() [2/2]

bool getFileStream ( GridFileInterfacePrx & filePrx,
std::ifstream & fs )

Caches the file locally and opens a filestream for it.

Parameters
filePrxfile proxy
fsfile stream to open.
Returns
true on succcess, false otherwise

◆ init()

void init ( std::string cachePath)
protected

◆ removeAttrDirectory()

bool removeAttrDirectory ( const EntityAttributeBasePtr & fileAttr)

Removes GridFS directory referenced by entity attribute.

Parameters
fileAttrentity attribute containing file reference(s)
Returns
true on succcess, false otherwise

◆ removeAttrFile()

bool removeAttrFile ( const EntityAttributeBasePtr & fileAttr,
unsigned int fileIndex )

◆ removeAttrFiles()

bool removeAttrFiles ( const EntityAttributeBasePtr & fileAttr)

Removes all GridFS files referenced by entity attribute.

Parameters
fileAttrentity attribute containing file reference(s)
Returns
true on succcess, false otherwise

◆ storeDirectoryToAttr()

bool storeDirectoryToAttr ( const std::string & filesDBName,
const std::string & localDirectoryName,
EntityAttributeBasePtr & fileAttr,
std::string excludeFilter = ".svn" )

Stores a complete directory tree in GridFS and puts a reference to it into entity attribute Overwrites any previously stored attribute.

Parameters
filesDBNameMongo database name to store file into
localDirectoryNamename of a directory to store
fileAttrentity attribute to store file reference into
Returns
true on succcess, false otherwise

◆ storeFilesToAttr()

bool storeFilesToAttr ( const std::string & filesDBName,
const std::string & localBaseDirectoryName,
const std::vector< std::string > & localFiles,
EntityAttributeBasePtr & fileAttr )

Stores a set of files with in GridFS and puts a reference to it into entity attribute.

The directory structure is preserved while localBaseDirectoryName and all preceding directories are removed from the filenames. Overwrites any previously stored attribute.

Parameters
filesDBNameMongo database name to store file into
localBaseDirectoryNamethe base directory. All file names will be made realtive to this directory
localFilesThe set of files. Absolute filenames.
fileAttrentity attribute to store file reference into
Returns
true on succcess, false otherwise

◆ storeFileToAttr()

std::string storeFileToAttr ( const std::string & filesDBName,
const std::string & localFileName,
EntityAttributeBasePtr & fileAttr,
const std::string & gridFSName = "" )

Stores a file in GridFS and puts a reference to it into entity attribute.

Overwrites any previously stored attribute.

Parameters
filesDBNameMongo database name to store file into
localFileNamename of a file to store
fileAttrentity attribute to store file reference into
gridFSNamename of the file in GridFS. Default: localFileName WITHOUT path
Returns
MongoDB id of the file object as returned by GridFS

The documentation for this class was generated from the following files: