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.page;
35
36 import fr.paris.lutece.portal.business.portlet.Portlet;
37 import fr.paris.lutece.portal.business.portlet.PortletHome;
38 import fr.paris.lutece.portal.service.image.ImageResource;
39 import fr.paris.lutece.util.ReferenceList;
40 import fr.paris.lutece.util.sql.DAOUtil;
41
42 import java.sql.Statement;
43 import java.sql.Timestamp;
44
45 import java.util.ArrayList;
46 import java.util.Collection;
47 import java.util.List;
48
49
50
51
52 public final class PageDAO implements IPageDAO
53 {
54
55 private static final String SQL_QUERY_SELECT = "SELECT a.id_parent, a.name, a.description, a.id_template, b.file_name, "
56 + " a.page_order, a.status, a.role , a.code_theme , a.node_status , a.image_content, a.mime_type, "
57 + " a.date_update, a.meta_keywords, a.meta_description, a.id_authorization_node, a.display_date_update, a.is_manual_date_update FROM core_page a, core_page_template b WHERE a.id_template = b.id_template AND a.id_page = ? ";
58 private static final String SQL_QUERY_SELECT_WITHOUT_IMAGE_CONTENT = "SELECT a.id_parent, a.name, a.description, a.id_template, b.file_name, "
59 + " a.page_order, a.status, a.role , a.code_theme , a.node_status , a.mime_type, "
60 + " a.date_update, a.meta_keywords, a.meta_description FROM core_page a INNER JOIN "
61 + " core_page_template b ON (a.id_template = b.id_template) WHERE a.id_page = ? ";
62 private static final String SQL_QUERY_SELECT_BY_ID_PORTLET = "SELECT a.id_page, a.id_parent, a.name, a.description, a.id_template, "
63 + " a.page_order, a.status, a.role , a.code_theme , a.node_status , a.image_content, a.mime_type, "
64 + " a.meta_keywords, a.meta_description,a.id_authorization_node FROM core_page a,core_portlet b WHERE a.id_page = b.id_page AND b.id_portlet = ? ";
65 private static final String SQL_QUERY_INSERT = "INSERT INTO core_page ( id_parent , name , description, date_update, "
66 + " id_template, page_order, status, role, date_creation, code_theme , node_status, image_content , mime_type , "
67 + " meta_keywords, meta_description,id_authorization_node, display_date_update, is_manual_date_update ) "
68 + " VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
69 private static final String SQL_QUERY_DELETE = "DELETE FROM core_page WHERE id_page = ?";
70 private static final String SQL_QUERY_UPDATE = "UPDATE core_page SET id_parent = ?, name = ?, description = ? , date_update = ? , "
71 + " id_template = ? , page_order = ? , status = ? , role = ? , code_theme = ? , node_status = ? , "
72 + " image_content = ? , mime_type = ? , meta_keywords = ?, meta_description = ? , id_authorization_node=? , display_date_update=? , is_manual_date_update=?"
73 + " WHERE id_page = ?";
74 private static final String SQL_QUERY_CHECKPK = "SELECT id_page FROM core_page WHERE id_page = ?";
75 private static final String SQL_QUERY_CHILDPAGE = "SELECT id_page , id_parent, name, description, "
76 + " page_order , status , role, code_theme, image_content, mime_type , meta_keywords, meta_description, date_update,id_authorization_node, display_date_update, is_manual_date_update "
77 + " FROM core_page WHERE id_parent = ? ORDER BY page_order";
78 private static final String SQL_QUERY_CHILDPAGE_MINIMAL_DATA = "SELECT id_page ,id_parent, name, description, role FROM core_page "
79 + " WHERE id_parent = ? ORDER BY page_order";
80 private static final String SQL_QUERY_SELECTALL = "SELECT id_page , id_parent, name, description, date_update, "
81 + " page_order, status, role, code_theme, image_content, mime_type , meta_keywords, meta_description,id_authorization_node, display_date_update, is_manual_date_update FROM core_page ";
82 private static final String SQL_QUERY_BY_ROLE_KEY = "SELECT id_page , id_parent, name, description, date_update, "
83 + " page_order, status, role, code_theme, image_content, mime_type , meta_keywords, meta_description,id_authorization_node, display_date_update, is_manual_date_update FROM core_page WHERE role = ? ";
84 private static final String SQL_QUERY_SELECT_PORTLET = "SELECT id_portlet FROM core_portlet WHERE id_page = ? ORDER BY portlet_order";
85 private static final String SQL_QUERY_UPDATE_PAGE_DATE = "UPDATE core_page SET date_update = ? WHERE id_page = ?";
86 private static final String SQL_QUERY_SELECTALL_NODE_PAGE = "SELECT id_page, name FROM core_page WHERE node_status = 0";
87 private static final String SQL_QUERY_NEW_CHILD_PAGE_ORDER = "SELECT max(page_order) FROM core_page WHERE id_parent = ?";
88 private static final String SQL_QUERY_CHECK_PAGE_EXIST = "SELECT id_page FROM core_page " + " WHERE id_page = ? ";
89 private static final String SQL_QUERY_SELECT_LAST_MODIFIED_PAGE = "SELECT id_page, id_parent, name, description, id_template, "
90 + " page_order, status, role , code_theme , node_status , mime_type, "
91 + " date_update, meta_keywords, meta_description,id_authorization_node, display_date_update, is_manual_date_update FROM core_page "
92 + " ORDER BY date_update DESC LIMIT 1";
93
94
95 private static final String SQL_QUERY_SELECT_RESOURCE_IMAGE = " SELECT image_content , mime_type FROM core_page " + " WHERE id_page = ? ";
96 private static final String SQL_QUERY_SELECT_CHILD_PAGE_FOR_MODIFY_AUTORISATION_NODE = " SELECT id_page FROM core_page "
97 + "WHERE id_parent=? AND( id_authorization_node IS NULL OR id_page != id_authorization_node ) ";
98 private static final String SQL_QUERY_UPDATE_AUTORISATION_NODE = " UPDATE core_page SET id_authorization_node = ? WHERE id_page=? ";
99
100
101
102
103
104
105
106 public void insert( Page page )
107 {
108 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, Statement.RETURN_GENERATED_KEYS ) )
109 {
110 page.setOrigParentPageId( page.getParentPageId( ) );
111
112 int nIndex = 1;
113 daoUtil.setInt( nIndex++, page.getParentPageId( ) );
114 daoUtil.setString( nIndex++, page.getName( ) );
115 daoUtil.setString( nIndex++, page.getDescription( ) );
116 daoUtil.setTimestamp( nIndex++, new Timestamp( new java.util.Date( ).getTime( ) ) );
117 daoUtil.setInt( nIndex++, page.getPageTemplateId( ) );
118 daoUtil.setInt( nIndex++, page.getOrder( ) );
119 daoUtil.setInt( nIndex++, page.getStatus( ) );
120 daoUtil.setString( nIndex++, page.getRole( ) );
121
122 daoUtil.setTimestamp( nIndex++, page.getDateUpdate( ) == null ? new Timestamp( new java.util.Date( ).getTime( ) ) : page.getDateUpdate( ) );
123 daoUtil.setString( nIndex++, page.getCodeTheme( ) );
124 daoUtil.setInt( nIndex++, page.getNodeStatus( ) );
125 daoUtil.setBytes( nIndex++, page.getImageContent( ) );
126 daoUtil.setString( nIndex++, page.getMimeType( ) );
127
128 if ( ( page.getMetaKeywords( ) != null ) && ( page.getMetaKeywords( ).length( ) > 0 ) )
129 {
130 daoUtil.setString( nIndex++, page.getMetaKeywords( ) );
131 }
132 else
133 {
134 daoUtil.setString( nIndex++, null );
135 }
136
137 if ( ( page.getMetaDescription( ) != null ) && ( page.getMetaDescription( ).length( ) > 0 ) )
138 {
139 daoUtil.setString( nIndex++, page.getMetaDescription( ) );
140 }
141 else
142 {
143 daoUtil.setString( nIndex++, null );
144 }
145
146 if ( page.getIdAuthorizationNode( ) != null )
147 {
148 daoUtil.setInt( nIndex++, page.getIdAuthorizationNode( ) );
149 }
150 else
151 {
152 daoUtil.setIntNull( nIndex++ );
153 }
154 daoUtil.setBoolean( nIndex++, page.getDisplayDateUpdate( ) );
155 daoUtil.setBoolean( nIndex, page.getIsManualDateUpdate( ) );
156
157 daoUtil.executeUpdate( );
158
159 if ( daoUtil.nextGeneratedKey( ) )
160 {
161 page.setId( daoUtil.getGeneratedKeyInt( 1 ) );
162 }
163 }
164 }
165
166
167
168
169 public Page load( int nPageId, boolean bPortlets )
170 {
171 Pagertal/business/page/Page.html#Page">Page page = new Page( );
172 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
173 {
174 daoUtil.setInt( 1, nPageId );
175
176 daoUtil.executeQuery( );
177
178 if ( daoUtil.next( ) )
179 {
180 page.setId( nPageId );
181 page.setParentPageId( daoUtil.getInt( 1 ) );
182 page.setOrigParentPageId( daoUtil.getInt( 1 ) );
183 page.setName( daoUtil.getString( 2 ) );
184 page.setDescription( daoUtil.getString( 3 ) );
185 page.setPageTemplateId( daoUtil.getInt( 4 ) );
186 page.setTemplate( daoUtil.getString( 5 ) );
187 page.setOrder( daoUtil.getInt( 6 ) );
188 page.setStatus( daoUtil.getInt( 7 ) );
189 page.setRole( daoUtil.getString( 8 ) );
190 page.setCodeTheme( daoUtil.getString( 9 ) );
191 page.setNodeStatus( daoUtil.getInt( 10 ) );
192 page.setImageContent( daoUtil.getBytes( 11 ) );
193 page.setMimeType( daoUtil.getString( 12 ) );
194 page.setDateUpdate( daoUtil.getTimestamp( 13 ) );
195 page.setMetaKeywords( daoUtil.getString( 14 ) );
196 page.setMetaDescription( daoUtil.getString( 15 ) );
197
198 if ( daoUtil.getObject( 16 ) != null )
199 {
200 page.setIdAuthorizationNode( daoUtil.getInt( 16 ) );
201 }
202
203 page.setDisplayDateUpdate( daoUtil.getBoolean( 17 ) );
204 page.setIsManualDateUpdate( daoUtil.getBoolean( 18 ) );
205
206
207 daoUtil.free( );
208
209
210 if ( bPortlets )
211 {
212 loadPortlets( page );
213 }
214 }
215
216 }
217
218 return page;
219 }
220
221
222
223
224 public Page loadWithoutImageContent( int nPageId, boolean bPortlets )
225 {
226 Pagertal/business/page/Page.html#Page">Page page = new Page( );
227 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_WITHOUT_IMAGE_CONTENT ) )
228 {
229 daoUtil.setInt( 1, nPageId );
230
231 daoUtil.executeQuery( );
232
233 if ( daoUtil.next( ) )
234 {
235 page.setId( nPageId );
236 page.setParentPageId( daoUtil.getInt( 1 ) );
237 page.setOrigParentPageId( daoUtil.getInt( 1 ) );
238 page.setName( daoUtil.getString( 2 ) );
239 page.setDescription( daoUtil.getString( 3 ) );
240 page.setPageTemplateId( daoUtil.getInt( 4 ) );
241 page.setTemplate( daoUtil.getString( 5 ) );
242 page.setOrder( daoUtil.getInt( 6 ) );
243 page.setStatus( daoUtil.getInt( 7 ) );
244 page.setRole( daoUtil.getString( 8 ) );
245 page.setCodeTheme( daoUtil.getString( 9 ) );
246 page.setNodeStatus( daoUtil.getInt( 10 ) );
247 page.setMimeType( daoUtil.getString( 11 ) );
248 page.setDateUpdate( daoUtil.getTimestamp( 12 ) );
249 page.setMetaKeywords( daoUtil.getString( 13 ) );
250 page.setMetaDescription( daoUtil.getString( 14 ) );
251
252 if ( daoUtil.getObject( 15 ) != null )
253 {
254 page.setIdAuthorizationNode( daoUtil.getInt( 15 ) );
255 }
256
257
258 daoUtil.free( );
259
260
261 if ( bPortlets )
262 {
263 loadPortlets( page );
264 }
265 }
266 }
267
268 return page;
269 }
270
271
272
273
274 public Page loadPageByIdPortlet( int nPorletId )
275 {
276 Pagertal/business/page/Page.html#Page">Page page = new Page( );
277 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_ID_PORTLET ) )
278 {
279 daoUtil.setInt( 1, nPorletId );
280
281 daoUtil.executeQuery( );
282
283 if ( daoUtil.next( ) )
284 {
285 page.setId( daoUtil.getInt( 1 ) );
286 page.setParentPageId( daoUtil.getInt( 2 ) );
287 page.setOrigParentPageId( daoUtil.getInt( 2 ) );
288 page.setName( daoUtil.getString( 3 ) );
289 page.setDescription( daoUtil.getString( 4 ) );
290 page.setPageTemplateId( daoUtil.getInt( 5 ) );
291 page.setOrder( daoUtil.getInt( 6 ) );
292 page.setStatus( daoUtil.getInt( 7 ) );
293 page.setRole( daoUtil.getString( 8 ) );
294 page.setCodeTheme( daoUtil.getString( 9 ) );
295 page.setNodeStatus( daoUtil.getInt( 10 ) );
296 page.setImageContent( daoUtil.getBytes( 11 ) );
297 page.setMimeType( daoUtil.getString( 12 ) );
298 page.setMetaKeywords( daoUtil.getString( 13 ) );
299 page.setMetaDescription( daoUtil.getString( 14 ) );
300 page.setIdAuthorizationNode( daoUtil.getInt( 15 ) );
301 }
302
303 }
304
305 return page;
306 }
307
308
309
310
311 public void delete( int nPageId )
312 {
313 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
314 {
315 daoUtil.setInt( 1, nPageId );
316
317 daoUtil.executeUpdate( );
318 }
319 }
320
321
322
323
324 public void store( Page page )
325 {
326 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE ) )
327 {
328
329 daoUtil.setInt( 1, page.getParentPageId( ) );
330 daoUtil.setString( 2, page.getName( ) );
331 daoUtil.setString( 3, page.getDescription( ) );
332 daoUtil.setTimestamp( 4, page.getDateUpdate( ) == null ? new Timestamp( new java.util.Date( ).getTime( ) ) : page.getDateUpdate( ) );
333 daoUtil.setInt( 5, page.getPageTemplateId( ) );
334 daoUtil.setInt( 6, page.getOrder( ) );
335 daoUtil.setInt( 7, page.getStatus( ) );
336 daoUtil.setString( 8, page.getRole( ) );
337 daoUtil.setString( 9, page.getCodeTheme( ) );
338 daoUtil.setInt( 10, page.getNodeStatus( ) );
339 daoUtil.setBytes( 11, page.getImageContent( ) );
340 daoUtil.setString( 12, page.getMimeType( ) );
341
342 if ( ( page.getMetaKeywords( ) != null ) && ( page.getMetaKeywords( ).length( ) > 0 ) )
343 {
344 daoUtil.setString( 13, page.getMetaKeywords( ) );
345 }
346 else
347 {
348 daoUtil.setString( 13, null );
349 }
350
351 if ( ( page.getMetaDescription( ) != null ) && ( page.getMetaDescription( ).length( ) > 0 ) )
352 {
353 daoUtil.setString( 14, page.getMetaDescription( ) );
354 }
355 else
356 {
357 daoUtil.setString( 14, null );
358 }
359
360 if ( page.getIdAuthorizationNode( ) != null )
361 {
362 daoUtil.setInt( 15, page.getIdAuthorizationNode( ) );
363 }
364 else
365 {
366 daoUtil.setIntNull( 15 );
367 }
368
369 daoUtil.setBoolean( 16, page.getDisplayDateUpdate( ) );
370 daoUtil.setBoolean( 17, page.getIsManualDateUpdate( ) );
371
372 daoUtil.setInt( 18, page.getId( ) );
373
374 daoUtil.executeUpdate( );
375 }
376 }
377
378
379
380
381
382
383
384
385 boolean checkPrimaryKey( int nKey )
386 {
387 boolean check = false;
388 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_CHECKPK ) )
389 {
390
391 daoUtil.setInt( 1, nKey );
392 daoUtil.executeQuery( );
393
394 if ( daoUtil.next( ) )
395 {
396 check = true;
397 }
398 }
399 return check;
400 }
401
402
403
404
405
406
407
408 void loadPortlets( Page page )
409 {
410 List<Integer> portletIds = new ArrayList<>( );
411 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_PORTLET ) )
412 {
413 daoUtil.setInt( 1, page.getId( ) );
414
415 daoUtil.executeQuery( );
416
417
418
419 while ( daoUtil.next( ) )
420 {
421 portletIds.add( Integer.valueOf( daoUtil.getInt( 1 ) ) );
422 }
423
424 }
425
426 ArrayList<Portlet> pageColl = new ArrayList<>( );
427
428 for ( Integer nPortletId : portletIds )
429 {
430 Portlet portlet = PortletHome.findByPrimaryKey( nPortletId );
431 pageColl.add( portlet );
432 }
433
434 page.setPortlets( pageColl );
435 }
436
437
438
439
440 public Collection<Page> selectChildPages( int nParentPageId )
441 {
442 Collection<Page> pageList = new ArrayList<>( );
443 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_CHILDPAGE ) )
444 {
445 daoUtil.setInt( 1, nParentPageId );
446
447 daoUtil.executeQuery( );
448
449 while ( daoUtil.next( ) )
450 {
451 Pagertal/business/page/Page.html#Page">Page page = new Page( );
452
453 page.setId( daoUtil.getInt( 1 ) );
454 page.setParentPageId( daoUtil.getInt( 2 ) );
455 page.setOrigParentPageId( daoUtil.getInt( 2 ) );
456 page.setName( daoUtil.getString( 3 ) );
457 page.setDescription( daoUtil.getString( 4 ) );
458 page.setOrder( daoUtil.getInt( 5 ) );
459 page.setStatus( daoUtil.getInt( 6 ) );
460 page.setRole( daoUtil.getString( 7 ) );
461 page.setCodeTheme( daoUtil.getString( 8 ) );
462 page.setImageContent( daoUtil.getBytes( 9 ) );
463 page.setMimeType( daoUtil.getString( 10 ) );
464 page.setMetaKeywords( daoUtil.getString( 11 ) );
465 page.setMetaDescription( daoUtil.getString( 12 ) );
466 page.setDateUpdate( daoUtil.getTimestamp( 13 ) );
467
468 if ( daoUtil.getObject( 14 ) != null )
469 {
470 page.setIdAuthorizationNode( daoUtil.getInt( 14 ) );
471 }
472 page.setDisplayDateUpdate( daoUtil.getBoolean( 15 ) );
473 page.setIsManualDateUpdate( daoUtil.getBoolean( 16 ) );
474
475 pageList.add( page );
476 }
477
478 }
479
480 return pageList;
481 }
482
483
484
485
486 public Collection<Page> selectChildPagesMinimalData( int nParentPageId )
487 {
488 Collection<Page> pageList = new ArrayList<>( );
489 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_CHILDPAGE_MINIMAL_DATA ) )
490 {
491 daoUtil.setInt( 1, nParentPageId );
492
493 daoUtil.executeQuery( );
494
495 while ( daoUtil.next( ) )
496 {
497 Pagertal/business/page/Page.html#Page">Page page = new Page( );
498 page.setId( daoUtil.getInt( 1 ) );
499 page.setParentPageId( daoUtil.getInt( 2 ) );
500 page.setOrigParentPageId( daoUtil.getInt( 2 ) );
501 page.setName( daoUtil.getString( 3 ) );
502 page.setDescription( daoUtil.getString( 4 ) );
503 page.setRole( daoUtil.getString( 5 ) );
504 pageList.add( page );
505 }
506
507 }
508
509 return pageList;
510 }
511
512
513
514
515 public List<Page> selectAllPages( )
516 {
517 List<Page> pageList = new ArrayList<>( );
518 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL ) )
519 {
520 daoUtil.executeQuery( );
521
522 while ( daoUtil.next( ) )
523 {
524 Pagertal/business/page/Page.html#Page">Page page = new Page( );
525
526 page.setId( daoUtil.getInt( 1 ) );
527 page.setParentPageId( daoUtil.getInt( 2 ) );
528 page.setOrigParentPageId( daoUtil.getInt( 2 ) );
529 page.setName( daoUtil.getString( 3 ) );
530 page.setDescription( daoUtil.getString( 4 ) );
531 page.setDateUpdate( daoUtil.getTimestamp( 5 ) );
532 page.setOrder( daoUtil.getInt( 6 ) );
533 page.setStatus( daoUtil.getInt( 7 ) );
534 page.setRole( daoUtil.getString( 8 ) );
535 page.setCodeTheme( daoUtil.getString( 9 ) );
536 page.setImageContent( daoUtil.getBytes( 10 ) );
537 page.setMimeType( daoUtil.getString( 11 ) );
538 page.setMetaKeywords( daoUtil.getString( 12 ) );
539 page.setMetaDescription( daoUtil.getString( 13 ) );
540
541 if ( daoUtil.getObject( 14 ) != null )
542 {
543 page.setIdAuthorizationNode( daoUtil.getInt( 14 ) );
544 }
545 page.setDisplayDateUpdate( daoUtil.getBoolean( 15 ) );
546 page.setIsManualDateUpdate( daoUtil.getBoolean( 16 ) );
547
548 pageList.add( page );
549 }
550
551 }
552
553 return pageList;
554 }
555
556
557
558
559 public void invalidatePage( int nPageId )
560 {
561 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_PAGE_DATE ) )
562 {
563
564 daoUtil.setTimestamp( 1, new Timestamp( new java.util.Date( ).getTime( ) ) );
565 daoUtil.setInt( 2, nPageId );
566
567 daoUtil.executeUpdate( );
568 }
569 }
570
571
572
573
574 public ReferenceList getPagesList( )
575 {
576 ReferenceListst.html#ReferenceList">ReferenceList listPages = new ReferenceList( );
577 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECTALL_NODE_PAGE ) )
578 {
579 daoUtil.executeQuery( );
580
581 while ( daoUtil.next( ) )
582 {
583 Pagertal/business/page/Page.html#Page">Page page = new Page( );
584 page.setId( daoUtil.getInt( 1 ) );
585 page.setName( daoUtil.getString( 2 ) );
586 listPages.addItem( page.getId( ), page.getName( ) + " ( " + page.getId( ) + " )" );
587 }
588
589 }
590
591 return listPages;
592 }
593
594
595
596
597
598
599
600
601 public Collection<Page> getPagesByRoleKey( String strRoleKey )
602 {
603 Collection<Page> pageList = new ArrayList<>( );
604 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_BY_ROLE_KEY ) )
605 {
606 daoUtil.setString( 1, strRoleKey );
607
608 daoUtil.executeQuery( );
609
610 while ( daoUtil.next( ) )
611 {
612 Pagertal/business/page/Page.html#Page">Page page = new Page( );
613
614 page.setId( daoUtil.getInt( 1 ) );
615 page.setParentPageId( daoUtil.getInt( 2 ) );
616 page.setOrigParentPageId( daoUtil.getInt( 2 ) );
617 page.setName( daoUtil.getString( 3 ) );
618 page.setDescription( daoUtil.getString( 4 ) );
619 page.setDateUpdate( daoUtil.getTimestamp( 5 ) );
620 page.setOrder( daoUtil.getInt( 6 ) );
621 page.setStatus( daoUtil.getInt( 7 ) );
622 page.setRole( daoUtil.getString( 8 ) );
623 page.setCodeTheme( daoUtil.getString( 9 ) );
624 page.setImageContent( daoUtil.getBytes( 10 ) );
625 page.setMimeType( daoUtil.getString( 11 ) );
626 page.setMetaKeywords( daoUtil.getString( 12 ) );
627 page.setMetaDescription( daoUtil.getString( 13 ) );
628
629 if ( daoUtil.getObject( 14 ) != null )
630 {
631 page.setIdAuthorizationNode( daoUtil.getInt( 14 ) );
632 }
633
634 page.setDisplayDateUpdate( daoUtil.getBoolean( 15 ) );
635 page.setIsManualDateUpdate( daoUtil.getBoolean( 16 ) );
636
637 pageList.add( page );
638 }
639
640 }
641
642 return pageList;
643 }
644
645
646
647
648 public int selectNewChildPageOrder( int nParentPageId )
649 {
650 int nPageOrder;
651 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_NEW_CHILD_PAGE_ORDER ) )
652 {
653 daoUtil.setInt( 1, nParentPageId );
654 daoUtil.executeQuery( );
655
656 if ( !daoUtil.next( ) )
657 {
658
659 nPageOrder = 1;
660 }
661
662 nPageOrder = daoUtil.getInt( 1 ) + 1;
663
664 }
665
666 return nPageOrder;
667 }
668
669
670
671
672 public ImageResource loadImageResource( int nIdPage )
673 {
674 ImageResource image = null;
675 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_RESOURCE_IMAGE ) )
676 {
677 daoUtil.setInt( 1, nIdPage );
678 daoUtil.executeQuery( );
679
680 if ( daoUtil.next( ) )
681 {
682 image = new ImageResource( );
683 image.setImage( daoUtil.getBytes( 1 ) );
684 image.setMimeType( daoUtil.getString( 2 ) );
685 }
686
687 }
688
689 return image;
690 }
691
692
693
694
695
696
697
698
699 public boolean checkPageExist( int nPageId )
700 {
701 boolean bPageExisted = false;
702 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_CHECK_PAGE_EXIST ) )
703 {
704
705 daoUtil.setInt( 1, nPageId );
706 daoUtil.executeQuery( );
707
708 if ( daoUtil.next( ) )
709 {
710 bPageExisted = true;
711 }
712
713 }
714
715 return bPageExisted;
716 }
717
718
719
720
721 public Page loadLastModifiedPage( )
722 {
723 Page page = null;
724 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_LAST_MODIFIED_PAGE ) )
725 {
726
727 daoUtil.executeQuery( );
728
729 if ( daoUtil.next( ) )
730 {
731 page = new Page( );
732
733 int nIndex = 1;
734 page.setId( daoUtil.getInt( nIndex++ ) );
735 page.setParentPageId( daoUtil.getInt( nIndex++ ) );
736 page.setOrigParentPageId( page.getParentPageId( ) );
737 page.setName( daoUtil.getString( nIndex++ ) );
738 page.setDescription( daoUtil.getString( nIndex++ ) );
739 page.setPageTemplateId( daoUtil.getInt( nIndex++ ) );
740 page.setOrder( daoUtil.getInt( nIndex++ ) );
741 page.setStatus( daoUtil.getInt( nIndex++ ) );
742 page.setRole( daoUtil.getString( nIndex++ ) );
743 page.setCodeTheme( daoUtil.getString( nIndex++ ) );
744 page.setNodeStatus( daoUtil.getInt( nIndex++ ) );
745 page.setMimeType( daoUtil.getString( nIndex++ ) );
746 page.setDateUpdate( daoUtil.getTimestamp( nIndex++ ) );
747 page.setMetaKeywords( daoUtil.getString( nIndex++ ) );
748 page.setMetaDescription( daoUtil.getString( nIndex++ ) );
749
750 if ( daoUtil.getObject( nIndex ) != null )
751 {
752 page.setIdAuthorizationNode( daoUtil.getInt( nIndex ) );
753 }
754 nIndex++;
755 page.setDisplayDateUpdate( daoUtil.getBoolean( nIndex++ ) );
756 page.setIsManualDateUpdate( daoUtil.getBoolean( nIndex++ ) );
757 }
758
759 }
760
761 return page;
762 }
763
764
765
766
767 public void updateAutorisationNode( int nIdPage, Integer nIdAutorisationNode )
768 {
769 StringBuilder strSQl = new StringBuilder( );
770 strSQl.append( SQL_QUERY_UPDATE_AUTORISATION_NODE );
771
772 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( strSQl.toString( ) ) )
773 {
774
775 if ( nIdAutorisationNode != null )
776 {
777 daoUtil.setInt( 1, nIdAutorisationNode );
778 }
779 else
780 {
781 daoUtil.setIntNull( 1 );
782 }
783
784 daoUtil.setInt( 2, nIdPage );
785
786 daoUtil.executeUpdate( );
787 }
788 }
789
790
791
792
793 public List<Integer> selectPageForChangeAutorisationNode( int nIdParentPage )
794 {
795 List<Integer> listIdPage = new ArrayList<>( );
796 try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_CHILD_PAGE_FOR_MODIFY_AUTORISATION_NODE ) )
797 {
798
799 daoUtil.setInt( 1, nIdParentPage );
800
801 daoUtil.executeQuery( );
802
803 while ( daoUtil.next( ) )
804 {
805 listIdPage.add( daoUtil.getInt( 1 ) );
806 }
807
808 }
809
810 return listIdPage;
811 }
812 }