Coverage Report - fr.paris.lutece.plugins.parisconnect.web.AlertJspBean
 
Classes in this File Line Coverage Branch Coverage Complexity
AlertJspBean
0 %
0/39
0 %
0/10
2
 
 1  
 /*
 2  
  * Copyright (c) 2002-2016, 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.parisconnect.web;
 35  
 
 36  
 import fr.paris.lutece.plugins.parisconnect.business.Alert;
 37  
 import fr.paris.lutece.plugins.parisconnect.business.AlertHome;
 38  
 import fr.paris.lutece.plugins.parisconnect.business.CategoryHome;
 39  
 import fr.paris.lutece.portal.service.message.AdminMessage;
 40  
 import fr.paris.lutece.portal.service.message.AdminMessageService;
 41  
 import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
 42  
 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
 43  
 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
 44  
 import fr.paris.lutece.util.url.UrlItem;
 45  
 
 46  
 import java.util.List;
 47  
 import java.util.Map;
 48  
 import javax.servlet.http.HttpServletRequest;
 49  
 
 50  
 /**
 51  
  * This class provides the user interface to manage Alert features ( manage, create, modify, remove )
 52  
  */
 53  
 @Controller( controllerJsp = "ManageAlerts.jsp", controllerPath = "jsp/admin/plugins/parisconnect/", right = "PARISCONNECT_MANAGEMENT" )
 54  0
 public class AlertJspBean extends ManageParisconnectJspBean
 55  
 {
 56  
     // Templates
 57  
     private static final String TEMPLATE_MANAGE_ALERTS = "/admin/plugins/parisconnect/manage_alerts.html";
 58  
     private static final String TEMPLATE_CREATE_ALERT = "/admin/plugins/parisconnect/create_alert.html";
 59  
     private static final String TEMPLATE_MODIFY_ALERT = "/admin/plugins/parisconnect/modify_alert.html";
 60  
 
 61  
     // Parameters
 62  
     private static final String PARAMETER_ID_ALERT = "id";
 63  
 
 64  
     // Properties for page titles
 65  
     private static final String PROPERTY_PAGE_TITLE_MANAGE_ALERTS = "parisconnect.manage_alerts.pageTitle";
 66  
     private static final String PROPERTY_PAGE_TITLE_MODIFY_ALERT = "parisconnect.modify_alert.pageTitle";
 67  
     private static final String PROPERTY_PAGE_TITLE_CREATE_ALERT = "parisconnect.create_alert.pageTitle";
 68  
 
 69  
     // Markers
 70  
     private static final String MARK_ALERT_LIST = "alert_list";
 71  
     private static final String MARK_ALERT = "parisconnect_alert";
 72  
     private static final String MARK_CATEGORY_LIST = "category_list";
 73  
 
 74  
     private static final String JSP_MANAGE_ALERTS = "jsp/admin/plugins/parisconnect/ManageAlerts.jsp";
 75  
 
 76  
     // Properties
 77  
     private static final String MESSAGE_CONFIRM_REMOVE_ALERT = "parisconnect.message.confirmRemoveAlert";
 78  
 
 79  
     // Validations
 80  
     private static final String VALIDATION_ATTRIBUTES_PREFIX = "parisconnect.model.entity.alert.attribute.";
 81  
 
 82  
     // Views
 83  
     private static final String VIEW_MANAGE_ALERTS = "manageAlerts";
 84  
     private static final String VIEW_CREATE_ALERT = "createAlert";
 85  
     private static final String VIEW_MODIFY_ALERT = "modifyAlert";
 86  
 
 87  
     // Actions
 88  
     private static final String ACTION_CREATE_ALERT = "createAlert";
 89  
     private static final String ACTION_MODIFY_ALERT = "modifyAlert";
 90  
     private static final String ACTION_REMOVE_ALERT = "removeAlert";
 91  
     private static final String ACTION_CONFIRM_REMOVE_ALERT = "confirmRemoveAlert";
 92  
 
 93  
     // Infos
 94  
     private static final String INFO_ALERT_CREATED = "parisconnect.info.alert.created";
 95  
     private static final String INFO_ALERT_UPDATED = "parisconnect.info.alert.updated";
 96  
     private static final String INFO_ALERT_REMOVED = "parisconnect.info.alert.removed";
 97  
     
 98  
     // Session variable to store working values
 99  
     private Alert _alert;
 100  
     
 101  
     /**
 102  
      * Build the Manage View
 103  
      * @param request The HTTP request
 104  
      * @return The page
 105  
      */
 106  
     @View( value = VIEW_MANAGE_ALERTS, defaultView = true )
 107  
     public String getManageAlerts( HttpServletRequest request )
 108  
     {
 109  0
         _alert = null;
 110  0
         List<Alert> listAlerts = AlertHome.getAlertsList(  );
 111  0
         Map<String, Object> model = getPaginatedListModel( request, MARK_ALERT_LIST, listAlerts, JSP_MANAGE_ALERTS );
 112  
         
 113  
         
 114  0
         model.put( MARK_CATEGORY_LIST, CategoryHome.getCategorysReferenceList() );
 115  
         
 116  0
         return getPage( PROPERTY_PAGE_TITLE_MANAGE_ALERTS, TEMPLATE_MANAGE_ALERTS, model );
 117  
     }
 118  
 
 119  
     /**
 120  
      * Returns the form to create a alert
 121  
      *
 122  
      * @param request The Http request
 123  
      * @return the html code of the alert form
 124  
      */
 125  
     @View( VIEW_CREATE_ALERT )
 126  
     public String getCreateAlert( HttpServletRequest request )
 127  
     {
 128  0
         _alert = ( _alert != null ) ? _alert : new Alert(  );
 129  
 
 130  0
         Map<String, Object> model = getModel(  );
 131  0
         model.put( MARK_ALERT, _alert );
 132  0
         model.put( MARK_CATEGORY_LIST, CategoryHome.getCategorysReferenceList() );
 133  
         
 134  
 
 135  0
         return getPage( PROPERTY_PAGE_TITLE_CREATE_ALERT, TEMPLATE_CREATE_ALERT, model );
 136  
     }
 137  
 
 138  
     /**
 139  
      * Process the data capture form of a new alert
 140  
      *
 141  
      * @param request The Http Request
 142  
      * @return The Jsp URL of the process result
 143  
      */
 144  
     @Action( ACTION_CREATE_ALERT )
 145  
     public String doCreateAlert( HttpServletRequest request )
 146  
     {
 147  0
         populate( _alert, request );
 148  
 
 149  
         // Check constraints
 150  0
         if ( !validateBean( _alert, VALIDATION_ATTRIBUTES_PREFIX ) )
 151  
         {
 152  0
             return redirectView( request, VIEW_CREATE_ALERT );
 153  
         }
 154  
 
 155  0
         AlertHome.create( _alert );
 156  0
         addInfo( INFO_ALERT_CREATED, getLocale(  ) );
 157  
 
 158  0
         return redirectView( request, VIEW_MANAGE_ALERTS );
 159  
     }
 160  
 
 161  
     /**
 162  
      * Manages the removal form of a alert whose identifier is in the http
 163  
      * request
 164  
      *
 165  
      * @param request The Http request
 166  
      * @return the html code to confirm
 167  
      */
 168  
     @Action( ACTION_CONFIRM_REMOVE_ALERT )
 169  
     public String getConfirmRemoveAlert( HttpServletRequest request )
 170  
     {
 171  0
         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_ALERT ) );
 172  0
         UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_ALERT ) );
 173  0
         url.addParameter( PARAMETER_ID_ALERT, nId );
 174  
 
 175  0
         String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_ALERT, url.getUrl(  ), AdminMessage.TYPE_CONFIRMATION );
 176  
 
 177  0
         return redirect( request, strMessageUrl );
 178  
     }
 179  
 
 180  
     /**
 181  
      * Handles the removal form of a alert
 182  
      *
 183  
      * @param request The Http request
 184  
      * @return the jsp URL to display the form to manage alerts
 185  
      */
 186  
     @Action( ACTION_REMOVE_ALERT )
 187  
     public String doRemoveAlert( HttpServletRequest request )
 188  
     {
 189  0
         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_ALERT ) );
 190  0
         AlertHome.remove( nId );
 191  0
         addInfo( INFO_ALERT_REMOVED, getLocale(  ) );
 192  
 
 193  0
         return redirectView( request, VIEW_MANAGE_ALERTS );
 194  
     }
 195  
 
 196  
     /**
 197  
      * Returns the form to update info about a alert
 198  
      *
 199  
      * @param request The Http request
 200  
      * @return The HTML form to update info
 201  
      */
 202  
     @View( VIEW_MODIFY_ALERT )
 203  
     public String getModifyAlert( HttpServletRequest request )
 204  
     {
 205  0
         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_ALERT ) );
 206  
 
 207  0
         if ( _alert == null || ( _alert.getId(  ) != nId ))
 208  
         {
 209  0
             _alert = AlertHome.findByPrimaryKey( nId );
 210  
         }
 211  
 
 212  0
         Map<String, Object> model = getModel(  );
 213  0
         model.put( MARK_CATEGORY_LIST, CategoryHome.getCategorysReferenceList() );
 214  
         
 215  0
         model.put( MARK_ALERT, _alert );
 216  
 
 217  0
         return getPage( PROPERTY_PAGE_TITLE_MODIFY_ALERT, TEMPLATE_MODIFY_ALERT, model );
 218  
     }
 219  
 
 220  
     /**
 221  
      * Process the change form of a alert
 222  
      *
 223  
      * @param request The Http request
 224  
      * @return The Jsp URL of the process result
 225  
      */
 226  
     @Action( ACTION_MODIFY_ALERT )
 227  
     public String doModifyAlert( HttpServletRequest request )
 228  
     {
 229  0
         populate( _alert, request );
 230  
 
 231  
         // Check constraints
 232  0
         if ( !validateBean( _alert, VALIDATION_ATTRIBUTES_PREFIX ) )
 233  
         {
 234  0
             return redirect( request, VIEW_MODIFY_ALERT, PARAMETER_ID_ALERT, _alert.getId( ) );
 235  
         }
 236  
 
 237  0
         AlertHome.update( _alert );
 238  0
         addInfo( INFO_ALERT_UPDATED, getLocale(  ) );
 239  
 
 240  0
         return redirectView( request, VIEW_MANAGE_ALERTS );
 241  
     }
 242  
 }