Wittyshare  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WsFsTreeOperations.cpp
Go to the documentation of this file.
1 /*
2  *
3  * Filename: WsFsTreeOperations.h
4  *
5  * Description:
6  *
7  * Created: 31/03/13 15:33:40
8  *
9  * Author: Benoit Daccache, ben.daccache@gmail.com
10  *
11  */
12 
13 #include "WsFsTreeOperations.h"
14 #include <iostream>
15 using namespace std;
16 #include <boost/lexical_cast.hpp>
17 
19 {
20  /* Get global properties instance */
22  m_conf = props;
23  int refresh;
24  try {
25  /* Get refresh rate of FileSystemTree */
26  refresh = boost::lexical_cast<int>(m_conf->get("global", "refresh_delay", "30"));
27  if (refresh == 0)
28  refresh = 30;
29  } catch (boost::bad_lexical_cast&) {
30  LOG(ERROR) << "WsFsDaemon::bind() : Cannot cast refresh delay to int. Check conf value. Assuming delay is 3600s";
31  refresh = 3600;
32  }
33  bool monitoring;
34  /* Check if Gamin is enabled */
35  if (m_conf->get("global", "monitoring", "false") == "true")
36  monitoring = true;
37  else
38  monitoring = false;
39  /* Instanciate the updater */
40  m_updater = new WsFsTreeUpdater(m_conf->get("global", "root_path", "."), refresh, monitoring);
41  /* Instanciate the Consultation and modification class */
42  m_consultation = new WsFsTreeConsultation(m_updater);
43  m_modification = new WsFsTreeModification(m_updater);
44 }
45 
46 
47 int WsFsTreeOperations::getPermissions( const std::set<std::string>& groups, const std::string& p)
48 {
49  return m_consultation->getPermissions(groups, p);
50 }
51 
52 WsNodeProperties* WsFsTreeOperations::getProperties ( const std::set<std::string>& groups, const std::string& p)
53 {
54  return m_consultation->getProperties(groups, p);
55 }
56 
57 std::string WsFsTreeOperations::getProperty( const std::set<std::string>& groups, const std::string& section, const std::string& p, const std::string& prop)
58 {
59  return m_consultation->getProperty(groups, section, p, prop);
60 }
61 
62 int WsFsTreeOperations::getLock(const std::set<std::string> groups, const std::string& uid, const std::string& path)
63 {
64  return m_consultation->getLock(groups, uid, path);
65 }
66 
67 int WsFsTreeOperations::putLock(const std::set<std::string> groups, const std::string& uid, const std::string& path)
68 {
69  return m_consultation->putLock(groups, uid, path);
70 }
71 
72 int WsFsTreeOperations::isLocked(const std::set<std::string> groups, const std::string& uid, const std::string& path, std::string& id)
73 {
74  return m_consultation->isLocked(groups, uid, path, id);
75 }
76 
77 WsAccessTree* WsFsTreeOperations::getAccessTree( const std::set<std::string>& groups)
78 {
79  return m_consultation->getAccessTree(groups);;
80 }
81 
82 
83 std::vector<WsResultItem> WsFsTreeOperations::getSearchResults( const std::set<std::string>& groups, const std::string& terms)
84 {
85  return m_consultation->getSearchResults(groups, terms);
86 }
87 
88 
90 {
91  return m_consultation->getRootPath();
92 }
93 
94 std::vector<std::string> WsFsTreeOperations::getTemplatesList( const std::set<std::string>& groups, const std::string& path)
95 {
96  return m_consultation->getTemplatesList(groups, path);
97 }
98 
99 int WsFsTreeOperations::saveProperties( const std::set<std::string>& groups, const std::string& json, const std::string& path)
100 {
101  return m_modification->saveProperties(groups, json, path);
102 }
103 
104 int WsFsTreeOperations::saveProperty( const std::set<std::string>& groups, const std::string& path, const std::string& section, const std::string& attr, const std::string& val)
105 {
106  return m_modification->saveProperty(groups, path, section, attr, val);
107 }
108 
109 int WsFsTreeOperations::createNode( const std::set<std::string>& groups, const std::string& uid, const string& path, int type)
110 {
111  return m_modification->createNode( groups, uid, path, type);
112 }
113 
114 int WsFsTreeOperations::deleteNode( const std::set<std::string>& groups, const std::string& uid, const string& path)
115 {
116  return m_modification->deleteNode(groups, uid, path);
117 }
118 
119 int WsFsTreeOperations::renameNode( const std::set<std::string>& groups, const std::string& uid, const string& path, const string& newPath)
120 {
121  return m_modification->renameNode(groups, uid, path, newPath);
122 }
123 
124 bool WsFsTreeOperations::isAdministrator( const std::set<std::string>& groups)
125 {
126  return m_modification->isAdministrator(groups);
127 }
128 
129 bool WsFsTreeOperations::isEditor( const std::set<std::string>& groups)
130 {
131  return m_modification->isEditor(groups);
132 }
133 
135 {
136  return m_updater->update();
137 }
138 
140 {
141  return m_consultation->getFsTreeStamp();
142 }
int putLock(const std::set< std::string > groups, const std::string &uid, const std::string &path)
unlocks the file by deleting the .config/locks/filename.lock file Only the owner of the lock can unlo...
std::string getProperty(const std::set< std::string > &groups, const std::string &section, const std::string &p, const std::string &prop)
get a property for a node corresponding to the path
Global properties class.
int saveProperty(const std::set< std::string > &groups, const std::string &path, const std::string &section, const std::string &attr, const std::string &val)
save a property of the node. The user must have access and edit rights for the node.
int saveProperties(const std::set< std::string > &groups, const std::string &json, const std::string &path)
save the properties of the node. The user must have access and edit rights for the node...
Reprensents an access tree.
Definition: WsAccessTree.h:24
Properties of a WsNode.
WsAccessTree * getAccessTree(const std::set< std::string > &groups)
Get the access tree starting from rootPath.
handles the update of the FileSystemTree
std::vector< WsResultItem > getSearchResults(const std::set< std::string > &groups, const std::string &terms)
Get the results for searching for "terms".
int renameNode(const std::set< std::string > &groups, const std::string &uid, const string &path, const string &newPath)
renames a node
int getLock(const std::set< std::string > groups, const std::string &uid, const std::string &path)
tries to acquire the lock for the path. @ return ErrorCode::Locked if the lock cannot be aquired beca...
WsNodeProperties * getProperties(const std::set< std::string > &groups, const std::string &p)
get properties of a node corresponding to the path
#define LOG
Definition: WsLogger.h:22
int getPermissions(const std::set< std::string > &groups, const std::string &p)
Get the permissions for a path for a set of groups.
Encapsulates modification operations on tree.
int deleteNode(const std::set< std::string > &groups, const std::string &uid, const string &path)
delete a node. The user must be an Admin on editor to remove the node
int isLocked(const std::set< std::string > groups, const std::string &uid, const std::string &path, std::string &id)
check is the path is already locked
bool isAdministrator(const std::set< std::string > &groups)
const std::string & getFsTreeStamp()
Get the stamp of the last WsFileSystemTree.
const std::string getRootPath()
static WsGlobalProperties * instance()
bool isEditor(const std::set< std::string > &groups)
int createNode(const std::set< std::string > &groups, const std::string &uid, const string &path, int type)
create a directory or File. If the node is a WsDirNode than it will be only accessible to the Admin a...
std::vector< std::string > getTemplatesList(const std::set< std::string > &groups, const std::string &path)
TODO.
#define ERROR
Definition: WsLogger.h:42
Encapsulates consultation of tree (no modification)
int update()
Update the WsFileSystemTree.