View Javadoc
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   	
35  package fr.paris.lutece.plugins.chatbot.modules.stationnement.web;
36  
37  import fr.paris.lutece.plugins.chatbot.modules.stationnement.business.NoFeesDay;
38  import fr.paris.lutece.plugins.chatbot.modules.stationnement.business.NoFeesDayHome;
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 NoFeesDay features ( manage, create, modify, remove )
52   */
53  @Controller( controllerJsp = "ManageNoFeesDays.jsp", controllerPath = "jsp/admin/plugins/chatbot/modules/stationnement/", right = "STATIONNEMENT_NOFEESDAYS_MANAGEMENT" )
54  public class NoFeesDayJspBean extends AbstractManageNoFeesDaysJspBean
55  {
56      // Templates
57      private static final String TEMPLATE_MANAGE_NOFEESDAYS = "/admin/plugins/chatbot/modules/stationnement/manage_nofeesdays.html";
58      private static final String TEMPLATE_CREATE_NOFEESDAY = "/admin/plugins/chatbot/modules/stationnement/create_nofeesday.html";
59      private static final String TEMPLATE_MODIFY_NOFEESDAY = "/admin/plugins/chatbot/modules/stationnement/modify_nofeesday.html";
60  
61      // Parameters
62      private static final String PARAMETER_ID_NOFEESDAY = "id";
63  
64      // Properties for page titles
65      private static final String PROPERTY_PAGE_TITLE_MANAGE_NOFEESDAYS = "module.chatbot.stationnement.manage_nofeesdays.pageTitle";
66      private static final String PROPERTY_PAGE_TITLE_MODIFY_NOFEESDAY = "module.chatbot.stationnement.modify_nofeesday.pageTitle";
67      private static final String PROPERTY_PAGE_TITLE_CREATE_NOFEESDAY = "module.chatbot.stationnement.create_nofeesday.pageTitle";
68  
69      // Markers
70      private static final String MARK_NOFEESDAY_LIST = "nofeesday_list";
71      private static final String MARK_NOFEESDAY = "nofeesday";
72  
73      private static final String JSP_MANAGE_NOFEESDAYS = "jsp/admin/plugins/chatbot/modules/stationnement/ManageNoFeesDays.jsp";
74  
75      // Properties
76      private static final String MESSAGE_CONFIRM_REMOVE_NOFEESDAY = "module.chatbot.stationnement.message.confirmRemoveNoFeesDay";
77  
78      // Validations
79      private static final String VALIDATION_ATTRIBUTES_PREFIX = "module.chatbot.stationnement.model.entity.nofeesday.attribute.";
80  
81      // Views
82      private static final String VIEW_MANAGE_NOFEESDAYS = "manageNoFeesDays";
83      private static final String VIEW_CREATE_NOFEESDAY = "createNoFeesDay";
84      private static final String VIEW_MODIFY_NOFEESDAY = "modifyNoFeesDay";
85  
86      // Actions
87      private static final String ACTION_CREATE_NOFEESDAY = "createNoFeesDay";
88      private static final String ACTION_MODIFY_NOFEESDAY = "modifyNoFeesDay";
89      private static final String ACTION_REMOVE_NOFEESDAY = "removeNoFeesDay";
90      private static final String ACTION_CONFIRM_REMOVE_NOFEESDAY = "confirmRemoveNoFeesDay";
91  
92      // Infos
93      private static final String INFO_NOFEESDAY_CREATED = "module.chatbot.stationnement.info.nofeesday.created";
94      private static final String INFO_NOFEESDAY_UPDATED = "module.chatbot.stationnement.info.nofeesday.updated";
95      private static final String INFO_NOFEESDAY_REMOVED = "module.chatbot.stationnement.info.nofeesday.removed";
96      
97      // Session variable to store working values
98      private NoFeesDay _nofeesday;
99      
100     /**
101      * Build the Manage View
102      * @param request The HTTP request
103      * @return The page
104      */
105     @View( value = VIEW_MANAGE_NOFEESDAYS, defaultView = true )
106     public String getManageNoFeesDays( HttpServletRequest request )
107     {
108         _nofeesday = null;
109         List<NoFeesDay> listNoFeesDays = NoFeesDayHome.getNoFeesDaysList(  );
110         Map<String, Object> model = getPaginatedListModel( request, MARK_NOFEESDAY_LIST, listNoFeesDays, JSP_MANAGE_NOFEESDAYS );
111 
112         return getPage( PROPERTY_PAGE_TITLE_MANAGE_NOFEESDAYS, TEMPLATE_MANAGE_NOFEESDAYS, model );
113     }
114 
115     /**
116      * Returns the form to create a nofeesday
117      *
118      * @param request The Http request
119      * @return the html code of the nofeesday form
120      */
121     @View( VIEW_CREATE_NOFEESDAY )
122     public String getCreateNoFeesDay( HttpServletRequest request )
123     {
124         _nofeesday = ( _nofeesday != null ) ? _nofeesday : new NoFeesDay(  );
125 
126         Map<String, Object> model = getModel(  );
127         model.put( MARK_NOFEESDAY, _nofeesday );
128 
129         return getPage( PROPERTY_PAGE_TITLE_CREATE_NOFEESDAY, TEMPLATE_CREATE_NOFEESDAY, model );
130     }
131 
132     /**
133      * Process the data capture form of a new nofeesday
134      *
135      * @param request The Http Request
136      * @return The Jsp URL of the process result
137      */
138     @Action( ACTION_CREATE_NOFEESDAY )
139     public String doCreateNoFeesDay( HttpServletRequest request )
140     {
141         populate( _nofeesday, request );
142 
143         // Check constraints
144         if ( !validateBean( _nofeesday, VALIDATION_ATTRIBUTES_PREFIX ) )
145         {
146             return redirectView( request, VIEW_CREATE_NOFEESDAY );
147         }
148 
149         NoFeesDayHome.create( _nofeesday );
150         addInfo( INFO_NOFEESDAY_CREATED, getLocale(  ) );
151 
152         return redirectView( request, VIEW_MANAGE_NOFEESDAYS );
153     }
154 
155     /**
156      * Manages the removal form of a nofeesday whose identifier is in the http
157      * request
158      *
159      * @param request The Http request
160      * @return the html code to confirm
161      */
162     @Action( ACTION_CONFIRM_REMOVE_NOFEESDAY )
163     public String getConfirmRemoveNoFeesDay( HttpServletRequest request )
164     {
165         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_NOFEESDAY ) );
166         UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_NOFEESDAY ) );
167         url.addParameter( PARAMETER_ID_NOFEESDAY, nId );
168 
169         String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_NOFEESDAY, url.getUrl(  ), AdminMessage.TYPE_CONFIRMATION );
170 
171         return redirect( request, strMessageUrl );
172     }
173 
174     /**
175      * Handles the removal form of a nofeesday
176      *
177      * @param request The Http request
178      * @return the jsp URL to display the form to manage nofeesdays
179      */
180     @Action( ACTION_REMOVE_NOFEESDAY )
181     public String doRemoveNoFeesDay( HttpServletRequest request )
182     {
183         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_NOFEESDAY ) );
184         NoFeesDayHome.remove( nId );
185         addInfo( INFO_NOFEESDAY_REMOVED, getLocale(  ) );
186 
187         return redirectView( request, VIEW_MANAGE_NOFEESDAYS );
188     }
189 
190     /**
191      * Returns the form to update info about a nofeesday
192      *
193      * @param request The Http request
194      * @return The HTML form to update info
195      */
196     @View( VIEW_MODIFY_NOFEESDAY )
197     public String getModifyNoFeesDay( HttpServletRequest request )
198     {
199         int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_NOFEESDAY ) );
200 
201         if ( _nofeesday == null || ( _nofeesday.getId(  ) != nId ))
202         {
203             _nofeesday = NoFeesDayHome.findByPrimaryKey( nId );
204         }
205 
206         Map<String, Object> model = getModel(  );
207         model.put( MARK_NOFEESDAY, _nofeesday );
208 
209         return getPage( PROPERTY_PAGE_TITLE_MODIFY_NOFEESDAY, TEMPLATE_MODIFY_NOFEESDAY, model );
210     }
211 
212     /**
213      * Process the change form of a nofeesday
214      *
215      * @param request The Http request
216      * @return The Jsp URL of the process result
217      */
218     @Action( ACTION_MODIFY_NOFEESDAY )
219     public String doModifyNoFeesDay( HttpServletRequest request )
220     {
221         populate( _nofeesday, request );
222 
223         // Check constraints
224         if ( !validateBean( _nofeesday, VALIDATION_ATTRIBUTES_PREFIX ) )
225         {
226             return redirect( request, VIEW_MODIFY_NOFEESDAY, PARAMETER_ID_NOFEESDAY, _nofeesday.getId( ) );
227         }
228 
229         NoFeesDayHome.update( _nofeesday );
230         addInfo( INFO_NOFEESDAY_UPDATED, getLocale(  ) );
231 
232         return redirectView( request, VIEW_MANAGE_NOFEESDAYS );
233     }
234 }