Coverage Report - fr.paris.lutece.plugins.releaser.web.ManageComponentReleaseJspBean
 
Classes in this File Line Coverage Branch Coverage Complexity
ManageComponentReleaseJspBean
0 %
0/34
0 %
0/30
6,333
 
 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 java.util.HashMap;
 37  
 import java.util.List;
 38  
 import java.util.Map;
 39  
 
 40  
 import javax.servlet.http.HttpServletRequest;
 41  
 
 42  
 import org.apache.commons.lang.StringUtils;
 43  
 
 44  
 import fr.paris.lutece.plugins.releaser.business.Component;
 45  
 import fr.paris.lutece.plugins.releaser.business.ReleaserUser;
 46  
 import fr.paris.lutece.plugins.releaser.service.ComponentService;
 47  
 import fr.paris.lutece.plugins.releaser.service.SiteService;
 48  
 import fr.paris.lutece.plugins.releaser.util.ReleaserUtils;
 49  
 import fr.paris.lutece.portal.service.template.AppTemplateService;
 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.util.ReferenceList;
 55  
 import fr.paris.lutece.util.html.HtmlTemplate;
 56  
 import fr.paris.lutece.util.html.Paginator;
 57  
 import fr.paris.lutece.util.json.AbstractJsonResponse;
 58  
 import fr.paris.lutece.util.json.JsonResponse;
 59  
 import fr.paris.lutece.util.json.JsonUtil;
 60  
 
 61  
 /**
 62  
  * ManageSiteRelease JSP Bean abstract class for JSP Bean
 63  
  */
 64  
 @Controller( controllerJsp = "ManageComponent.jsp", controllerPath = "jsp/admin/plugins/releaser/", right = "RELEASER_MANAGEMENT" )
 65  0
 public class ManageComponentReleaseJspBean extends MVCAdminJspBean
 66  
 {
 67  
     // Parameters
 68  
 
 69  
     private static final String PARAMETER_SEARCH = "search";
 70  
 
 71  
     // Views
 72  
     private static final String VIEW_MANAGE_COMPONENT = "manageComponent";
 73  
     // Actions
 74  
 
 75  
     private static final String TEMPLATE_MANAGE_COMPONENT = "/admin/plugins/releaser/manage_component.html";
 76  
 
 77  
     private static final String MARK_LIST_COMPONENT = "list_component";
 78  
     private static final String MARK_PAGINATOR = "paginator";
 79  
 
 80  
     private static final String MARK_SEARCH = "search";
 81  
     private static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
 82  
 
 83  
     private static final String JSP_MANAGE_COMPONENT = "jsp/admin/plugins/releaser/ManageComponent.jsp";
 84  
     private static final String JSP_MANAGE_CLUSTERS = "ManageClusters.jsp";
 85  
 
 86  
     private static final String ACTION_CHANGE_COMPONENT_NEXT_RELEASE_VERSION = "versionComponent";
 87  
     private static final String ACTION_RELEASE_COMPONENT = "releaseComponent";
 88  
 
 89  
     private static final String PARAMETER_ARTIFACT_ID = "artifact_id";
 90  
 
 91  
     private String _strSearch;
 92  
     private String _strCurrentPageIndex;
 93  
     Paginator<Component> _paginatorComponents;
 94  
 
 95  
     @View( value = VIEW_MANAGE_COMPONENT, defaultView = true )
 96  
     public String getManageComponent( HttpServletRequest request )
 97  
     {
 98  
 
 99  0
         _strSearch = request.getParameter( PARAMETER_SEARCH )!=null?request.getParameter( PARAMETER_SEARCH ):_strSearch;
 100  0
         String stCurrentPageIndexOld = _strCurrentPageIndex;
 101  0
         _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
 102  
 
 103  0
         if ( ReleaserUtils.getReleaserUser( request, getLocale( ) ) == null )
 104  
         {
 105  0
             return redirect( request, JSP_MANAGE_CLUSTERS );
 106  
         }
 107  
 
 108  0
         if (  !StringUtils.isEmpty( request.getParameter( PARAMETER_SEARCH )) || (_strCurrentPageIndex!=null && !_strCurrentPageIndex.equals( stCurrentPageIndexOld )) )
 109  
         {
 110  
 
 111  0
             _paginatorComponents = ComponentService.getService( ).getSearchComponent( _strSearch, request, getLocale( ), JSP_MANAGE_COMPONENT,
 112  
                     _strCurrentPageIndex );
 113  
 
 114  
         }
 115  
 
 116  0
         Map<String, Object> model = getModel( );
 117  0
         model.put( MARK_SEARCH, _strSearch );
 118  0
         model.put( MARK_LIST_COMPONENT, _paginatorComponents!=null?_paginatorComponents.getPageItems( ):null );
 119  0
         model.put( MARK_PAGINATOR, _paginatorComponents );
 120  0
         model.put( MARK_NB_ITEMS_PER_PAGE,_paginatorComponents!=null?_paginatorComponents.getItemsPerPage( ):null );
 121  
 
 122  0
         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_COMPONENT, getLocale( ), model );
 123  0
         return template.getHtml( );
 124  
     }
 125  
 
 126  
     @Action( ACTION_CHANGE_COMPONENT_NEXT_RELEASE_VERSION )
 127  
     public String doChangeComponentNextReleaseVersion( HttpServletRequest request )
 128  
     {
 129  0
         String strArtifactId = request.getParameter( PARAMETER_ARTIFACT_ID );
 130  
 
 131  0
         if ( strArtifactId != null && _paginatorComponents != null )
 132  
         {
 133  
 
 134  0
             for ( Component component : _paginatorComponents.getPageItems( ) )
 135  
             {
 136  
 
 137  0
                 if ( component.getArtifactId( ).equals( strArtifactId ) )
 138  
                 {
 139  
 
 140  0
                     ComponentService.getService( ).changeNextReleaseVersion( component );
 141  0
                     break;
 142  
                 }
 143  0
             }
 144  
 
 145  
         }
 146  
 
 147  0
         return redirectView( request, VIEW_MANAGE_COMPONENT );
 148  
     }
 149  
 
 150  
     @Action( ACTION_RELEASE_COMPONENT )
 151  
     public String doReleaseComponent( HttpServletRequest request )
 152  
     {
 153  0
         String strArtifactId = request.getParameter( PARAMETER_ARTIFACT_ID );
 154  0
         AbstractJsonResponse jsonResponse = null;
 155  0
         Integer nIdContext = null;
 156  
 
 157  0
         if ( strArtifactId != null && _paginatorComponents != null )
 158  
         {
 159  
 
 160  0
             for ( Component component : _paginatorComponents.getPageItems( ) )
 161  
             {
 162  0
                 if ( component.getArtifactId( ).equals( strArtifactId ) )
 163  
                 {
 164  0
                     nIdContext = ComponentService.getService( ).release( component, getLocale( ), getUser( ), request,true );
 165  0
                     break;
 166  
                 }
 167  0
             }
 168  
         }
 169  0
         jsonResponse = new JsonResponse( nIdContext );
 170  
 
 171  0
         return JsonUtil.buildJsonResponse( jsonResponse );
 172  
     }
 173  
 
 174  
 }