|
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>
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 LogSenderPtr & | getLogSender () 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 |
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them stored in entity attributes (s.
Definition at line 42 of file GridFileManager.h.
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.
databasePrx | CommonStorage proxy. It can be obtained either directly or via getCommonStorage() method of WorkingMemory and PriorKnowledge. |
Definition at line 40 of file GridFileManager.cpp.
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.
databasePrx | CommonStorage proxy. It can be obtained either directly or via getCommonStorage() method of WorkingMemory and PriorKnowledge. |
cachePath | Path where to store cache files. Path may contain environmenta variables, which get replaced by their value. |
Definition at line 55 of file GridFileManager.cpp.
|
override |
Definition at line 63 of file GridFileManager.cpp.
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.
filesDBName | Mongo database name to store file into |
localFileName | name of a file to store (gets turned into an absolute path) |
fileAttr | entity attribute to store file reference into |
gridFSName | name of the file in GridFS. Default: localFileName WITHOUT path |
Definition at line 256 of file GridFileManager.cpp.
bool ensureFileInCache | ( | const EntityAttributeBasePtr & | fileAttr, |
std::string & | cacheFileName, | ||
bool | preserveOriginalName = false |
||
) |
Caches the file locally and returns the filename.
fileAttr | entity attribute containing a file reference |
cacheFileName | name of local file |
preserveOriginalName | whether 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) |
Definition at line 173 of file GridFileManager.cpp.
bool ensureFileInCache | ( | GridFileInterfacePrx & | filePrx, |
std::string & | cacheFileName, | ||
bool | preserveOriginalName = false |
||
) |
Caches the file locally and returns the filename.
filePrx | file proxy |
cacheFileName | name of local file |
preserveOriginalName | whether 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) |
Definition at line 99 of file GridFileManager.cpp.
bool ensureFilesInCache | ( | const EntityAttributeBasePtr & | fileAttr, |
bool | preserveOriginalNames = false |
||
) |
Caches multiple files locally.
Version without returning the cache file names
fileAttr | entity attribute containing file references |
preserveOriginalName | whether 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) |
Definition at line 217 of file GridFileManager.cpp.
bool ensureFilesInCache | ( | const EntityAttributeBasePtr & | fileAttr, |
std::vector< std::string > & | cacheFileNames, | ||
bool | preserveOriginalNames = false |
||
) |
Caches multiple files locally.
fileAttr | entity attribute containing file references |
cacheFileNames | names of caches files |
preserveOriginalName | whether 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) |
Definition at line 191 of file GridFileManager.cpp.
|
inline |
Definition at line 232 of file GridFileManager.h.
std::string getFileCachePath | ( | ) | const |
Retrieves a local path where files will be cached.
Definition at line 94 of file GridFileManager.cpp.
bool getFileStream | ( | const EntityAttributeBasePtr & | fileAttr, |
std::ifstream & | fs | ||
) |
Caches the file locally and opens a filestream for it.
fileAttr | entity attribute containing a file reference |
fs | file stream to open. |
Definition at line 240 of file GridFileManager.cpp.
bool getFileStream | ( | GridFileInterfacePrx & | filePrx, |
std::ifstream & | fs | ||
) |
Caches the file locally and opens a filestream for it.
filePrx | file proxy |
fs | file stream to open. |
Definition at line 225 of file GridFileManager.cpp.
|
protected |
Definition at line 67 of file GridFileManager.cpp.
bool removeAttrDirectory | ( | const EntityAttributeBasePtr & | fileAttr | ) |
Removes GridFS directory referenced by entity attribute.
fileAttr | entity attribute containing file reference(s) |
bool removeAttrFile | ( | const EntityAttributeBasePtr & | fileAttr, |
unsigned int | fileIndex | ||
) |
bool removeAttrFiles | ( | const EntityAttributeBasePtr & | fileAttr | ) |
Removes all GridFS files referenced by entity attribute.
fileAttr | entity attribute containing file reference(s) |
Definition at line 364 of file GridFileManager.cpp.
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.
filesDBName | Mongo database name to store file into |
localDirectoryName | name of a directory to store |
fileAttr | entity attribute to store file reference into |
Definition at line 290 of file GridFileManager.cpp.
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.
filesDBName | Mongo database name to store file into |
localBaseDirectoryName | the base directory. All file names will be made realtive to this directory |
localFiles | The set of files. Absolute filenames. |
fileAttr | entity attribute to store file reference into |
Definition at line 326 of file GridFileManager.cpp.
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.
filesDBName | Mongo database name to store file into |
localFileName | name of a file to store |
fileAttr | entity attribute to store file reference into |
gridFSName | name of the file in GridFS. Default: localFileName WITHOUT path |
Definition at line 249 of file GridFileManager.cpp.