View Javadoc
1   /*
2    * Copyright (c) 2002-2021, City of 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.releaser.web;
35  
36  import fr.paris.lutece.plugins.releaser.business.Cluster;
37  import fr.paris.lutece.plugins.releaser.business.ClusterHome;
38  import fr.paris.lutece.plugins.releaser.business.ReleaserUser;
39  import fr.paris.lutece.plugins.releaser.business.RepositoryType;
40  import fr.paris.lutece.plugins.releaser.business.Site;
41  import fr.paris.lutece.plugins.releaser.business.SiteHome;
42  import fr.paris.lutece.plugins.releaser.service.ClusterResourceIdService;
43  import fr.paris.lutece.plugins.releaser.service.ClusterService;
44  import fr.paris.lutece.plugins.releaser.service.ComponentService;
45  import fr.paris.lutece.plugins.releaser.service.SiteResourceIdService;
46  import fr.paris.lutece.plugins.releaser.service.SiteService;
47  import fr.paris.lutece.plugins.releaser.util.ConstanteUtils;
48  import fr.paris.lutece.plugins.releaser.util.ReleaserUtils;
49  import fr.paris.lutece.portal.business.user.AdminUser;
50  import fr.paris.lutece.portal.service.admin.AccessDeniedException;
51  import fr.paris.lutece.portal.service.admin.AdminUserService;
52  import fr.paris.lutece.portal.service.i18n.I18nService;
53  import fr.paris.lutece.portal.service.message.AdminMessage;
54  import fr.paris.lutece.portal.service.message.AdminMessageService;
55  import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
56  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
57  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
58  import fr.paris.lutece.util.url.UrlItem;
59  
60  import java.util.List;
61  import java.util.Map;
62  import javax.servlet.http.HttpServletRequest;
63  
64  import org.apache.commons.lang3.StringUtils;
65  
66  /**
67   * This class provides the user interface to manage Cluster features ( manage, create, modify, remove )
68   */
69  @Controller( controllerJsp = "ManageClusters.jsp", controllerPath = "jsp/admin/plugins/releaser/", right = "RELEASER_MANAGEMENT" )
70  public class ClusterJspBean extends ManageSitesJspBean
71  {
72      // Templates
73      private static final String TEMPLATE_MANAGE_CLUSTERS = "/admin/plugins/releaser/manage_clusters.html";
74      private static final String TEMPLATE_CREATE_CLUSTER = "/admin/plugins/releaser/create_cluster.html";
75      private static final String TEMPLATE_MODIFY_CLUSTER = "/admin/plugins/releaser/modify_cluster.html";
76      private static final String TEMPLATE_CREATE_SITE = "/admin/plugins/releaser/create_site.html";
77      private static final String TEMPLATE_MODIFY_SITE = "/admin/plugins/releaser/modify_site.html";
78  
79      // Parameters
80      private static final String PARAMETER_ID_CLUSTER = "id";
81      private static final String PARAMETER_ID_SITE = "id";
82      private static final String PARAMETER_ID_SITE_ERROR = "id_site_error";
83  
84      private static final String PARAMETER_ERROR = "error";
85  
86      // Properties for page titles
87      private static final String PROPERTY_PAGE_TITLE_MANAGE_CLUSTERS = "releaser.manage_clusters.pageTitle";
88      private static final String PROPERTY_PAGE_TITLE_MODIFY_CLUSTER = "releaser.modify_cluster.pageTitle";
89      private static final String PROPERTY_PAGE_TITLE_CREATE_CLUSTER = "releaser.create_cluster.pageTitle";
90      private static final String PROPERTY_PAGE_TITLE_MODIFY_SITE = "releaser.modify_site.pageTitle";
91      private static final String PROPERTY_PAGE_TITLE_CREATE_SITE = "releaser.create_site.pageTitle";
92  
93      // Properties
94      private static final String MESSAGE_CONFIRM_REMOVE_SITE = "releaser.message.confirmRemoveSite";
95  
96      // Messages
97      private static final String MESSAGE_ACCESS_DENIED = "releaser.message.accesDenied";
98      private static final String MESSAGE_SITE_ALREADY_EXIST = "releaser.message.siteAlreadyExist";
99  
100     // Markers
101     private static final String MARK_CLUSTER_LIST = "cluster_list";
102     private static final String MARK_CLUSTER = "cluster";
103     private static final String MARK_CLUSTERS_LIST = "clusters_list";
104     private static final String MARK_SITE = "site";
105 
106     private static final String MARK_IS_APPLICATION_ACCOUNT = "is_application_account";
107     private static final String MARK_IS_ADD_CLUSTER_AUTHORIZED = "add_cluster_authorized";
108     private static final String MARK_IS_SEARCH_COMPONENT_AUTHORIZED = "search_component_authorized";
109 
110     private static final String JSP_MANAGE_CLUSTERS = "jsp/admin/plugins/releaser/ManageClusters.jsp";
111     private static final String JSP_MANAGE_SITE_RELEASE = "ManageSiteRelease.jsp";
112     private static final String JSP_MANAGE_COMPONENT = "ManageComponent.jsp";
113 
114     // Properties
115     private static final String MESSAGE_CONFIRM_REMOVE_CLUSTER = "releaser.message.confirmRemoveCluster";
116 
117     // Validations
118     private static final String VALIDATION_ATTRIBUTES_PREFIX = "releaser.model.entity.cluster.attribute.";
119     private static final String VALIDATION_ATTRIBUTES_SITE_PREFIX = "releaser.model.entity.site.attribute.";
120     private static final String VALIDATION_ATTRIBUTES_USER_PREFIX = "releaser.model.entity.user.attribute.";
121 
122     // Views
123     private static final String VIEW_MANAGE_CLUSTERS = "manageClusters";
124     private static final String VIEW_CREATE_CLUSTER = "createCluster";
125     private static final String VIEW_MODIFY_CLUSTER = "modifyCluster";
126     private static final String VIEW_MANAGE_SITES = "manageSites";
127     private static final String VIEW_CREATE_SITE = "createSite";
128     private static final String VIEW_MODIFY_SITE = "modifySite";
129 
130     // Actions
131     private static final String ACTION_CREATE_CLUSTER = "createCluster";
132     private static final String ACTION_RELEASE_SITE = "releaseSite";
133     private static final String ACTION_RELEASE_COMPONENT = "releaseComponent";
134 
135     private static final String ACTION_MODIFY_CLUSTER = "modifyCluster";
136     private static final String ACTION_REMOVE_CLUSTER = "removeCluster";
137     private static final String ACTION_CONFIRM_REMOVE_CLUSTER = "confirmRemoveCluster";
138     private static final String ACTION_CREATE_SITE = "createSite";
139     private static final String ACTION_MODIFY_SITE = "modifySite";
140     private static final String ACTION_REMOVE_SITE = "removeSite";
141     private static final String ACTION_CONFIRM_REMOVE_SITE = "confirmRemoveSite";
142 
143     // Infos
144     private static final String INFO_CLUSTER_CREATED = "releaser.info.cluster.created";
145     private static final String INFO_CLUSTER_UPDATED = "releaser.info.cluster.updated";
146     private static final String INFO_CLUSTER_REMOVED = "releaser.info.cluster.removed";
147     private static final String INFO_SITE_CREATED = "releaser.info.site.created";
148     private static final String INFO_SITE_UPDATED = "releaser.info.site.updated";
149     private static final String INFO_SITE_REMOVED = "releaser.info.site.removed";
150 
151     // Session variable to store working values
152     private Cluster _cluster;
153     private Site _site;
154 
155     /**
156      * Build the Manage View
157      * 
158      * @param request
159      *            The HTTP request
160      * @return The page
161      */
162     @View( value = VIEW_MANAGE_CLUSTERS, defaultView = true )
163     public String getManageClusters( HttpServletRequest request )
164     {
165         _cluster = null;
166         _site = null;
167 
168         AdminUser adminUser = AdminUserService.getAdminUser( request );
169         List<Cluster> listClusters = ClusterService.getUserClusters( adminUser );
170 
171         Map<String, Object> model = getPaginatedListModel( request, MARK_CLUSTER_LIST, listClusters, JSP_MANAGE_CLUSTERS );
172 
173         model.put( ConstanteUtils.MARK_USER, ReleaserUtils.getReleaserUser( request, getLocale( ) ) );
174         model.put( MARK_IS_APPLICATION_ACCOUNT, ReleaserUtils.isApplicationAccountEnable( ) );
175         model.put( ConstanteUtils.MARK_REPO_TYPE_GITHUB, RepositoryType.GITHUB );
176         model.put( ConstanteUtils.MARK_REPO_TYPE_GITLAB, RepositoryType.GITLAB );
177         model.put( ConstanteUtils.MARK_REPO_TYPE_SVN, RepositoryType.SVN );
178         model.put( MARK_IS_ADD_CLUSTER_AUTHORIZED, ClusterService.IsAddClusterAuthorized( adminUser ) );
179         model.put( MARK_IS_SEARCH_COMPONENT_AUTHORIZED, ComponentService.IsSearchComponentAuthorized( adminUser ) );
180         if ( request.getParameter( PARAMETER_ID_SITE_ERROR ) != null )
181         {
182             // Load information site after authentication error
183             int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_SITE_ERROR ) );
184             model.put( MARK_SITE, SiteHome.findByPrimaryKey( nId ) );
185         }
186 
187         return getPage( PROPERTY_PAGE_TITLE_MANAGE_CLUSTERS, TEMPLATE_MANAGE_CLUSTERS, model );
188     }
189 
190     /**
191      * Returns the form to create a cluster
192      *
193      * @param request
194      *            The Http request
195      * @return the html code of the cluster form
196      * @throws AccessDeniedException
197      */
198     @View( VIEW_CREATE_CLUSTER )
199     public String getCreateCluster( HttpServletRequest request ) throws AccessDeniedException
200     {
201 
202         if ( !ClusterService.IsAddClusterAuthorized( AdminUserService.getAdminUser( request ) ) )
203         {
204             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
205         }
206 
207         _cluster = ( _cluster != null ) ? _cluster : new Cluster( );
208 
209         Map<String, Object> model = getModel( );
210         model.put( MARK_CLUSTER, _cluster );
211 
212         return getPage( PROPERTY_PAGE_TITLE_CREATE_CLUSTER, TEMPLATE_CREATE_CLUSTER, model );
213     }
214 
215     /**
216      * Process the data capture form of a new cluster
217      *
218      * @param request
219      *            The Http Request
220      * @return The Jsp URL of the process result
221      * @throws AccessDeniedException
222      */
223     @Action( ACTION_CREATE_CLUSTER )
224     public String doCreateCluster( HttpServletRequest request ) throws AccessDeniedException
225     {
226 
227         if ( !ClusterService.IsAddClusterAuthorized( AdminUserService.getAdminUser( request ) ) )
228         {
229             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
230         }
231 
232         populate( _cluster, request );
233 
234         // Check constraints
235         if ( !validateBean( _cluster, VALIDATION_ATTRIBUTES_PREFIX ) )
236         {
237             return redirectView( request, VIEW_CREATE_CLUSTER );
238         }
239 
240         ClusterHome.create( _cluster );
241         addInfo( INFO_CLUSTER_CREATED, getLocale( ) );
242 
243         return redirectView( request, VIEW_MANAGE_CLUSTERS );
244     }
245 
246     /**
247      * Process the data capture form of a new cluster
248      *
249      * @param request
250      *            The Http Request
251      * @return The Jsp URL of the process result
252      * @throws AccessDeniedException
253      */
254     @Action( ACTION_RELEASE_COMPONENT )
255     public String doReleaseComponent( HttpServletRequest request ) throws AccessDeniedException
256     {
257 
258         ReleaserUser user = ReleaserUtils.getReleaserUser( request, getLocale( ) );
259         if ( user == null )
260         {
261             user = new ReleaserUser( );
262 
263         }
264         populate( user, request );
265         ReleaserUtils.setReleaserUser( request, user );
266 
267         // Check constraints
268         if ( !validateBean( user, VALIDATION_ATTRIBUTES_USER_PREFIX ) )
269         {
270             redirectView( request, VIEW_MANAGE_CLUSTERS );
271         }
272 
273         return redirect( request, JSP_MANAGE_COMPONENT );
274     }
275 
276     /**
277      * Process the data capture form of a new cluster
278      *
279      * @param request
280      *            The Http Request
281      * @return The Jsp URL of the process result
282      * @throws AccessDeniedException
283      */
284     @Action( ACTION_RELEASE_SITE )
285     public String doReleaseSite( HttpServletRequest request ) throws AccessDeniedException
286     {
287 
288         if ( !SiteService.IsUserAuthorized( AdminUserService.getAdminUser( request ), request.getParameter( PARAMETER_ID_SITE ),
289                 SiteResourceIdService.PERMISSION_RELEASE ) )
290         {
291             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
292         }
293 
294         ReleaserUser user = ReleaserUtils.getReleaserUser( request, getLocale( ) );
295         String strIdSite = request.getParameter( PARAMETER_ID_SITE );
296         String strError = request.getParameter( PARAMETER_ERROR );
297         if ( user == null )
298         {
299             user = new ReleaserUser( );
300 
301         }
302         ReleaserUtils.populateReleaserUser( request, user );
303         ReleaserUtils.setReleaserUser( request, user );
304 
305         // Check Authentication
306         if ( user == null || !StringUtils.isEmpty( strError ) )
307         {
308             addError( strError );
309             return redirect( request, VIEW_MANAGE_CLUSTERS, PARAMETER_ID_SITE_ERROR, ReleaserUtils.convertStringToInt( strIdSite ) );
310         }
311 
312         return redirect( request, JSP_MANAGE_SITE_RELEASE + "?" + PARAMETER_ID_SITE + "=" + strIdSite );
313     }
314 
315     /**
316      * Manages the removal form of a cluster whose identifier is in the http request
317      *
318      * @param request
319      *            The Http request
320      * @return the html code to confirm
321      * @throws AccessDeniedException
322      */
323     @Action( ACTION_CONFIRM_REMOVE_CLUSTER )
324     public String getConfirmRemoveCluster( HttpServletRequest request ) throws AccessDeniedException
325     {
326 
327         if ( !ClusterService.IsUserAuthorized( AdminUserService.getAdminUser( request ), request.getParameter( PARAMETER_ID_CLUSTER ),
328                 ClusterResourceIdService.PERMISSION_DELETE ) )
329         {
330             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
331         }
332 
333         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CLUSTER ) );
334         UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_CLUSTER ) );
335         url.addParameter( PARAMETER_ID_CLUSTER, nId );
336 
337         String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_CLUSTER, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
338 
339         return redirect( request, strMessageUrl );
340     }
341 
342     /**
343      * Handles the removal form of a cluster
344      *
345      * @param request
346      *            The Http request
347      * @return the jsp URL to display the form to manage clusters
348      * @throws AccessDeniedException
349      */
350     @Action( ACTION_REMOVE_CLUSTER )
351     public String doRemoveCluster( HttpServletRequest request ) throws AccessDeniedException
352     {
353 
354         if ( !ClusterService.IsUserAuthorized( AdminUserService.getAdminUser( request ), request.getParameter( PARAMETER_ID_CLUSTER ),
355                 ClusterResourceIdService.PERMISSION_DELETE ) )
356         {
357             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
358         }
359 
360         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CLUSTER ) );
361 
362         ClusterHome.remove( nId );
363         addInfo( INFO_CLUSTER_REMOVED, getLocale( ) );
364 
365         return redirectView( request, VIEW_MANAGE_CLUSTERS );
366     }
367 
368     /**
369      * Returns the form to update info about a cluster
370      *
371      * @param request
372      *            The Http request
373      * @return The HTML form to update info
374      * @throws AccessDeniedException
375      */
376     @View( VIEW_MODIFY_CLUSTER )
377     public String getModifyCluster( HttpServletRequest request ) throws AccessDeniedException
378     {
379 
380         if ( !ClusterService.IsUserAuthorized( AdminUserService.getAdminUser( request ), request.getParameter( PARAMETER_ID_CLUSTER ),
381                 ClusterResourceIdService.PERMISSION_MODIFY ) )
382         {
383             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
384         }
385 
386         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CLUSTER ) );
387 
388         if ( _cluster == null || ( _cluster.getId( ) != nId ) )
389         {
390             _cluster = ClusterHome.findByPrimaryKey( nId );
391         }
392 
393         Map<String, Object> model = getModel( );
394         model.put( MARK_CLUSTER, _cluster );
395 
396         return getPage( PROPERTY_PAGE_TITLE_MODIFY_CLUSTER, TEMPLATE_MODIFY_CLUSTER, model );
397     }
398 
399     /**
400      * Process the change form of a cluster
401      *
402      * @param request
403      *            The Http request
404      * @return The Jsp URL of the process result
405      * @throws AccessDeniedException
406      */
407     @Action( ACTION_MODIFY_CLUSTER )
408     public String doModifyCluster( HttpServletRequest request ) throws AccessDeniedException
409     {
410 
411         if ( !ClusterService.IsUserAuthorized( AdminUserService.getAdminUser( request ), request.getParameter( PARAMETER_ID_CLUSTER ),
412                 ClusterResourceIdService.PERMISSION_MODIFY ) )
413         {
414             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
415         }
416 
417         populate( _cluster, request );
418 
419         // Check constraints
420         if ( !validateBean( _cluster, VALIDATION_ATTRIBUTES_PREFIX ) )
421         {
422             return redirect( request, VIEW_MODIFY_CLUSTER, PARAMETER_ID_CLUSTER, _cluster.getId( ) );
423         }
424 
425         ClusterHome.update( _cluster );
426         addInfo( INFO_CLUSTER_UPDATED, getLocale( ) );
427 
428         return redirectView( request, VIEW_MANAGE_CLUSTERS );
429     }
430 
431     /**
432      * Returns the form to create a site
433      *
434      * @param request
435      *            The Http request
436      * @return the html code of the site form
437      * @throws AccessDeniedException
438      */
439     @View( VIEW_CREATE_SITE )
440     public String getCreateSite( HttpServletRequest request ) throws AccessDeniedException
441     {
442 
443         if ( !ClusterService.IsUserAuthorized( AdminUserService.getAdminUser( request ), request.getParameter( PARAMETER_ID_CLUSTER ),
444                 ClusterResourceIdService.PERMISSION_ADD_SITE_TO_CLUSTER ) )
445         {
446             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
447         }
448 
449         _site = ( _site != null ) ? _site : new Site( );
450 
451         String strIdCluster = request.getParameter( PARAMETER_ID_CLUSTER );
452         _site.setIdCluster( ReleaserUtils.convertStringToInt( strIdCluster ) );
453         Map<String, Object> model = getModel( );
454         model.put( MARK_SITE, _site );
455         model.put( MARK_CLUSTERS_LIST, ClusterHome.getClustersReferenceList( ) );
456 
457         return getPage( PROPERTY_PAGE_TITLE_CREATE_SITE, TEMPLATE_CREATE_SITE, model );
458     }
459 
460     /**
461      * Process the data capture form of a new site
462      *
463      * @param request
464      *            The Http Request
465      * @return The Jsp URL of the process result
466      * @throws AccessDeniedException
467      */
468     @Action( ACTION_CREATE_SITE )
469     public String doCreateSite( HttpServletRequest request ) throws AccessDeniedException
470     {
471 
472         if ( !ClusterService.IsUserAuthorized( AdminUserService.getAdminUser( request ), request.getParameter( PARAMETER_ID_CLUSTER ),
473                 ClusterResourceIdService.PERMISSION_ADD_SITE_TO_CLUSTER ) )
474         {
475             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
476         }
477 
478         populate( _site, request );
479 
480         // Check constraints
481         if ( !validateBean( _site, VALIDATION_ATTRIBUTES_SITE_PREFIX ) )
482         {
483             return redirectView( request, VIEW_CREATE_SITE );
484         }
485 
486         if ( SiteService.IsSiteAlreadyExist( _site.getName( ), _site.getArtifactId( ), _site.getScmUrl( ) ) )
487         {
488             String errorMessage = I18nService.getLocalizedString( MESSAGE_SITE_ALREADY_EXIST, getLocale( ) );
489             addError( errorMessage );
490             return redirectView( request, VIEW_CREATE_SITE );
491         }
492 
493         SiteHome.create( _site );
494         addInfo( INFO_SITE_CREATED, getLocale( ) );
495 
496         return redirectView( request, VIEW_MANAGE_SITES );
497     }
498 
499     /**
500      * Manages the removal form of a site whose identifier is in the http request
501      *
502      * @param request
503      *            The Http request
504      * @return the html code to confirm
505      * @throws AccessDeniedException
506      */
507     @Action( ACTION_CONFIRM_REMOVE_SITE )
508     public String getConfirmRemoveSite( HttpServletRequest request ) throws AccessDeniedException
509     {
510 
511         if ( !SiteService.IsUserAuthorized( AdminUserService.getAdminUser( request ), request.getParameter( PARAMETER_ID_SITE ),
512                 SiteResourceIdService.PERMISSION_DELETE ) )
513         {
514             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
515         }
516 
517         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_SITE ) );
518         UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_SITE ) );
519         url.addParameter( PARAMETER_ID_SITE, nId );
520 
521         String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_SITE, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
522 
523         return redirect( request, strMessageUrl );
524     }
525 
526     /**
527      * Handles the removal form of a site
528      *
529      * @param request
530      *            The Http request
531      * @return the jsp URL to display the form to manage sites
532      * @throws AccessDeniedException
533      */
534     @Action( ACTION_REMOVE_SITE )
535     public String doRemoveSite( HttpServletRequest request ) throws AccessDeniedException
536     {
537 
538         if ( !SiteService.IsUserAuthorized( AdminUserService.getAdminUser( request ), request.getParameter( PARAMETER_ID_SITE ),
539                 SiteResourceIdService.PERMISSION_DELETE ) )
540         {
541             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
542         }
543 
544         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_SITE ) );
545         SiteHome.remove( nId );
546         SiteService.removeComponentAsProjectBySite( nId );
547         addInfo( INFO_SITE_REMOVED, getLocale( ) );
548 
549         return redirectView( request, VIEW_MANAGE_SITES );
550     }
551 
552     /**
553      * Returns the form to update info about a site
554      *
555      * @param request
556      *            The Http request
557      * @return The HTML form to update info
558      * @throws AccessDeniedException
559      */
560     @View( VIEW_MODIFY_SITE )
561     public String getModifySite( HttpServletRequest request ) throws AccessDeniedException
562     {
563 
564         if ( !SiteService.IsUserAuthorized( AdminUserService.getAdminUser( request ), request.getParameter( PARAMETER_ID_SITE ),
565                 SiteResourceIdService.PERMISSION_MODIFY ) )
566         {
567             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
568         }
569 
570         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_SITE ) );
571 
572         if ( _site == null || ( _site.getId( ) != nId ) )
573         {
574             _site = SiteHome.findByPrimaryKey( nId );
575         }
576 
577         Map<String, Object> model = getModel( );
578         model.put( MARK_SITE, _site );
579         model.put( MARK_CLUSTERS_LIST, ClusterHome.getClustersReferenceList( ) );
580 
581         return getPage( PROPERTY_PAGE_TITLE_MODIFY_SITE, TEMPLATE_MODIFY_SITE, model );
582     }
583 
584     /**
585      * Process the change form of a site
586      *
587      * @param request
588      *            The Http request
589      * @return The Jsp URL of the process result
590      * @throws AccessDeniedException
591      */
592     @Action( ACTION_MODIFY_SITE )
593     public String doModifySite( HttpServletRequest request ) throws AccessDeniedException
594     {
595 
596         if ( !SiteService.IsUserAuthorized( AdminUserService.getAdminUser( request ), request.getParameter( PARAMETER_ID_SITE ),
597                 SiteResourceIdService.PERMISSION_MODIFY ) )
598         {
599             throw new AccessDeniedException( MESSAGE_ACCESS_DENIED );
600         }
601 
602         populate( _site, request );
603 
604         // Check constraints
605         if ( !validateBean( _site, VALIDATION_ATTRIBUTES_SITE_PREFIX ) )
606         {
607             return redirect( request, VIEW_MODIFY_SITE, PARAMETER_ID_SITE, _site.getId( ) );
608         }
609 
610         SiteHome.update( _site );
611         addInfo( INFO_SITE_UPDATED, getLocale( ) );
612 
613         return redirectView( request, VIEW_MANAGE_SITES );
614     }
615 }