View Javadoc
1   /*
2    * Copyright (c) 2002-2018, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
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   * Jsp Bean to manage appointment form resources
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       * Path of this controller
73       */
74      public static final String PATH_MANAGE_APPOINTMENT_FORM_RESOURCE_TYPE = "jsp/admin/plugins/appointment/modules/resource/";
75  
76      /**
77       * JSP name of this controller
78       */
79      public static final String JSP_MANAGE_APPOINTMENT_FORM_RESOURCE_TYPE = "ManageAppointmentFormResources.jsp";
80  
81      /**
82       * Url of the JSP of this controller, with its full path (without the base URL)
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      // Views
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      // Actions
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     // Marks
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     // Parameters
109     private static final String PARAMETER_ID_FORM = "id_form";
110     private static final String PARAMETER_ID_FORM_RESOURCE_TYPE = "idFormResourceType";
111 
112     // Messages
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     // Templates
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     // Session variable to store working values
128     private static final String SESSION_ATTRIBUTE_APPOINTMENT_FORM = "appointment.session.appointmentForm";
129     
130     /**
131      * Manage the resources of an appointment form
132      * 
133      * @param request
134      *            the request
135      * @return The HTML content to display
136      * @throws AccessDeniedException
137      *             If the user is not authorized to access this feature
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      * Get the page to create an appointment form resource type
185      * 
186      * @param request
187      *            the request
188      * @return The page to create an appointment form resource type
189      * @throws AccessDeniedException
190      *             If the user is not authorized to access this feature
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      * Do create an appointment form resource type
241      * 
242      * @param request
243      *            the request
244      * @return The next URL to redirect to
245      * @throws AccessDeniedException
246      *             If the user is not authorized to access this feature
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      * Get the page to modify an appointment form resource type
277      * 
278      * @param request
279      *            The request
280      * @return The HTML content to display
281      * @throws AccessDeniedException
282      *             If the user is not authorized to access this feature
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      * Do modify an appointment form resource type
325      * 
326      * @param request
327      *            The request
328      * @return The next URL to redirect to
329      * @throws AccessDeniedException
330      *             If the user is not authorized to access this feature
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         // Need to save the configuration for these two boolean because the populate method lost them
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      * Do confirm the removal of an appointment form resource type
378      * 
379      * @param request
380      *            the request
381      * @return the next URL to redirect to
382      * @throws AccessDeniedException
383      *             If the user is not authorized to access this feature
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      * Do remove an appointment form resource type
419      * 
420      * @param request
421      *            The request
422      * @return The newt URL to redirect to
423      * @throws AccessDeniedException
424      *             If the user is not authorized to access this feature
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      * Do set a form resource type as the attribute containing the admin user associated with an appointment, so that when the attribute is modified, the admin
457      * user associated with the appointment is also modified
458      * 
459      * @param request
460      *            The request
461      * @return The next URL to redirect to
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      * Do set a form resource type as the attribute containing the localization of appointments
479      * 
480      * @param request
481      *            The request
482      * @return The next URL to redirect to
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      * Get the URL to manage appointment form resource types
500      * 
501      * @param nIdForm
502      *            the id of the form
503      * @param request
504      *            The request
505      * @return The requested URL
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 }