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.plugins.mylutece.modules.wssodatabase.authentication.business;
35
36 import fr.paris.lutece.portal.service.plugin.Plugin;
37 import fr.paris.lutece.util.sql.DAOUtil;
38
39 import java.util.ArrayList;
40 import java.util.List;
41
42
43
44
45
46 public final class WssoProfilDAO implements IWssoProfilDAO
47 {
48
49 private static final String SQL_QUERY_INSERT = " INSERT INTO mylutece_wsso_profil ( code, description ) VALUES ( ?, ? ) ";
50 private static final String SQL_QUERY_DELETE = " DELETE FROM mylutece_wsso_profil WHERE code = ? ";
51 private static final String SQL_QUERY_UPDATE_DESCRIPTION = " UPDATE mylutece_wsso_profil SET description = ? WHERE code = ? ";
52 private static final String SQL_QUERY_FIND_ALL = " SELECT code, description FROM mylutece_wsso_profil ORDER BY code, description";
53 private static final String SQL_QUERY_FIND_BY_CODE_AND_DESCRIPTION = " SELECT code, description FROM mylutece_wsso_profil WHERE code = ? and description = ?";
54 private static final String SQL_QUERY_FIND_BY_DESCRIPTION = " SELECT code, description FROM mylutece_wsso_profil WHERE description = ? ";
55 private static final String SQL_QUERY_FIND_BY_CODE = " SELECT code, description FROM mylutece_wsso_profil WHERE code = ? ";
56 private static final String SQL_SELECT_WSSO_PROFILS_CODE_FROM_PASSWORD = "SELECT b.mylutece_wsso_profil_code FROM mylutece_wsso_user a INNER JOIN mylutece_wsso_profil_user b on a.mylutece_wsso_user_id = b.mylutece_wsso_user_id AND b.mylutece_wsso_user_id = ? ";
57 private static final String SQL_QUERY_CHECK_PROFIL_ASSIGNED_TO_USER = " SELECT count(*) FROM mylutece_wsso_profil_user WHERE mylutece_wsso_profil_code = ?";
58
59
60 private static WssoProfilDAO _dao = new WssoProfilDAO( );
61
62
63
64
65 private WssoProfilDAO( )
66 {
67 }
68
69
70
71
72
73
74 static WssoProfilDAO getInstance( )
75 {
76 return _dao;
77 }
78
79
80
81
82
83
84
85 public void insert( WssoProfil wssoProfil, Plugin plugin )
86 {
87 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
88 daoUtil.setString( 1, wssoProfil.getCode( ) );
89 daoUtil.setString( 2, wssoProfil.getDescription( ) );
90
91 daoUtil.executeUpdate( );
92 daoUtil.free( );
93 }
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128 public void delete( WssoProfil wssoProfil, Plugin plugin )
129 {
130 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
131 daoUtil.setString( 1, wssoProfil.getCode( ) );
132
133 daoUtil.executeUpdate( );
134 daoUtil.free( );
135 }
136
137
138
139
140
141
142 public void store( WssoProfil wssoProfil, Plugin plugin )
143 {
144 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_DESCRIPTION, plugin );
145 daoUtil.setString( 1, wssoProfil.getDescription( ) );
146 daoUtil.setString( 2, wssoProfil.getCode( ) );
147
148 daoUtil.executeUpdate( );
149 daoUtil.free( );
150 }
151
152
153
154
155
156
157 public List<WssoProfil> selectWssoProfilList( Plugin plugin )
158 {
159 List<WssoProfil> listWssoProfils = new ArrayList<WssoProfil>( );
160 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_ALL, plugin );
161 daoUtil.executeQuery( );
162
163 while ( daoUtil.next( ) )
164 {
165 WssoProfil wssoProfil = new WssoProfil( );
166 wssoProfil.setCode( daoUtil.getString( 1 ) );
167 wssoProfil.setDescription( daoUtil.getString( 2 ) );
168
169 listWssoProfils.add( wssoProfil );
170 }
171
172 daoUtil.free( );
173
174 return listWssoProfils;
175 }
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215 public WssoProfil load( String strCode, Plugin plugin )
216 {
217 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_CODE, plugin );
218 daoUtil.setString( 1, strCode );
219 daoUtil.executeQuery( );
220
221 WssoProfil wssoProfil = null;
222
223 if ( daoUtil.next( ) )
224 {
225 wssoProfil = new WssoProfil( );
226 wssoProfil.setCode( daoUtil.getString( 1 ) );
227 wssoProfil.setDescription( daoUtil.getString( 2 ) );
228 }
229
230 daoUtil.free( );
231
232 return wssoProfil;
233 }
234
235
236
237
238
239 @Override
240 public WssoProfil findWssoProfilByCodeAndDescription( String strCode, String strDescription, Plugin plugin )
241 {
242 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_CODE_AND_DESCRIPTION, plugin );
243 daoUtil.setString( 1, strCode );
244 daoUtil.setString( 2, strDescription );
245 daoUtil.executeQuery( );
246
247 WssoProfil wssoProfil = null;
248
249 while ( daoUtil.next( ) )
250 {
251 wssoProfil = new WssoProfil( );
252 wssoProfil.setCode( daoUtil.getString( 1 ) );
253 wssoProfil.setDescription( daoUtil.getString( 2 ) );
254 }
255
256 daoUtil.free( );
257
258 return wssoProfil;
259 }
260
261
262
263
264
265 @Override
266 public List<WssoProfil> findWssoProfilsByDescription( String strDescription, Plugin plugin )
267 {
268 List<WssoProfil> listWssoProfils = new ArrayList<WssoProfil>( );
269 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_DESCRIPTION, plugin );
270 daoUtil.setString( 1, strDescription );
271 daoUtil.executeQuery( );
272
273 while ( daoUtil.next( ) )
274 {
275 WssoProfil wssoProfil = new WssoProfil( );
276 wssoProfil.setCode( daoUtil.getString( 1 ) );
277 wssoProfil.setDescription( daoUtil.getString( 2 ) );
278
279 listWssoProfils.add( wssoProfil );
280 }
281
282 daoUtil.free( );
283
284 return listWssoProfils;
285 }
286
287
288
289
290
291 @Override
292 public List<String> findWssoProfilsForUser( int nWssoUserId, Plugin plugin )
293 {
294 List<String> listCodeProfils = new ArrayList<String>( );
295 DAOUtil daoUtil = new DAOUtil( SQL_SELECT_WSSO_PROFILS_CODE_FROM_PASSWORD, plugin );
296 daoUtil.setInt( 1, nWssoUserId );
297 daoUtil.executeQuery( );
298
299 while ( daoUtil.next( ) )
300 {
301 listCodeProfils.add( daoUtil.getString( 1 ) );
302 }
303
304 daoUtil.free( );
305
306 return listCodeProfils;
307 }
308
309
310
311
312
313 @Override
314 public boolean checkProfilAssigned( String strCode, Plugin plugin )
315 {
316 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_CHECK_PROFIL_ASSIGNED_TO_USER, plugin );
317 daoUtil.setString( 1, strCode );
318 daoUtil.executeQuery( );
319
320 WssoProfil wssoProfil = null;
321
322 int nbrAssignation = 0;
323
324 while ( daoUtil.next( ) )
325 {
326 nbrAssignation = daoUtil.getInt( 1 );
327 }
328
329 daoUtil.free( );
330
331 if ( nbrAssignation > 0 )
332 {
333 return true;
334 }
335
336 return false;
337 }
338 }