Coverage Report - fr.paris.lutece.plugins.releaser.web.ClusterJspBean
 
Classes in this File Line Coverage Branch Coverage Complexity
ClusterJspBean
0 %
0/91
0 %
0/28
2,2
 
 1  
 /*
 2  
  * Copyright (c) 2002-2017, 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.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.Site;
 40  
 import fr.paris.lutece.plugins.releaser.business.SiteHome;
 41  
 import fr.paris.lutece.plugins.releaser.service.SiteService;
 42  
 import fr.paris.lutece.plugins.releaser.util.ReleaserUtils;
 43  
 import fr.paris.lutece.portal.service.message.AdminMessage;
 44  
 import fr.paris.lutece.portal.service.message.AdminMessageService;
 45  
 import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
 46  
 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
 47  
 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
 48  
 import fr.paris.lutece.util.url.UrlItem;
 49  
 
 50  
 import java.util.List;
 51  
 import java.util.Map;
 52  
 import javax.servlet.http.HttpServletRequest;
 53  
 
 54  
 /**
 55  
  * This class provides the user interface to manage Cluster features ( manage, create, modify, remove )
 56  
  */
 57  
 @Controller( controllerJsp = "ManageClusters.jsp", controllerPath = "jsp/admin/plugins/releaser/", right = "RELEASER_MANAGEMENT" )
 58  0
 public class ClusterJspBean extends ManageSitesJspBean
 59  
 {
 60  
     // Templates
 61  
     private static final String TEMPLATE_MANAGE_CLUSTERS = "/admin/plugins/releaser/manage_clusters.html";
 62  
     private static final String TEMPLATE_CREATE_CLUSTER = "/admin/plugins/releaser/create_cluster.html";
 63  
     private static final String TEMPLATE_MODIFY_CLUSTER = "/admin/plugins/releaser/modify_cluster.html";
 64  
     private static final String TEMPLATE_CREATE_SITE = "/admin/plugins/releaser/create_site.html";
 65  
     private static final String TEMPLATE_MODIFY_SITE = "/admin/plugins/releaser/modify_site.html";
 66  
 
 67  
     // Parameters
 68  
     private static final String PARAMETER_ID_CLUSTER = "id";
 69  
     private static final String PARAMETER_ID_SITE = "id";
 70  
 
 71  
     // Properties for page titles
 72  
     private static final String PROPERTY_PAGE_TITLE_MANAGE_CLUSTERS = "releaser.manage_clusters.pageTitle";
 73  
     private static final String PROPERTY_PAGE_TITLE_MODIFY_CLUSTER = "releaser.modify_cluster.pageTitle";
 74  
     private static final String PROPERTY_PAGE_TITLE_CREATE_CLUSTER = "releaser.create_cluster.pageTitle";
 75  
     private static final String PROPERTY_PAGE_TITLE_MODIFY_SITE = "releaser.modify_site.pageTitle";
 76  
     private static final String PROPERTY_PAGE_TITLE_CREATE_SITE = "releaser.create_site.pageTitle";
 77  
 
 78  
     // Properties
 79  
     private static final String MESSAGE_CONFIRM_REMOVE_SITE = "releaser.message.confirmRemoveSite";
 80  
 
 81  
     // Markers
 82  
     private static final String MARK_CLUSTER_LIST = "cluster_list";
 83  
     private static final String MARK_CLUSTER = "cluster";
 84  
     private static final String MARK_CLUSTERS_LIST = "clusters_list";
 85  
     private static final String MARK_SITE = "site";
 86  
     private static final String MARK_USER = "user";
 87  
     private static final String MARK_IS_APPLICATION_ACCOUNT = "is_application_account";
 88  
     
 89  
     
 90  
 
 91  
     private static final String JSP_MANAGE_CLUSTERS = "jsp/admin/plugins/releaser/ManageClusters.jsp";
 92  
     private static final String JSP_MANAGE_SITE_RELEASE = "ManageSiteRelease.jsp";
 93  
      private static final String JSP_MANAGE_COMPONENT = "ManageComponent.jsp";
 94  
 
 95  
     // Properties
 96  
     private static final String MESSAGE_CONFIRM_REMOVE_CLUSTER = "releaser.message.confirmRemoveCluster";
 97  
 
 98  
     // Validations
 99  
     private static final String VALIDATION_ATTRIBUTES_PREFIX = "releaser.model.entity.cluster.attribute.";
 100  
     private static final String VALIDATION_ATTRIBUTES_SITE_PREFIX = "releaser.model.entity.site.attribute.";
 101  
     private static final String VALIDATION_ATTRIBUTES_USER_PREFIX = "releaser.model.entity.user.attribute.";
 102  
     
 103  
 
 104  
     // Views
 105  
     private static final String VIEW_MANAGE_CLUSTERS = "manageClusters";
 106  
     private static final String VIEW_CREATE_CLUSTER = "createCluster";
 107  
     private static final String VIEW_MODIFY_CLUSTER = "modifyCluster";
 108  
     private static final String VIEW_MANAGE_SITES = "manageSites";
 109  
     private static final String VIEW_CREATE_SITE = "createSite";
 110  
     private static final String VIEW_MODIFY_SITE = "modifySite";
 111  
 
 112  
     // Actions
 113  
     private static final String ACTION_CREATE_CLUSTER = "createCluster";
 114  
     private static final String ACTION_RELEASE_SITE = "releaseSite";
 115  
     private static final String ACTION_RELEASE_COMPONENT = "releaseComponent";
 116  
     
 117  
     
 118  
     private static final String ACTION_MODIFY_CLUSTER = "modifyCluster";
 119  
     private static final String ACTION_REMOVE_CLUSTER = "removeCluster";
 120  
     private static final String ACTION_CONFIRM_REMOVE_CLUSTER = "confirmRemoveCluster";
 121  
     private static final String ACTION_CREATE_SITE = "createSite";
 122  
     private static final String ACTION_MODIFY_SITE = "modifySite";
 123  
     private static final String ACTION_REMOVE_SITE = "removeSite";
 124  
     private static final String ACTION_CONFIRM_REMOVE_SITE = "confirmRemoveSite";
 125  
 
 126  
     // Infos
 127  
     private static final String INFO_CLUSTER_CREATED = "releaser.info.cluster.created";
 128  
     private static final String INFO_CLUSTER_UPDATED = "releaser.info.cluster.updated";
 129  
     private static final String INFO_CLUSTER_REMOVED = "releaser.info.cluster.removed";
 130  
     private static final String INFO_SITE_CREATED = "releaser.info.site.created";
 131  
     private static final String INFO_SITE_UPDATED = "releaser.info.site.updated";
 132  
     private static final String INFO_SITE_REMOVED = "releaser.info.site.removed";
 133  
 
 134  
     // Session variable to store working values
 135  
     private Cluster _cluster;
 136  
     private Site _site;
 137  
 
 138  
     /**
 139  
      * Build the Manage View
 140  
      * 
 141  
      * @param request
 142  
      *            The HTTP request
 143  
      * @return The page
 144  
      */
 145  
     @View( value = VIEW_MANAGE_CLUSTERS, defaultView = true )
 146  
     public String getManageClusters( HttpServletRequest request )
 147  
     {
 148  0
         _cluster = null;
 149  0
         _site = null;
 150  0
         List<Cluster> listClusters = ClusterHome.getClustersList( );
 151  0
         Map<String, Object> model = getPaginatedListModel( request, MARK_CLUSTER_LIST, listClusters, JSP_MANAGE_CLUSTERS );
 152  0
         model.put( MARK_USER, ReleaserUtils.getReleaserUser( request, getLocale( ) ));
 153  0
         model.put( MARK_IS_APPLICATION_ACCOUNT, ReleaserUtils.isApplicationAccountEnable( ));
 154  
         
 155  0
         return getPage( PROPERTY_PAGE_TITLE_MANAGE_CLUSTERS, TEMPLATE_MANAGE_CLUSTERS, model );
 156  
     }
 157  
 
 158  
     /**
 159  
      * Returns the form to create a cluster
 160  
      *
 161  
      * @param request
 162  
      *            The Http request
 163  
      * @return the html code of the cluster form
 164  
      */
 165  
     @View( VIEW_CREATE_CLUSTER )
 166  
     public String getCreateCluster( HttpServletRequest request )
 167  
     {
 168  0
         _cluster = ( _cluster != null ) ? _cluster : new Cluster( );
 169  
 
 170  0
         Map<String, Object> model = getModel( );
 171  0
         model.put( MARK_CLUSTER, _cluster );
 172  
 
 173  0
         return getPage( PROPERTY_PAGE_TITLE_CREATE_CLUSTER, TEMPLATE_CREATE_CLUSTER, model );
 174  
     }
 175  
     
 176  
     
 177  
     /**
 178  
      * Process the data capture form of a new cluster
 179  
      *
 180  
      * @param request
 181  
      *            The Http Request
 182  
      * @return The Jsp URL of the process result
 183  
      */
 184  
     @Action( ACTION_CREATE_CLUSTER )
 185  
     public String doCreateCluster( HttpServletRequest request )
 186  
     {
 187  0
         populate( _cluster, request );
 188  
 
 189  
         // Check constraints
 190  0
         if ( !validateBean( _cluster, VALIDATION_ATTRIBUTES_PREFIX ) )
 191  
         {
 192  0
             return redirectView( request, VIEW_CREATE_CLUSTER );
 193  
         }
 194  
 
 195  0
         ClusterHome.create( _cluster );
 196  0
         addInfo( INFO_CLUSTER_CREATED, getLocale( ) );
 197  
 
 198  0
         return redirectView( request, VIEW_MANAGE_CLUSTERS );
 199  
     }
 200  
     
 201  
     /**
 202  
      * Process the data capture form of a new cluster
 203  
      *
 204  
      * @param request
 205  
      *            The Http Request
 206  
      * @return The Jsp URL of the process result
 207  
      */
 208  
     @Action( ACTION_RELEASE_COMPONENT )
 209  
     public String doReleaseComponent( HttpServletRequest request )
 210  
     {
 211  0
         ReleaserUser user=ReleaserUtils.getReleaserUser( request, getLocale( ) );
 212  0
          if(user==null)
 213  
         {
 214  0
             user=new ReleaserUser( );
 215  
             
 216  
         }
 217  0
         populate( user, request );
 218  
         
 219  
 
 220  
         // Check constraints
 221  0
         if ( !validateBean( user, VALIDATION_ATTRIBUTES_USER_PREFIX ) )
 222  
         {
 223  
             
 224  0
             redirectView( request, VIEW_MANAGE_CLUSTERS );
 225  
         }
 226  
        
 227  0
         ReleaserUtils.setReleaserUser( request, user );
 228  
         
 229  0
         return redirect( request, JSP_MANAGE_COMPONENT );
 230  
     }
 231  
 
 232  
     /**
 233  
      * Process the data capture form of a new cluster
 234  
      *
 235  
      * @param request
 236  
      *            The Http Request
 237  
      * @return The Jsp URL of the process result
 238  
      */
 239  
     @Action( ACTION_RELEASE_SITE )
 240  
     public String doReleaseSite( HttpServletRequest request )
 241  
     {
 242  0
         ReleaserUser user=ReleaserUtils.getReleaserUser( request, getLocale( ) );
 243  0
         String strIdSite=request.getParameter( PARAMETER_ID_SITE );
 244  0
         if(user==null)
 245  
         {
 246  0
             user=new ReleaserUser( );
 247  
             
 248  
         }
 249  0
         populate( user, request );
 250  
         
 251  
 
 252  
         // Check constraints
 253  0
         if ( !validateBean( user, VALIDATION_ATTRIBUTES_USER_PREFIX ) )
 254  
         {
 255  
             
 256  0
             redirectView( request, VIEW_MANAGE_CLUSTERS );
 257  
         }
 258  
         //Init Svn component acount with svn site account
 259  0
         user.setSvnComponentAccountLogin( user.getSvnSiteAccountLogin( ) );
 260  0
         user.setSvnComponentAccountPassword( user.getSvnSiteAccountPassword( ) );
 261  
        
 262  0
         ReleaserUtils.setReleaserUser( request, user );
 263  
         
 264  0
         return redirect( request, JSP_MANAGE_SITE_RELEASE+"?id_site="+strIdSite );
 265  
     }
 266  
 
 267  
     /**
 268  
      * Manages the removal form of a cluster whose identifier is in the http request
 269  
      *
 270  
      * @param request
 271  
      *            The Http request
 272  
      * @return the html code to confirm
 273  
      */
 274  
     @Action( ACTION_CONFIRM_REMOVE_CLUSTER )
 275  
     public String getConfirmRemoveCluster( HttpServletRequest request )
 276  
     {
 277  0
         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CLUSTER ) );
 278  0
         UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_CLUSTER ) );
 279  0
         url.addParameter( PARAMETER_ID_CLUSTER, nId );
 280  
 
 281  0
         String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_CLUSTER, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
 282  
 
 283  0
         return redirect( request, strMessageUrl );
 284  
     }
 285  
 
 286  
     /**
 287  
      * Handles the removal form of a cluster
 288  
      *
 289  
      * @param request
 290  
      *            The Http request
 291  
      * @return the jsp URL to display the form to manage clusters
 292  
      */
 293  
     @Action( ACTION_REMOVE_CLUSTER )
 294  
     public String doRemoveCluster( HttpServletRequest request )
 295  
     {
 296  0
         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CLUSTER ) );
 297  0
         ClusterHome.remove( nId );
 298  0
         addInfo( INFO_CLUSTER_REMOVED, getLocale( ) );
 299  
 
 300  0
         return redirectView( request, VIEW_MANAGE_CLUSTERS );
 301  
     }
 302  
 
 303  
     /**
 304  
      * Returns the form to update info about a cluster
 305  
      *
 306  
      * @param request
 307  
      *            The Http request
 308  
      * @return The HTML form to update info
 309  
      */
 310  
     @View( VIEW_MODIFY_CLUSTER )
 311  
     public String getModifyCluster( HttpServletRequest request )
 312  
     {
 313  0
         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CLUSTER ) );
 314  
 
 315  0
         if ( _cluster == null || ( _cluster.getId( ) != nId ) )
 316  
         {
 317  0
             _cluster = ClusterHome.findByPrimaryKey( nId );
 318  
         }
 319  
 
 320  0
         Map<String, Object> model = getModel( );
 321  0
         model.put( MARK_CLUSTER, _cluster );
 322  
 
 323  0
         return getPage( PROPERTY_PAGE_TITLE_MODIFY_CLUSTER, TEMPLATE_MODIFY_CLUSTER, model );
 324  
     }
 325  
 
 326  
     /**
 327  
      * Process the change form of a cluster
 328  
      *
 329  
      * @param request
 330  
      *            The Http request
 331  
      * @return The Jsp URL of the process result
 332  
      */
 333  
     @Action( ACTION_MODIFY_CLUSTER )
 334  
     public String doModifyCluster( HttpServletRequest request )
 335  
     {
 336  0
         populate( _cluster, request );
 337  
 
 338  
         // Check constraints
 339  0
         if ( !validateBean( _cluster, VALIDATION_ATTRIBUTES_PREFIX ) )
 340  
         {
 341  0
             return redirect( request, VIEW_MODIFY_CLUSTER, PARAMETER_ID_CLUSTER, _cluster.getId( ) );
 342  
         }
 343  
 
 344  0
         ClusterHome.update( _cluster );
 345  0
         addInfo( INFO_CLUSTER_UPDATED, getLocale( ) );
 346  
 
 347  0
         return redirectView( request, VIEW_MANAGE_CLUSTERS );
 348  
     }
 349  
 
 350  
     /**
 351  
      * Returns the form to create a site
 352  
      *
 353  
      * @param request
 354  
      *            The Http request
 355  
      * @return the html code of the site form
 356  
      */
 357  
     @View( VIEW_CREATE_SITE )
 358  
     public String getCreateSite( HttpServletRequest request )
 359  
     {
 360  0
         _site = ( _site != null ) ? _site : new Site( );
 361  
 
 362  0
         Map<String, Object> model = getModel( );
 363  0
         model.put( MARK_SITE, _site );
 364  0
         model.put( MARK_CLUSTERS_LIST, ClusterHome.getClustersReferenceList( ) );
 365  
 
 366  0
         return getPage( PROPERTY_PAGE_TITLE_CREATE_SITE, TEMPLATE_CREATE_SITE, model );
 367  
     }
 368  
 
 369  
     /**
 370  
      * Process the data capture form of a new site
 371  
      *
 372  
      * @param request
 373  
      *            The Http Request
 374  
      * @return The Jsp URL of the process result
 375  
      */
 376  
     @Action( ACTION_CREATE_SITE )
 377  
     public String doCreateSite( HttpServletRequest request )
 378  
     {
 379  0
         populate( _site, request );
 380  
 
 381  
         // Check constraints
 382  0
         if ( !validateBean( _site, VALIDATION_ATTRIBUTES_SITE_PREFIX ) )
 383  
         {
 384  0
             return redirectView( request, VIEW_CREATE_SITE );
 385  
         }
 386  
 
 387  0
         SiteHome.create( _site );
 388  0
         addInfo( INFO_SITE_CREATED, getLocale( ) );
 389  
 
 390  0
         return redirectView( request, VIEW_MANAGE_SITES );
 391  
     }
 392  
 
 393  
     /**
 394  
      * Manages the removal form of a site whose identifier is in the http request
 395  
      *
 396  
      * @param request
 397  
      *            The Http request
 398  
      * @return the html code to confirm
 399  
      */
 400  
     @Action( ACTION_CONFIRM_REMOVE_SITE )
 401  
     public String getConfirmRemoveSite( HttpServletRequest request )
 402  
     {
 403  0
         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_SITE ) );
 404  0
         UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_SITE ) );
 405  0
         url.addParameter( PARAMETER_ID_SITE, nId );
 406  
 
 407  0
         String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_SITE, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
 408  
 
 409  0
         return redirect( request, strMessageUrl );
 410  
     }
 411  
 
 412  
     /**
 413  
      * Handles the removal form of a site
 414  
      *
 415  
      * @param request
 416  
      *            The Http request
 417  
      * @return the jsp URL to display the form to manage sites
 418  
      */
 419  
     @Action( ACTION_REMOVE_SITE )
 420  
     public String doRemoveSite( HttpServletRequest request )
 421  
     {
 422  0
         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_SITE ) );
 423  0
         SiteHome.remove( nId );
 424  0
         SiteService.removeComponentAsProjectBySite( nId );
 425  0
         addInfo( INFO_SITE_REMOVED, getLocale( ) );
 426  
 
 427  0
         return redirectView( request, VIEW_MANAGE_SITES );
 428  
     }
 429  
 
 430  
     /**
 431  
      * Returns the form to update info about a site
 432  
      *
 433  
      * @param request
 434  
      *            The Http request
 435  
      * @return The HTML form to update info
 436  
      */
 437  
     @View( VIEW_MODIFY_SITE )
 438  
     public String getModifySite( HttpServletRequest request )
 439  
     {
 440  0
         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_SITE ) );
 441  
 
 442  0
         if ( _site == null || ( _site.getId( ) != nId ) )
 443  
         {
 444  0
             _site = SiteHome.findByPrimaryKey( nId );
 445  
         }
 446  
 
 447  0
         Map<String, Object> model = getModel( );
 448  0
         model.put( MARK_SITE, _site );
 449  
 
 450  0
         return getPage( PROPERTY_PAGE_TITLE_MODIFY_SITE, TEMPLATE_MODIFY_SITE, model );
 451  
     }
 452  
 
 453  
     /**
 454  
      * Process the change form of a site
 455  
      *
 456  
      * @param request
 457  
      *            The Http request
 458  
      * @return The Jsp URL of the process result
 459  
      */
 460  
     @Action( ACTION_MODIFY_SITE )
 461  
     public String doModifySite( HttpServletRequest request )
 462  
     {
 463  0
         populate( _site, request );
 464  
 
 465  
         // Check constraints
 466  0
         if ( !validateBean( _site, VALIDATION_ATTRIBUTES_SITE_PREFIX ) )
 467  
         {
 468  0
             return redirect( request, VIEW_MODIFY_SITE, PARAMETER_ID_SITE, _site.getId( ) );
 469  
         }
 470  
 
 471  0
         SiteHome.update( _site );
 472  0
         addInfo( INFO_SITE_UPDATED, getLocale( ) );
 473  
 
 474  0
         return redirectView( request, VIEW_MANAGE_SITES );
 475  
     }
 476  
 
 477  
 }