1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.pluginwizard.web;
35
36 import fr.paris.lutece.plugins.pluginwizard.business.ConfigurationKey;
37 import fr.paris.lutece.plugins.pluginwizard.business.ConfigurationKeyHome;
38 import fr.paris.lutece.portal.service.message.AdminMessage;
39 import fr.paris.lutece.portal.service.message.AdminMessageService;
40 import fr.paris.lutece.portal.service.template.AppTemplateService;
41 import fr.paris.lutece.portal.service.util.AppPropertiesService;
42 import fr.paris.lutece.portal.web.admin.PluginAdminPageJspBean;
43 import fr.paris.lutece.portal.web.constants.Messages;
44 import fr.paris.lutece.portal.web.util.LocalizedPaginator;
45 import fr.paris.lutece.util.html.HtmlTemplate;
46 import fr.paris.lutece.util.html.Paginator;
47 import fr.paris.lutece.util.url.UrlItem;
48
49 import java.util.Collection;
50 import java.util.HashMap;
51 import java.util.List;
52 import java.util.Map;
53
54 import javax.servlet.http.HttpServletRequest;
55
56
57
58
59 public class PluginwizardJspBean extends PluginAdminPageJspBean
60 {
61
62
63
64
65
66
67 private static final long serialVersionUID = -4166510254090826796L;
68
69
70
71
72
73 public static final String RIGHT_MANAGE_PLUGINWIZARD = "PLUGINWIZARD_MANAGEMENT";
74
75
76 private static final String PARAMETER_PAGE_INDEX = "page_index";
77 private static final String PARAMETER_ID_KEY = "configurationkey_id_key";
78 private static final String PARAMETER_KEY_DESCRIPTION = "configurationkey_key_description";
79 private static final String PARAMETER_KEY_VALUE = "configurationkey_key_value";
80
81
82 private static final String TEMPLATE_MANAGE_CONFIGURATIONKEYS = "/admin/plugins/pluginwizard/manage_configurationkey.html";
83 private static final String TEMPLATE_CREATE_CONFIGURATIONKEY = "/admin/plugins/pluginwizard/create_configurationkey.html";
84 private static final String TEMPLATE_MODIFY_CONFIGURATIONKEY = "/admin/plugins/pluginwizard/modify_configurationkey.html";
85
86
87 private static final String PROPERTY_PAGE_TITLE_MANAGE_CONFIGURATIONKEYS = "pluginwizard.manage_configurationkeys.pageTitle";
88 private static final String PROPERTY_PAGE_TITLE_MODIFY_CONFIGURATIONKEY = "pluginwizard.modify_configurationkey.pageTitle";
89 private static final String PROPERTY_PAGE_TITLE_CREATE_CONFIGURATIONKEY = "pluginwizard.create_configurationkey.pageTitle";
90
91
92 private static final String MARK_CONFIGURATIONKEY_LIST = "configurationkey_list";
93 private static final String MARK_CONFIGURATIONKEY = "configurationkey";
94 private static final String MARK_PAGINATOR = "paginator";
95 private static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
96
97
98 private static final String JSP_DO_REMOVE_CONFIGURATIONKEY = "jsp/admin/plugins/pluginwizard/DoRemoveConfigurationKey.jsp";
99 private static final String JSP_MANAGE_CONFIGURATIONKEYS = "jsp/admin/plugins/pluginwizard/ManageConfigurationKeys.jsp";
100 private static final String JSP_REDIRECT_TO_MANAGE_CONFIGURATIONKEYS = "ManageConfigurationKeys.jsp";
101
102
103 private static final String PROPERTY_DEFAULT_LIST_CONFIGURATIONKEY_PER_PAGE = "pluginwizard.listConfigurationKeys.itemsPerPage";
104
105
106 private static final String MESSAGE_CONFIRM_REMOVE_CONFIGURATIONKEY = "pluginwizard.message.confirmRemoveConfigurationKey";
107
108
109 private int _nDefaultItemsPerPage;
110 private String _strCurrentPageIndex;
111 private int _nItemsPerPage;
112
113
114
115
116
117
118
119
120 public String getManageConfigurationKeys( HttpServletRequest request )
121 {
122 setPageTitleProperty( PROPERTY_PAGE_TITLE_MANAGE_CONFIGURATIONKEYS );
123
124 _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
125 _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_DEFAULT_LIST_CONFIGURATIONKEY_PER_PAGE, 5 );
126 _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage, _nDefaultItemsPerPage );
127
128 UrlItem url = new UrlItem( JSP_MANAGE_CONFIGURATIONKEYS );
129 String strUrl = url.getUrl( );
130 Collection<ConfigurationKey> listCONFIGURATIONKEYs = ConfigurationKeyHome.getConfigurationKeysList( );
131 LocalizedPaginator paginator = new LocalizedPaginator( (List<ConfigurationKey>) listCONFIGURATIONKEYs, _nItemsPerPage, strUrl, PARAMETER_PAGE_INDEX,
132 _strCurrentPageIndex, getLocale( ) );
133
134 Map<String, Object> model = new HashMap<String, Object>( );
135
136 model.put( MARK_NB_ITEMS_PER_PAGE, "" + _nItemsPerPage );
137 model.put( MARK_PAGINATOR, paginator );
138 model.put( MARK_CONFIGURATIONKEY_LIST, paginator.getPageItems( ) );
139
140 HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_MANAGE_CONFIGURATIONKEYS, getLocale( ), model );
141
142 return getAdminPage( templateList.getHtml( ) );
143 }
144
145
146
147
148
149
150
151
152 public String getCreateConfigurationKey( HttpServletRequest request )
153 {
154 setPageTitleProperty( PROPERTY_PAGE_TITLE_CREATE_CONFIGURATIONKEY );
155
156 Map<String, Object> model = new HashMap<String, Object>( );
157
158 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_CONFIGURATIONKEY, getLocale( ), model );
159
160 return getAdminPage( template.getHtml( ) );
161 }
162
163
164
165
166
167
168
169
170 public String doCreateConfigurationKey( HttpServletRequest request )
171 {
172 ConfigurationKeyess/ConfigurationKey.html#ConfigurationKey">ConfigurationKey configurationkey = new ConfigurationKey( );
173 String strKeyDescription = request.getParameter( PARAMETER_KEY_DESCRIPTION );
174 String strKeyValue = request.getParameter( PARAMETER_KEY_VALUE );
175
176 if ( strKeyDescription.equals( "" ) )
177 {
178 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
179 }
180
181 if ( strKeyValue.equals( "" ) )
182 {
183 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
184 }
185
186 configurationkey.setKeyDescription( strKeyDescription );
187 configurationkey.setKeyValue( strKeyValue );
188
189 ConfigurationKeyHome.create( configurationkey );
190
191 return JSP_REDIRECT_TO_MANAGE_CONFIGURATIONKEYS;
192 }
193
194
195
196
197
198
199
200
201 public String getConfirmRemoveConfigurationKey( HttpServletRequest request )
202 {
203 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_KEY ) );
204 UrlItem url = new UrlItem( JSP_DO_REMOVE_CONFIGURATIONKEY );
205 url.addParameter( PARAMETER_ID_KEY, nId );
206
207 return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_CONFIGURATIONKEY, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
208 }
209
210
211
212
213
214
215
216
217 public String doRemoveConfigurationKey( HttpServletRequest request )
218 {
219 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_KEY ) );
220 ConfigurationKeyHome.remove( nId );
221
222 return JSP_REDIRECT_TO_MANAGE_CONFIGURATIONKEYS;
223 }
224
225
226
227
228
229
230
231
232 public String getModifyConfigurationKey( HttpServletRequest request )
233 {
234 setPageTitleProperty( PROPERTY_PAGE_TITLE_MODIFY_CONFIGURATIONKEY );
235
236 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_KEY ) );
237 ConfigurationKey configurationkey = ConfigurationKeyHome.findByPrimaryKey( nId );
238
239 Map<String, Object> model = new HashMap<String, Object>( );
240 model.put( MARK_CONFIGURATIONKEY, configurationkey );
241
242 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_CONFIGURATIONKEY, getLocale( ), model );
243
244 return getAdminPage( template.getHtml( ) );
245 }
246
247
248
249
250
251
252
253
254 public String doModifyConfigurationKey( HttpServletRequest request )
255 {
256 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_KEY ) );
257 String strKeyDescription = request.getParameter( PARAMETER_KEY_DESCRIPTION );
258 String strValue = request.getParameter( PARAMETER_KEY_VALUE );
259 ConfigurationKey configurationkey = ConfigurationKeyHome.findByPrimaryKey( nId );
260
261 if ( ( nId == 0 ) || ( strValue == null ) || ( strKeyDescription == null ) || strValue.equals( "" ) || strKeyDescription.equals( "" ) )
262 {
263 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
264 }
265
266 configurationkey.setIdKey( nId );
267 configurationkey.setKeyDescription( strKeyDescription );
268 configurationkey.setKeyValue( strValue );
269 ConfigurationKeyHome.update( configurationkey );
270
271 return JSP_REDIRECT_TO_MANAGE_CONFIGURATIONKEYS;
272 }
273 }