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.AppointmentHome;
39 import fr.paris.lutece.plugins.transparency.business.ElectedOfficial;
40 import fr.paris.lutece.plugins.transparency.business.ElectedOfficialAppointment;
41 import fr.paris.lutece.plugins.transparency.business.ElectedOfficialAppointmentHome;
42 import fr.paris.lutece.plugins.transparency.business.ElectedOfficialHome;
43 import fr.paris.lutece.plugins.transparency.business.Lobby;
44 import fr.paris.lutece.plugins.transparency.business.LobbyAppointment;
45 import fr.paris.lutece.plugins.transparency.business.LobbyAppointmentHome;
46 import fr.paris.lutece.plugins.transparency.business.LobbyHome;
47 import fr.paris.lutece.plugins.transparency.service.ExportAppointmentService;
48 import fr.paris.lutece.portal.business.user.AdminUser;
49 import fr.paris.lutece.portal.service.message.AdminMessage;
50 import fr.paris.lutece.portal.service.message.AdminMessageService;
51 import fr.paris.lutece.portal.service.util.AppPathService;
52 import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
53 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
54 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
55 import fr.paris.lutece.util.ReferenceList;
56 import fr.paris.lutece.util.string.StringUtil;
57 import fr.paris.lutece.util.url.UrlItem;
58 import java.io.IOException;
59 import java.sql.Date;
60
61 import java.util.List;
62 import java.util.Map;
63 import javax.servlet.http.HttpServletRequest;
64 import javax.servlet.http.HttpServletResponse;
65 import org.codehaus.plexus.util.StringUtils;
66
67
68
69
70 @Controller( controllerJsp = "ManageAppointments.jsp", controllerPath = "jsp/admin/plugins/transparency/", right = "TRANSPARENCY_APPOINTMENTS_MANAGEMENT" )
71 public class AppointmentJspBean extends AbstractManageAppointementsJspBean
72 {
73
74 private static final String TEMPLATE_MANAGE_APPOINTMENTS = "/admin/plugins/transparency/manage_appointments.html";
75 private static final String TEMPLATE_CREATE_APPOINTMENT = "/admin/plugins/transparency/create_appointment.html";
76 private static final String TEMPLATE_MODIFY_APPOINTMENT = "/admin/plugins/transparency/modify_appointment.html";
77
78
79 private static final String PARAMETER_ID_APPOINTMENT = "id";
80 private static final String PARAMETER_ID_ELECTED_OFFICIAL = "id_elected_official";
81 private static final String PARAMETER_ID_LOBBY = "lobby_id";
82 private static final String PARAMETER_SELECT_LOBBY = "lobby_select";
83
84
85 private static final String PROPERTY_PAGE_TITLE_MANAGE_APPOINTMENTS = "transparency.manage_appointments.pageTitle";
86 private static final String PROPERTY_PAGE_TITLE_MODIFY_APPOINTMENT = "transparency.modify_appointment.pageTitle";
87 private static final String PROPERTY_PAGE_TITLE_CREATE_APPOINTMENT = "transparency.create_appointment.pageTitle";
88
89
90 private static final String MARK_APPOINTMENT_LIST = "appointment_list";
91 private static final String MARK_APPOINTMENT = "appointment";
92 private static final String MARK_ELECTEDOFFICIALS_LIST = "electedofficials_list";
93 private static final String MARK_BASE_URL = "base_url";
94
95
96 private static final String JSP_MANAGE_APPOINTMENTS = "jsp/admin/plugins/transparency/ManageAppointments.jsp";
97
98
99 private static final String MESSAGE_CONFIRM_REMOVE_APPOINTMENT = "transparency.message.confirmRemoveAppointment";
100
101
102 private static final String VALIDATION_ATTRIBUTES_PREFIX = "transparency.model.entity.appointment.attribute.";
103
104
105 private static final String VIEW_MANAGE_APPOINTMENTS = "manageAppointments";
106 private static final String VIEW_CREATE_APPOINTMENT = "createAppointment";
107 private static final String VIEW_MODIFY_APPOINTMENT = "modifyAppointment";
108
109
110 private static final String ACTION_CREATE_APPOINTMENT = "createAppointment";
111 private static final String ACTION_MODIFY_APPOINTMENT = "modifyAppointment";
112 private static final String ACTION_REMOVE_APPOINTMENT = "removeAppointment";
113 private static final String ACTION_EXPORT_APPOINTMENT = "exportAppointment";
114 private static final String ACTION_CONFIRM_REMOVE_APPOINTMENT = "confirmRemoveAppointment";
115
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_APPOINTMENT_EXPORTED = "transparency.info.appointment.exported";
122
123
124 private Appointment _appointment;
125
126
127
128
129
130
131
132
133 @View( value = VIEW_MANAGE_APPOINTMENTS, defaultView = true )
134 public String getManageAppointments( HttpServletRequest request )
135 {
136 _appointment = null;
137 AdminUser user = getUser( );
138 List<Appointment> listAppointments;
139
140 listAppointments = AppointmentHome.getFullAppointmentsList( );
141
142 Map<String, Object> model = getPaginatedListModel( request, MARK_APPOINTMENT_LIST, listAppointments, JSP_MANAGE_APPOINTMENTS );
143
144 return getPage( PROPERTY_PAGE_TITLE_MANAGE_APPOINTMENTS, TEMPLATE_MANAGE_APPOINTMENTS, model );
145 }
146
147
148
149
150
151
152
153
154 @View( VIEW_CREATE_APPOINTMENT )
155 public String getCreateAppointment( HttpServletRequest request )
156 {
157 _appointment = ( _appointment != null ) ? _appointment : new Appointment( );
158
159 ReferenceList electedOfficialsList = ElectedOfficialHome.getElectedOfficialsReferenceList( );
160
161 Map<String, Object> model = getModel( );
162 model.put( MARK_APPOINTMENT, _appointment );
163 model.put( MARK_ELECTEDOFFICIALS_LIST, electedOfficialsList );
164 model.put( MARK_BASE_URL, AppPathService.getBaseUrl( request ) );
165
166 return getPage( PROPERTY_PAGE_TITLE_CREATE_APPOINTMENT, TEMPLATE_CREATE_APPOINTMENT, model );
167 }
168
169
170
171
172
173
174
175
176 @Action( ACTION_CREATE_APPOINTMENT )
177 public String doCreateAppointment( HttpServletRequest request )
178 {
179
180 populate( _appointment, request, request.getLocale( ) );
181
182
183 if ( !validateBean( _appointment, VALIDATION_ATTRIBUTES_PREFIX ) )
184 {
185 return redirectView( request, VIEW_CREATE_APPOINTMENT );
186 }
187
188
189 AppointmentHome.create( _appointment );
190
191
192 String strIdElectedOfficial = request.getParameter( PARAMETER_ID_ELECTED_OFFICIAL );
193
194 ElectedOfficial electedOfficial = ElectedOfficialHome.findByPrimaryKey( strIdElectedOfficial );
195 if ( electedOfficial != null )
196 {
197 ElectedOfficialAppointmentHome.create( new ElectedOfficialAppointment( strIdElectedOfficial, _appointment.getId( ) ) );
198 _appointment.getElectedOfficialList( ).add( electedOfficial );
199 }
200
201
202 String strIdLobby = request.getParameter( PARAMETER_ID_LOBBY );
203 String strSelectLobby = request.getParameter( PARAMETER_SELECT_LOBBY );
204
205 int idLobby = StringUtil.getIntValue( strIdLobby, -1 );
206
207 Lobby lobby = LobbyHome.findByPrimaryKey( idLobby );
208 if ( idLobby > 0 && lobby != null )
209 {
210 LobbyAppointmentHome.create( new LobbyAppointment( lobby.getId( ), _appointment.getId( ) ) );
211 _appointment.getLobbyList( ).add( lobby );
212 }
213 else
214 if ( !StringUtils.isBlank( strSelectLobby ) )
215 {
216 Lobby newLobby = new Lobby( );
217 newLobby.setName( strSelectLobby );
218 newLobby.setVersionDate( new Date( ( new java.util.Date( ) ).getTime( ) ) );
219 newLobby = LobbyHome.create( newLobby );
220
221 LobbyAppointmentHome.create( new LobbyAppointment( newLobby.getId( ), _appointment.getId( ) ) );
222 _appointment.getLobbyList( ).add( newLobby );
223
224 }
225
226 addInfo( INFO_APPOINTMENT_CREATED, getLocale( ) );
227
228 return redirectView( request, VIEW_MANAGE_APPOINTMENTS );
229 }
230
231
232
233
234
235
236
237
238 @Action( ACTION_CONFIRM_REMOVE_APPOINTMENT )
239 public String getConfirmRemoveAppointment( HttpServletRequest request )
240 {
241 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_APPOINTMENT ) );
242 UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_APPOINTMENT ) );
243 url.addParameter( PARAMETER_ID_APPOINTMENT, nId );
244
245 String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_APPOINTMENT, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
246
247 return redirect( request, strMessageUrl );
248 }
249
250
251
252
253
254
255
256
257 @Action( ACTION_REMOVE_APPOINTMENT )
258 public String doRemoveAppointment( HttpServletRequest request )
259 {
260 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_APPOINTMENT ) );
261 AppointmentHome.remove( nId );
262 addInfo( INFO_APPOINTMENT_REMOVED, getLocale( ) );
263
264 return redirectView( request, VIEW_MANAGE_APPOINTMENTS );
265 }
266
267
268
269
270
271
272
273
274 @View( VIEW_MODIFY_APPOINTMENT )
275 public String getModifyAppointment( HttpServletRequest request )
276 {
277 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_APPOINTMENT ) );
278
279 if ( _appointment == null || ( _appointment.getId( ) != nId ) )
280 {
281 _appointment = AppointmentHome.getFullAppointmentById( nId );
282 }
283
284 ReferenceList electedOfficialsList = ElectedOfficialHome.getElectedOfficialsReferenceList( );
285
286 Map<String, Object> model = getModel( );
287 model.put( MARK_APPOINTMENT, _appointment );
288 model.put( MARK_ELECTEDOFFICIALS_LIST, electedOfficialsList );
289 model.put( MARK_BASE_URL, AppPathService.getBaseUrl( request ) );
290
291 return getPage( PROPERTY_PAGE_TITLE_MODIFY_APPOINTMENT, TEMPLATE_MODIFY_APPOINTMENT, model );
292 }
293
294
295
296
297
298
299
300
301 @Action( ACTION_MODIFY_APPOINTMENT )
302 public String doModifyAppointment( HttpServletRequest request )
303 {
304
305 populate( _appointment, request, request.getLocale( ) );
306
307
308 if ( !validateBean( _appointment, VALIDATION_ATTRIBUTES_PREFIX ) )
309 {
310 return redirect( request, VIEW_MODIFY_APPOINTMENT, PARAMETER_ID_APPOINTMENT, _appointment.getId( ) );
311 }
312
313 AppointmentHome.update( _appointment );
314
315
316 String strIdLobby = request.getParameter( PARAMETER_ID_LOBBY );
317 String strSelectLobby = request.getParameter( PARAMETER_SELECT_LOBBY );
318
319 int idLobby = StringUtil.getIntValue( strIdLobby, -1 );
320
321 Lobby lobby = LobbyHome.findByPrimaryKey( idLobby );
322
323
324 if ( idLobby > 0 && lobby != null && lobby.getName( ).equals( strSelectLobby ) )
325 {
326 LobbyAppointmentHome.removeByAppointmentId( _appointment.getId( ) );
327 LobbyAppointmentHome.create( new LobbyAppointment( lobby.getId( ), _appointment.getId( ) ) );
328 _appointment.getLobbyList( ).add( lobby );
329 }
330 else
331 if ( !StringUtils.isBlank( strSelectLobby ) )
332 {
333 Lobby newLobby = new Lobby( );
334 newLobby.setName( strSelectLobby );
335 newLobby.setVersionDate( new Date( ( new java.util.Date( ) ).getTime( ) ) );
336 newLobby = LobbyHome.create( newLobby );
337
338 LobbyAppointmentHome.removeByAppointmentId( _appointment.getId( ) );
339 LobbyAppointmentHome.create( new LobbyAppointment( newLobby.getId( ), _appointment.getId( ) ) );
340 _appointment.getLobbyList( ).add( newLobby );
341
342 }
343
344 addInfo( INFO_APPOINTMENT_UPDATED, getLocale( ) );
345
346 return redirectView( request, VIEW_MANAGE_APPOINTMENTS );
347 }
348
349
350
351
352
353
354
355
356 @Action( ACTION_EXPORT_APPOINTMENT )
357 public void doExportAppointment( HttpServletRequest request, HttpServletResponse response )
358 {
359
360 List<Appointment> listAppointments = AppointmentHome.getFullAppointmentsList( );
361 try {
362 ExportAppointmentService.exportAppointmentToCSV(request, response, listAppointments);
363 } catch (IOException ex) {
364 addInfo( ex.getLocalizedMessage( ), getLocale( ) );
365
366 }
367
368
369
370
371 }
372
373
374 }