Wtx ~ Wt Extension Library
WtxLib
PermissionItemTpl.h
1 /**************************************************************************
2 ###########################################################################
3 ##
4 ## $SHOWOFFDB_BEGIN_LICENSE$
5 ## Copyright (C) 2011 Lorimark Solutions, LLC and/or its subsidiary(-ies).
6 ## All rights reserved.
7 ## Contact: Lorimark Solutions, LLC (info@showoff-db.org)
8 ##
9 ## This file is part of the Showoff Database Application Framework.
10 ##
11 ## Commercial Usage
12 ## Licensees holding valid ShowoffDB Commercial licenses may use this file in
13 ## accordance with the ShowoffDB Commercial License Agreement provided with the
14 ## Software or, alternatively, in accordance with the terms contained in
15 ## a written agreement between you and Lorimark Solutions, LLC.
16 ##
17 ## GNU Lesser General Public License Usage
18 ## Alternatively, this file may be used under the terms of the GNU Lesser
19 ## General Public License version 2.1 as published by the Free Software
20 ## Foundation and appearing in the file LICENSE.LGPL included in the
21 ## packaging of this file. Please review the following information to
22 ## ensure the GNU Lesser General Public License version 2.1 requirements
23 ## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ##
25 ## In addition, as a special exception, Lorimark Solutions, LLC gives
26 ## you certain additional rights. These rights are described in the
27 ## Lorimark Solutions, LLC ShowoffDB LGPL Exception version 1.0, included in
28 ## the file LGPL_EXCEPTION.txt in this package.
29 ##
30 ## GNU General Public License Usage
31 ## Alternatively, this file may be used under the terms of the GNU
32 ## General Public License version 3.0 as published by the Free Software
33 ## Foundation and appearing in the file LICENSE.GPL included in the
34 ## packaging of this file. Please review the following information to
35 ## ensure the GNU General Public License version 3.0 requirements will be
36 ## met: http://www.gnu.org/copyleft/gpl.html.
37 ##
38 ## If you have questions regarding the use of this file, please contact
39 ## Lorimark Solutions, LLC at info@showoff-db.org.
40 ## $SHOWOFFDB_END_LICENSE$
41 ##
42 #############################################################################
43 ****************************************************************************/
44 
45 
46 #ifndef __WTX_DBO_PERMISSIONITEMTPL_H_234e0174_6b7d_11e8_b503_fb1ef3651ec0__
47 #define __WTX_DBO_PERMISSIONITEMTPL_H_234e0174_6b7d_11e8_b503_fb1ef3651ec0__
48 
49 #include <Wt/WLocalDateTime.h>
50 
51 #include <Wtx/Dbo/PermissionTableDef.h>
52 #include <Wtx/Dbo/BaseItemTpl.h>
53 #include <Wtx/Dbo/FieldNumber.h>
54 #include <Wtx/Dbo/FieldFloat.h>
55 #include <Wtx/Dbo/FieldInt.h>
56 #include <Wtx/Dbo/FieldBigInt.h>
57 #include <Wtx/Dbo/FieldCurrency.h>
58 #include <Wtx/Dbo/FieldLookup.h>
59 #include <Wtx/Dbo/FieldBoolean.h>
60 #include <Wtx/Dbo/FieldTextLine.h>
61 #include <Wtx/Dbo/FieldTextMemo.h>
62 #include <Wtx/Dbo/FieldDate.h>
63 #include <Wtx/Dbo/FieldDateTime.h>
64 #include <Wtx/Dbo/FieldHasMany.h>
65 #include <Wtx/Dbo/FieldBelongsTo.h>
66 #include <Wtx/Dbo/FieldWeak.h>
67 
68 #ifdef UIDFIELD_FORMAT_UUID
69 #include <uuid/uuid.h>
70 #else
71 #include <Wt/WRandom.h>
72 #endif
73 
74 namespace Wtx {
75  namespace Dbo {
76 
77 template <class C> class PermissionItemTpl
78 : public BaseItemTpl<C>
79 {
80  public:
81 
83  : BaseItemTpl<C>()
84  {
85  }
86 
87  PermissionItemTpl( const std::string & key, const std::string & cfy = "" )
88  : BaseItemTpl<C>( key, cfy )
89  {
90  createdOn().setValue( Wt::WDateTime( Wt::WLocalDateTime::currentDateTime().date(), Wt::WLocalDateTime::currentDateTime().time() ) );
91  changedOn().setValue( Wt::WDateTime( Wt::WLocalDateTime::currentDateTime().date(), Wt::WLocalDateTime::currentDateTime().time() ) );
92 
93 #ifdef UIDFIELD_FORMAT_UUID
94  /*
95  ** generate a more complicated uuid string
96  **
97  ** In order to generate a uuid string, a few libraries need to be
98  ** linked in to the project. On linux this is done with the
99  ** following:
100  **
101  ** sudo apt-get install uuid-dev
102  **
103  ** To use the uuid method the following things need to be added
104  ** to the CMAKE:
105  **
106  ** add_definitions(-DUIDFIELD_FORMAT_UUID)
107  ** target_link_libraries(myproject wt wthttp wtdbo wtdbosqlite3 uuid)
108  **
109  */
110  uuid_t uuid;
111  uuid_generate(uuid);
112 
113  char uuidout[41];
114  uuidout[0] = '{';
115  uuid_unparse_lower( uuid, uuidout+1 );
116  uuidout[37] = '}';
117  uuidout[38] = 0;
118  uidField.setValue( std::string( uuidout ) );
119 #else
120  /*
121  ** generate simple random string
122  **
123  */
124  uidField().setValue( Wt::WRandom::generateId(20) );
125 #endif
126 
127  pMode().setValue(0);
128  pUser().setValue(0);
129  pGroup().setValue(0);
130  }
131 
132  virtual ~PermissionItemTpl()
133  {
134  }
135 
136  static PermissionTableDef & TableDef()
137  {
138  return C::TableDef();
139  }
140 
141  Wtx::Dbo::Field<std::string> & uidField() { return m_uidField; }
142  const Wtx::Dbo::Field<std::string> & uidField() const { return m_uidField; }
143 
144  Wtx::Dbo::FieldNumber & pMode() { return m_pMode; }
145  const Wtx::Dbo::FieldNumber & pMode() const { return m_pMode; }
146 
147  Wtx::Dbo::FieldDateTime & createdOn() { return m_createdOn; }
148  const Wtx::Dbo::Field<Wt::WDateTime> & createdOn() const { return m_createdOn; }
149 
150  Wtx::Dbo::FieldDateTime & changedOn() { return m_changedOn; }
151  const Wtx::Dbo::Field<Wt::WDateTime> & changedOn() const { return m_changedOn; }
152 
153  Wtx::Dbo::Field<int> & pUser() { return m_pUser; }
154  const Wtx::Dbo::Field<int> & pUser() const { return m_pUser; }
155 
156  Wtx::Dbo::Field<int> & pGroup() { return m_pGroup; }
157  const Wtx::Dbo::Field<int> & pGroup() const { return m_pGroup; }
158 
159  Wtx::Dbo::Field<std::string> & sessionLock() { return m_sessionLock; }
160  const Wtx::Dbo::Field<std::string> & sessionLock() const { return m_sessionLock; }
161 
162  bool setLock( const std::string & value )
163  {
164  sessionLock()
165  .setValue
166  (
167  Wt::WString("{1},{2}")
168  .arg( Wt::WDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz").toUTF8() )
169  .arg( value )
170  .toUTF8()
171  );
172 
173  return true;
174  }
175 
176  bool unLock()
177  {
178  sessionLock()
179  .setValue("");
180 
181  return true;
182  }
183 
184  bool isLocked() const
185  {
186  return sessionLock().value() != "";
187  }
188 
189  Wt::WDateTime lockTime() const
190  {
191  return Wt::WDateTime::fromString( sessionLock().value(), "yyyyMMddhhmmsszzz" );
192  }
193 
194  Wtx::Dbo::Field<std::string> m_uidField;
195  Wtx::Dbo::FieldNumber m_pMode;
196  Wtx::Dbo::FieldDateTime m_createdOn;
197  Wtx::Dbo::FieldDateTime m_changedOn;
198  Wtx::Dbo::Field<int> m_pUser;
199  Wtx::Dbo::Field<int> m_pGroup;
200  Wtx::Dbo::Field<std::string> m_sessionLock;
201 
202  template<class Action> void persist( Action & a )
203  {
205  m_uidField.persist( a, &TableDef().UidFieldDef );
206  m_pMode.persist( a, &TableDef().PModeFieldDef );
207  m_createdOn.persist( a, &TableDef().CreatedOnFieldDef );
208  m_changedOn.persist( a, &TableDef().ChangedOnFieldDef );
209 // pUser.persist( a, &TableDef().PUserFieldDef );
210 // pGroup.persist( a, &TableDef().PGroupFieldDef );
211  m_sessionLock.persist( a, &TableDef().SessionLockFieldDef );
212  }
213 
214  private:
215 
216 }; // endtemplate <class C> class PermissionItemTpl
217 
218  } // endnamespace Dbo
219 } // endnamespace Wtx
220 
221 
222 #endif
223 
224 
Table Definition.
Definition: TableDef.h:72
witty extension library
Definition: Activity.h:51