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.announce.business;
35
36 import fr.paris.lutece.plugins.announce.service.AnnounceCacheService;
37 import fr.paris.lutece.plugins.announce.service.AnnouncePlugin;
38 import fr.paris.lutece.plugins.announce.service.announcesearch.AnnounceSearchService;
39 import fr.paris.lutece.plugins.genericattributes.business.Response;
40 import fr.paris.lutece.plugins.genericattributes.business.ResponseHome;
41 import fr.paris.lutece.portal.business.file.FileHome;
42 import fr.paris.lutece.portal.service.plugin.Plugin;
43 import fr.paris.lutece.portal.service.plugin.PluginService;
44 import fr.paris.lutece.portal.service.resource.ExtendableResourceRemovalListenerService;
45 import fr.paris.lutece.portal.service.security.LuteceUser;
46 import fr.paris.lutece.portal.service.spring.SpringContextService;
47 import fr.paris.lutece.portal.service.workflow.WorkflowService;
48
49 import java.sql.Timestamp;
50
51 import java.util.ArrayList;
52 import java.util.List;
53
54
55
56
57 public final class AnnounceHome
58 {
59
60 private static IAnnounceDAO _dao = SpringContextService.getBean( "announce.announceDAO" );
61 private static Plugin _plugin = PluginService.getPlugin( AnnouncePlugin.PLUGIN_NAME );
62
63
64
65
66 private AnnounceHome( )
67 {
68 }
69
70
71
72
73
74
75
76
77 public static Announce../../../../../../fr/paris/lutece/plugins/announce/business/Announce.html#Announce">Announce create( Announce announce )
78 {
79 announce.setDateModification( new Timestamp( System.currentTimeMillis( ) ) );
80 updateAnnouncePublicationTime( announce );
81 _dao.insert( announce, _plugin );
82
83 if ( announce.getPublished( ) && !announce.getSuspended( ) && !announce.getSuspendedByUser( ) )
84 {
85 AnnounceSearchService.getInstance( ).addIndexerAction( announce.getId( ), IndexerAction.TASK_CREATE, _plugin );
86 AnnounceCacheService.getService( ).removeKey( AnnounceCacheService.getListIdPublishedAnnouncesCacheKey( ) );
87 }
88
89 return announce;
90 }
91
92
93
94
95
96
97
98
99 public static Announce../../../../../../fr/paris/lutece/plugins/announce/business/Announce.html#Announce">Announce update( Announce announce )
100 {
101 announce.setDateModification( new Timestamp( System.currentTimeMillis( ) ) );
102 _dao.store( announce, _plugin );
103
104 if ( announce.getPublished( ) && !announce.getSuspended( ) && !announce.getSuspendedByUser( ) )
105 {
106 AnnounceSearchService.getInstance( ).addIndexerAction( announce.getId( ), IndexerAction.TASK_MODIFY, _plugin );
107 }
108 else
109 {
110 AnnounceSearchService.getInstance( ).addIndexerAction( announce.getId( ), IndexerAction.TASK_DELETE, _plugin );
111 }
112
113 AnnounceCacheService.getService( ).removeKey( AnnounceCacheService.getListIdPublishedAnnouncesCacheKey( ) );
114 AnnounceCacheService.getService( ).putInCache( AnnounceCacheService.getAnnounceCacheKey( announce.getId( ) ), announce );
115
116 return announce;
117 }
118
119
120
121
122
123
124
125 public static void remove( int nAnnounceId )
126 {
127 AnnounceSearchService.getInstance( ).addIndexerAction( nAnnounceId, IndexerAction.TASK_DELETE, _plugin );
128
129 List<Integer> listIdResponse = findListIdResponse( nAnnounceId );
130
131 for ( int nIdResponse : listIdResponse )
132 {
133 ResponseHome.remove( nIdResponse );
134 }
135
136 removeAnnounceResponse( nAnnounceId );
137
138 ExtendableResourceRemovalListenerService.doRemoveResourceExtentions( Announce.RESOURCE_TYPE, Integer.toString( nAnnounceId ) );
139
140 if ( WorkflowService.getInstance( ).isAvailable( ) )
141 {
142 WorkflowService.getInstance( ).doRemoveWorkFlowResource( nAnnounceId, Announce.RESOURCE_TYPE );
143 }
144
145 _dao.delete( nAnnounceId, _plugin );
146 AnnounceCacheService.getService( ).removeKey( AnnounceCacheService.getListIdPublishedAnnouncesCacheKey( ) );
147 AnnounceCacheService.getService( ).removeKey( AnnounceCacheService.getAnnounceCacheKey( nAnnounceId ) );
148 }
149
150
151
152
153
154
155
156
157
158
159
160 public static Announce findByPrimaryKey( int nKey )
161 {
162 Announce./../../../../fr/paris/lutece/plugins/announce/business/Announce.html#Announce">Announce announce = (Announce) AnnounceCacheService.getService( ).getFromCache( AnnounceCacheService.getAnnounceCacheKey( nKey ) );
163
164 if ( announce == null )
165 {
166 announce = _dao.load( nKey, _plugin );
167
168 if ( announce != null )
169 {
170 AnnounceCacheService.getService( ).putInCache( AnnounceCacheService.getAnnounceCacheKey( announce.getId( ) ), announce );
171 }
172 }
173
174 return announce;
175 }
176
177
178
179
180
181
182
183
184 public static Integer findIdByImageResponse( int nIdResponse )
185 {
186 return _dao.findIdByImageResponse( nIdResponse, _plugin );
187 }
188
189
190
191
192
193
194
195
196 public static List<Integer> findAll( AnnounceSort announceSort )
197 {
198 return _dao.selectAll( announceSort, _plugin );
199 }
200
201
202
203
204
205
206
207
208 public static List<Integer> findAllPublishedId( AnnounceSort announceSort )
209 {
210 List<Integer> listIds = (List<Integer>) AnnounceCacheService.getService( ).getFromCache( AnnounceCacheService.getListIdPublishedAnnouncesCacheKey( ) );
211
212 if ( listIds == null )
213 {
214 listIds = _dao.selectAllPublishedId( announceSort, _plugin );
215 AnnounceCacheService.getService( ).putInCache( AnnounceCacheService.getListIdPublishedAnnouncesCacheKey( ), listIds );
216 }
217
218 return _dao.selectAllPublishedId( announceSort, _plugin );
219 }
220
221
222
223
224
225
226
227
228 public static List<Announce> findAllPublished( AnnounceSort announceSort )
229 {
230 return _dao.selectAllPublished( announceSort, _plugin );
231 }
232
233
234
235
236
237
238
239
240
241
242 public static List<Announce> findByListId( List<Integer> listIdAnnounces, AnnounceSort announceSort )
243 {
244 return _dao.findByListId( listIdAnnounces, announceSort, _plugin );
245 }
246
247
248
249
250
251
252
253
254
255
256 public static List<Announce> getAnnouncesForUser( LuteceUser user, AnnounceSort announceSort )
257 {
258 return _dao.selectAllForUser( user.getName( ), announceSort, _plugin );
259 }
260
261
262
263
264
265
266
267
268
269
270 public static List<Announce> getAnnouncesForUser( String user, AnnounceSort announceSort )
271 {
272 return _dao.selectAllForUser( user, announceSort, _plugin );
273 }
274
275
276
277
278
279
280
281
282
283
284 public static List<Integer> getPublishedAnnouncesForCategory( Category category, AnnounceSort announceSort )
285 {
286 return _dao.selectAllPublishedForCategory( category, announceSort, _plugin );
287 }
288
289
290
291
292
293
294
295 public static void setPublished( Announce announce )
296 {
297 updateAnnouncePublicationTime( announce );
298 _dao.setPublished( announce, _plugin );
299
300 if ( announce.getPublished( ) && !announce.getSuspended( ) && !announce.getSuspendedByUser( ) )
301 {
302 AnnounceSearchService.getInstance( ).addIndexerAction( announce.getId( ), IndexerAction.TASK_CREATE, _plugin );
303 }
304 else
305 {
306 AnnounceSearchService.getInstance( ).addIndexerAction( announce.getId( ), IndexerAction.TASK_DELETE, _plugin );
307 }
308
309 AnnounceCacheService.getService( ).removeKey( AnnounceCacheService.getListIdPublishedAnnouncesCacheKey( ) );
310 AnnounceCacheService.getService( ).removeKey( AnnounceCacheService.getAnnounceCacheKey( announce.getId( ) ) );
311 }
312
313 public static void setHasNotifed( Announce announce )
314 {
315 _dao.setHasNotifed( announce, _plugin );
316
317 AnnounceCacheService.getService( ).removeKey( AnnounceCacheService.getAnnounceCacheKey( announce.getId( ) ) );
318 }
319
320
321
322
323
324
325
326 public static void setSuspended( Announce announce )
327 {
328 updateAnnouncePublicationTime( announce );
329 _dao.setSuspended( announce, _plugin );
330
331 if ( announce.getPublished( ) && !announce.getSuspended( ) && !announce.getSuspendedByUser( ) )
332 {
333 AnnounceSearchService.getInstance( ).addIndexerAction( announce.getId( ), IndexerAction.TASK_CREATE, _plugin );
334 }
335 else
336 {
337 AnnounceSearchService.getInstance( ).addIndexerAction( announce.getId( ), IndexerAction.TASK_DELETE, _plugin );
338 }
339
340 AnnounceCacheService.getService( ).removeKey( AnnounceCacheService.getListIdPublishedAnnouncesCacheKey( ) );
341 AnnounceCacheService.getService( ).removeKey( AnnounceCacheService.getAnnounceCacheKey( announce.getId( ) ) );
342 }
343
344
345
346
347
348
349
350 public static void setSuspendedByUser( Announce announce )
351 {
352 updateAnnouncePublicationTime( announce );
353 _dao.setSuspendedByUser( announce, _plugin );
354
355 if ( announce.getPublished( ) && !announce.getSuspended( ) && !announce.getSuspendedByUser( ) )
356 {
357 AnnounceSearchService.getInstance( ).addIndexerAction( announce.getId( ), IndexerAction.TASK_CREATE, _plugin );
358 }
359 else
360 {
361 AnnounceSearchService.getInstance( ).addIndexerAction( announce.getId( ), IndexerAction.TASK_DELETE, _plugin );
362 }
363
364 AnnounceCacheService.getService( ).removeKey( AnnounceCacheService.getListIdPublishedAnnouncesCacheKey( ) );
365 AnnounceCacheService.getService( ).removeKey( AnnounceCacheService.getAnnounceCacheKey( announce.getId( ) ) );
366 }
367
368
369
370
371
372
373
374
375 public static List<Integer> findIdAnnouncesByDateCreation( Timestamp timestamp )
376 {
377 return _dao.findIdAnnouncesByDateCreation( timestamp, _plugin );
378 }
379
380
381
382
383
384
385
386
387 public static List<Integer> findIdAnnouncesByDatePublication( long lMinPublicationTime )
388 {
389 return _dao.findIdAnnouncesByDatePublication( lMinPublicationTime, _plugin );
390 }
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406 public static void insertAnnounceResponse( int nIdAnnounce, int nIdResponse, boolean bIsImage )
407 {
408 _dao.insertAnnounceResponse( nIdAnnounce, nIdResponse, bIsImage, _plugin );
409 }
410
411
412
413
414
415
416
417
418 public static List<Integer> findListIdResponse( int nIdAnnounce )
419 {
420 return _dao.findListIdResponse( nIdAnnounce, _plugin );
421 }
422
423
424
425
426
427
428
429
430 public static List<Integer> findListIdImageResponse( int nIdAnnounce )
431 {
432 return _dao.findListIdImageResponse( nIdAnnounce, _plugin );
433 }
434
435
436
437
438
439
440
441
442
443
444 public static List<Response> findListResponse( int nIdAnnounce, boolean bLoadFiles )
445 {
446 List<Integer> listIdResponse = findListIdResponse( nIdAnnounce );
447 List<Response> listResponse = new ArrayList<>( listIdResponse.size( ) );
448
449 for ( Integer nIdResponse : listIdResponse )
450 {
451 Response response = ResponseHome.findByPrimaryKey( nIdResponse );
452
453 if ( response != null )
454 {
455 if ( bLoadFiles && ( response.getFile( ) != null ) )
456 {
457 response.setFile( FileHome.findByPrimaryKey( response.getFile( ).getIdFile( ) ) );
458 }
459
460 listResponse.add( response );
461 }
462 }
463
464 return listResponse;
465 }
466
467
468
469
470
471
472
473 public static void removeAnnounceResponse( int nIdAnnounce )
474 {
475 _dao.deleteAnnounceResponse( nIdAnnounce, _plugin );
476 }
477
478
479
480
481
482
483
484
485 private static void updateAnnouncePublicationTime( Announce announce )
486 {
487 if ( announce.getPublished( ) && !announce.getSuspended( ) && !announce.getSuspendedByUser( ) )
488 {
489 announce.setTimePublication( System.currentTimeMillis( ) );
490 }
491 }
492 }