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.links.business.portlet;
35
36 import fr.paris.lutece.plugins.links.business.Link;
37 import fr.paris.lutece.portal.business.portlet.Portlet;
38 import fr.paris.lutece.util.ReferenceList;
39 import fr.paris.lutece.util.sql.DAOUtil;
40
41 import java.util.ArrayList;
42 import java.util.Collection;
43
44
45
46
47
48 public final class LinksPortletDAO implements ILinksPortletDAO
49 {
50
51 private static final String SQL_QUERY_SELECT = " SELECT id_portlet FROM core_portlet WHERE id_portlet = ? ";
52 private static final String SQL_QUERY_INSERT = " INSERT INTO link_list_portlet ( id_portlet, id_link, link_order ) VALUES ( ? , ? , ? )";
53 private static final String SQL_QUERY_DELETE = " DELETE FROM link_list_portlet WHERE id_portlet = ? ";
54 private static final String SQL_QUERY_DELETE_LINK_PORTLET = " DELETE FROM link_portlet WHERE id_portlet = ? ";
55 private static final String SQL_QUERY_DELETE_LINK = " DELETE FROM link_list_portlet WHERE id_portlet=? AND id_link = ? ";
56 private static final String SQL_QUERY_SELECT_LINK = " SELECT id_link, name, url FROM link ORDER BY name ";
57 private static final String SQL_QUERY_SELECT_ID_LINK = " SELECT id_link FROM link_list_portlet WHERE id_portlet = ? AND id_link = ? ";
58 private static final String SQL_QUERY_SELECT_LINK_IN_PORTLET_LIST = " SELECT a.id_link, a.name, a.url, a.description, a.image_content, a.mime_type, a.workgroup_key " +
59 " FROM link a, link_list_portlet b WHERE a.id_link = b.id_link AND b.id_portlet = ? " +
60 " ORDER BY b.link_order";
61 private static final String SQL_QUERY_SELECT_LINK_ORDER = " SELECT link_order FROM link_list_portlet WHERE id_portlet = ? AND id_link = ? ";
62 private static final String SQL_QUERY_SELECT_MAX_ORDER = " SELECT max( link_order ) FROM link_list_portlet WHERE id_portlet= ? ";
63 private static final String SQL_QUERY_SELECT_PORTLET_MAX_ORDER = " SELECT max( portlet_link_order ) FROM link_portlet ";
64 private static final String SQL_QUERY_UPDATE_LINK_ORDER = " UPDATE link_list_portlet SET link_order = ? WHERE id_portlet = ? AND id_link = ? ";
65 private static final String SQL_QUERY_SELECT_LINK_ID_BY_ORDER = " SELECT id_link FROM link_list_portlet WHERE id_portlet = ? AND link_order = ? ";
66 private static final String SQL_QUERY_SELECT_UNSELECTED_PORTLET = " SELECT a.id_portlet, a.name FROM core_portlet a " +
67 " LEFT JOIN link_portlet b ON a.id_portlet=b.id_portlet WHERE b.id_portlet is NULL " +
68 " AND a.id_portlet_type= ? ";
69 private static final String SQL_QUERY_SELECT_PORTLET_LINK_PAGE = " SELECT a.id_portlet, a.portlet_link_order, b.name " +
70 " FROM link_portlet a, core_portlet b WHERE a.portlet_link_order > -1 " +
71 " AND a.id_portlet=b.id_portlet ORDER BY a.portlet_link_order ";
72 private static final String SQL_QUERY_SELECT_PORTLET_LINK_ORDER = " SELECT portlet_link_order FROM link_portlet WHERE id_portlet = ? ";
73 private static final String SQL_QUERY_DELETE_PORTLET = " DELETE FROM link_portlet WHERE id_portlet= ? ";
74 private static final String SQL_QUERY_DELETE_LINK_FROM_PORTLET = " DELETE FROM link_list_portlet WHERE id_link= ? ";
75 private static final String SQL_QUERY_INSERT_INTO_PORTLET = " INSERT INTO link_portlet ( id_portlet, portlet_link_order ) VALUES ( ? , ? ) ";
76 private static final String SQL_QUERY_SELECT_PORTLET_ID = " SELECT id_portlet FROM link_portlet WHERE portlet_link_order = ? ";
77 private static final String SQL_QUERY_UPDATE_PORTLET_LINK = " UPDATE link_portlet SET portlet_link_order = ? WHERE id_portlet = ? ";
78 private static final String SQL_QUERY_SELECT_URL_LIST = " SELECT virtual_host_key, url FROM link_virtual_host WHERE id_link = ? ";
79
80
81
82
83
84
85
86
87
88 public void insert( Portlet portlet )
89 {
90 }
91
92
93
94
95
96
97
98
99 public void insertLink( int nPortletId, int nLinkId, int nOrder )
100 {
101 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT ) )
102 {
103 daoUtil.setInt( 1, nPortletId );
104 daoUtil.setInt( 2, nLinkId );
105 daoUtil.setInt( 3, nOrder );
106
107 daoUtil.executeUpdate( );
108 }
109 }
110
111
112
113
114
115
116
117 public void deleteLink( int nPortletId, int nLinkId )
118 {
119 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_LINK ) )
120 {
121 daoUtil.setInt( 1, nPortletId );
122 daoUtil.setInt( 2, nLinkId );
123
124 daoUtil.executeUpdate( );
125 }
126 }
127
128
129
130
131
132 public void delete( int nPortletId )
133 {
134 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
135 {
136 daoUtil.setInt( 1, nPortletId );
137 daoUtil.executeUpdate( );
138 }
139
140 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_LINK_PORTLET ) )
141 {
142 daoUtil.setInt( 1, nPortletId );
143 daoUtil.executeUpdate( );
144 }
145 }
146
147
148
149
150
151
152 public Portlet load( int nPortletId )
153 {
154 LinksPortletnks/business/portlet/LinksPortlet.html#LinksPortlet">LinksPortlet portlet = new LinksPortlet( );
155
156 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
157 {
158 daoUtil.setInt( 1, nPortletId );
159 daoUtil.executeQuery( );
160
161 if ( daoUtil.next( ) )
162 {
163 portlet.setId( daoUtil.getInt( 1 ) );
164 }
165 }
166
167 return portlet;
168 }
169
170
171
172
173
174 public void store( Portlet portlet )
175 {
176 }
177
178
179
180
181
182 public ReferenceList selectLinksList( )
183 {
184 ReferenceList list = new ReferenceList( );
185
186 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_LINK ) )
187 {
188 daoUtil.executeQuery( );
189
190 while ( daoUtil.next( ) )
191 {
192 list.addItem( daoUtil.getInt( 1 ), daoUtil.getString( 2 ) + " " + daoUtil.getString( 3 ) );
193 }
194 }
195
196 return list;
197 }
198
199
200
201
202
203
204
205 public boolean testDuplicate( int nPortletId, int nLinkId )
206 {
207 boolean bResult;
208
209 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ID_LINK ) )
210 {
211 daoUtil.setInt( 1, nPortletId );
212 daoUtil.setInt( 2, nLinkId );
213 daoUtil.executeQuery( );
214
215 bResult = daoUtil.next( );
216 }
217
218 return bResult;
219 }
220
221
222
223
224
225
226
227 public Collection<Link> selectLinksInPortletList( int nPortletId )
228 {
229 ArrayList<Link> list = new ArrayList<>( );
230
231 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_LINK_IN_PORTLET_LIST ) )
232 {
233 daoUtil.setInt( 1, nPortletId );
234 daoUtil.executeQuery( );
235
236 while ( daoUtil.next( ) )
237 {
238 Link/plugins/links/business/Link.html#Link">Link link = new Link( );
239 link.setId( daoUtil.getInt( 1 ) );
240 link.setName( daoUtil.getString( 2 ) );
241 link.setUrl( daoUtil.getString( 3 ) );
242 link.setDescription( daoUtil.getString( 4 ) );
243 link.setImageContent( daoUtil.getBytes( 5 ) );
244 link.setMimeType( daoUtil.getString( 6 ) );
245 link.setWorkgroupKey( daoUtil.getString( 7 ) );
246 link.setOptionalUrls( this.selectUrlsList( link.getId( ) ) );
247 list.add( link );
248 }
249 }
250
251 return list;
252 }
253
254
255
256
257
258
259
260
261 public int selectLinkOrder( int nPortletId, int nLinkId )
262 {
263 int nOrder = 0;
264
265 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_LINK_ORDER ) )
266 {
267 daoUtil.setInt( 1, nPortletId );
268 daoUtil.setInt( 2, nLinkId );
269 daoUtil.executeQuery( );
270
271 if ( daoUtil.next( ) )
272 {
273 nOrder = daoUtil.getInt( 1 );
274 }
275 }
276
277 return nOrder;
278 }
279
280
281
282
283
284
285 public int selectMaxOrder( int nPortletId )
286 {
287 int nOrder = 0;
288
289 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_MAX_ORDER ) )
290 {
291 daoUtil.setInt( 1, nPortletId );
292 daoUtil.executeQuery( );
293
294 if ( daoUtil.next( ) )
295 {
296 nOrder = daoUtil.getInt( 1 );
297 }
298 }
299
300 return nOrder;
301 }
302
303
304
305
306
307 public int selectPortletMaxOrder( )
308 {
309 int nOrder = 0;
310
311 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_PORTLET_MAX_ORDER ) )
312 {
313 daoUtil.executeQuery( );
314
315 if ( daoUtil.next( ) )
316 {
317 nOrder = daoUtil.getInt( 1 );
318 }
319 }
320
321 return nOrder;
322 }
323
324
325
326
327
328
329
330
331 public void storeLinkOrder( int nOrder, int nPortletId, int nLinkId )
332 {
333 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_LINK_ORDER ) )
334 {
335 daoUtil.setInt( 1, nOrder );
336 daoUtil.setInt( 2, nPortletId );
337 daoUtil.setInt( 3, nLinkId );
338
339 daoUtil.executeUpdate( );
340 }
341 }
342
343
344
345
346
347
348
349 public int selectLinkIdByOrder( int nPortletId, int nOrder )
350 {
351 int nResult = 0;
352
353 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_LINK_ID_BY_ORDER ) )
354 {
355 daoUtil.setInt( 1, nPortletId );
356 daoUtil.setInt( 2, nOrder );
357 daoUtil.executeQuery( );
358
359 if ( daoUtil.next( ) )
360 {
361 nResult = daoUtil.getInt( 1 );
362 }
363 }
364
365 return nResult;
366 }
367
368
369
370
371
372 public ReferenceList findUnselectedPortlets( )
373 {
374 ReferenceList list = new ReferenceList( );
375 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_UNSELECTED_PORTLET ) )
376 {
377 String strPortletTypeId = LinksPortletHome.getInstance( ).getPortletTypeId( );
378
379 daoUtil.setString( 1, strPortletTypeId );
380 daoUtil.executeQuery( );
381
382 while ( daoUtil.next( ) )
383 {
384 list.addItem( daoUtil.getInt( 1 ), daoUtil.getString( 2 ) );
385 }
386 }
387
388 return list;
389 }
390
391
392
393
394
395
396 public Collection<Portlet> selectPortletsInLinksPage( )
397 {
398 ArrayList<Portlet> list = new ArrayList<>( );
399 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_PORTLET_LINK_PAGE ) )
400 {
401 daoUtil.executeQuery( );
402
403 while ( daoUtil.next( ) )
404 {
405 LinksPortletnks/business/portlet/LinksPortlet.html#LinksPortlet">LinksPortlet portlet = new LinksPortlet( );
406 portlet.setId( daoUtil.getInt( 1 ) );
407 portlet.setPortletOrder( daoUtil.getInt( 2 ) );
408 portlet.setName( daoUtil.getString( 3 ) );
409 list.add( portlet );
410 }
411 }
412
413 return list;
414 }
415
416
417
418
419
420
421 public int selectPortletOrder( int nPortletId )
422 {
423 int nOrder = 0;
424
425 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_PORTLET_LINK_ORDER ) )
426 {
427 daoUtil.setInt( 1, nPortletId );
428 daoUtil.executeQuery( );
429
430 if ( daoUtil.next( ) )
431 {
432 nOrder = daoUtil.getInt( 1 );
433 }
434 }
435
436 return nOrder;
437 }
438
439
440
441
442
443 public void removePortlet( int nPortletId )
444 {
445 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_PORTLET ) )
446 {
447 daoUtil.setInt( 1, nPortletId );
448 daoUtil.executeUpdate( );
449 }
450 }
451
452
453
454
455
456 public void removeLinkFromPortlets( int nLinkId )
457 {
458 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_LINK_FROM_PORTLET ) )
459 {
460 daoUtil.setInt( 1, nLinkId );
461 daoUtil.executeUpdate( );
462 }
463 }
464
465
466
467
468
469
470 public void insertPortlet( int nPortletId, int nOrder )
471 {
472 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT_INTO_PORTLET ) )
473 {
474 daoUtil.setInt( 1, nPortletId );
475 daoUtil.setInt( 2, nOrder );
476 daoUtil.executeUpdate( );
477 }
478 }
479
480
481
482
483
484
485 public int selectPortletIdByOrder( int nOrder )
486 {
487 int nResult = 0;
488
489 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_PORTLET_ID ) )
490 {
491 daoUtil.setInt( 1, nOrder );
492 daoUtil.executeQuery( );
493
494 if ( daoUtil.next( ) )
495 {
496 nResult = daoUtil.getInt( 1 );
497 }
498 }
499
500 return nResult;
501 }
502
503
504
505
506
507
508
509 public void storePortletOrder( int nOrder, int nPortletId )
510 {
511 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE_PORTLET_LINK ) )
512 {
513 daoUtil.setInt( 1, nOrder );
514 daoUtil.setInt( 2, nPortletId );
515 daoUtil.executeUpdate( );
516 }
517 }
518
519
520
521
522
523
524
525 private ReferenceList selectUrlsList( int idLink )
526 {
527 ReferenceList list = new ReferenceList( );
528 try( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_URL_LIST ) )
529 {
530 daoUtil.setInt( 1, idLink );
531 daoUtil.executeQuery( );
532
533 while ( daoUtil.next( ) )
534 {
535 list.addItem( daoUtil.getString( 1 ), daoUtil.getString( 2 ) );
536 }
537 }
538
539 return list;
540 }
541 }