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
45 public final class RightDAO implements IRightDAO
46 {
47
48 private static final String SQL_QUERY_SELECT = " SELECT id_right, name, level_right, " +
49 " admin_url, description, plugin_name, id_feature_group, icon_url, documentation_url, id_order " +
50 " FROM core_admin_right " + " WHERE id_right = ? ";
51 private static final String SQL_QUERY_INSERT = " INSERT INTO core_admin_right ( id_right , name, level_right, admin_url , " +
52 " description, plugin_name, id_feature_group, icon_url, documentation_url, id_order ) " +
53 " VALUES ( ?, ?, ?, ? , ?, ?, ?, ?, ?, ? )";
54 private static final String SQL_QUERY_UPDATE = " UPDATE core_admin_right SET name = ?, admin_url = ? , description = ? , " +
55 " plugin_name = ?, id_feature_group = ?, icon_url = ?, level_right = ?, documentation_url = ?, id_order = ? WHERE id_right = ?";
56 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 " +
57 " FROM core_admin_right WHERE level_right >= ? ORDER BY id_order ASC, id_right ASC";
58 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 " +
59 " FROM core_admin_right WHERE id_feature_group = ? ORDER BY id_order ASC, id_right ASC";
60 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 " +
61 " FROM core_admin_right WHERE id_feature_group IS null ORDER BY id_order ASC, id_right ASC";
62 private static final String SQL_QUERY_DELETE_USERRIGHT = " DELETE FROM core_user_right WHERE id_right = ?";
63 private static final String SQL_QUERY_DELETE_ADMINRIGHT = " DELETE FROM core_admin_right WHERE id_right = ?";
64
65
66
67
68
69
70
71
72 public void insert( Right right )
73 {
74 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT );
75
76 daoUtil.setString( 1, right.getId( ) );
77 daoUtil.setString( 2, right.getNameKey( ) );
78 daoUtil.setInt( 3, right.getLevel( ) );
79 daoUtil.setString( 4, right.getUrl( ) );
80 daoUtil.setString( 5, right.getDescriptionKey( ) );
81 daoUtil.setString( 6, right.getPluginName( ) );
82 daoUtil.setString( 7, right.getFeatureGroup( ) );
83 daoUtil.setString( 8, right.getIconUrl( ) );
84 daoUtil.setString( 9, right.getDocumentationUrl( ) );
85 daoUtil.setInt( 10, right.getOrder( ) );
86
87 daoUtil.executeUpdate( );
88 daoUtil.free( );
89 }
90
91
92
93
94
95
96 public Right load( String strId )
97 {
98 Right right = null;
99 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT );
100 daoUtil.setString( 1, strId );
101
102 daoUtil.executeQuery( );
103
104 if ( daoUtil.next( ) )
105 {
106 right = new Right( );
107 right.setId( daoUtil.getString( 1 ) );
108 right.setNameKey( daoUtil.getString( 2 ) );
109 right.setLevel( daoUtil.getInt( 3 ) );
110 right.setUrl( daoUtil.getString( 4 ) );
111 right.setDescriptionKey( daoUtil.getString( 5 ) );
112 right.setPluginName( daoUtil.getString( 6 ) );
113 right.setFeatureGroup( daoUtil.getString( 7 ) );
114 right.setIconUrl( daoUtil.getString( 8 ) );
115 right.setDocumentationUrl( daoUtil.getString( 9 ) );
116 right.setOrder( daoUtil.getInt( 10 ) );
117 }
118
119 daoUtil.free( );
120
121 return right;
122 }
123
124
125
126
127
128 public void delete( String strIdRight )
129 {
130
131 DAOUtil daoUtilUser = new DAOUtil( SQL_QUERY_DELETE_USERRIGHT );
132 daoUtilUser.setString( 1, strIdRight );
133 daoUtilUser.executeUpdate( );
134 daoUtilUser.free( );
135
136
137 DAOUtil daoUtilAdmin = new DAOUtil( SQL_QUERY_DELETE_ADMINRIGHT );
138 daoUtilAdmin.setString( 1, strIdRight );
139 daoUtilAdmin.executeUpdate( );
140 daoUtilAdmin.free( );
141 }
142
143
144
145
146
147 public void store( Right right )
148 {
149 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE );
150
151 daoUtil.setString( 1, right.getNameKey( ) );
152 daoUtil.setString( 2, right.getUrl( ) );
153 daoUtil.setString( 3, right.getDescriptionKey( ) );
154 daoUtil.setString( 4, right.getPluginName( ) );
155 daoUtil.setString( 5, right.getFeatureGroup( ) );
156 daoUtil.setString( 6, right.getIconUrl( ) );
157 daoUtil.setInt( 7, right.getLevel( ) );
158 daoUtil.setString( 8, right.getDocumentationUrl( ) );
159 daoUtil.setInt( 9, right.getOrder( ) );
160 daoUtil.setString( 10, right.getId( ) );
161
162 daoUtil.executeUpdate( );
163 daoUtil.free( );
164 }
165
166
167
168
169
170 public Collection<Right> selectRightsList( )
171 {
172 return selectRightsList( 0 );
173 }
174
175
176
177
178
179
180
181
182 public Collection<Right> selectRightsList( int nLevel )
183 {
184 Collection<Right> rightList = new ArrayList<Right>( );
185 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL );
186 daoUtil.setInt( 1, nLevel );
187 daoUtil.executeQuery( );
188
189 while ( daoUtil.next( ) )
190 {
191 Right right = new Right( );
192
193 right.setId( daoUtil.getString( 1 ) );
194 right.setNameKey( daoUtil.getString( 2 ) );
195 right.setLevel( daoUtil.getInt( 3 ) );
196 right.setUrl( daoUtil.getString( 4 ) );
197 right.setDescriptionKey( daoUtil.getString( 5 ) );
198 right.setPluginName( daoUtil.getString( 6 ) );
199 right.setFeatureGroup( daoUtil.getString( 7 ) );
200 right.setIconUrl( daoUtil.getString( 8 ) );
201 right.setDocumentationUrl( daoUtil.getString( 9 ) );
202 right.setOrder( daoUtil.getInt( 10 ) );
203
204 rightList.add( right );
205 }
206
207 daoUtil.free( );
208
209 return rightList;
210 }
211
212
213
214
215
216
217
218
219 public Collection<Right> selectRightsList( String strFeatureGroup )
220 {
221 Collection<Right> rightList = new ArrayList<Right>( );
222 String strQuery = SQL_QUERY_SELECTALL_FOR_FEATUREGROUP;
223
224 if ( strFeatureGroup == null )
225 {
226 strQuery = SQL_QUERY_SELECTALL_FOR_FEATUREGROUP_IS_NULL;
227 }
228
229 DAOUtil daoUtil = new DAOUtil( strQuery );
230
231 if ( strFeatureGroup != null )
232 {
233 daoUtil.setString( 1, strFeatureGroup );
234 }
235
236 daoUtil.executeQuery( );
237
238 while ( daoUtil.next( ) )
239 {
240 Right right = new Right( );
241
242 right.setId( daoUtil.getString( 1 ) );
243 right.setNameKey( daoUtil.getString( 2 ) );
244 right.setLevel( daoUtil.getInt( 3 ) );
245 right.setUrl( daoUtil.getString( 4 ) );
246 right.setDescriptionKey( daoUtil.getString( 5 ) );
247 right.setPluginName( daoUtil.getString( 6 ) );
248 right.setFeatureGroup( daoUtil.getString( 7 ) );
249 right.setIconUrl( daoUtil.getString( 8 ) );
250 right.setDocumentationUrl( daoUtil.getString( 9 ) );
251 right.setOrder( daoUtil.getInt( 10 ) );
252
253 rightList.add( right );
254 }
255
256 daoUtil.free( );
257
258 return rightList;
259 }
260 }