1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.portal.business.right;
35
36 import fr.paris.lutece.util.sql.DAOUtil;
37
38 import java.util.ArrayList;
39 import java.util.Collection;
40
41
42
43
44 public final class RightDAO implements IRightDAO
45 {
46
47 private static final String SQL_QUERY_SELECT = " SELECT id_right, name, level_right, "
48 + " admin_url, description, plugin_name, id_feature_group, icon_url, documentation_url, id_order, is_external_feature " + " FROM core_admin_right "
49 + " WHERE id_right = ? ";
50 private static final String SQL_QUERY_INSERT = " INSERT INTO core_admin_right ( id_right , name, level_right, admin_url , "
51 + " description, plugin_name, id_feature_group, icon_url, documentation_url, id_order, is_external_feature ) "
52 + " VALUES ( ?, ?, ?, ? , ?, ?, ?, ?, ?, ?, ? )";
53 private static final String SQL_QUERY_UPDATE = " UPDATE core_admin_right SET name = ?, admin_url = ? , description = ? , "
54 + " plugin_name = ?, id_feature_group = ?, icon_url = ?, level_right = ?, documentation_url = ?, id_order = ?, is_external_feature = ? WHERE id_right = ?";
55 private static final String SQL_QUERY_SELECTALL_EXTERNAL_FEATURES = " SELECT id_right, name, level_right, admin_url, description, plugin_name, id_feature_group, icon_url, documentation_url, id_order, is_external_feature "
56 + " FROM core_admin_right WHERE level_right >= ? AND is_external_feature = 1 ORDER BY id_order ASC, id_right ASC";
57 private static final String SQL_QUERY_SELECTALL = " SELECT id_right, name, level_right, admin_url, description, plugin_name, id_feature_group, icon_url, documentation_url, id_order, is_external_feature "
58 + " FROM core_admin_right WHERE level_right >= ? ORDER BY id_order ASC, id_right ASC";
59 private static final String SQL_QUERY_SELECTALL_FOR_FEATUREGROUP = " SELECT id_right, name, level_right, admin_url, description, plugin_name, id_feature_group, icon_url, documentation_url, id_order, is_external_feature "
60 + " FROM core_admin_right WHERE id_feature_group = ? ORDER BY id_order ASC, id_right ASC";
61 private static final String SQL_QUERY_SELECTALL_FOR_FEATUREGROUP_IS_NULL = " SELECT id_right, name, level_right, admin_url, description, plugin_name, id_feature_group, icon_url, documentation_url, id_order, is_external_feature "
62 + " FROM core_admin_right WHERE id_feature_group IS null ORDER BY id_order ASC, id_right ASC";
63 private static final String SQL_QUERY_DELETE_USERRIGHT = " DELETE FROM core_user_right WHERE id_right = ?";
64 private static final String SQL_QUERY_DELETE_ADMINRIGHT = " DELETE FROM core_admin_right WHERE id_right = ?";
65
66
67
68
69
70
71
72
73
74
75 public void insert( Right right )
76 {
77 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT ) )
78 {
79
80 daoUtil.setString( 1, right.getId( ) );
81 daoUtil.setString( 2, right.getNameKey( ) );
82 daoUtil.setInt( 3, right.getLevel( ) );
83 daoUtil.setString( 4, right.getUrl( ) );
84 daoUtil.setString( 5, right.getDescriptionKey( ) );
85 daoUtil.setString( 6, right.getPluginName( ) );
86 daoUtil.setString( 7, right.getFeatureGroup( ) );
87 daoUtil.setString( 8, right.getIconUrl( ) );
88 daoUtil.setString( 9, right.getDocumentationUrl( ) );
89 daoUtil.setInt( 10, right.getOrder( ) );
90 daoUtil.setBoolean( 11, right.isExternalFeature( ) );
91
92 daoUtil.executeUpdate( );
93 }
94 }
95
96
97
98
99
100
101
102
103 public Right load( String strId )
104 {
105 Right right = null;
106 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
107 {
108 daoUtil.setString( 1, strId );
109
110 daoUtil.executeQuery( );
111
112 if ( daoUtil.next( ) )
113 {
114 right = new Right( );
115 right.setId( daoUtil.getString( 1 ) );
116 right.setNameKey( daoUtil.getString( 2 ) );
117 right.setLevel( daoUtil.getInt( 3 ) );
118 right.setUrl( daoUtil.getString( 4 ) );
119 right.setDescriptionKey( daoUtil.getString( 5 ) );
120 right.setPluginName( daoUtil.getString( 6 ) );
121 right.setFeatureGroup( daoUtil.getString( 7 ) );
122 right.setIconUrl( daoUtil.getString( 8 ) );
123 right.setDocumentationUrl( daoUtil.getString( 9 ) );
124 right.setOrder( daoUtil.getInt( 10 ) );
125 right.setExternalFeature( daoUtil.getBoolean( 11 ) );
126 }
127
128 }
129
130 return right;
131 }
132
133
134
135
136
137
138
139 public void delete( String strIdRight )
140 {
141
142 try ( DAOUtilUtil.html#DAOUtil">DAOUtil daoUtilUser = new DAOUtil( SQL_QUERY_DELETE_USERRIGHT ) )
143 {
144 daoUtilUser.setString( 1, strIdRight );
145 daoUtilUser.executeUpdate( );
146 }
147
148
149 try ( DAOUtiltil.html#DAOUtil">DAOUtil daoUtilAdmin = new DAOUtil( SQL_QUERY_DELETE_ADMINRIGHT ) )
150 {
151 daoUtilAdmin.setString( 1, strIdRight );
152 daoUtilAdmin.executeUpdate( );
153 }
154 }
155
156
157
158
159
160
161
162 public void store( Right right )
163 {
164 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE ) )
165 {
166
167 daoUtil.setString( 1, right.getNameKey( ) );
168 daoUtil.setString( 2, right.getUrl( ) );
169 daoUtil.setString( 3, right.getDescriptionKey( ) );
170 daoUtil.setString( 4, right.getPluginName( ) );
171 daoUtil.setString( 5, right.getFeatureGroup( ) );
172 daoUtil.setString( 6, right.getIconUrl( ) );
173 daoUtil.setInt( 7, right.getLevel( ) );
174 daoUtil.setString( 8, right.getDocumentationUrl( ) );
175 daoUtil.setInt( 9, right.getOrder( ) );
176 daoUtil.setBoolean( 10, right.isExternalFeature( ) );
177 daoUtil.setString( 11, right.getId( ) );
178
179 daoUtil.executeUpdate( );
180 }
181 }
182
183
184
185
186
187
188 public Collection<Right> selectRightsList( )
189 {
190 return selectRightsList( 0 );
191 }
192
193
194
195
196
197
198
199
200 public Collection<Right> selectRightsList( int nLevel )
201 {
202 Collection<Right> rightList = new ArrayList<>( );
203 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL ) )
204 {
205 daoUtil.setInt( 1, nLevel );
206 daoUtil.executeQuery( );
207
208 while ( daoUtil.next( ) )
209 {
210 Rightal/business/right/Right.html#Right">Right right = new Right( );
211
212 right.setId( daoUtil.getString( 1 ) );
213 right.setNameKey( daoUtil.getString( 2 ) );
214 right.setLevel( daoUtil.getInt( 3 ) );
215 right.setUrl( daoUtil.getString( 4 ) );
216 right.setDescriptionKey( daoUtil.getString( 5 ) );
217 right.setPluginName( daoUtil.getString( 6 ) );
218 right.setFeatureGroup( daoUtil.getString( 7 ) );
219 right.setIconUrl( daoUtil.getString( 8 ) );
220 right.setDocumentationUrl( daoUtil.getString( 9 ) );
221 right.setOrder( daoUtil.getInt( 10 ) );
222 right.setExternalFeature( daoUtil.getBoolean( 11 ) );
223
224 rightList.add( right );
225 }
226
227 }
228
229 return rightList;
230 }
231
232
233
234
235
236
237 public Collection<Right> selectExternalRightsList( )
238 {
239 return selectExternalRightsList( 0 );
240 }
241
242
243
244
245
246
247
248
249 @Override
250 public Collection<Right> selectExternalRightsList( int nLevel )
251 {
252 Collection<Right> rightList = new ArrayList<>( );
253 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL_EXTERNAL_FEATURES ) )
254 {
255 daoUtil.setInt( 1, nLevel );
256 daoUtil.executeQuery( );
257
258 while ( daoUtil.next( ) )
259 {
260 Rightal/business/right/Right.html#Right">Right right = new Right( );
261
262 right.setId( daoUtil.getString( 1 ) );
263 right.setNameKey( daoUtil.getString( 2 ) );
264 right.setLevel( daoUtil.getInt( 3 ) );
265 right.setUrl( daoUtil.getString( 4 ) );
266 right.setDescriptionKey( daoUtil.getString( 5 ) );
267 right.setPluginName( daoUtil.getString( 6 ) );
268 right.setFeatureGroup( daoUtil.getString( 7 ) );
269 right.setIconUrl( daoUtil.getString( 8 ) );
270 right.setDocumentationUrl( daoUtil.getString( 9 ) );
271 right.setOrder( daoUtil.getInt( 10 ) );
272 right.setExternalFeature( daoUtil.getBoolean( 11 ) );
273
274 rightList.add( right );
275 }
276
277 }
278
279 return rightList;
280 }
281
282
283
284
285
286
287
288
289 public Collection<Right> selectRightsList( String strFeatureGroup )
290 {
291 Collection<Right> rightList = new ArrayList<>( );
292 String strQuery = SQL_QUERY_SELECTALL_FOR_FEATUREGROUP;
293
294 if ( strFeatureGroup == null )
295 {
296 strQuery = SQL_QUERY_SELECTALL_FOR_FEATUREGROUP_IS_NULL;
297 }
298
299 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( strQuery ) )
300 {
301
302 if ( strFeatureGroup != null )
303 {
304 daoUtil.setString( 1, strFeatureGroup );
305 }
306
307 daoUtil.executeQuery( );
308
309 while ( daoUtil.next( ) )
310 {
311 Rightal/business/right/Right.html#Right">Right right = new Right( );
312
313 right.setId( daoUtil.getString( 1 ) );
314 right.setNameKey( daoUtil.getString( 2 ) );
315 right.setLevel( daoUtil.getInt( 3 ) );
316 right.setUrl( daoUtil.getString( 4 ) );
317 right.setDescriptionKey( daoUtil.getString( 5 ) );
318 right.setPluginName( daoUtil.getString( 6 ) );
319 right.setFeatureGroup( daoUtil.getString( 7 ) );
320 right.setIconUrl( daoUtil.getString( 8 ) );
321 right.setDocumentationUrl( daoUtil.getString( 9 ) );
322 right.setOrder( daoUtil.getInt( 10 ) );
323 right.setExternalFeature( daoUtil.getBoolean( 11 ) );
324
325 rightList.add( right );
326 }
327
328 }
329
330 return rightList;
331 }
332 }