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. More...
 
bool ensureFileInCache (const EntityAttributeBasePtr &fileAttr, std::string &cacheFileName, bool preserveOriginalName=false)
 Caches the file locally and returns the filename. More...
 
bool ensureFileInCache (GridFileInterfacePrx &filePrx, std::string &cacheFileName, bool preserveOriginalName=false)
 Caches the file locally and returns the filename. More...
 
bool ensureFilesInCache (const EntityAttributeBasePtr &fileAttr, bool preserveOriginalNames=false)
 Caches multiple files locally. More...
 
bool ensureFilesInCache (const EntityAttributeBasePtr &fileAttr, std::vector< std::string > &cacheFileNames, bool preserveOriginalNames=false)
 Caches multiple files locally. More...
 
CommonStorageInterfacePrx getDBPrx () const
 
std::string getFileCachePath () const
 Retrieves a local path where files will be cached. More...
 
bool getFileStream (const EntityAttributeBasePtr &fileAttr, std::ifstream &fs)
 Caches the file locally and opens a filestream for it. More...
 
bool getFileStream (GridFileInterfacePrx &filePrx, std::ifstream &fs)
 Caches the file locally and opens a filestream for it. More...
 
 GridFileManager (const CommonStorageInterfacePrx &databasePrx)
 Constructs new GridFileManager. More...
 
 GridFileManager (const CommonStorageInterfacePrx &databasePrx, const std::string &cachePath)
 Constructs new GridFileManager. More...
 
bool removeAttrDirectory (const EntityAttributeBasePtr &fileAttr)
 Removes GridFS directory referenced by entity attribute. More...
 
bool removeAttrFile (const EntityAttributeBasePtr &fileAttr, unsigned int fileIndex)
 
bool removeAttrFiles (const EntityAttributeBasePtr &fileAttr)
 Removes all GridFS files referenced by entity attribute. More...
 
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. More...
 
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. More...
 
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. More...
 
 ~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. More...
 
MessageTypeT getEffectiveLoggingLevel () const
 
 Logging ()
 
void setLocalMinimumLoggingLevel (MessageTypeT level)
 With setLocalMinimumLoggingLevel the minimum verbosity-level of log-messages can be set. More...
 
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 LogSenderPtrgetLogSender () const
 Retrieve log sender. More...
 
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)

Definition at line 42 of file GridFileManager.h.

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.

Definition at line 40 of file GridFileManager.cpp.

+ Here is the call graph for this function:

◆ 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.

Definition at line 55 of file GridFileManager.cpp.

+ Here is the call graph for this function:

◆ ~GridFileManager()

~GridFileManager ( )
override

Definition at line 63 of file GridFileManager.cpp.

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

Definition at line 256 of file GridFileManager.cpp.

+ Here is the caller graph for this function:

◆ 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

Definition at line 173 of file GridFileManager.cpp.

+ Here is the call graph for this function:

◆ 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

Definition at line 99 of file GridFileManager.cpp.

+ Here is the caller graph for this function:

◆ 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

Definition at line 217 of file GridFileManager.cpp.

+ Here is the call graph for this function:

◆ 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

Definition at line 191 of file GridFileManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDBPrx()

CommonStorageInterfacePrx getDBPrx ( ) const
inline

Definition at line 232 of file GridFileManager.h.

◆ getFileCachePath()

std::string getFileCachePath ( ) const

Retrieves a local path where files will be cached.

Definition at line 94 of file GridFileManager.cpp.

◆ 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

Definition at line 240 of file GridFileManager.cpp.

+ Here is the call graph for this function:

◆ 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

Definition at line 225 of file GridFileManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init()

void init ( std::string  cachePath)
protected

Definition at line 67 of file GridFileManager.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 
)

Definition at line 350 of file GridFileManager.cpp.

+ Here is the caller graph for this function:

◆ 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

Definition at line 364 of file GridFileManager.cpp.

+ Here is the call graph for this function:

◆ 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

Definition at line 290 of file GridFileManager.cpp.

+ Here is the call graph for this function:

◆ 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

Definition at line 326 of file GridFileManager.cpp.

+ Here is the call graph for this function:

◆ 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

Definition at line 249 of file GridFileManager.cpp.

+ Here is the call graph for this function:

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