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.formengine.web.notice;
35
36 import fr.paris.lutece.plugins.formengine.business.Notice;
37 import fr.paris.lutece.plugins.formengine.business.NoticeFilter;
38 import fr.paris.lutece.plugins.formengine.business.NoticeGroup;
39 import fr.paris.lutece.plugins.formengine.business.NoticeGroupFilter;
40 import fr.paris.lutece.plugins.formengine.business.NoticeGroupHome;
41 import fr.paris.lutece.plugins.formengine.business.NoticeHome;
42 import fr.paris.lutece.plugins.formengine.service.FormsRegistrationService;
43 import fr.paris.lutece.plugins.formengine.util.NoticeUtils;
44 import fr.paris.lutece.portal.business.mailinglist.MailingList;
45 import fr.paris.lutece.portal.business.mailinglist.MailingListHome;
46 import fr.paris.lutece.portal.service.admin.AdminUserService;
47 import fr.paris.lutece.portal.service.i18n.I18nService;
48 import fr.paris.lutece.portal.service.message.AdminMessage;
49 import fr.paris.lutece.portal.service.message.AdminMessageService;
50 import fr.paris.lutece.portal.service.plugin.Plugin;
51 import fr.paris.lutece.portal.service.template.AppTemplateService;
52 import fr.paris.lutece.portal.service.util.AppLogService;
53 import fr.paris.lutece.portal.service.util.AppPathService;
54 import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService;
55 import fr.paris.lutece.portal.web.admin.PluginAdminPageJspBean;
56 import fr.paris.lutece.util.ReferenceItem;
57 import fr.paris.lutece.util.ReferenceList;
58 import fr.paris.lutece.util.html.HtmlTemplate;
59 import fr.paris.lutece.util.html.Paginator;
60 import fr.paris.lutece.util.url.UrlItem;
61
62 import org.apache.commons.lang.StringUtils;
63
64 import java.sql.Timestamp;
65
66 import java.text.SimpleDateFormat;
67
68 import java.util.Collection;
69 import java.util.HashMap;
70 import java.util.List;
71 import java.util.Locale;
72 import java.util.Map;
73
74 import javax.servlet.http.HttpServletRequest;
75
76
77
78
79
80
81 public class NoticeJspBean extends PluginAdminPageJspBean
82 {
83
84 public static final String RIGHT_NOTICE_MANAGEMENT = "NOTICE_MANAGEMENT";
85
86
87 private static final String MARK_WEBAPP_URL = "webapp_url";
88 private static final String MARK_LOCALE = "locale";
89 private static final String MARK_LIST_STATUT = "notice_statut";
90 private static final String MARK_LIST_USER_GROUP = "notice_user_group";
91 private static final String MARK_PAGINATOR = "paginator";
92 private static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
93 private static final String MARK_NOTICE_LIST = "notice_list";
94 private static final String MARK_NOTICE_GROUP_LIST = "notice_group_list";
95 private static final String MARK_WORKGROUP_LIST = "user_workgroup_list";
96 private static final String MARK_MAILING_LIST = "mailing_list";
97 private static final String MARK_FORM = "form_list";
98 private static final String MARK_NOTICE = "notice";
99 private static final String MARK_NOTICE_GROUP = "notice_group";
100 private static final String MARK_NOTICE_GROUP_ID = "notice_group_id";
101 private static final String MARK_DATE_DU_JOUR = "date_du_jour";
102 private static final String MARK_USER_WORKGROUP_SELECTED = "user_workgroup_selected";
103 private static final String MARK_ACTIVE_SELECTED = "active_selected";
104 private static final String MARK_FORM_SELECTED = "form_selected";
105 private static final String MARK_FORM_MAP = "form_map";
106
107
108 private static final String PARAMETER_CANCEL = "cancel";
109 private static final String PARAMETER_ACTIVE = "active";
110 private static final String PARAMETER_WORKGROUP = "workgroup";
111 private static final String PARAMETER_TITLE = "title";
112 private static final String PARAMETER_MESSAGE = "message";
113 private static final String PARAMETER_DATE_DEBUT = "date_begin_disponibility";
114 private static final String PARAMETER_DATE_FIN = "date_end_disponibility";
115 private static final String PARAMETER_ID_MAILINIG_LIST = "mailing";
116 private static final String PARAMETER_FORM = "form";
117 private static final String PARAMETER_ID_NOTICE = "id_notice";
118 private static final String PARAMETER_ID_NOTICE_GROUP = "id_notice_group";
119 private static final String PARAMETER_ORDER = "order";
120
121
122 private static final String PROPERTY_CREATE_NOTICE_PAGE_TITLE = "formengine.adminFeature.notice_create.name";
123 private static final String PROPERTY_CREATE_NOTICE_GROUP_PAGE_TITLE = "formengine.adminFeature.notice_group_create.name";
124 private static final String PROPERTY_COPY_NOTICE_TITLE = "formengine.adminFeature.notice_copy.name";
125 private static final String PROPERTY_COPY_NOTICE_GROUP_TITLE = "formengine.adminFeature.notice_copy_notice_group.name";
126 private static final String PROPERTY_MODIFY_NOTICE_TITLE = "formengine.notice.label.modify_notice.title";
127 private static final String PROPERTY_MODIFY_NOTICE_GROUP_TITLE = "formengine.adminFeature.notice_group_modify.name";
128 private static final String PROPERTY_MANAGE_NOTICE_GROUP_TITLE = "formengine.notice_group.label.manage.title";
129
130
131 private static final String JSP_MANAGE_NOTICE_GROUP = "jsp/admin/plugins/formengine/ManageNoticeGroup.jsp";
132 private static final String JSP_MANAGE_NOTICE = "jsp/admin/plugins/formengine/ManageNotice.jsp";
133 private static final String JSP_DO_REMOVE_NOTICE = "jsp/admin/plugins/formengine/DoRemoveNotice.jsp";
134 private static final String JSP_DO_REMOVE_NOTICE_GROUP = "jsp/admin/plugins/formengine/DoRemoveNoticeGroup.jsp";
135
136
137 private static final String TEMPLATE_FORMENGINE_NOTICE = "/admin/plugins/formengine/notice/manage_formengine_notice.html";
138 private static final String TEMPLATE_FORMENGINE_CREATE_NOTICE = "/admin/plugins/formengine/notice/create_notice.html";
139 private static final String TEMPLATE_MODIFY_NOTICE = "/admin/plugins/formengine/notice/modify_notice.html";
140 private static final String TEMPLATE_MANAGE_NOTICE_GROUP = "/admin/plugins/formengine/notice/manage_formengine_notice_group.html";
141 private static final String TEMPLATE_CREATE_NOTICE_GROUP = "/admin/plugins/formengine/notice/create_notice_group.html";
142 private static final String TEMPLATE_MODIFY_NOTICE_GROUP = "/admin/plugins/formengine/notice/modify_notice_group.html";
143
144
145 private static final String MESSAGE_NOTICE_MANDATORY = "formengine.notice.message.mandatory.field";
146 private static final String MESSAGE_FIELD_TITLE = "formengine.notice.message.title";
147 private static final String MESSAGE_FIELD_MESSAGE = "formengine.notice.message.message";
148 private static final String MESSAGE_ERROR_DATE = "formengine.notice.message.error_date";
149 private static final String MESSAGE_ERROR_NOTICE_GROUP = "formengine.notice.message.noticegroup";
150 private static final String MESSAGE_CONFIRM_REMOVE_NOTICE = "formengine.notice.message.remove_notice";
151 private static final String MESSAGE_CONFIRM_REMOVE_NOTICE_GROUP = "formengine.notice_group.message.remove_notice_group";
152 private static final String MESSAGE_ALL = "formengine.notice.message.all";
153 private static final String MESSAGE_ACTIVATED = "formengine.notice.message.activated";
154 private static final String MESSAGE_NOT_ACTIVATED = "formengine.notice.message.notActivated";
155 private static final String MESSAGE_NONE = "formengine.notice.message.none";
156 private static final String MESSAGE_FIELD_FORM = "formengine.notice.message.form";
157
158
159 private static final String CONSTANT_NO_FORM = "-1";
160
161
162 private static final int DEFAULT_ITEMS_PER_PAGE = 10;
163 private int _nItemsPerPage;
164 private String _strCurrentPageIndex;
165 private int _nIdActive = -1;
166 private String _strWorkGroup = AdminWorkgroupService.ALL_GROUPS;
167 private int _nIdNoticeGroup;
168 private String _strForm = NoticeGroupFilter.ALL_STRING;
169
170
171
172
173
174 private ReferenceList initRefListStatut( )
175 {
176 ReferenceList refListStatut = new ReferenceList( );
177
178 refListStatut.addItem( -1, I18nService.getLocalizedString( MESSAGE_ALL, getLocale( ) ) );
179 refListStatut.addItem( 0, I18nService.getLocalizedString( MESSAGE_NOT_ACTIVATED, getLocale( ) ) );
180 refListStatut.addItem( 1, I18nService.getLocalizedString( MESSAGE_ACTIVATED, getLocale( ) ) );
181
182 return refListStatut;
183 }
184
185
186
187
188
189 private ReferenceList initRefListUserGroup( )
190 {
191 return AdminWorkgroupService.getUserWorkgroups( getUser( ), getLocale( ) );
192 }
193
194
195
196
197
198 private ReferenceList initRefListMailingList( )
199 {
200 ReferenceList refListMailingList = new ReferenceList( );
201 Collection<MailingList> colMailingList = MailingListHome.findAll( );
202 int count = 0;
203 refListMailingList.addItem( -1, I18nService.getLocalizedString( MESSAGE_NONE, getLocale( ) ) );
204
205 for ( MailingList mailingList : colMailingList )
206 {
207 refListMailingList.addItem( count, mailingList.getName( ) );
208 count++;
209 }
210
211 return refListMailingList;
212 }
213
214
215
216
217
218 private ReferenceList initRefListFormsList( )
219 {
220 ReferenceList refListForms = FormsRegistrationService.getListForm( );
221 ReferenceItem refItem = new ReferenceItem( );
222 refItem.setCode( NoticeGroupFilter.ALL_STRING );
223 refItem.setName( I18nService.getLocalizedString( MESSAGE_ALL, getLocale( ) ) );
224 refListForms.add( 0, refItem );
225
226 return refListForms;
227 }
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253 public String getManageNoticeGroup( HttpServletRequest request )
254 {
255 setPageTitleProperty( PROPERTY_MANAGE_NOTICE_GROUP_TITLE );
256
257 String strFilterForm = request.getParameter( PARAMETER_FORM );
258 String strFilterWorkgroup = request.getParameter( PARAMETER_WORKGROUP );
259 String strFilterStatus = request.getParameter( PARAMETER_ACTIVE );
260
261 if ( StringUtils.isNotBlank( strFilterForm ) )
262 {
263 _strForm = strFilterForm;
264 }
265
266 if ( StringUtils.isNotBlank( strFilterWorkgroup ) )
267 {
268 _strWorkGroup = strFilterWorkgroup;
269 }
270
271 if ( StringUtils.isNotBlank( strFilterStatus ) )
272 {
273 _nIdActive = NoticeUtils.convertStringToInt( strFilterStatus );
274 }
275
276 NoticeGroupFilter filter = new NoticeGroupFilter( );
277 filter.setForm( _strForm );
278 filter.setIsEnbled( _nIdActive );
279 filter.setWorkGroup( _strWorkGroup );
280
281 _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
282 _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage,
283 DEFAULT_ITEMS_PER_PAGE );
284
285 List<NoticeGroup> listNoticeGroup = NoticeGroupHome.findByFilter( filter, getPlugin( ) );
286
287 listNoticeGroup = (List<NoticeGroup>) AdminWorkgroupService.getAuthorizedCollection( listNoticeGroup,
288 getUser( ) );
289
290 Paginator<NoticeGroup> paginator = new Paginator<NoticeGroup>( listNoticeGroup, _nItemsPerPage,
291 getJspManageNoticeGroup( request ), Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
292
293 Map<String, Object> model = new HashMap<String, Object>( );
294
295 model.put( MARK_LIST_STATUT, initRefListStatut( ) );
296 model.put( MARK_ACTIVE_SELECTED, _nIdActive );
297 model.put( MARK_LIST_USER_GROUP, initRefListUserGroup( ) );
298 model.put( MARK_USER_WORKGROUP_SELECTED, _strWorkGroup );
299 model.put( MARK_PAGINATOR, paginator );
300 model.put( MARK_FORM, initRefListFormsList( ) );
301 model.put( MARK_FORM_SELECTED, _strForm );
302 model.put( MARK_NOTICE_GROUP_LIST, paginator.getPageItems( ) );
303 model.put( MARK_FORM_MAP, FormsRegistrationService.getMapForm( ) );
304 model.put( MARK_NB_ITEMS_PER_PAGE, "" + _nItemsPerPage );
305
306 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_NOTICE_GROUP, getLocale( ), model );
307
308 return getAdminPage( template.getHtml( ) );
309 }
310
311
312
313
314
315
316 public String getCreateNoticeGroup( HttpServletRequest request )
317 {
318 Map<String, Object> model = new HashMap<String, Object>( );
319 setPageTitleProperty( PROPERTY_CREATE_NOTICE_GROUP_PAGE_TITLE );
320
321 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
322 model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
323 model.put( MARK_MAILING_LIST, initRefListMailingList( ) );
324 model.put( MARK_WORKGROUP_LIST, initRefListUserGroup( ) );
325 model.put( MARK_FORM, FormsRegistrationService.getListForm( ) );
326
327 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_NOTICE_GROUP, getLocale( ), model );
328
329 return getAdminPage( template.getHtml( ) );
330 }
331
332
333
334
335
336
337 public String getModifyNoticeGroup( HttpServletRequest request )
338 {
339 String strIdNoticeGroup = request.getParameter( PARAMETER_ID_NOTICE_GROUP );
340
341 if ( StringUtils.isBlank( strIdNoticeGroup ) )
342 {
343 return getNoticeManagement( request );
344 }
345
346 int nIdNotice = NoticeUtils.convertStringToInt( strIdNoticeGroup );
347
348 if ( nIdNotice == -1 )
349 {
350 return getNoticeManagement( request );
351 }
352
353 NoticeGroup noticeGroup = NoticeGroupHome.findByPrimaryKey( nIdNotice, getPlugin( ) );
354
355 if ( ( noticeGroup == null ) )
356 {
357 return getNoticeManagement( request );
358 }
359
360 Locale locale = getLocale( );
361
362 Map<String, Object> model = new HashMap<String, Object>( );
363
364 model.put( MARK_WORKGROUP_LIST, initRefListUserGroup( ) );
365 model.put( MARK_MAILING_LIST, initRefListMailingList( ) );
366 model.put( MARK_NOTICE_GROUP, noticeGroup );
367 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
368 model.put( MARK_LOCALE, getLocale( ) );
369 model.put( MARK_FORM, FormsRegistrationService.getListForm( ) );
370
371 setPageTitleProperty( PROPERTY_MODIFY_NOTICE_GROUP_TITLE );
372
373 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_NOTICE_GROUP, locale, model );
374
375 return getAdminPage( template.getHtml( ) );
376 }
377
378
379
380
381
382
383
384 private String getFields( NoticeGroup noticeGroup, HttpServletRequest request )
385 {
386 String strForm = request.getParameter( PARAMETER_FORM );
387 String strTitle = request.getParameter( PARAMETER_TITLE );
388 String strWorkgroupKey = request.getParameter( PARAMETER_WORKGROUP );
389
390 if ( StringUtils.isBlank( strForm ) || CONSTANT_NO_FORM.equals( strForm ) )
391 {
392 return buildUrlMessageMissingField( I18nService.getLocalizedString( MESSAGE_FIELD_FORM, getLocale( ) ),
393 request );
394 }
395
396 if ( StringUtils.isBlank( strTitle ) )
397 {
398 return buildUrlMessageMissingField( I18nService.getLocalizedString( MESSAGE_FIELD_TITLE, getLocale( ) ),
399 request );
400 }
401
402 noticeGroup.setForm( strForm );
403 noticeGroup.setTitle( strTitle );
404 noticeGroup.setWorkgroupKey( strWorkgroupKey );
405
406 return null;
407 }
408
409
410
411
412
413
414
415 private String buildUrlMessageMissingField( String strField, HttpServletRequest request )
416 {
417 Object[] messageArgs = { strField, };
418
419 return AdminMessageService.getMessageUrl( request, MESSAGE_NOTICE_MANDATORY, messageArgs, AdminMessage.TYPE_STOP );
420 }
421
422
423
424
425
426
427 public String doCreateNoticeGroup( HttpServletRequest request )
428 {
429 if ( request.getParameter( PARAMETER_CANCEL ) != null )
430 {
431 return getJspManageNoticeGroup( request );
432 }
433
434 NoticeGroup noticeGroup = new NoticeGroup( );
435 String strError = getFields( noticeGroup, request );
436
437 if ( strError != null )
438 {
439 return strError;
440 }
441
442 NoticeGroupHome.create( noticeGroup, getPlugin( ) );
443
444 return getHomeUrl( request );
445 }
446
447
448
449
450
451
452 public String doModifyNoticeGroup( HttpServletRequest request )
453 {
454 if ( request.getParameter( PARAMETER_CANCEL ) != null )
455 {
456 return getJspManageNoticeGroup( request );
457 }
458
459 String strIdNoticeGroup = request.getParameter( PARAMETER_ID_NOTICE_GROUP );
460
461 if ( StringUtils.isBlank( strIdNoticeGroup ) )
462 {
463 return getJspManageNoticeGroup( request );
464 }
465
466 int nIdNoticeGroup = NoticeUtils.convertStringToInt( strIdNoticeGroup );
467
468 if ( nIdNoticeGroup == -1 )
469 {
470 return getJspManageNoticeGroup( request );
471 }
472
473 NoticeGroup noticeGroup = NoticeGroupHome.findByPrimaryKey( nIdNoticeGroup, getPlugin( ) );
474 String strError = getFields( noticeGroup, request );
475
476 if ( strError != null )
477 {
478 return strError;
479 }
480
481 NoticeGroupHome.update( noticeGroup, getPlugin( ) );
482
483 return getHomeUrl( request );
484 }
485
486
487
488
489
490
491 public String getConfirmRemoveNoticeGroup( HttpServletRequest request )
492 {
493 UrlItem urlItem = new UrlItem( AppPathService.getBaseUrl( request ) + JSP_DO_REMOVE_NOTICE_GROUP );
494
495 Map<Object, Object> requestParameters = new HashMap<Object, Object>( );
496 requestParameters.put( PARAMETER_ID_NOTICE_GROUP, request.getParameter( PARAMETER_ID_NOTICE_GROUP ) );
497
498 return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_NOTICE_GROUP, urlItem.getUrl( ),
499 AdminMessage.TYPE_CONFIRMATION, requestParameters );
500 }
501
502
503
504
505
506
507 public String doRemoveNoticeGroup( HttpServletRequest request )
508 {
509 String strIdNoticeGroup = request.getParameter( PARAMETER_ID_NOTICE_GROUP );
510
511 if ( StringUtils.isBlank( strIdNoticeGroup ) )
512 {
513 return getJspManageNoticeGroup( request );
514 }
515
516 int nIdNoticeGroup = NoticeUtils.convertStringToInt( strIdNoticeGroup );
517
518 if ( nIdNoticeGroup == -1 )
519 {
520 return getJspManageNoticeGroup( request );
521 }
522
523 NoticeGroupHome.remove( nIdNoticeGroup, getPlugin( ) );
524
525 return getHomeUrl( request );
526 }
527
528
529
530
531
532
533 public String getNoticeManagement( HttpServletRequest request )
534 {
535 List<Notice> listNotice;
536 String strWorkGroup = request.getParameter( PARAMETER_WORKGROUP );
537 String strActive = request.getParameter( PARAMETER_ACTIVE );
538 String strIdNoticeGroup = request.getParameter( PARAMETER_ID_NOTICE_GROUP );
539
540 _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
541 _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage,
542 DEFAULT_ITEMS_PER_PAGE );
543
544 if ( ( strActive != null ) && !strActive.equals( NoticeUtils.EMPTY_STRING ) )
545 {
546 _nIdActive = NoticeUtils.convertStringToInt( strActive );
547 }
548
549 if ( ( strWorkGroup != null ) && !strWorkGroup.equals( NoticeUtils.EMPTY_STRING ) )
550 {
551 _strWorkGroup = strWorkGroup;
552 }
553
554 int nIdNoticeGroup = NoticeUtils.convertStringToInt( strIdNoticeGroup );
555
556 if ( nIdNoticeGroup != -1 )
557 {
558 _nIdNoticeGroup = nIdNoticeGroup;
559 }
560
561
562
563
564
565 NoticeFilter filter = new NoticeFilter( );
566 filter.setIsEnabled( _nIdActive );
567 filter.setWorkGroup( _strWorkGroup );
568 filter.setIdNoticeGroup( _nIdNoticeGroup );
569
570 listNotice = NoticeHome.getNoticeList( filter, getPlugin( ) );
571 listNotice = (List<Notice>) AdminWorkgroupService.getAuthorizedCollection( listNotice, getUser( ) );
572
573 String strURL = getJspManageNotice( request );
574
575
576
577
578
579 Paginator<Notice> paginator = new Paginator<Notice>( listNotice, _nItemsPerPage, strURL,
580 Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
581
582 Map<String, Object> model = new HashMap<String, Object>( );
583
584 model.put( MARK_LIST_STATUT, initRefListStatut( ) );
585 model.put( MARK_ACTIVE_SELECTED, _nIdActive );
586 model.put( MARK_LIST_USER_GROUP, initRefListUserGroup( ) );
587 model.put( MARK_USER_WORKGROUP_SELECTED, _strWorkGroup );
588 model.put( MARK_PAGINATOR, paginator );
589 model.put( MARK_NB_ITEMS_PER_PAGE, "" + _nItemsPerPage );
590 model.put( MARK_NOTICE_LIST, paginator.getPageItems( ) );
591 model.put( MARK_DATE_DU_JOUR, "" + NoticeUtils.getDate( NoticeUtils.getCurrentDate( ), null ) );
592
593
594 setPageTitleProperty( NoticeUtils.EMPTY_STRING );
595
596 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_FORMENGINE_NOTICE, getLocale( ), model );
597
598 return getAdminPage( template.getHtml( ) );
599 }
600
601
602
603
604
605
606 public String doChangeNoticeOrder( HttpServletRequest request )
607 {
608 String strOrder = request.getParameter( PARAMETER_ORDER );
609 String strIdNotice = request.getParameter( PARAMETER_ID_NOTICE );
610
611 if ( StringUtils.isBlank( strOrder ) || StringUtils.isBlank( strIdNotice ) )
612 {
613 return getJspManageNotice( request );
614 }
615
616 int nIdNotice = NoticeUtils.convertStringToInt( strIdNotice );
617 int nOrder = NoticeUtils.convertStringToInt( strOrder );
618
619 if ( ( nIdNotice == -1 ) || ( nOrder == -1 ) )
620 {
621 return getJspManageNotice( request );
622 }
623
624 Notice notice = NoticeHome.findByPrimaryKey( nIdNotice, getPlugin( ) );
625
626 if ( notice == null )
627 {
628 return getJspManageNotice( request );
629 }
630
631
632 int nOldOrder = notice.getOrder( );
633
634
635 NoticeFilter filter = new NoticeFilter( );
636 filter.setIdNoticeGroup( notice.getIdNoticeGroup( ) );
637
638 List<Notice> listNotices = NoticeHome.getNoticeList( filter, getPlugin( ) );
639
640 if ( nOrder < nOldOrder )
641 {
642 for ( Notice currentNotice : listNotices )
643 {
644 if ( !notice.equals( currentNotice ) )
645 {
646 int nCurrentOrder = currentNotice.getOrder( );
647
648 if ( ( nCurrentOrder >= nOrder ) && ( nCurrentOrder < nOldOrder ) )
649 {
650 currentNotice.setOrder( nCurrentOrder + 1 );
651 NoticeHome.update( currentNotice, getPlugin( ) );
652 }
653 }
654 }
655 }
656 else if ( nOrder > nOldOrder )
657 {
658 for ( Notice currentNotice : listNotices )
659 {
660 if ( !notice.equals( currentNotice ) )
661 {
662 int nCurrentOrder = currentNotice.getOrder( );
663
664 if ( ( nCurrentOrder <= nOrder ) && ( nCurrentOrder > nOldOrder ) )
665 {
666 currentNotice.setOrder( nCurrentOrder - 1 );
667 NoticeHome.update( currentNotice, getPlugin( ) );
668 }
669 }
670 }
671 }
672
673 notice.setOrder( nOrder );
674 NoticeHome.update( notice, getPlugin( ) );
675
676 return getJspManageNotice( request );
677 }
678
679
680
681
682
683
684 public String getCreateNotice( HttpServletRequest request )
685 {
686 Map<String, Object> model = new HashMap<String, Object>( );
687 setPageTitleProperty( PROPERTY_CREATE_NOTICE_PAGE_TITLE );
688
689 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
690 model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
691 model.put( MARK_MAILING_LIST, initRefListMailingList( ) );
692 model.put( MARK_WORKGROUP_LIST, initRefListUserGroup( ) );
693
694
695 model.put( MARK_FORM, FormsRegistrationService.getListForm( ) );
696 model.put( MARK_NOTICE_GROUP_ID, _nIdNoticeGroup );
697
698 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_FORMENGINE_CREATE_NOTICE, getLocale( ), model );
699
700 return getAdminPage( template.getHtml( ) );
701 }
702
703
704
705
706
707
708 public String doCreateNotice( HttpServletRequest request )
709 {
710 if ( ( request.getParameter( PARAMETER_CANCEL ) == null ) )
711 {
712 Notice notice = new Notice( );
713 String strError = getNoticeData( request, notice );
714
715 if ( strError != null )
716 {
717 return strError;
718 }
719
720 notice.setOrder( NoticeHome.findMaxOrderForNoticeGroup( notice.getIdNoticeGroup( ), getPlugin( ) ) + 1 );
721
722 NoticeHome.create( notice, getPlugin( ) );
723 }
724
725 return getJspManageNotice( request );
726 }
727
728
729
730
731
732
733 public String getModifyNotice( HttpServletRequest request )
734 {
735 Plugin plugin = getPlugin( );
736 String strIdNotice = request.getParameter( PARAMETER_ID_NOTICE );
737 int nIdNotice = -1;
738 Notice notice;
739
740 if ( ( strIdNotice != null ) && !strIdNotice.equals( NoticeUtils.EMPTY_STRING ) )
741 {
742 try
743 {
744 nIdNotice = Integer.parseInt( strIdNotice );
745 }
746 catch ( NumberFormatException ne )
747 {
748 AppLogService.error( ne );
749
750 return getNoticeManagement( request );
751 }
752 }
753
754 notice = NoticeHome.findByPrimaryKey( nIdNotice, plugin );
755
756 if ( ( notice == null ) )
757 {
758 return getNoticeManagement( request );
759 }
760
761 Locale locale = getLocale( );
762
763 Map<String, Object> model = new HashMap<String, Object>( );
764
765 model.put( MARK_WORKGROUP_LIST, initRefListUserGroup( ) );
766 model.put( MARK_MAILING_LIST, initRefListMailingList( ) );
767
768
769 model.put( MARK_NOTICE, notice );
770 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
771 model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
772 model.put( MARK_FORM, FormsRegistrationService.getListForm( ) );
773
774 setPageTitleProperty( PROPERTY_MODIFY_NOTICE_TITLE );
775
776 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_NOTICE, locale, model );
777
778 return getAdminPage( template.getHtml( ) );
779 }
780
781
782
783
784
785
786 public String doModifyNotice( HttpServletRequest request )
787 {
788 if ( request.getParameter( PARAMETER_CANCEL ) == null )
789 {
790 Plugin plugin = getPlugin( );
791 String strIdNotice = request.getParameter( PARAMETER_ID_NOTICE );
792 int nIdNotice = -1;
793 Notice notice;
794
795 if ( ( strIdNotice != null ) && !strIdNotice.equals( NoticeUtils.EMPTY_STRING ) )
796 {
797 try
798 {
799 nIdNotice = Integer.parseInt( strIdNotice );
800 }
801 catch ( NumberFormatException ne )
802 {
803 AppLogService.error( ne );
804 }
805 }
806
807 if ( nIdNotice != -1 )
808 {
809 notice = NoticeHome.findByPrimaryKey( nIdNotice, plugin );
810
811 if ( ( notice == null ) )
812 {
813 return getJspManageNotice( request );
814 }
815
816 String strError = getNoticeData( request, notice );
817
818 if ( strError != null )
819 {
820 return strError;
821 }
822
823 notice.setIdNotice( nIdNotice );
824
825 NoticeHome.update( notice, getPlugin( ) );
826
827
828
829
830
831 }
832 }
833
834 return getJspManageNotice( request );
835 }
836
837
838
839
840
841
842 public String doCopyNoticeGroup( HttpServletRequest request )
843 {
844 String strIdNotice = request.getParameter( PARAMETER_ID_NOTICE_GROUP );
845
846 if ( StringUtils.isBlank( strIdNotice ) )
847 {
848 return getHomeUrl( request );
849 }
850
851 int nIdNoticeGroup = NoticeUtils.convertStringToInt( strIdNotice );
852
853 if ( nIdNoticeGroup != -1 )
854 {
855 NoticeGroup noticeGroup = NoticeGroupHome.findByPrimaryKey( nIdNoticeGroup, getPlugin( ) );
856
857 Object[] tabFormTileCopy = { noticeGroup.getTitle( ) };
858 String strTitleCopyForm = I18nService.getLocalizedString( PROPERTY_COPY_NOTICE_GROUP_TITLE,
859 tabFormTileCopy, getLocale( ) );
860
861 if ( strTitleCopyForm != null )
862 {
863 noticeGroup.setTitle( strTitleCopyForm );
864 }
865
866 NoticeGroupHome.create( noticeGroup, getPlugin( ) );
867 }
868
869 return getHomeUrl( request );
870 }
871
872
873
874
875
876
877 public String doCopyNotice( HttpServletRequest request )
878 {
879 Plugin plugin = getPlugin( );
880 Notice notice;
881 String strIdNotice = request.getParameter( PARAMETER_ID_NOTICE );
882 int nIdNotice = -1;
883
884 if ( request.getParameter( PARAMETER_ID_NOTICE ) == null )
885 {
886 return getHomeUrl( request );
887 }
888
889 try
890 {
891 nIdNotice = Integer.parseInt( strIdNotice );
892 }
893 catch ( NumberFormatException ne )
894 {
895 AppLogService.error( ne );
896 }
897
898 if ( ( nIdNotice != -1 ) )
899 {
900 notice = NoticeHome.findByPrimaryKey( nIdNotice, plugin );
901
902 Object[] tabFormTileCopy = { notice.getTitle( ) };
903 String strTitleCopyForm = I18nService.getLocalizedString( PROPERTY_COPY_NOTICE_TITLE, tabFormTileCopy,
904 getLocale( ) );
905
906 if ( strTitleCopyForm != null )
907 {
908 notice.setTitle( strTitleCopyForm );
909 }
910
911 notice.setOrder( NoticeHome.findMaxOrderForNoticeGroup( notice.getIdNoticeGroup( ), getPlugin( ) ) + 1 );
912
913 NoticeHome.create( notice, plugin );
914 }
915
916 return getJspManageNotice( request );
917 }
918
919
920
921
922
923
924 public String doDisableNotice( HttpServletRequest request )
925 {
926 Notice notice;
927 Plugin plugin = getPlugin( );
928 String strIdNotice = request.getParameter( PARAMETER_ID_NOTICE );
929 int nIdNotice = -1;
930
931 if ( ( strIdNotice == null ) )
932 {
933 return getHomeUrl( request );
934 }
935
936 try
937 {
938 nIdNotice = Integer.parseInt( strIdNotice );
939 notice = NoticeHome.findByPrimaryKey( nIdNotice, plugin );
940 }
941 catch ( NumberFormatException ne )
942 {
943 AppLogService.error( ne );
944
945 return getHomeUrl( request );
946 }
947
948 if ( nIdNotice != -1 )
949 {
950 notice.setEnabled( false );
951 NoticeHome.update( notice, getPlugin( ) );
952 }
953
954 return getJspManageNotice( request );
955 }
956
957
958
959
960
961
962 public String doEnableNoticeGroup( HttpServletRequest request )
963 {
964 String strIdNoticeGroup = request.getParameter( PARAMETER_ID_NOTICE_GROUP );
965
966 if ( StringUtils.isBlank( strIdNoticeGroup ) )
967 {
968 return getHomeUrl( request );
969 }
970
971 int nIdNoticeGroup = NoticeUtils.convertStringToInt( strIdNoticeGroup );
972
973 if ( nIdNoticeGroup == -1 )
974 {
975 return getHomeUrl( request );
976 }
977
978 NoticeGroup noticeGroup = NoticeGroupHome.findByPrimaryKey( nIdNoticeGroup, getPlugin( ) );
979
980 if ( noticeGroup == null )
981 {
982 AppLogService.error( "Formengine : No notice group found for id=" + nIdNoticeGroup );
983
984 return getHomeUrl( request );
985 }
986
987 if ( !noticeGroup.isEnabled( ) )
988 {
989 noticeGroup.setEnabled( true );
990 NoticeGroupHome.update( noticeGroup, getPlugin( ) );
991 }
992
993 return getHomeUrl( request );
994 }
995
996
997
998
999
1000
1001 public String doDisableNoticeGroup( HttpServletRequest request )
1002 {
1003 String strIdNoticeGroup = request.getParameter( PARAMETER_ID_NOTICE_GROUP );
1004
1005 if ( StringUtils.isBlank( strIdNoticeGroup ) )
1006 {
1007 return getHomeUrl( request );
1008 }
1009
1010 int nIdNoticeGroup = NoticeUtils.convertStringToInt( strIdNoticeGroup );
1011
1012 if ( nIdNoticeGroup == -1 )
1013 {
1014 return getHomeUrl( request );
1015 }
1016
1017 NoticeGroup noticeGroup = NoticeGroupHome.findByPrimaryKey( nIdNoticeGroup, getPlugin( ) );
1018
1019 if ( noticeGroup == null )
1020 {
1021 AppLogService.error( "Formengine : No notice group found for id=" + nIdNoticeGroup );
1022
1023 return getHomeUrl( request );
1024 }
1025
1026 if ( noticeGroup.isEnabled( ) )
1027 {
1028 noticeGroup.setEnabled( false );
1029 NoticeGroupHome.update( noticeGroup, getPlugin( ) );
1030 }
1031
1032 return getHomeUrl( request );
1033 }
1034
1035
1036
1037
1038
1039
1040 public String doEnableNotice( HttpServletRequest request )
1041 {
1042 Notice notice;
1043 Plugin plugin = getPlugin( );
1044 String strIdNotice = request.getParameter( PARAMETER_ID_NOTICE );
1045 int nIdNotice = -1;
1046
1047 if ( ( strIdNotice == null ) )
1048 {
1049 return getHomeUrl( request );
1050 }
1051
1052 try
1053 {
1054 nIdNotice = Integer.parseInt( strIdNotice );
1055 notice = NoticeHome.findByPrimaryKey( nIdNotice, plugin );
1056 }
1057 catch ( NumberFormatException ne )
1058 {
1059 AppLogService.error( ne );
1060
1061 return getHomeUrl( request );
1062 }
1063
1064 if ( nIdNotice != -1 )
1065 {
1066
1067
1068
1069
1070
1071
1072 notice.setEnabled( true );
1073 NoticeHome.update( notice, getPlugin( ) );
1074 }
1075
1076 return getJspManageNotice( request );
1077 }
1078
1079
1080
1081
1082
1083
1084
1085 private String getNoticeData( HttpServletRequest request, Notice notice )
1086 {
1087 String strTitle = request.getParameter( PARAMETER_TITLE );
1088 String strMessage = request.getParameter( PARAMETER_MESSAGE );
1089 String strWorkgroup = request.getParameter( PARAMETER_WORKGROUP );
1090 String strMailingList = request.getParameter( PARAMETER_ID_MAILINIG_LIST );
1091 String strDateDebut = request.getParameter( PARAMETER_DATE_DEBUT );
1092 String strDateFin = request.getParameter( PARAMETER_DATE_FIN );
1093 String strIdNoticeGroup = request.getParameter( PARAMETER_ID_NOTICE_GROUP );
1094
1095
1096
1097
1098 String strFieldError = NoticeUtils.EMPTY_STRING;
1099
1100
1101
1102
1103
1104 if ( ( strTitle == null ) || strTitle.trim( ).equals( NoticeUtils.EMPTY_STRING ) )
1105 {
1106 strFieldError = MESSAGE_FIELD_TITLE;
1107 }
1108
1109 else if ( ( ( strMessage == null ) || strMessage.trim( ).equals( NoticeUtils.EMPTY_STRING ) )
1110 )
1111 {
1112 strFieldError = MESSAGE_FIELD_MESSAGE;
1113 }
1114
1115 int nIdNoticeGroup = -1;
1116
1117 if ( StringUtils.isBlank( strIdNoticeGroup ) )
1118 {
1119 strFieldError = MESSAGE_ERROR_NOTICE_GROUP;
1120 }
1121 else
1122 {
1123 nIdNoticeGroup = NoticeUtils.convertStringToInt( strIdNoticeGroup );
1124
1125 if ( nIdNoticeGroup == -1 )
1126 {
1127 strFieldError = MESSAGE_ERROR_NOTICE_GROUP;
1128 }
1129 }
1130
1131 if ( !strFieldError.equals( NoticeUtils.EMPTY_STRING ) )
1132 {
1133 Object[] tabRequiredFields = { I18nService.getLocalizedString( strFieldError, getLocale( ) ) };
1134
1135 return AdminMessageService.getMessageUrl( request, MESSAGE_NOTICE_MANDATORY, tabRequiredFields,
1136 AdminMessage.TYPE_STOP );
1137 }
1138
1139 notice.setTitle( strTitle );
1140 notice.setMessage( strMessage );
1141 notice.setWorkgroupKey( strWorkgroup );
1142 notice.setIdNoticeGroup( nIdNoticeGroup );
1143
1144 try
1145 {
1146 int nMailingListId = Integer.parseInt( strMailingList );
1147 notice.setIdDiffusion( nMailingListId );
1148 }
1149 catch ( NumberFormatException ne )
1150 {
1151 AppLogService.error( ne );
1152
1153 return getHomeUrl( request );
1154 }
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195 Timestamp tDateDebut = null;
1196 Timestamp tDateFin = null;
1197
1198 if ( ( strDateDebut != null ) && !strDateDebut.equals( NoticeUtils.EMPTY_STRING ) )
1199 {
1200 tDateDebut = NoticeUtils.getDate( strDateDebut, true );
1201 notice.setDateDebut( tDateDebut );
1202 }
1203
1204 if ( ( strDateFin != null ) && !strDateFin.equals( NoticeUtils.EMPTY_STRING ) )
1205 {
1206 tDateFin = NoticeUtils.getDate( strDateFin, false );
1207 notice.setDateFin( tDateFin );
1208 NoticeUtils.getTime( tDateFin );
1209 }
1210
1211 if ( ( tDateFin != null ) && ( tDateDebut != null ) )
1212 {
1213 if ( tDateFin.compareTo( tDateDebut ) < 0 )
1214 {
1215 Object[] tabErrorDate = null;
1216
1217 return AdminMessageService.getMessageUrl( request, MESSAGE_ERROR_DATE, tabErrorDate,
1218 AdminMessage.TYPE_STOP );
1219 }
1220 }
1221
1222 return null;
1223 }
1224
1225
1226
1227
1228
1229
1230
1231 public String getRemoveNotice( HttpServletRequest request )
1232 {
1233 UrlItem url = new UrlItem( JSP_DO_REMOVE_NOTICE );
1234 url.addParameter( PARAMETER_ID_NOTICE, request.getParameter( PARAMETER_ID_NOTICE ) );
1235
1236 return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_NOTICE, url.getUrl( ),
1237 AdminMessage.TYPE_CONFIRMATION );
1238 }
1239
1240
1241
1242
1243
1244
1245 public String doRemoveNotice( HttpServletRequest request )
1246 {
1247 String strIdNotice = request.getParameter( PARAMETER_ID_NOTICE );
1248 Plugin plugin = getPlugin( );
1249 int nIdNotice = -1;
1250
1251 if ( request.getParameter( PARAMETER_ID_NOTICE ) == null )
1252 {
1253 return getHomeUrl( request );
1254 }
1255
1256 try
1257 {
1258 nIdNotice = Integer.parseInt( strIdNotice );
1259 }
1260 catch ( NumberFormatException ne )
1261 {
1262 AppLogService.error( ne );
1263 }
1264
1265 if ( ( nIdNotice != -1 ) )
1266 {
1267 NoticeHome.remove( nIdNotice, plugin );
1268 }
1269
1270 return getJspManageNotice( request );
1271 }
1272
1273
1274
1275
1276
1277
1278 private String getJspManageNotice( HttpServletRequest request )
1279 {
1280 return AppPathService.getBaseUrl( request ) + JSP_MANAGE_NOTICE;
1281 }
1282
1283
1284
1285
1286
1287
1288 private String getJspManageNoticeGroup( HttpServletRequest request )
1289 {
1290 return AppPathService.getBaseUrl( request ) + JSP_MANAGE_NOTICE_GROUP;
1291 }
1292
1293
1294
1295
1296
1297
1298 public static java.util.Date stringToDate( String sDate )
1299 {
1300 SimpleDateFormat sdf = new SimpleDateFormat( "dd/MM/yyyy" );
1301 java.util.Date date = null;
1302
1303 try
1304 {
1305 date = sdf.parse( sDate );
1306 }
1307 catch ( Exception e )
1308 {
1309 AppLogService.error( e );
1310 }
1311
1312 return date;
1313 }
1314 }