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.directory.business;
35
36 import fr.paris.lutece.plugins.directory.utils.DirectoryUtils;
37 import fr.paris.lutece.portal.service.plugin.Plugin;
38 import fr.paris.lutece.portal.service.util.AppLogService;
39 import fr.paris.lutece.util.sql.DAOUtil;
40
41 import java.util.ArrayList;
42 import java.util.List;
43
44
45
46
47 public final class EntryDAO implements IEntryDAO
48 {
49
50 private static final String SQL_QUERY_NEW_PK = "SELECT MAX( id_entry ) FROM directory_entry";
51 private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = "SELECT ent.id_type,typ.title_key,typ.is_group,"
52 + "typ.is_comment,typ.is_mylutece_user,typ.class_name,ent.id_entry,ent.id_directory,directory.title,ent.id_entry_parent,ent.title,"
53 + "ent.help_message,ent.help_message_search,ent.entry_comment,ent.is_mandatory,ent.is_indexed,ent.is_indexed_as_title,ent.is_indexed_as_summary,"
54 + "ent.is_shown_in_search,ent.is_shown_in_result_list,ent.is_shown_in_result_record,ent.is_fields_in_line,ent.entry_position,"
55 + "ent.display_width,ent.display_height,ent.is_role_associated,ent.is_workgroup_associated,ent.is_multiple_search_fields,ent.is_shown_in_history,ent.id_entry_associate,ent.request_sql,ent.is_add_value_search_all,ent.label_value_search_all,ent.map_provider,ent.is_autocomplete_entry,ent.is_shown_in_export,ent.is_shown_in_completeness, ent.num_row, ent.num_column "
56 + "FROM directory_entry ent,directory_entry_type typ,directory_directory directory WHERE ent.id_entry = ? and ent.id_type=typ.id_type and "
57 + "ent.id_directory=directory.id_directory";
58 private static final String SQL_QUERY_INSERT = "INSERT INTO directory_entry ( "
59 + "id_entry,id_entry_parent,id_directory,id_type,title,help_message,help_message_search,entry_comment,is_mandatory,"
60 + "is_indexed,is_indexed_as_title,is_indexed_as_summary,is_shown_in_search,is_shown_in_result_list,is_shown_in_result_record,is_fields_in_line,entry_position,display_width,display_height "
61 + ",is_role_associated,is_workgroup_associated,is_multiple_search_fields,is_shown_in_history,id_entry_associate,request_sql,is_add_value_search_all,label_value_search_all,map_provider,is_autocomplete_entry,is_shown_in_export,is_shown_in_completeness, num_row, num_column )VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
62 private static final String SQL_QUERY_DELETE = "DELETE FROM directory_entry WHERE id_entry = ? ";
63 private static final String SQL_QUERY_UPDATE = "UPDATE directory_entry SET "
64 + "id_entry=?,id_entry_parent=?,id_directory=?,id_type=?,title=?,help_message=?,help_message_search=?,"
65 + "entry_comment=?,is_mandatory=?,is_indexed=?,is_indexed_as_title=?,is_indexed_as_summary=?,is_shown_in_search=?,is_shown_in_result_list=?,"
66 + "is_shown_in_result_record=?,is_fields_in_line=?,entry_position=? ,display_width=?,display_height=?,"
67 + "is_role_associated=?,is_workgroup_associated=?,is_multiple_search_fields=?,is_shown_in_history=?,id_entry_associate=?,request_sql=?,is_add_value_search_all=?,label_value_search_all=?, map_provider=?, is_autocomplete_entry=?, is_shown_in_export=?, is_shown_in_completeness=?, num_row = ?, num_column = ? WHERE id_entry=?";
68 private static final String SQL_QUERY_SELECT_ENTRY_BY_FILTER = "SELECT ent.id_type,typ.title_key,typ.is_group,"
69 + "typ.is_comment,typ.is_mylutece_user,typ.class_name,ent.id_entry,ent.id_directory,"
70 + "ent.id_entry_parent,ent.title,ent.help_message,ent.help_message_search,"
71 + "ent.entry_comment,ent.is_mandatory,ent.is_indexed,ent.is_indexed_as_title,ent.is_indexed_as_summary,ent.is_shown_in_search,ent.is_shown_in_result_list,ent.is_shown_in_result_record,"
72 + "ent.is_fields_in_line,ent.entry_position,ent.display_width,ent.display_height,ent.is_role_associated,ent.is_workgroup_associated, "
73 + "ent.is_multiple_search_fields,ent.is_shown_in_history,ent.id_entry_associate ,ent.request_sql,ent.is_add_value_search_all,ent.label_value_search_all,ent.map_provider,ent.is_autocomplete_entry,ent.is_shown_in_export,ent.is_shown_in_completeness "
74 + "FROM directory_entry ent,directory_entry_type typ ";
75 private static final String SQL_QUERY_SELECT_ENTRY_ANONYMIZE = "SELECT ent.id_entry, ent.title, ent.anonymize, det.class_name, det.title_key FROM directory_entry ent INNER JOIN directory_entry_type det ON (ent.id_type=det.id_type) ";
76 private static final String SQL_QUERY_UPDATE_ENTRY_ANONYMIZE = "UPDATE directory_entry SET anonymize = ? WHERE id_entry = ?";
77 private static final String SQL_QUERY_SELECT_NUMBER_ENTRY_BY_FILTER = "SELECT COUNT(ent.id_entry) " + "FROM directory_entry ent,directory_entry_type typ ";
78 private static final String SQL_QUERY_NEW_POSITION = "SELECT MAX(entry_position) " + "FROM directory_entry WHERE id_directory = ? ";
79 private static final String SQL_FILTER_ID_DIRECTORY = " ent.id_directory = ? ";
80 private static final String SQL_FILTER_POSITION = " ent.entry_position = ? ";
81 private static final String SQL_FILTER_ID_PARENT = " ent.id_entry_parent = ? ";
82 private static final String SQL_FILTER_ID_PARENT_IS_NULL = " ent.id_entry_parent IS NULL ";
83 private static final String SQL_FILTER_IS_GROUP = " typ.is_group = ? ";
84 private static final String SQL_FILTER_IS_COMMENT = " typ.is_comment = ? ";
85 private static final String SQL_FILTER_IS_MYLUTECE_USER = " typ.is_mylutece_user = ? ";
86 private static final String SQL_FILTER_IS_SHOWN_IN_RESULT_LIST = " ent.is_shown_in_result_list=?";
87 private static final String SQL_FILTER_IS_SHOWN_IN_RESULT_RECORD = " ent.is_shown_in_result_record=?";
88 private static final String SQL_FILTER_IS_SHOWN_IN_HISTORY = " ent.is_shown_in_history=?";
89 private static final String SQL_FILTER_IS_INDEXED = " ent.is_indexed=?";
90 private static final String SQL_FILTER_IS_INDEXED_AS_TITLE = " ent.is_indexed_as_title=?";
91 private static final String SQL_FILTER_IS_INDEXED_AS_SUMMARY = " ent.is_indexed_as_summary=?";
92 private static final String SQL_FILTER_IS_ROLE_ASSOCIATED = " ent.is_role_associated=?";
93 private static final String SQL_FILTER_IS_WORKGROUP_ASSOCIATED = " ent.is_workgroup_associated=?";
94 private static final String SQL_FILTER_ASSOCIATION_ON_ID_TYPE = " ent.id_type=typ.id_type";
95 private static final String SQL_ORDER_BY_POSITION = " ORDER BY ent.entry_position ";
96 private static final String SQL_FILTER_ID_TYPE = " typ.id_type = ? ";
97 private static final String SQL_FILTER_ID_ENTRY_ASSOCIATE = " ent.id_entry_associate = ? ";
98 private static final String SQL_FILTER_IS_AUTOCOMPLETE_ENTRY = " ent.is_autocomplete_entry = ? ";
99 private static final String SQL_FILTER_IS_SHOWN_IN_EXPORT = " ent.is_shown_in_export = ? ";
100 private static final String SQL_FILTER_IS_SHOWN_IN_COMPLETENESS = " ent.is_shown_in_completeness = ? ";
101 private static final String CONSTANT_PARENTHESIS_LEFT = " ( ";
102 private static final String CONSTANT_PARENTHESIS_RIGHT = " ) ";
103 private static final String SQL_QUERY_SELECT_ENTRIES_WITHOUT_PARENT = "SELECT ent.id_type,typ.title_key,typ.is_group,"
104 + "typ.is_comment,typ.is_mylutece_user,typ.class_name,ent.id_entry,ent.id_directory,"
105 + "ent.id_entry_parent,ent.title,ent.help_message,ent.help_message_search,"
106 + "ent.entry_comment,ent.is_mandatory,ent.is_indexed,ent.is_indexed_as_title,ent.is_indexed_as_summary,ent.is_shown_in_search,ent.is_shown_in_result_list,ent.is_shown_in_result_record,"
107 + "ent.is_fields_in_line,ent.entry_position,ent.display_width,ent.display_height,ent.is_role_associated,ent.is_workgroup_associated, "
108 + "ent.is_multiple_search_fields,ent.is_shown_in_history,ent.id_entry_associate ,ent.request_sql,ent.is_add_value_search_all,ent.label_value_search_all,ent.map_provider,ent.is_autocomplete_entry,ent.is_shown_in_export,ent.is_shown_in_completeness "
109 + "FROM directory_entry ent,directory_entry_type typ WHERE ent.id_type = typ.id_type AND id_entry_parent IS NULL AND id_directory=? ORDER BY ent.entry_position ";
110
111
112
113
114
115
116
117
118 private int newPrimaryKey( Plugin plugin )
119 {
120 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_PK, plugin );
121 daoUtil.executeQuery( );
122
123 int nKey;
124
125 if ( !daoUtil.next( ) )
126 {
127
128 nKey = 1;
129 }
130
131 nKey = daoUtil.getInt( 1 ) + 1;
132 daoUtil.free( );
133
134 return nKey;
135 }
136
137
138
139
140
141
142
143
144
145
146 private int newPosition( int nIdDirectory, Plugin plugin )
147 {
148 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_POSITION, plugin );
149 daoUtil.setInt( 1, nIdDirectory );
150 daoUtil.executeQuery( );
151
152 int nPos;
153
154 if ( !daoUtil.next( ) )
155 {
156
157 nPos = 1;
158 }
159
160 nPos = daoUtil.getInt( 1 ) + 1;
161 daoUtil.free( );
162
163 return nPos;
164 }
165
166
167
168
169 @Override
170 public synchronized int insert( IEntry entry, Plugin plugin )
171 {
172 entry.setIdEntry( newPrimaryKey( plugin ) );
173 entry.setPosition( newPosition( entry.getDirectory( ).getIdDirectory( ), plugin ) );
174
175 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, plugin );
176 daoUtil.setInt( 1, entry.getIdEntry( ) );
177
178 if ( entry.getParent( ) != null )
179 {
180 daoUtil.setInt( 2, entry.getParent( ).getIdEntry( ) );
181 }
182 else
183 {
184 daoUtil.setIntNull( 2 );
185 }
186
187 daoUtil.setInt( 3, entry.getDirectory( ).getIdDirectory( ) );
188 daoUtil.setInt( 4, entry.getEntryType( ).getIdType( ) );
189 daoUtil.setString( 5, trimEntryTitle( entry ) );
190 daoUtil.setString( 6, entry.getHelpMessage( ) );
191 daoUtil.setString( 7, entry.getHelpMessageSearch( ) );
192 daoUtil.setString( 8, entry.getComment( ) );
193 daoUtil.setBoolean( 9, entry.isMandatory( ) );
194 daoUtil.setBoolean( 10, entry.isIndexed( ) );
195 daoUtil.setBoolean( 11, entry.isIndexedAsTitle( ) );
196 daoUtil.setBoolean( 12, entry.isIndexedAsSummary( ) );
197 daoUtil.setBoolean( 13, entry.isShownInAdvancedSearch( ) );
198 daoUtil.setBoolean( 14, entry.isShownInResultList( ) );
199 daoUtil.setBoolean( 15, entry.isShownInResultRecord( ) );
200 daoUtil.setBoolean( 16, entry.isFieldInLine( ) );
201 daoUtil.setInt( 17, entry.getPosition( ) );
202 daoUtil.setInt( 18, entry.getDisplayWidth( ) );
203 daoUtil.setInt( 19, entry.getDisplayHeight( ) );
204 daoUtil.setBoolean( 20, entry.isRoleAssociated( ) );
205 daoUtil.setBoolean( 21, entry.isWorkgroupAssociated( ) );
206 daoUtil.setBoolean( 22, entry.isMultipleSearchFields( ) );
207 daoUtil.setBoolean( 23, entry.isShownInHistory( ) );
208 daoUtil.setInt( 24, entry.getEntryAssociate( ) );
209 daoUtil.setString( 25, entry.getRequestSQL( ) );
210 daoUtil.setBoolean( 26, entry.isAddValueAllSearch( ) );
211 daoUtil.setString( 27, entry.getLabelValueAllSearch( ) );
212
213
214 String strMapProvider = ( entry.getMapProvider( ) == null ) ? DirectoryUtils.EMPTY_STRING : entry.getMapProvider( ).getKey( );
215 daoUtil.setString( 28, strMapProvider );
216 daoUtil.setBoolean( 29, entry.isAutocompleteEntry( ) );
217 daoUtil.setBoolean( 30, entry.isShownInExport( ) );
218 daoUtil.setBoolean( 31, entry.isShownInCompleteness( ) );
219 daoUtil.setInt( 32, entry.getNumberRow( ) );
220 daoUtil.setInt( 33, entry.getNumberColumn( ) );
221
222 daoUtil.executeUpdate( );
223 daoUtil.free( );
224
225 return entry.getIdEntry( );
226 }
227
228
229
230
231 @Override
232 public IEntry load( int nId, Plugin plugin )
233 {
234 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, plugin );
235 daoUtil.setInt( 1, nId );
236 daoUtil.executeQuery( );
237
238 boolean bException = false;
239 IEntry entry = null;
240 EntryType entryType = null;
241 IEntry entryParent = null;
242 Directory directory = null;
243
244 if ( daoUtil.next( ) )
245 {
246 entryType = new EntryType( );
247 entryType.setIdType( daoUtil.getInt( 1 ) );
248 entryType.setTitleI18nKey( daoUtil.getString( 2 ) );
249 entryType.setGroup( daoUtil.getBoolean( 3 ) );
250 entryType.setComment( daoUtil.getBoolean( 4 ) );
251 entryType.setMyLuteceUser( daoUtil.getBoolean( 5 ) );
252 entryType.setClassName( daoUtil.getString( 6 ) );
253
254 try
255 {
256 entry = (IEntry) Class.forName( entryType.getClassName( ) ).newInstance( );
257 }
258 catch( ClassNotFoundException e )
259 {
260
261 AppLogService.error( e );
262 bException = true;
263 }
264 catch( InstantiationException e )
265 {
266
267 AppLogService.error( e );
268 bException = true;
269 }
270 catch( IllegalAccessException e )
271 {
272
273 AppLogService.error( e );
274 bException = true;
275 }
276
277 if ( bException )
278 {
279 daoUtil.free( );
280
281 return null;
282 }
283
284 entry.setEntryType( entryType );
285 entry.setIdEntry( daoUtil.getInt( 7 ) );
286
287 directory = new Directory( );
288 directory.setIdDirectory( daoUtil.getInt( 8 ) );
289 directory.setTitle( daoUtil.getString( 9 ) );
290 entry.setDirectory( directory );
291
292 if ( daoUtil.getObject( 10 ) != null )
293 {
294 entryParent = new Entry( );
295 entryParent.setIdEntry( daoUtil.getInt( 10 ) );
296 entry.setParent( entryParent );
297 }
298
299 entry.setTitle( daoUtil.getString( 11 ) );
300 entry.setHelpMessage( daoUtil.getString( 12 ) );
301 entry.setHelpMessageSearch( daoUtil.getString( 13 ) );
302 entry.setComment( daoUtil.getString( 14 ) );
303 entry.setMandatory( daoUtil.getBoolean( 15 ) );
304 entry.setIndexed( daoUtil.getBoolean( 16 ) );
305 entry.setIndexedAsTitle( daoUtil.getBoolean( 17 ) );
306 entry.setIndexedAsSummary( daoUtil.getBoolean( 18 ) );
307 entry.setShownInAdvancedSearch( daoUtil.getBoolean( 19 ) );
308 entry.setShownInResultList( daoUtil.getBoolean( 20 ) );
309 entry.setShownInResultRecord( daoUtil.getBoolean( 21 ) );
310 entry.setFieldInLine( daoUtil.getBoolean( 22 ) );
311 entry.setPosition( daoUtil.getInt( 23 ) );
312 entry.setDisplayWidth( daoUtil.getInt( 24 ) );
313 entry.setDisplayHeight( daoUtil.getInt( 25 ) );
314 entry.setRoleAssociated( daoUtil.getBoolean( 26 ) );
315 entry.setWorkgroupAssociated( daoUtil.getBoolean( 27 ) );
316 entry.setMultipleSearchFields( daoUtil.getBoolean( 28 ) );
317 entry.setShownInHistory( daoUtil.getBoolean( 29 ) );
318 entry.setEntryAssociate( daoUtil.getInt( 30 ) );
319 entry.setRequestSQL( daoUtil.getString( 31 ) );
320 entry.setAddValueAllSearch( daoUtil.getBoolean( 32 ) );
321 entry.setLabelValueAllSearch( daoUtil.getString( 33 ) );
322 entry.setMapProvider( MapProviderManager.getMapProvider( daoUtil.getString( 34 ) ) );
323 entry.setAutocompleteEntry( daoUtil.getBoolean( 35 ) );
324 entry.setShownInExport( daoUtil.getBoolean( 36 ) );
325 entry.setShownInCompleteness( daoUtil.getBoolean( 37 ) );
326 entry.setNumberRow( daoUtil.getInt( 38 ) );
327 entry.setNumberColumn( daoUtil.getInt( 39 ) );
328 }
329
330 daoUtil.free( );
331
332 return entry;
333 }
334
335
336
337
338 @Override
339 public void delete( int nIdEntry, Plugin plugin )
340 {
341 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin );
342 daoUtil.setInt( 1, nIdEntry );
343 daoUtil.executeUpdate( );
344 daoUtil.free( );
345 }
346
347
348
349
350 @Override
351 public void store( IEntry entry, Plugin plugin )
352 {
353 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, plugin );
354
355 daoUtil.setInt( 1, entry.getIdEntry( ) );
356
357 if ( entry.getParent( ) != null )
358 {
359 daoUtil.setInt( 2, entry.getParent( ).getIdEntry( ) );
360 }
361 else
362 {
363 daoUtil.setIntNull( 2 );
364 }
365
366 daoUtil.setInt( 3, entry.getDirectory( ).getIdDirectory( ) );
367 daoUtil.setInt( 4, entry.getEntryType( ).getIdType( ) );
368 daoUtil.setString( 5, trimEntryTitle( entry ) );
369 daoUtil.setString( 6, entry.getHelpMessage( ) );
370 daoUtil.setString( 7, entry.getHelpMessageSearch( ) );
371 daoUtil.setString( 8, entry.getComment( ) );
372 daoUtil.setBoolean( 9, entry.isMandatory( ) );
373 daoUtil.setBoolean( 10, entry.isIndexed( ) );
374 daoUtil.setBoolean( 11, entry.isIndexedAsTitle( ) );
375 daoUtil.setBoolean( 12, entry.isIndexedAsSummary( ) );
376 daoUtil.setBoolean( 13, entry.isShownInAdvancedSearch( ) );
377 daoUtil.setBoolean( 14, entry.isShownInResultList( ) );
378 daoUtil.setBoolean( 15, entry.isShownInResultRecord( ) );
379 daoUtil.setBoolean( 16, entry.isFieldInLine( ) );
380 daoUtil.setInt( 17, entry.getPosition( ) );
381 daoUtil.setInt( 18, entry.getDisplayWidth( ) );
382 daoUtil.setInt( 19, entry.getDisplayHeight( ) );
383 daoUtil.setBoolean( 20, entry.isRoleAssociated( ) );
384 daoUtil.setBoolean( 21, entry.isWorkgroupAssociated( ) );
385 daoUtil.setBoolean( 22, entry.isMultipleSearchFields( ) );
386 daoUtil.setBoolean( 23, entry.isShownInHistory( ) );
387 daoUtil.setInt( 24, entry.getEntryAssociate( ) );
388 daoUtil.setString( 25, entry.getRequestSQL( ) );
389 daoUtil.setBoolean( 26, entry.isAddValueAllSearch( ) );
390 daoUtil.setString( 27, entry.getLabelValueAllSearch( ) );
391
392
393 String strMapProvider = ( entry.getMapProvider( ) == null ) ? DirectoryUtils.EMPTY_STRING : entry.getMapProvider( ).getKey( );
394 daoUtil.setString( 28, strMapProvider );
395
396 daoUtil.setBoolean( 29, entry.isAutocompleteEntry( ) );
397 daoUtil.setBoolean( 30, entry.isShownInExport( ) );
398 daoUtil.setBoolean( 31, entry.isShownInCompleteness( ) );
399 daoUtil.setInt( 32, entry.getNumberRow( ) );
400 daoUtil.setInt( 33, entry.getNumberColumn( ) );
401
402 daoUtil.setInt( 34, entry.getIdEntry( ) );
403
404 daoUtil.executeUpdate( );
405 daoUtil.free( );
406 }
407
408
409
410
411
412
413
414
415 private List<String> setSelectFilter( EntryFilter filter )
416 {
417 List<String> listStrFilter = new ArrayList<String>( );
418
419 listStrFilter.add( SQL_FILTER_ASSOCIATION_ON_ID_TYPE );
420
421 if ( filter.containsPosition( ) )
422 {
423 listStrFilter.add( SQL_FILTER_POSITION );
424 }
425
426 if ( filter.containsIdDirectory( ) )
427 {
428 listStrFilter.add( SQL_FILTER_ID_DIRECTORY );
429 }
430
431 if ( filter.containsIdEntryParent( ) )
432 {
433 listStrFilter.add( SQL_FILTER_ID_PARENT );
434 }
435
436 if ( filter.containsIsEntryParentNull( ) )
437 {
438 listStrFilter.add( SQL_FILTER_ID_PARENT_IS_NULL );
439 }
440
441 if ( filter.containsIsGroup( ) )
442 {
443 listStrFilter.add( SQL_FILTER_IS_GROUP );
444 }
445
446 if ( filter.containsIsShownInResultList( ) )
447 {
448 listStrFilter.add( SQL_FILTER_IS_SHOWN_IN_RESULT_LIST );
449 }
450
451 if ( filter.containsIsShownInResultRecord( ) )
452 {
453 listStrFilter.add( SQL_FILTER_IS_SHOWN_IN_RESULT_RECORD );
454 }
455
456 if ( filter.containsIsShownInHistory( ) )
457 {
458 listStrFilter.add( SQL_FILTER_IS_SHOWN_IN_HISTORY );
459 }
460
461 if ( filter.containsIsIndexed( ) )
462 {
463 listStrFilter.add( SQL_FILTER_IS_INDEXED );
464 }
465
466 if ( filter.containsIsIndexedAsTitle( ) )
467 {
468 listStrFilter.add( SQL_FILTER_IS_INDEXED_AS_TITLE );
469 }
470
471 if ( filter.containsIsIndexedAsSummary( ) )
472 {
473 listStrFilter.add( SQL_FILTER_IS_INDEXED_AS_SUMMARY );
474 }
475
476 if ( filter.containsIsComment( ) )
477 {
478 listStrFilter.add( SQL_FILTER_IS_COMMENT );
479 }
480
481 if ( filter.containsIsMyLuteceUser( ) )
482 {
483 listStrFilter.add( SQL_FILTER_IS_MYLUTECE_USER );
484 }
485
486 if ( filter.containsIsWorkgroupAssociated( ) )
487 {
488 listStrFilter.add( SQL_FILTER_IS_WORKGROUP_ASSOCIATED );
489 }
490
491 if ( filter.containsIsRoleAssociated( ) )
492 {
493 listStrFilter.add( SQL_FILTER_IS_ROLE_ASSOCIATED );
494 }
495
496 if ( filter.containsIdType( ) )
497 {
498 listStrFilter.add( SQL_FILTER_ID_TYPE );
499 }
500
501 if ( filter.containsIdEntryAssociate( ) )
502 {
503 listStrFilter.add( SQL_FILTER_ID_ENTRY_ASSOCIATE );
504 }
505
506 if ( filter.containsIsAutocompleteEntry( ) )
507 {
508 listStrFilter.add( SQL_FILTER_IS_AUTOCOMPLETE_ENTRY );
509 }
510
511 if ( filter.containsIsShownInExport( ) )
512 {
513 listStrFilter.add( SQL_FILTER_IS_SHOWN_IN_EXPORT );
514 }
515
516 if ( filter.containsIsShownInCompleteness( ) )
517 {
518 listStrFilter.add( SQL_FILTER_IS_SHOWN_IN_COMPLETENESS );
519 }
520
521 return listStrFilter;
522 }
523
524 private int setSelectFilterValues( EntryFilter filter, DAOUtil daoUtil, int index )
525 {
526 int nIndex = index;
527
528 if ( filter.containsPosition( ) )
529 {
530 daoUtil.setInt( nIndex, filter.getPosition( ) );
531 nIndex++;
532 }
533
534 if ( filter.containsIdDirectory( ) )
535 {
536 daoUtil.setInt( nIndex, filter.getIdDirectory( ) );
537 nIndex++;
538 }
539
540 if ( filter.containsIdEntryParent( ) )
541 {
542 daoUtil.setInt( nIndex, filter.getIdEntryParent( ) );
543 nIndex++;
544 }
545
546 if ( filter.containsIsGroup( ) )
547 {
548 daoUtil.setBoolean( nIndex, filter.getIsGroup( ) == EntryFilter.FILTER_TRUE );
549 nIndex++;
550 }
551
552 if ( filter.containsIsShownInResultList( ) )
553 {
554 daoUtil.setBoolean( nIndex, filter.getIsShownInResultList( ) == EntryFilter.FILTER_TRUE );
555 nIndex++;
556 }
557
558 if ( filter.containsIsShownInResultRecord( ) )
559 {
560 daoUtil.setBoolean( nIndex, filter.getIsShownInResultRecord( ) == EntryFilter.FILTER_TRUE );
561 nIndex++;
562 }
563
564 if ( filter.containsIsShownInHistory( ) )
565 {
566 daoUtil.setBoolean( nIndex, filter.getIsShownInHistory( ) == EntryFilter.FILTER_TRUE );
567 nIndex++;
568 }
569
570 if ( filter.containsIsIndexed( ) )
571 {
572 daoUtil.setBoolean( nIndex, filter.getIsIndexed( ) == EntryFilter.FILTER_TRUE );
573 nIndex++;
574 }
575
576 if ( filter.containsIsIndexedAsTitle( ) )
577 {
578 daoUtil.setBoolean( nIndex, filter.getIsIndexedAsTitle( ) == EntryFilter.FILTER_TRUE );
579 nIndex++;
580 }
581
582 if ( filter.containsIsIndexedAsSummary( ) )
583 {
584 daoUtil.setBoolean( nIndex, filter.getIsIndexedAsSummary( ) == EntryFilter.FILTER_TRUE );
585 nIndex++;
586 }
587
588 if ( filter.containsIsComment( ) )
589 {
590 daoUtil.setBoolean( nIndex, filter.getIsComment( ) == EntryFilter.FILTER_TRUE );
591 nIndex++;
592 }
593
594 if ( filter.containsIsMyLuteceUser( ) )
595 {
596 daoUtil.setBoolean( nIndex, filter.getIsMyLuteceUser( ) == EntryFilter.FILTER_TRUE );
597 nIndex++;
598 }
599
600 if ( filter.containsIsWorkgroupAssociated( ) )
601 {
602 daoUtil.setBoolean( nIndex, filter.getIsWorkgroupAssociated( ) == EntryFilter.FILTER_TRUE );
603 nIndex++;
604 }
605
606 if ( filter.containsIsRoleAssociated( ) )
607 {
608 daoUtil.setBoolean( nIndex, filter.getIsRoleAssociated( ) == EntryFilter.FILTER_TRUE );
609 nIndex++;
610 }
611
612 if ( filter.containsIdType( ) )
613 {
614 daoUtil.setInt( nIndex, filter.getIdType( ) );
615 nIndex++;
616 }
617
618 if ( filter.containsIdEntryAssociate( ) )
619 {
620 daoUtil.setInt( nIndex, filter.getIdEntryAssociate( ) );
621 nIndex++;
622 }
623
624 if ( filter.containsIsAutocompleteEntry( ) )
625 {
626 daoUtil.setBoolean( nIndex, filter.getIsAutocompleteEntry( ) == EntryFilter.FILTER_TRUE );
627 nIndex++;
628 }
629
630 if ( filter.containsIsShownInExport( ) )
631 {
632 daoUtil.setBoolean( nIndex, filter.getIsShownInExport( ) == EntryFilter.FILTER_TRUE );
633 nIndex++;
634 }
635
636 if ( filter.containsIsShownInCompleteness( ) )
637 {
638 daoUtil.setBoolean( nIndex, filter.getIsShownInCompleteness( ) == EntryFilter.FILTER_TRUE );
639 nIndex++;
640 }
641
642 return nIndex;
643 }
644
645 private IEntry getValuesFromQuery( DAOUtil daoUtil )
646 {
647 EntryType entryType = null;
648 IEntry entryParent = null;
649 IEntry entry = null;
650 Directory directory = null;
651 boolean bException = false;
652
653 entryType = new EntryType( );
654 entryType.setIdType( daoUtil.getInt( 1 ) );
655 entryType.setTitleI18nKey( daoUtil.getString( 2 ) );
656 entryType.setGroup( daoUtil.getBoolean( 3 ) );
657 entryType.setComment( daoUtil.getBoolean( 4 ) );
658 entryType.setMyLuteceUser( daoUtil.getBoolean( 5 ) );
659 entryType.setClassName( daoUtil.getString( 6 ) );
660
661 try
662 {
663 entry = (IEntry) Class.forName( entryType.getClassName( ) ).newInstance( );
664 }
665 catch( ClassNotFoundException e )
666 {
667
668 AppLogService.error( e );
669 bException = true;
670 }
671 catch( InstantiationException e )
672 {
673
674 AppLogService.error( e );
675 bException = true;
676 }
677 catch( IllegalAccessException e )
678 {
679
680 AppLogService.error( e );
681 bException = true;
682 }
683
684 if ( bException )
685 {
686 daoUtil.free( );
687
688 return null;
689 }
690
691 entry.setEntryType( entryType );
692 entry.setIdEntry( daoUtil.getInt( 7 ) );
693
694 directory = new Directory( );
695 directory.setIdDirectory( daoUtil.getInt( 8 ) );
696 entry.setDirectory( directory );
697
698 if ( daoUtil.getObject( 9 ) != null )
699 {
700 entryParent = new Entry( );
701 entryParent.setIdEntry( daoUtil.getInt( 9 ) );
702 entry.setParent( entryParent );
703 }
704
705 entry.setTitle( daoUtil.getString( 10 ) );
706 entry.setHelpMessage( daoUtil.getString( 11 ) );
707 entry.setHelpMessageSearch( daoUtil.getString( 12 ) );
708 entry.setComment( daoUtil.getString( 13 ) );
709 entry.setMandatory( daoUtil.getBoolean( 14 ) );
710 entry.setIndexed( daoUtil.getBoolean( 15 ) );
711 entry.setIndexedAsTitle( daoUtil.getBoolean( 16 ) );
712 entry.setIndexedAsSummary( daoUtil.getBoolean( 17 ) );
713 entry.setShownInAdvancedSearch( daoUtil.getBoolean( 18 ) );
714 entry.setShownInResultList( daoUtil.getBoolean( 19 ) );
715 entry.setShownInResultRecord( daoUtil.getBoolean( 20 ) );
716 entry.setFieldInLine( daoUtil.getBoolean( 21 ) );
717 entry.setPosition( daoUtil.getInt( 22 ) );
718 entry.setDisplayWidth( daoUtil.getInt( 23 ) );
719 entry.setDisplayHeight( daoUtil.getInt( 24 ) );
720 entry.setRoleAssociated( daoUtil.getBoolean( 25 ) );
721 entry.setWorkgroupAssociated( daoUtil.getBoolean( 26 ) );
722 entry.setMultipleSearchFields( daoUtil.getBoolean( 27 ) );
723 entry.setShownInHistory( daoUtil.getBoolean( 28 ) );
724 entry.setEntryAssociate( daoUtil.getInt( 29 ) );
725 entry.setRequestSQL( daoUtil.getString( 30 ) );
726 entry.setAddValueAllSearch( daoUtil.getBoolean( 31 ) );
727 entry.setLabelValueAllSearch( daoUtil.getString( 32 ) );
728 entry.setMapProvider( MapProviderManager.getMapProvider( daoUtil.getString( 33 ) ) );
729 entry.setAutocompleteEntry( daoUtil.getBoolean( 34 ) );
730 entry.setShownInExport( daoUtil.getBoolean( 35 ) );
731 entry.setShownInCompleteness( daoUtil.getBoolean( 36 ) );
732
733 return entry;
734 }
735
736
737
738
739
740
741
742
743 private String trimEntryTitle( IEntry entry )
744 {
745 String strEntryTitle = entry.getTitle( );
746
747 if ( strEntryTitle != null )
748 {
749 strEntryTitle = strEntryTitle.trim( );
750 }
751
752 return strEntryTitle;
753 }
754
755
756
757
758 @Override
759 public List<IEntry> selectEntryListByFilter( EntryFilter filter, Plugin plugin )
760 {
761 List<IEntry> entryList = new ArrayList<IEntry>( );
762 IEntry entry = null;
763
764 List<String> listStrFilter = setSelectFilter( filter );
765
766 String strSQL = DirectoryUtils.buildRequetteWithFilter( SQL_QUERY_SELECT_ENTRY_BY_FILTER, listStrFilter, SQL_ORDER_BY_POSITION );
767 DAOUtil daoUtil = new DAOUtil( strSQL, plugin );
768 int nIndex = 1;
769 nIndex = setSelectFilterValues( filter, daoUtil, nIndex );
770
771 daoUtil.executeQuery( );
772
773 while ( daoUtil.next( ) )
774 {
775 entry = getValuesFromQuery( daoUtil );
776
777 if ( entry == null )
778 {
779 return null;
780 }
781
782 entryList.add( entry );
783 }
784
785 daoUtil.free( );
786
787 return entryList;
788 }
789
790
791
792
793 @Override
794 public int selectNumberEntryByFilter( EntryFilter filter, Plugin plugin )
795 {
796 int nNumberEntry = 0;
797 List<String> listStrFilter = new ArrayList<String>( );
798
799 listStrFilter.add( SQL_FILTER_ASSOCIATION_ON_ID_TYPE );
800
801 if ( filter.containsIdDirectory( ) )
802 {
803 listStrFilter.add( SQL_FILTER_ID_DIRECTORY );
804 }
805
806 if ( filter.containsIdEntryParent( ) )
807 {
808 listStrFilter.add( SQL_FILTER_ID_PARENT );
809 }
810
811 if ( filter.containsIsEntryParentNull( ) )
812 {
813 listStrFilter.add( SQL_FILTER_ID_PARENT_IS_NULL );
814 }
815
816 if ( filter.containsIsGroup( ) )
817 {
818 listStrFilter.add( SQL_FILTER_IS_GROUP );
819 }
820
821 if ( filter.containsIsShownInResultList( ) )
822 {
823 listStrFilter.add( SQL_FILTER_IS_SHOWN_IN_RESULT_LIST );
824 }
825
826 if ( filter.containsIsIndexed( ) )
827 {
828 listStrFilter.add( SQL_FILTER_IS_INDEXED );
829 }
830
831 if ( filter.containsIsIndexedAsTitle( ) )
832 {
833 listStrFilter.add( SQL_FILTER_IS_INDEXED_AS_TITLE );
834 }
835
836 if ( filter.containsIsIndexedAsSummary( ) )
837 {
838 listStrFilter.add( SQL_FILTER_IS_INDEXED_AS_SUMMARY );
839 }
840
841 if ( filter.containsIsComment( ) )
842 {
843 listStrFilter.add( SQL_FILTER_IS_COMMENT );
844 }
845
846 if ( filter.containsIsMyLuteceUser( ) )
847 {
848 listStrFilter.add( SQL_FILTER_IS_MYLUTECE_USER );
849 }
850
851 if ( filter.containsIsWorkgroupAssociated( ) )
852 {
853 listStrFilter.add( SQL_FILTER_IS_WORKGROUP_ASSOCIATED );
854 }
855
856 if ( filter.containsIsRoleAssociated( ) )
857 {
858 listStrFilter.add( SQL_FILTER_IS_ROLE_ASSOCIATED );
859 }
860
861 if ( filter.containsIdType( ) )
862 {
863 listStrFilter.add( SQL_FILTER_ID_TYPE );
864 }
865
866 if ( filter.containsIdEntryAssociate( ) )
867 {
868 listStrFilter.add( SQL_FILTER_ID_ENTRY_ASSOCIATE );
869 }
870
871 if ( filter.containsIsAutocompleteEntry( ) )
872 {
873 listStrFilter.add( SQL_FILTER_IS_AUTOCOMPLETE_ENTRY );
874 }
875
876 if ( filter.containsIsShownInExport( ) )
877 {
878 listStrFilter.add( SQL_FILTER_IS_SHOWN_IN_EXPORT );
879 }
880
881 if ( filter.containsIsShownInCompleteness( ) )
882 {
883 listStrFilter.add( SQL_FILTER_IS_SHOWN_IN_COMPLETENESS );
884 }
885
886 String strSQL = DirectoryUtils.buildRequetteWithFilter( SQL_QUERY_SELECT_NUMBER_ENTRY_BY_FILTER, listStrFilter, null );
887
888 DAOUtil daoUtil = new DAOUtil( strSQL, plugin );
889 int nIndex = 1;
890
891 if ( filter.containsIdDirectory( ) )
892 {
893 daoUtil.setInt( nIndex, filter.getIdDirectory( ) );
894 nIndex++;
895 }
896
897 if ( filter.containsIdEntryParent( ) )
898 {
899 daoUtil.setInt( nIndex, filter.getIdEntryParent( ) );
900 nIndex++;
901 }
902
903 if ( filter.containsIsGroup( ) )
904 {
905 daoUtil.setBoolean( nIndex, filter.getIsGroup( ) == EntryFilter.FILTER_TRUE );
906 nIndex++;
907 }
908
909 if ( filter.containsIsShownInResultList( ) )
910 {
911 daoUtil.setBoolean( nIndex, filter.getIsShownInResultList( ) == EntryFilter.FILTER_TRUE );
912 nIndex++;
913 }
914
915 if ( filter.containsIsIndexed( ) )
916 {
917 daoUtil.setBoolean( nIndex, filter.getIsIndexed( ) == EntryFilter.FILTER_TRUE );
918 nIndex++;
919 }
920
921 if ( filter.containsIsIndexedAsTitle( ) )
922 {
923 daoUtil.setBoolean( nIndex, filter.getIsIndexedAsTitle( ) == EntryFilter.FILTER_TRUE );
924 nIndex++;
925 }
926
927 if ( filter.containsIsIndexedAsSummary( ) )
928 {
929 daoUtil.setBoolean( nIndex, filter.getIsIndexedAsSummary( ) == EntryFilter.FILTER_TRUE );
930 nIndex++;
931 }
932
933 if ( filter.containsIsComment( ) )
934 {
935 daoUtil.setBoolean( nIndex, filter.getIsComment( ) == EntryFilter.FILTER_TRUE );
936 nIndex++;
937 }
938
939 if ( filter.containsIsMyLuteceUser( ) )
940 {
941 daoUtil.setBoolean( nIndex, filter.getIsMyLuteceUser( ) == EntryFilter.FILTER_TRUE );
942 nIndex++;
943 }
944
945 if ( filter.containsIsWorkgroupAssociated( ) )
946 {
947 daoUtil.setBoolean( nIndex, filter.getIsWorkgroupAssociated( ) == EntryFilter.FILTER_TRUE );
948 nIndex++;
949 }
950
951 if ( filter.containsIsRoleAssociated( ) )
952 {
953 daoUtil.setBoolean( nIndex, filter.getIsRoleAssociated( ) == EntryFilter.FILTER_TRUE );
954 nIndex++;
955 }
956
957 if ( filter.containsIdType( ) )
958 {
959 daoUtil.setInt( nIndex, filter.getIdType( ) );
960 nIndex++;
961 }
962
963 if ( filter.containsIdEntryAssociate( ) )
964 {
965 daoUtil.setInt( nIndex, filter.getIdEntryAssociate( ) );
966 nIndex++;
967 }
968
969 if ( filter.containsIsAutocompleteEntry( ) )
970 {
971 daoUtil.setBoolean( nIndex, filter.getIsAutocompleteEntry( ) == EntryFilter.FILTER_TRUE );
972 nIndex++;
973 }
974
975 if ( filter.containsIsShownInExport( ) )
976 {
977 daoUtil.setBoolean( nIndex, filter.getIsShownInExport( ) == EntryFilter.FILTER_TRUE );
978 nIndex++;
979 }
980
981 if ( filter.containsIsShownInCompleteness( ) )
982 {
983 daoUtil.setBoolean( nIndex, filter.getIsShownInCompleteness( ) == EntryFilter.FILTER_TRUE );
984 nIndex++;
985 }
986
987 daoUtil.executeQuery( );
988
989 if ( daoUtil.next( ) )
990 {
991 nNumberEntry = daoUtil.getInt( 1 );
992 }
993
994 daoUtil.free( );
995
996 return nNumberEntry;
997 }
998
999
1000
1001
1002 @Override
1003 public List<IEntry> selectEntryListByTypeByFilter( List<Integer> idTypeEntryList, EntryFilter filter, Plugin plugin )
1004 {
1005 List<IEntry> entryList = new ArrayList<IEntry>( );
1006 IEntry entry = null;
1007
1008 List<String> listStrFilter = setSelectFilter( filter );
1009
1010 String strSQL = DirectoryUtils.buildRequetteWithFilter( SQL_QUERY_SELECT_ENTRY_BY_FILTER, listStrFilter, null );
1011
1012 StringBuffer strBuffer = new StringBuffer( );
1013 strBuffer.append( strSQL );
1014
1015 if ( ( idTypeEntryList != null ) && ( idTypeEntryList.size( ) > 0 ) )
1016 {
1017 if ( listStrFilter.size( ) > 0 )
1018 {
1019 strBuffer.append( DirectoryUtils.CONSTANT_AND );
1020 strBuffer.append( CONSTANT_PARENTHESIS_LEFT );
1021 }
1022 else
1023 {
1024 strBuffer.append( DirectoryUtils.CONSTANT_WHERE );
1025 }
1026
1027 for ( int i = 0; i < idTypeEntryList.size( ); i++ )
1028 {
1029 if ( i != 0 )
1030 {
1031 strBuffer.append( DirectoryUtils.CONSTANT_OR );
1032 }
1033
1034 strBuffer.append( SQL_FILTER_ID_TYPE );
1035 }
1036
1037 strBuffer.append( CONSTANT_PARENTHESIS_RIGHT );
1038 }
1039 else
1040 {
1041 return entryList;
1042 }
1043
1044 strSQL = strBuffer.toString( );
1045
1046 DAOUtil daoUtil = new DAOUtil( strSQL, plugin );
1047 int nIndex = 1;
1048
1049 nIndex = setSelectFilterValues( filter, daoUtil, nIndex );
1050
1051 for ( int idType : idTypeEntryList )
1052 {
1053 daoUtil.setInt( nIndex, idType );
1054 nIndex++;
1055 }
1056
1057 daoUtil.executeQuery( );
1058
1059 while ( daoUtil.next( ) )
1060 {
1061 entry = getValuesFromQuery( daoUtil );
1062
1063 if ( entry == null )
1064 {
1065 return null;
1066 }
1067
1068 entryList.add( entry );
1069 }
1070
1071 daoUtil.free( );
1072
1073 return entryList;
1074 }
1075
1076
1077
1078
1079 @Override
1080 public List<IEntry> getEntryListAnonymizeStatus( Plugin plugin )
1081 {
1082 List<IEntry> entryList = new ArrayList<IEntry>( );
1083 IEntry entry = null;
1084
1085 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ENTRY_ANONYMIZE, plugin );
1086 daoUtil.executeQuery( );
1087
1088 while ( daoUtil.next( ) )
1089 {
1090 entry = new Entry( );
1091 entry.setIdEntry( daoUtil.getInt( 1 ) );
1092 entry.setTitle( daoUtil.getString( 2 ) );
1093 entry.setAnonymize( daoUtil.getBoolean( 3 ) );
1094
1095 EntryType entryType = new EntryType( );
1096 entryType.setClassName( daoUtil.getString( 4 ) );
1097 entryType.setTitleI18nKey( daoUtil.getString( 5 ) );
1098 entry.setEntryType( entryType );
1099 entryList.add( entry );
1100 }
1101
1102 daoUtil.free( );
1103
1104 return entryList;
1105 }
1106
1107
1108
1109
1110 @Override
1111 public void updateEntryAnonymizeStatus( Integer nEntryId, Boolean bAnonymize, Plugin plugin )
1112 {
1113 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_ENTRY_ANONYMIZE, plugin );
1114 daoUtil.setBoolean( 1, bAnonymize );
1115 daoUtil.setInt( 2, nEntryId );
1116 daoUtil.executeUpdate( );
1117 daoUtil.free( );
1118 }
1119
1120
1121
1122
1123 @Override
1124 public List<IEntry> findEntriesWithoutParent( Plugin plugin, int nIdDirectory )
1125 {
1126 List<IEntry> listResult = new ArrayList<IEntry>( );
1127 DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ENTRIES_WITHOUT_PARENT );
1128 daoUtil.setInt( 1, nIdDirectory );
1129 daoUtil.executeQuery( );
1130
1131 while ( daoUtil.next( ) )
1132 {
1133 IEntry entry = getValuesFromQuery( daoUtil );
1134
1135 if ( entry == null )
1136 {
1137 return null;
1138 }
1139
1140 listResult.add( entry );
1141 }
1142
1143 daoUtil.free( );
1144
1145 return listResult;
1146 }
1147 }