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.appointment.modules.resource.web;
35
36 import fr.paris.lutece.plugins.appointment.modules.resource.business.AppointmentFormResourceType;
37 import fr.paris.lutece.plugins.appointment.modules.resource.business.AppointmentFormResourceTypeHome;
38 import fr.paris.lutece.plugins.appointment.service.AppointmentResourceIdService;
39 import fr.paris.lutece.plugins.appointment.service.FormService;
40 import fr.paris.lutece.plugins.appointment.web.AppointmentFormJspBean;
41 import fr.paris.lutece.plugins.appointment.web.dto.AppointmentFormDTO;
42 import fr.paris.lutece.plugins.resource.business.IResourceType;
43 import fr.paris.lutece.plugins.resource.service.ResourceService;
44 import fr.paris.lutece.portal.business.user.AdminUser;
45 import fr.paris.lutece.portal.service.admin.AccessDeniedException;
46 import fr.paris.lutece.portal.service.message.AdminMessage;
47 import fr.paris.lutece.portal.service.message.AdminMessageService;
48 import fr.paris.lutece.portal.service.rbac.RBACService;
49 import fr.paris.lutece.portal.service.util.AppPathService;
50 import fr.paris.lutece.portal.util.mvc.admin.MVCAdminJspBean;
51 import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
52 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
53 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
54 import fr.paris.lutece.portal.util.mvc.utils.MVCUtils;
55 import fr.paris.lutece.util.ReferenceList;
56 import fr.paris.lutece.util.url.UrlItem;
57
58 import org.apache.commons.lang.StringUtils;
59
60 import java.util.List;
61 import java.util.Map;
62
63 import javax.servlet.http.HttpServletRequest;
64
65
66
67
68 @Controller( controllerJsp = AppointmentFormResourcesJspBean.JSP_MANAGE_APPOINTMENT_FORM_RESOURCE_TYPE, controllerPath = AppointmentFormResourcesJspBean.PATH_MANAGE_APPOINTMENT_FORM_RESOURCE_TYPE, right = AppointmentFormJspBean.RIGHT_MANAGEAPPOINTMENTFORM )
69 public class AppointmentFormResourcesJspBean extends MVCAdminJspBean
70 {
71
72
73
74 public static final String PATH_MANAGE_APPOINTMENT_FORM_RESOURCE_TYPE = "jsp/admin/plugins/appointment/modules/resource/";
75
76
77
78
79 public static final String JSP_MANAGE_APPOINTMENT_FORM_RESOURCE_TYPE = "ManageAppointmentFormResources.jsp";
80
81
82
83
84 public static final String JSP_URL_MANAGE_APPOINTMENT_FORM_RESOURCE_TYPE = PATH_MANAGE_APPOINTMENT_FORM_RESOURCE_TYPE
85 + JSP_MANAGE_APPOINTMENT_FORM_RESOURCE_TYPE;
86 private static final long serialVersionUID = -7228498724499752562L;
87
88
89 private static final String VIEW_MANAGE_FORM_RESOURCES = "manageFormResources";
90 private static final String VIEW_CREATE_RESOURCE_TYPE = "createFormResourceType";
91 private static final String VIEW_MODIFY_RESOURCE_TYPE = "modifyFormResourceType";
92 private static final String VIEW_CONFIRM_REMOVE_RESOURCE_TYPE = "confirmRemoveFormResourceType";
93
94
95 private static final String ACTION_DO_CREATE_FORM_RESOURCE_TYPE = "doCreateFormResourceType";
96 private static final String ACTION_DO_MODIFY_FORM_RESOURCE_TYPE = "doModifyFormResourceType";
97 private static final String ACTION_DO_REMOVE_FORM_RESOURCE_TYPE = "doRemoveFormResourceType";
98 private static final String ACTION_DO_SET_ADMIN_DEFAULT_RESOURCE_TYPE = "doSetAdminDefaultResourceType";
99 private static final String ACTION_DO_SET_LOCATION_DEFAULT_RESOURCE_TYPE = "doSetLocationDefaultResourceType";
100
101
102 private static final String MARK_LIST_RESOURCE_TYPES = "listResourceTypes";
103 private static final String MARK_LIST_FORM_RESOURCE_TYPES = "listFormResourceTypes";
104 private static final String MARK_FORM_RESOURCE_TYPE = "formResourceType";
105 private static final String MARK_ADMIN_USER_RESOURCE_TYPE = "adminUserResourceType";
106 private static final String MARK_LOCALE = "language";
107
108
109 private static final String PARAMETER_ID_FORM = "id_form";
110 private static final String PARAMETER_ID_FORM_RESOURCE_TYPE = "idFormResourceType";
111
112
113 private static final String MESSAGE_MANAGE_FORM_RESOURCES_PAGE_TITLE = "module.appointment.resource.manageAppointmentFormResources.pageTitle";
114 private static final String MESSAGE_CREATE_FORM_RESOURCES_PAGE_TITLE = "module.appointment.resource.createAppointmentFormResources.pageTitle";
115 private static final String MESSAGE_MODIFY_FORM_RESOURCES_PAGE_TITLE = "module.appointment.resource.modifyAppointmentFormResources.pageTitle";
116 private static final String MESSAGE_APPOINTMENT_FORM_RESOURCE_TYPE_CREATED = "module.appointment.resource.createAppointmentFormResources.appointmentFormResourceTypeCreated";
117 private static final String MESSAGE_APPOINTMENT_FORM_RESOURCE_TYPE_MODIFIED = "module.appointment.resource.modifyAppointmentFormResources.appointmentFormResourceTypeModified";
118 private static final String MESSAGE_CONFIRM_REMOVE_FORM_RESOURCE_TYPE = "module.appointment.resource.removeAppointmentFormResource.confirmRemoveResourceType";
119 private static final String VALIDATION_ATTRIBUTES_PREFIX = "module.appointment.resource.model.entity.appointmentFormResourceType.attribute.";
120
121
122 private static final String TEMPLATE_MANAGE_FORM_RESOURCES = "admin/plugins/appointment/modules/resource/manage_form_resources.html";
123 private static final String TEMPLATE_CREATE_FORM_RESOURCES = "admin/plugins/appointment/modules/resource/create_form_resources.html";
124 private static final String TEMPLATE_MODIFY_FORM_RESOURCES = "admin/plugins/appointment/modules/resource/modify_form_resources.html";
125 private AppointmentFormResourceType _formResourceType;
126
127
128 private static final String SESSION_ATTRIBUTE_APPOINTMENT_FORM = "appointment.session.appointmentForm";
129
130
131
132
133
134
135
136
137
138
139 @View( value = VIEW_MANAGE_FORM_RESOURCES )
140 public String getManageFormResources( HttpServletRequest request ) throws AccessDeniedException
141 {
142 _formResourceType = null;
143
144 String strIdForm = request.getParameter( PARAMETER_ID_FORM );
145
146 if ( StringUtils.isEmpty( strIdForm ) || !StringUtils.isNumeric( strIdForm ) )
147 {
148 return redirect( request, AppointmentFormJspBean.getURLManageAppointmentForms( request ) );
149 }
150
151 int nIdForm = Integer.parseInt( strIdForm );
152
153 if ( !RBACService.isAuthorized( AppointmentFormDTO.RESOURCE_TYPE, strIdForm, AppointmentResourceIdService.PERMISSION_MODIFY_FORM, getUser( ) ) )
154 {
155 throw new AccessDeniedException( AppointmentResourceIdService.PERMISSION_MODIFY_FORM );
156 }
157
158 AppointmentFormDTO appointmentForm = (AppointmentFormDTO) request.getSession( ).getAttribute( SESSION_ATTRIBUTE_APPOINTMENT_FORM );
159 if ( ( appointmentForm == null ) || ( nIdForm != appointmentForm.getIdForm( ) ) )
160 {
161 appointmentForm = FormService.buildAppointmentForm( nIdForm, 0, 0 );
162 }
163
164 if ( appointmentForm == null )
165 {
166 return redirect( request, AppointmentFormJspBean.getURLManageAppointmentForms( request ) );
167 }
168
169 Map<String, Object> model = getModel( );
170
171 List<IResourceType> listResourceTypes = ResourceService.getInstance( ).getResourceTypesList( );
172
173 model.put( MARK_LIST_RESOURCE_TYPES, listResourceTypes );
174 model.put( MARK_LIST_FORM_RESOURCE_TYPES, AppointmentFormResourceTypeHome.findResourceTypesListFromIdForm( nIdForm ) );
175 model.put( MARK_ADMIN_USER_RESOURCE_TYPE, AdminUser.RESOURCE_TYPE );
176 model.put( MARK_LOCALE, getLocale( ) );
177
178 AppointmentFormJspBean.addElementsToModel( request, appointmentForm, getUser( ), getLocale( ), model );
179
180 return getPage( MESSAGE_MANAGE_FORM_RESOURCES_PAGE_TITLE, TEMPLATE_MANAGE_FORM_RESOURCES, model );
181 }
182
183
184
185
186
187
188
189
190
191
192 @View( value = VIEW_CREATE_RESOURCE_TYPE )
193 public String getCreateFormResourceType( HttpServletRequest request ) throws AccessDeniedException
194 {
195 AppointmentFormResourceType formResourceType;
196 int nIdForm;
197
198 if ( _formResourceType != null )
199 {
200 formResourceType = _formResourceType;
201 _formResourceType = null;
202 nIdForm = formResourceType.getIdAppointmentForm( );
203 }
204 else
205 {
206 String strIdForm = request.getParameter( PARAMETER_ID_FORM );
207
208 if ( StringUtils.isEmpty( strIdForm ) || !StringUtils.isNumeric( strIdForm ) )
209 {
210 return redirect( request, AppointmentFormJspBean.getURLManageAppointmentForms( request ) );
211 }
212
213 formResourceType = null;
214 nIdForm = Integer.parseInt( strIdForm );
215 }
216
217 if ( !RBACService.isAuthorized( AppointmentFormDTO.RESOURCE_TYPE, Integer.toString( nIdForm ), AppointmentResourceIdService.PERMISSION_MODIFY_FORM,
218 getUser( ) ) )
219 {
220 throw new AccessDeniedException( AppointmentResourceIdService.PERMISSION_MODIFY_FORM );
221 }
222
223 ReferenceList refListResourceTypes = new ReferenceList( );
224
225 for ( IResourceType resourceType : ResourceService.getInstance( ).getResourceTypesList( ) )
226 {
227 refListResourceTypes.addItem( resourceType.getResourceTypeName( ), resourceType.getResourceTypeDescription( ) );
228 }
229
230 Map<String, Object> model = getModel( );
231 model.put( MARK_FORM_RESOURCE_TYPE, formResourceType );
232 model.put( MARK_LIST_RESOURCE_TYPES, refListResourceTypes );
233 model.put( PARAMETER_ID_FORM, nIdForm );
234 model.put( MARK_LOCALE, getLocale( ) );
235
236 return getPage( MESSAGE_CREATE_FORM_RESOURCES_PAGE_TITLE, TEMPLATE_CREATE_FORM_RESOURCES, model );
237 }
238
239
240
241
242
243
244
245
246
247
248 @Action( value = ACTION_DO_CREATE_FORM_RESOURCE_TYPE )
249 public String doCreateFormResourceType( HttpServletRequest request ) throws AccessDeniedException
250 {
251 AppointmentFormResourceTypeource/business/AppointmentFormResourceType.html#AppointmentFormResourceType">AppointmentFormResourceType formResourceType = new AppointmentFormResourceType( );
252
253 populate( formResourceType, request );
254
255 if ( !RBACService.isAuthorized( AppointmentFormDTO.RESOURCE_TYPE, Integer.toString( formResourceType.getIdAppointmentForm( ) ),
256 AppointmentResourceIdService.PERMISSION_MODIFY_FORM, getUser( ) ) )
257 {
258 throw new AccessDeniedException( AppointmentResourceIdService.PERMISSION_MODIFY_FORM );
259 }
260
261 if ( !validateBean( formResourceType, VALIDATION_ATTRIBUTES_PREFIX ) )
262 {
263 _formResourceType = formResourceType;
264
265 return redirectView( request, VIEW_CREATE_RESOURCE_TYPE );
266 }
267
268 AppointmentFormResourceTypeHome.insert( formResourceType );
269
270 addInfo( MESSAGE_APPOINTMENT_FORM_RESOURCE_TYPE_CREATED, getLocale( ) );
271
272 return redirect( request, getUrlManageAppointmentFormResourceType( formResourceType.getIdAppointmentForm( ), request ) );
273 }
274
275
276
277
278
279
280
281
282
283
284 @View( value = VIEW_MODIFY_RESOURCE_TYPE )
285 public String getModifyFormResourceType( HttpServletRequest request ) throws AccessDeniedException
286 {
287 AppointmentFormResourceType formResourceType;
288
289 String strId = request.getParameter( PARAMETER_ID_FORM_RESOURCE_TYPE );
290
291 if ( StringUtils.isEmpty( strId ) || !StringUtils.isNumeric( strId ) )
292 {
293 formResourceType = _formResourceType;
294 _formResourceType = null;
295 }
296 else
297 {
298 int nId = Integer.parseInt( strId );
299 formResourceType = AppointmentFormResourceTypeHome.findByPrimaryKey( nId );
300 }
301
302 if ( formResourceType == null )
303 {
304 return getManageFormResources( request );
305 }
306
307 if ( !RBACService.isAuthorized( AppointmentFormDTO.RESOURCE_TYPE, Integer.toString( formResourceType.getIdAppointmentForm( ) ),
308 AppointmentResourceIdService.PERMISSION_MODIFY_FORM, getUser( ) ) )
309 {
310 throw new AccessDeniedException( AppointmentResourceIdService.PERMISSION_MODIFY_FORM );
311 }
312
313 List<IResourceType> listResourceTypes = ResourceService.getInstance( ).getResourceTypesList( );
314
315 Map<String, Object> model = getModel( );
316 model.put( MARK_FORM_RESOURCE_TYPE, formResourceType );
317 model.put( MARK_LIST_RESOURCE_TYPES, listResourceTypes );
318 model.put( MARK_LOCALE, getLocale( ) );
319
320 return getPage( MESSAGE_MODIFY_FORM_RESOURCES_PAGE_TITLE, TEMPLATE_MODIFY_FORM_RESOURCES, model );
321 }
322
323
324
325
326
327
328
329
330
331
332 @Action( value = ACTION_DO_MODIFY_FORM_RESOURCE_TYPE )
333 public String doModifyFormResourceType( HttpServletRequest request ) throws AccessDeniedException
334 {
335 String strIdFormResourceType = request.getParameter( PARAMETER_ID_FORM_RESOURCE_TYPE );
336
337 if ( StringUtils.isEmpty( strIdFormResourceType ) || !StringUtils.isNumeric( strIdFormResourceType ) )
338 {
339 return redirect( request, AppointmentFormJspBean.getURLManageAppointmentForms( request ) );
340 }
341
342 int nIdFormResourceType = Integer.parseInt( strIdFormResourceType );
343
344 AppointmentFormResourceType formResourceType = AppointmentFormResourceTypeHome.findByPrimaryKey( nIdFormResourceType );
345
346 if ( formResourceType == null )
347 {
348 return redirect( request, AppointmentFormJspBean.getURLManageAppointmentForms( request ) );
349 }
350
351 if ( !RBACService.isAuthorized( AppointmentFormDTO.RESOURCE_TYPE, Integer.toString( formResourceType.getIdAppointmentForm( ) ),
352 AppointmentResourceIdService.PERMISSION_MODIFY_FORM, getUser( ) ) )
353 {
354 throw new AccessDeniedException( AppointmentResourceIdService.PERMISSION_MODIFY_FORM );
355 }
356
357 boolean bIsAppointmentAdminUser = formResourceType.getIsAppointmentAdminUser();
358 boolean bIsLocation = formResourceType.getIsLocation();
359 populate( formResourceType, request );
360 formResourceType.setIsAppointmentAdminUser(bIsAppointmentAdminUser);
361 formResourceType.setIsLocation(bIsLocation);
362 if ( !validateBean( formResourceType, VALIDATION_ATTRIBUTES_PREFIX ) )
363 {
364 _formResourceType = formResourceType;
365
366 return redirectView( request, VIEW_MODIFY_RESOURCE_TYPE );
367 }
368
369 AppointmentFormResourceTypeHome.update( formResourceType );
370
371 addInfo( MESSAGE_APPOINTMENT_FORM_RESOURCE_TYPE_MODIFIED, getLocale( ) );
372
373 return redirect( request, getUrlManageAppointmentFormResourceType( formResourceType.getIdAppointmentForm( ), request ) );
374 }
375
376
377
378
379
380
381
382
383
384
385 @View( value = VIEW_CONFIRM_REMOVE_RESOURCE_TYPE )
386 public String getConfirmRemoveFormResourceType( HttpServletRequest request ) throws AccessDeniedException
387 {
388 String strIdFormResourceType = request.getParameter( PARAMETER_ID_FORM_RESOURCE_TYPE );
389
390 if ( StringUtils.isEmpty( strIdFormResourceType ) || !StringUtils.isNumeric( strIdFormResourceType ) )
391 {
392 return getManageFormResources( request );
393 }
394
395 int nIdFormResourceType = Integer.parseInt( strIdFormResourceType );
396 AppointmentFormResourceType formResourceType = AppointmentFormResourceTypeHome.findByPrimaryKey( nIdFormResourceType );
397
398 if ( formResourceType == null )
399 {
400 return getManageFormResources( request );
401 }
402
403 if ( !RBACService.isAuthorized( AppointmentFormDTO.RESOURCE_TYPE, Integer.toString( formResourceType.getIdAppointmentForm( ) ),
404 AppointmentResourceIdService.PERMISSION_MODIFY_FORM, getUser( ) ) )
405 {
406 throw new AccessDeniedException( AppointmentResourceIdService.PERMISSION_MODIFY_FORM );
407 }
408
409 UrlItem urlItem = new UrlItem( JSP_URL_MANAGE_APPOINTMENT_FORM_RESOURCE_TYPE );
410 urlItem.addParameter( MVCUtils.PARAMETER_ACTION, ACTION_DO_REMOVE_FORM_RESOURCE_TYPE );
411 urlItem.addParameter( PARAMETER_ID_FORM_RESOURCE_TYPE, strIdFormResourceType );
412
413 return redirect( request,
414 AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_FORM_RESOURCE_TYPE, urlItem.getUrl( ), AdminMessage.TYPE_CONFIRMATION ) );
415 }
416
417
418
419
420
421
422
423
424
425
426 @Action( value = ACTION_DO_REMOVE_FORM_RESOURCE_TYPE )
427 public String doRemoveFormResourceType( HttpServletRequest request ) throws AccessDeniedException
428 {
429 String strIdFormResourceType = request.getParameter( PARAMETER_ID_FORM_RESOURCE_TYPE );
430
431 if ( StringUtils.isEmpty( strIdFormResourceType ) || !StringUtils.isNumeric( strIdFormResourceType ) )
432 {
433 return redirect( request, AppointmentFormJspBean.getURLManageAppointmentForms( request ) );
434 }
435
436 int nIdFormResourceType = Integer.parseInt( strIdFormResourceType );
437 AppointmentFormResourceType formResourceType = AppointmentFormResourceTypeHome.findByPrimaryKey( nIdFormResourceType );
438
439 if ( formResourceType == null )
440 {
441 return redirect( request, AppointmentFormJspBean.getURLManageAppointmentForms( request ) );
442 }
443
444 if ( !RBACService.isAuthorized( AppointmentFormDTO.RESOURCE_TYPE, Integer.toString( formResourceType.getIdAppointmentForm( ) ),
445 AppointmentResourceIdService.PERMISSION_MODIFY_FORM, getUser( ) ) )
446 {
447 throw new AccessDeniedException( AppointmentResourceIdService.PERMISSION_MODIFY_FORM );
448 }
449
450 AppointmentFormResourceTypeHome.remove( nIdFormResourceType );
451
452 return redirect( request, getUrlManageAppointmentFormResourceType( formResourceType.getIdAppointmentForm( ), request ) );
453 }
454
455
456
457
458
459
460
461
462
463 @Action( ACTION_DO_SET_ADMIN_DEFAULT_RESOURCE_TYPE )
464 public String doSetAdminDefaultResourceType( HttpServletRequest request )
465 {
466 String strIdFormResourceType = request.getParameter( PARAMETER_ID_FORM_RESOURCE_TYPE );
467 int nIdFormResourceType = Integer.parseInt( strIdFormResourceType );
468 AppointmentFormResourceType formResourceType = AppointmentFormResourceTypeHome.findByPrimaryKey( nIdFormResourceType );
469
470 AppointmentFormResourceTypeHome.resetAppAdminUser( formResourceType.getIdAppointmentForm( ) );
471 formResourceType.setIsAppointmentAdminUser( true );
472 AppointmentFormResourceTypeHome.update( formResourceType );
473
474 return redirect( request, VIEW_MANAGE_FORM_RESOURCES, PARAMETER_ID_FORM, formResourceType.getIdAppointmentForm( ) );
475 }
476
477
478
479
480
481
482
483
484 @Action( ACTION_DO_SET_LOCATION_DEFAULT_RESOURCE_TYPE )
485 public String doSetLocalizationDefaultResourceType( HttpServletRequest request )
486 {
487 String strIdFormResourceType = request.getParameter( PARAMETER_ID_FORM_RESOURCE_TYPE );
488 int nIdFormResourceType = Integer.parseInt( strIdFormResourceType );
489 AppointmentFormResourceType formResourceType = AppointmentFormResourceTypeHome.findByPrimaryKey( nIdFormResourceType );
490
491 AppointmentFormResourceTypeHome.resetLocalization( formResourceType.getIdAppointmentForm( ) );
492 formResourceType.setIsLocation( true );
493 AppointmentFormResourceTypeHome.update( formResourceType );
494
495 return redirect( request, VIEW_MANAGE_FORM_RESOURCES, PARAMETER_ID_FORM, formResourceType.getIdAppointmentForm( ) );
496 }
497
498
499
500
501
502
503
504
505
506
507 public static final String getUrlManageAppointmentFormResourceType( int nIdForm, HttpServletRequest request )
508 {
509 UrlItem urlItem = new UrlItem( AppPathService.getBaseUrl( request ) + JSP_URL_MANAGE_APPOINTMENT_FORM_RESOURCE_TYPE );
510 urlItem.addParameter( MVCUtils.PARAMETER_VIEW, VIEW_MANAGE_FORM_RESOURCES );
511 urlItem.addParameter( PARAMETER_ID_FORM, nIdForm );
512
513 return urlItem.getUrl( );
514 }
515 }