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
35 package fr.paris.lutece.plugins.transparency.web;
36
37 import fr.paris.lutece.plugins.transparency.business.Appointment;
38 import fr.paris.lutece.plugins.transparency.business.AppointmentFilter;
39 import fr.paris.lutece.plugins.transparency.business.AppointmentHome;
40 import fr.paris.lutece.plugins.transparency.business.ElectedOfficial;
41 import fr.paris.lutece.plugins.transparency.business.ElectedOfficialAppointment;
42 import fr.paris.lutece.plugins.transparency.business.ElectedOfficialAppointmentHome;
43 import fr.paris.lutece.plugins.transparency.business.ElectedOfficialHome;
44 import fr.paris.lutece.plugins.transparency.business.Lobby;
45 import fr.paris.lutece.plugins.transparency.business.LobbyAppointment;
46 import fr.paris.lutece.plugins.transparency.business.LobbyAppointmentHome;
47 import fr.paris.lutece.plugins.transparency.business.LobbyHome;
48 import fr.paris.lutece.portal.service.i18n.I18nService;
49 import fr.paris.lutece.portal.service.message.SiteMessage;
50 import fr.paris.lutece.portal.service.util.AppPathService;
51 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
52 import fr.paris.lutece.portal.web.xpages.XPage;
53 import fr.paris.lutece.portal.util.mvc.xpage.MVCApplication;
54 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
55 import fr.paris.lutece.portal.util.mvc.xpage.annotations.Controller;
56 import fr.paris.lutece.util.string.StringUtil;
57 import fr.paris.lutece.util.url.UrlItem;
58 import fr.paris.lutece.portal.service.message.SiteMessageException;
59 import fr.paris.lutece.portal.service.message.SiteMessageService;
60 import fr.paris.lutece.portal.service.security.LuteceUser;
61 import fr.paris.lutece.portal.service.security.SecurityService;
62 import fr.paris.lutece.portal.service.security.UserNotSignedException;
63 import fr.paris.lutece.util.ReferenceList;
64 import fr.paris.lutece.util.html.Paginator;
65 import java.sql.Date;
66 import java.util.List;
67 import java.util.Map;
68 import javax.servlet.http.HttpServletRequest;
69 import org.codehaus.plexus.util.StringUtils;
70
71
72
73
74 @Controller( xpageName = "meeting", pageTitleI18nKey = "transparency.xpage.appointment.pageTitle", pagePathI18nKey = "transparency.xpage.appointment.pagePathLabel" )
75 public class AppointmentXPage extends MVCApplication
76 {
77
78 private static final String TEMPLATE_MANAGE_APPOINTMENTS = "/skin/plugins/transparency/manage_appointments.html";
79 private static final String TEMPLATE_DETAIL_APPOINTMENT = "/skin/plugins/transparency/detail_appointment.html";
80 private static final String TEMPLATE_CREATE_APPOINTMENT = "/skin/plugins/transparency/create_appointment.html";
81 private static final String TEMPLATE_MODIFY_APPOINTMENT = "/skin/plugins/transparency/modify_appointment.html";
82
83
84 private static final String PARAMETER_ID_APPOINTMENT = "id";
85 private static final String PARAMETER_SEARCH_PERIOD = "search_period";
86 private static final String PARAMETER_SEARCH_ELECTED_OFFICIAL = "search_elected_official";
87 private static final String PARAMETER_SEARCH_LOBBY = "search_lobby";
88 private static final String PARAMETER_SEARCH_TITLE = "search_title";
89 private static final String PARAMETER_ID_ELECTED_OFFICIAL = "id_elected_official";
90 private static final String PARAMETER_ID_LOBBY = "lobby_id";
91 private static final String PARAMETER_SELECT_LOBBY = "lobby_select";
92 private static final String PARAMETER_SORTED_ATTRIBUTE_NAME = "sorted_attribute_name";
93 private static final String PARAMETER_START_DATE = "start_date";
94 private static final String PARAMETER_ASC = "asc_sort";
95
96
97 private static final String MARK_APPOINTMENT_LIST = "appointment_list";
98 private static final String MARK_APPOINTMENT = "appointment";
99 private static final String MARK_BASE_URL = "base_url";
100 private static final String MARK_IS_AUTHENTICATED = "is_authenticated";
101 private static final String MARK_ELECTEDOFFICIALS_LIST = "electedofficials_list";
102 private static final String MARK_PAGINATOR = "paginator" ;
103 private static final String MARK_SEARCH_FILTER = "search_filter" ;
104
105
106 private static final String VIEW_MANAGE_APPOINTMENTS = "manageAppointments";
107 private static final String VIEW_DETAIL_APPOINTMENT = "detailAppointment";
108 private static final String VIEW_CREATE_APPOINTMENT = "createAppointment";
109 private static final String VIEW_MODIFY_APPOINTMENT = "modifyAppointment";
110
111
112 private static final String ACTION_CREATE_APPOINTMENT = "createAppointment";
113 private static final String ACTION_MODIFY_APPOINTMENT = "modifyAppointment";
114 private static final String ACTION_REMOVE_APPOINTMENT = "removeAppointment";
115 private static final String ACTION_CONFIRM_REMOVE_APPOINTMENT = "confirmRemoveAppointment";
116
117
118 private static final String INFO_APPOINTMENT_CREATED = "transparency.info.appointment.created";
119 private static final String INFO_APPOINTMENT_UPDATED = "transparency.info.appointment.updated";
120 private static final String INFO_APPOINTMENT_REMOVED = "transparency.info.appointment.removed";
121 private static final String INFO_ACCESS_DENIED = "transparency.info.appointment.accessdenied";
122
123
124 private static final String ERROR_APPOINTMENT_VALIDATION_LOBBY_MANDATORY = "transparency.validation.appointment.Lobby.notEmpty";
125
126
127
128 private static final String MESSAGE_CONFIRM_REMOVE_APPOINTMENT = "transparency.message.confirmRemoveAppointment";
129
130
131 private Appointment _appointment;
132 private List<Integer> _appointmentIdsList;
133 private AppointmentFilter _filter = new AppointmentFilter( );
134
135 private int _nItemsPerPage = 10;
136 private String _strCurrentPageIndex = "1";
137
138
139 private static int CONSTANT_DEFAULT_SEARCH_PERIOD = 92 ;
140
141
142
143
144
145
146
147
148
149 @View( value = VIEW_MANAGE_APPOINTMENTS, defaultView = true )
150 public XPage getManageAppointments( HttpServletRequest request )
151 {
152 _appointment = null;
153 List<Appointment> appointmentList = null;
154 boolean isAuthenticated = false;
155 Paginator<Integer> paginator ;
156
157
158 String idUser = null;
159 try
160 {
161 idUser = checkMyLuteceAuthentication( request );
162 if ( idUser != null )
163 isAuthenticated = true;
164 }
165 catch( UserNotSignedException e )
166 {
167
168 isAuthenticated = false;
169 }
170
171
172 if ( request.getParameter( Paginator.PARAMETER_PAGE_INDEX ) != null && _appointmentIdsList != null )
173 {
174
175 _strCurrentPageIndex = request.getParameter( Paginator.PARAMETER_PAGE_INDEX );
176 paginator = new Paginator<Integer>( _appointmentIdsList, _nItemsPerPage, getViewFullUrl( VIEW_MANAGE_APPOINTMENTS ),
177 Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
178
179 _filter.setListIds( paginator.getPageItems( ) );
180
181
182 appointmentList = AppointmentHome.getFullAppointmentsList( _filter );
183 }
184 else if ( request.getParameter( PARAMETER_SORTED_ATTRIBUTE_NAME ) != null && _appointmentIdsList != null )
185 {
186
187 if ( request.getParameter( PARAMETER_SORTED_ATTRIBUTE_NAME ).equals( PARAMETER_START_DATE ) )
188 {
189 if ( request.getParameter( PARAMETER_ASC ) != null && request.getParameter( PARAMETER_ASC ).equals( "true" ) )
190 {
191 _filter.setOrderBy( PARAMETER_START_DATE + " ASC " );
192 }
193 else
194 {
195 _filter.setOrderBy( PARAMETER_START_DATE + " DESC " );
196 }
197 }
198
199
200 _strCurrentPageIndex = "1" ;
201 _filter.setListIds( null ) ;
202
203
204 _appointmentIdsList = AppointmentHome.getAppointmentIdsList( _filter );
205
206 paginator = new Paginator<Integer>( _appointmentIdsList, _nItemsPerPage, getViewFullUrl( VIEW_MANAGE_APPOINTMENTS ) ,
207 Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
208
209 _filter.setListIds( paginator.getPageItems( ) );
210
211
212 appointmentList = AppointmentHome.getFullAppointmentsList( _filter );
213 }
214 else
215 {
216
217 String strSearchPeriod = request.getParameter( PARAMETER_SEARCH_PERIOD );
218 String strSearchElectedOfficial = request.getParameter( PARAMETER_SEARCH_ELECTED_OFFICIAL );
219 String strSearchLobby = request.getParameter( PARAMETER_SEARCH_LOBBY );
220 String strSearchTitle = request.getParameter( PARAMETER_SEARCH_TITLE );
221
222
223 if ( strSearchPeriod != null ) _filter.setNumberOfDays( StringUtil.getIntValue( strSearchPeriod, CONSTANT_DEFAULT_SEARCH_PERIOD ) );
224 _filter.setLobbyName( strSearchLobby );
225 _filter.setElectedOfficialName( strSearchElectedOfficial );
226 _filter.setUserId( idUser );
227 _filter.setTitle( strSearchTitle );
228
229
230 _strCurrentPageIndex = "1" ;
231 _filter.setListIds( null ) ;
232 _filter.setOrderBy( null );
233
234
235 _appointmentIdsList = AppointmentHome.getAppointmentIdsList( _filter );
236
237 paginator = new Paginator<Integer>( _appointmentIdsList, _nItemsPerPage, getViewFullUrl( VIEW_MANAGE_APPOINTMENTS ) ,
238 Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
239
240 _filter.setListIds( paginator.getPageItems( ) );
241
242
243 appointmentList = AppointmentHome.getFullAppointmentsList( _filter );
244
245 }
246
247 Map<String, Object> model = getModel( );
248 model.put( MARK_APPOINTMENT_LIST, appointmentList );
249 model.put( MARK_BASE_URL, AppPathService.getBaseUrl( request ) );
250 model.put( MARK_IS_AUTHENTICATED, isAuthenticated );
251 model.put( MARK_PAGINATOR, paginator);
252 model.put( MARK_SEARCH_FILTER, _filter);
253
254 return getXPage( TEMPLATE_MANAGE_APPOINTMENTS, request.getLocale( ), model );
255 }
256
257
258
259
260
261
262
263
264 @View( VIEW_DETAIL_APPOINTMENT )
265 public XPage getDetailAppointment( HttpServletRequest request )
266 {
267 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_APPOINTMENT ) );
268
269 if ( _appointment == null || ( _appointment.getId( ) != nId ) )
270 {
271 _appointment = AppointmentHome.findByPrimaryKey( nId );
272 }
273
274 _appointment.setElectedOfficialList( ElectedOfficialHome.getElectedOfficialsListByAppointment( _appointment.getId( ) ) );
275 _appointment.setLobbyList( LobbyHome.getLobbiesListByAppointment( _appointment.getId( ) ) );
276
277 Map<String, Object> model = getModel( );
278 model.put( MARK_APPOINTMENT, _appointment );
279
280 return getXPage( TEMPLATE_DETAIL_APPOINTMENT, request.getLocale( ), model );
281 }
282
283
284
285
286
287
288
289
290
291 @View( VIEW_CREATE_APPOINTMENT )
292 public XPage getCreateAppointment( HttpServletRequest request ) throws UserNotSignedException
293 {
294 _appointment = ( _appointment != null ) ? _appointment : new Appointment( );
295
296
297 String idUser = checkMyLuteceAuthentication( request );
298
299 ReferenceList electedOfficialsList = ElectedOfficialHome.getElectedOfficialsReferenceListByDelegation( idUser );
300
301 Map<String, Object> model = getModel( );
302 model.put( MARK_APPOINTMENT, _appointment );
303 model.put( MARK_ELECTEDOFFICIALS_LIST, electedOfficialsList );
304 model.put( MARK_BASE_URL, AppPathService.getBaseUrl( request ) );
305
306 return getXPage( TEMPLATE_CREATE_APPOINTMENT, request.getLocale( ), model );
307 }
308
309
310
311
312
313
314
315
316
317 @Action( ACTION_CREATE_APPOINTMENT )
318 public XPage doCreateAppointment( HttpServletRequest request ) throws UserNotSignedException
319 {
320
321
322 String idUser = checkMyLuteceAuthentication( request );
323
324 populate( _appointment, request, request.getLocale( ) );
325
326
327 if ( !validateBean( _appointment ) )
328 {
329 return redirectView( request, VIEW_CREATE_APPOINTMENT );
330 }
331
332
333 String strIdLobby = request.getParameter( PARAMETER_ID_LOBBY );
334 String strSelectLobby = request.getParameter( PARAMETER_SELECT_LOBBY );
335
336 if ( StringUtils.isBlank(strSelectLobby) )
337 {
338 addError( I18nService.getLocalizedString( ERROR_APPOINTMENT_VALIDATION_LOBBY_MANDATORY, request.getLocale( ) ) );
339 return redirectView( request, VIEW_CREATE_APPOINTMENT );
340 }
341
342 AppointmentHome.create( _appointment );
343
344
345 String strIdElectedOfficial = request.getParameter( PARAMETER_ID_ELECTED_OFFICIAL );
346
347 ElectedOfficial electedOfficial = ElectedOfficialHome.findByPrimaryKey( strIdElectedOfficial );
348 if ( electedOfficial != null )
349 {
350 ElectedOfficialAppointmentHome.create( new ElectedOfficialAppointment( strIdElectedOfficial, _appointment.getId( ) ) );
351 _appointment.getElectedOfficialList( ).add( electedOfficial );
352 }
353
354
355 int idLobby = StringUtil.getIntValue( strIdLobby, -1 );
356
357 Lobby lobby = LobbyHome.findByPrimaryKey( idLobby );
358
359
360 if ( idLobby > 0 && lobby != null && lobby.getName().replaceAll("[&<>\"]","").equals(strSelectLobby) )
361 {
362 LobbyAppointmentHome.create( new LobbyAppointment( lobby.getId( ), _appointment.getId( ) ) );
363 _appointment.getLobbyList( ).add( lobby );
364 }
365 else
366 if ( !StringUtils.isBlank( strSelectLobby ) )
367 {
368 Lobby newLobby = new Lobby( );
369 newLobby.setName( strSelectLobby );
370 newLobby.setVersionDate( new Date( ( new java.util.Date( ) ).getTime( ) ) );
371 newLobby = LobbyHome.create( newLobby );
372
373 LobbyAppointmentHome.create( new LobbyAppointment( newLobby.getId( ), _appointment.getId( ) ) );
374 _appointment.getLobbyList( ).add( newLobby );
375
376 }
377 addInfo( INFO_APPOINTMENT_CREATED, getLocale( request ) );
378
379 return redirectView( request, VIEW_MANAGE_APPOINTMENTS );
380 }
381
382
383
384
385
386
387
388
389
390 @Action( ACTION_CONFIRM_REMOVE_APPOINTMENT )
391 public XPage getConfirmRemoveAppointment( HttpServletRequest request ) throws SiteMessageException
392 {
393 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_APPOINTMENT ) );
394
395 UrlItem url = new UrlItem( getActionFullUrl(ACTION_REMOVE_APPOINTMENT) );
396 url.addParameter( PARAMETER_ID_APPOINTMENT, nId );
397
398 SiteMessageService.setMessage( request, MESSAGE_CONFIRM_REMOVE_APPOINTMENT, SiteMessage.TYPE_CONFIRMATION, url.getUrl( ) );
399 return null;
400 }
401
402
403
404
405
406
407
408
409 @Action( ACTION_REMOVE_APPOINTMENT )
410 public XPage doRemoveAppointment( HttpServletRequest request ) throws UserNotSignedException
411 {
412
413 String idUser = checkMyLuteceAuthentication( request );
414
415 int nIdAppointment = Integer.parseInt( request.getParameter( PARAMETER_ID_APPOINTMENT ) );
416
417
418 AppointmentFilter filter = new AppointmentFilter( );
419 filter.setIdAppointment( nIdAppointment );
420 filter.setUserId( idUser );
421
422 List<Appointment> listAppointment = AppointmentHome.getFullAppointmentsList( filter );
423
424 if ( listAppointment == null || listAppointment.isEmpty( ) )
425 {
426
427 addInfo( INFO_ACCESS_DENIED, getLocale( request ) );
428 return redirectView( request, VIEW_MANAGE_APPOINTMENTS );
429 }
430
431
432 AppointmentHome.remove( nIdAppointment );
433 addInfo( INFO_APPOINTMENT_REMOVED, getLocale( request ) );
434
435 return redirectView( request, VIEW_MANAGE_APPOINTMENTS );
436 }
437
438
439
440
441
442
443
444
445
446 @View( VIEW_MODIFY_APPOINTMENT )
447 public XPage getModifyAppointment( HttpServletRequest request ) throws UserNotSignedException
448 {
449 int nIdAppointment = Integer.parseInt( request.getParameter( PARAMETER_ID_APPOINTMENT ) );
450
451
452 String idUser = checkMyLuteceAuthentication( request );
453
454
455 AppointmentFilter filter = new AppointmentFilter( );
456 filter.setIdAppointment( nIdAppointment );
457 filter.setUserId( idUser );
458
459 List<Appointment> listAppointment = AppointmentHome.getFullAppointmentsList( filter );
460
461 if ( listAppointment == null || listAppointment.isEmpty( ) )
462 {
463
464 addInfo( INFO_ACCESS_DENIED, getLocale( request ) );
465 return redirectView( request, VIEW_MANAGE_APPOINTMENTS );
466 }
467
468
469 _appointment = listAppointment.get( 0 );
470
471 ReferenceList electedOfficialsList = ElectedOfficialHome.getElectedOfficialsReferenceListByDelegation( idUser );
472
473 Map<String, Object> model = getModel( );
474 model.put( MARK_APPOINTMENT, _appointment );
475 model.put( MARK_ELECTEDOFFICIALS_LIST, electedOfficialsList );
476 model.put( MARK_BASE_URL, AppPathService.getBaseUrl( request ) );
477
478 return getXPage( TEMPLATE_MODIFY_APPOINTMENT, request.getLocale( ), model );
479 }
480
481
482
483
484
485
486
487
488
489 @Action( ACTION_MODIFY_APPOINTMENT )
490 public XPage doModifyAppointment( HttpServletRequest request ) throws UserNotSignedException
491 {
492
493 String idUser = checkMyLuteceAuthentication( request );
494
495 populate( _appointment, request, request.getLocale( ) );
496
497
498 if ( !validateBean( _appointment ) )
499 {
500 return redirect( request, VIEW_MODIFY_APPOINTMENT, PARAMETER_ID_APPOINTMENT, _appointment.getId( ) );
501 }
502
503 AppointmentHome.update( _appointment );
504
505
506 String strIdLobby = request.getParameter( PARAMETER_ID_LOBBY );
507 String strSelectLobby = request.getParameter( PARAMETER_SELECT_LOBBY );
508
509 int idLobby = StringUtil.getIntValue( strIdLobby, -1 );
510
511 Lobby lobby = LobbyHome.findByPrimaryKey( idLobby );
512
513
514
515 if ( idLobby > 0 && lobby != null && lobby.getName( ).replaceAll("[&<>\"]","").equals( strSelectLobby ) )
516 {
517 LobbyAppointmentHome.removeByAppointmentId( _appointment.getId( ) );
518 LobbyAppointmentHome.create( new LobbyAppointment( lobby.getId( ), _appointment.getId( ) ) );
519 _appointment.getLobbyList( ).add( lobby );
520 }
521 else
522 if ( !StringUtils.isBlank( strSelectLobby ) )
523 {
524 Lobby newLobby = new Lobby( );
525 newLobby.setName( strSelectLobby );
526 newLobby.setVersionDate( new Date( ( new java.util.Date( ) ).getTime( ) ) );
527 newLobby = LobbyHome.create( newLobby );
528
529 LobbyAppointmentHome.removeByAppointmentId( _appointment.getId( ) );
530 LobbyAppointmentHome.create( new LobbyAppointment( newLobby.getId( ), _appointment.getId( ) ) );
531 _appointment.getLobbyList( ).add( newLobby );
532
533 }
534
535 addInfo( INFO_APPOINTMENT_UPDATED, getLocale( request ) );
536
537 return redirectView( request, VIEW_MANAGE_APPOINTMENTS );
538 }
539
540
541
542
543
544
545
546
547 private String checkMyLuteceAuthentication( HttpServletRequest request ) throws UserNotSignedException
548 {
549
550 if ( !SecurityService.isAuthenticationEnable( ) )
551 return null;
552
553 LuteceUser luteceUser = SecurityService.getInstance( ).getRegisteredUser( request );
554
555
556 if ( luteceUser == null )
557 throw new UserNotSignedException( );
558
559 return luteceUser.getName( );
560 }
561
562 }