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.htmlpage.web;
35
36 import fr.paris.lutece.plugins.htmlpage.business.HtmlPage;
37 import fr.paris.lutece.plugins.htmlpage.business.HtmlPageHome;
38 import fr.paris.lutece.plugins.htmlpage.service.EnumStatus;
39 import fr.paris.lutece.plugins.htmlpage.utils.HtmlPageUtil;
40 import fr.paris.lutece.portal.business.role.RoleHome;
41 import fr.paris.lutece.portal.service.message.AdminMessage;
42 import fr.paris.lutece.portal.service.message.AdminMessageService;
43 import fr.paris.lutece.portal.service.template.AppTemplateService;
44 import fr.paris.lutece.portal.service.util.AppPathService;
45 import fr.paris.lutece.portal.service.util.AppPropertiesService;
46 import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService;
47 import fr.paris.lutece.portal.web.admin.PluginAdminPageJspBean;
48 import fr.paris.lutece.portal.web.constants.Messages;
49 import fr.paris.lutece.util.ReferenceList;
50 import fr.paris.lutece.util.html.HtmlTemplate;
51 import fr.paris.lutece.util.html.Paginator;
52 import fr.paris.lutece.util.url.UrlItem;
53
54 import java.sql.Timestamp;
55 import java.util.Collection;
56 import java.util.HashMap;
57 import java.util.List;
58 import java.util.Map;
59
60 import javax.servlet.http.HttpServletRequest;
61
62 import org.apache.commons.lang3.StringUtils;
63
64
65
66
67
68 public class HtmlPageJspBean extends PluginAdminPageJspBean
69 {
70
71 public static final String RIGHT_MANAGE_HTMLPAGE = "HTMLPAGE_MANAGEMENT";
72
73
74 private static final String PROPERTY_PAGE_TITLE_HTMLPAGE_LIST = "htmlpage.manage_htmlpage.pageTitle";
75 private static final String PROPERTY_PAGE_TITLE_MODIFY = "htmlpage.modify_htmlpage.pageTitle";
76 private static final String PROPERTY_PAGE_TITLE_CREATE = "htmlpage.create_htmlpage.pageTitle";
77
78
79 private static final String PROPERTY_DEFAULT_HTMLPAGE_LIST_PER_PAGE = "htmlpage.htmlPageList.itemsPerPage";
80
81
82 private static final String MESSAGE_CONFIRM_REMOVE_HTMLPAGE = "htmlpage.message.confirmRemoveHtmlPage";
83 private static final String MESSAGE_INVALID_DATE_START = "htmlpage.message.invalidDateStart";
84 private static final String MESSAGE_INVALID_DATE_END = "htmlpage.message.invalidDateEnd";
85
86
87 private static final String MARK_LIST_HTMLPAGE_LIST = "htmlpage_list";
88 private static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
89 private static final String MARK_WORKGROUPS_LIST = "workgroups_list";
90 private static final String MARK_WEBAPP_URL = "webapp_url";
91 private static final String MARK_PROD_URL = "prod_url";
92
93 private static final String MARK_LOCALE = "locale";
94 private static final String MARK_HTML_CONTENT = "html_content";
95 private static final String MARK_HTMLPAGE = "htmlpage";
96 private static final String MARK_ROLES_LIST = "roles_list";
97 private static final String MARK_PAGINATOR = "paginator";
98 private static final String MARK_STATUS = "status_list";
99
100
101 private static final String PARAMETER_HTMLPAGE_ID = "id_htmlpage";
102 private static final String PARAMETER_HTMLPAGE_DESCRIPTION = "description";
103 private static final String PARAMETER_HTMLPAGE_STATUS = "status";
104 private static final String PARAMETER_HTMLPAGE_WORKGROUP = "workgroup";
105 private static final String PARAMETER_HTMLPAGE_HTML_CONTENT = "html_content";
106 private static final String PARAMETER_ID_HTMLPAGE_LIST = "htmlpage_list_id";
107 private static final String PARAMETER_HTMLPAGE_ROLE = "role";
108 private static final String PARAMETER_PAGE_INDEX = "page_index";
109 private static final String PARAMETER_HTMLPAGE_DATE_START = "date_start";
110 private static final String PARAMETER_HTMLPAGE_DATE_END = "date_end";
111
112
113 private static final String TEMPLATE_MANAGE_HTMLPAGE = "/admin/plugins/htmlpage/manage_htmlpage.html";
114 private static final String TEMPLATE_CREATE_HTMLPAGE = "/admin/plugins/htmlpage/create_htmlpage.html";
115 private static final String TEMPLATE_MODIFY_HTMLPAGE = "/admin/plugins/htmlpage/modify_htmlpage.html";
116
117
118 private static final String JSP_DO_REMOVE_HTMLPAGE = "jsp/admin/plugins/htmlpage/DoRemoveHtmlPage.jsp";
119 private static final String JSP_REDIRECT_TO_MANAGE_HTMLPAGE = "ManageHtmlPage.jsp";
120
121
122 private int _nDefaultItemsPerPage;
123 private String _strCurrentPageIndex;
124 private int _nItemsPerPage;
125
126
127
128
129
130
131
132
133 public String getManageHtmlPage( HttpServletRequest request )
134 {
135 setPageTitleProperty( PROPERTY_PAGE_TITLE_HTMLPAGE_LIST );
136
137 _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
138 _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_DEFAULT_HTMLPAGE_LIST_PER_PAGE, 50 );
139 _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage, _nDefaultItemsPerPage );
140
141 Collection<HtmlPage> listHtmlPageList = HtmlPageHome.findAll( getPlugin( ) );
142 listHtmlPageList = AdminWorkgroupService.getAuthorizedCollection( listHtmlPageList, getUser( ) );
143
144 Paginator paginator = new Paginator( (List<HtmlPage>) listHtmlPageList, _nItemsPerPage, getHomeUrl( request ), PARAMETER_PAGE_INDEX,
145 _strCurrentPageIndex );
146
147 Map<String, Object> model = new HashMap<String, Object>( );
148 model.put( MARK_NB_ITEMS_PER_PAGE, "" + _nItemsPerPage );
149 model.put( MARK_PAGINATOR, paginator );
150 model.put( MARK_LIST_HTMLPAGE_LIST, paginator.getPageItems( ) );
151
152 HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_MANAGE_HTMLPAGE, getLocale( ), model );
153
154 return getAdminPage( templateList.getHtml( ) );
155 }
156
157
158
159
160
161
162
163
164 public String getCreateHtmlPage( HttpServletRequest request )
165 {
166 setPageTitleProperty( PROPERTY_PAGE_TITLE_CREATE );
167
168 Map<String, Object> model = new HashMap<String, Object>( );
169 ReferenceList workgroupsList = AdminWorkgroupService.getUserWorkgroups( getUser( ), getLocale( ) );
170 model.put( MARK_WORKGROUPS_LIST, workgroupsList );
171 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
172 model.put( MARK_PROD_URL, AppPathService.getProdUrl(request) );
173 model.put( MARK_LOCALE, getLocale( ) );
174 model.put( MARK_HTML_CONTENT, "" );
175 model.put( MARK_ROLES_LIST, RoleHome.getRolesList( ) );
176 model.put( MARK_STATUS, EnumStatus.getReferenceList( ) );
177
178 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_HTMLPAGE, getLocale( ), model );
179
180 return getAdminPage( template.getHtml( ) );
181 }
182
183
184
185
186
187
188
189
190 public String doCreateHtmlPage( HttpServletRequest request )
191 {
192 String strDescription = request.getParameter( PARAMETER_HTMLPAGE_DESCRIPTION );
193 String strHtmlContent = request.getParameter( PARAMETER_HTMLPAGE_HTML_CONTENT );
194 String strStatus = request.getParameter( PARAMETER_HTMLPAGE_STATUS );
195 String strWorkgroup = request.getParameter( PARAMETER_HTMLPAGE_WORKGROUP );
196 String strRole = request.getParameter( PARAMETER_HTMLPAGE_ROLE );
197
198
199 if ( ( strDescription == null ) || strDescription.trim( ).equals( "" ) )
200 {
201 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
202 }
203
204 HtmlPagemlpage/business/HtmlPage.html#HtmlPage">HtmlPage htmlpage = new HtmlPage( );
205
206 htmlpage.setDescription( strDescription );
207 htmlpage.setHtmlContent( strHtmlContent );
208 htmlpage.setStatus( Integer.parseInt( strStatus ) );
209 htmlpage.setWorkgroup( strWorkgroup );
210 htmlpage.setRole( strRole );
211
212 String strDateStart = request.getParameter( PARAMETER_HTMLPAGE_DATE_START );
213 String strDateEnd = request.getParameter( PARAMETER_HTMLPAGE_DATE_END );
214
215 Timestamp dateStart = HtmlPageUtil.convertToTimestamp( strDateStart );
216 Timestamp dateEnd = HtmlPageUtil.convertToTimestamp( strDateEnd );
217
218 if ( StringUtils.isNotEmpty( strDateStart ) && dateStart == null )
219 {
220 return AdminMessageService.getMessageUrl( request, MESSAGE_INVALID_DATE_START, AdminMessage.TYPE_STOP );
221 }
222
223 if ( StringUtils.isNotEmpty( strDateEnd ) && dateEnd == null )
224 {
225 return AdminMessageService.getMessageUrl( request, MESSAGE_INVALID_DATE_END, AdminMessage.TYPE_STOP );
226 }
227
228
229 htmlpage.setDateStart( dateStart );
230 htmlpage.setDateEnd( dateEnd );
231
232 HtmlPageHome.create( htmlpage, getPlugin( ) );
233
234
235 return JSP_REDIRECT_TO_MANAGE_HTMLPAGE;
236 }
237
238
239
240
241
242
243
244
245 public String doDuplicateHtmlPage( HttpServletRequest request )
246 {
247 int nId = Integer.parseInt( request.getParameter( PARAMETER_HTMLPAGE_ID ) );
248
249 HtmlPage htmlpage = HtmlPageHome.findByPrimaryKey( nId, getPlugin( ) );
250
251 HtmlPagesiness/HtmlPage.html#HtmlPage">HtmlPage duplicateHtmlPage = new HtmlPage( );
252 duplicateHtmlPage.setDescription( htmlpage.getDescription( ) );
253 duplicateHtmlPage.setHtmlContent( htmlpage.getHtmlContent( ) );
254 duplicateHtmlPage.setStatus( htmlpage.getStatus( ) );
255 duplicateHtmlPage.setWorkgroup( htmlpage.getWorkgroup( ) );
256 duplicateHtmlPage.setRole( htmlpage.getRole( ) );
257
258 HtmlPageHome.create( duplicateHtmlPage, getPlugin( ) );
259
260
261 return JSP_REDIRECT_TO_MANAGE_HTMLPAGE;
262 }
263
264
265
266
267
268
269
270
271 public String getModifyHtmlPage( HttpServletRequest request )
272 {
273 setPageTitleProperty( PROPERTY_PAGE_TITLE_MODIFY );
274
275 int nId = Integer.parseInt( request.getParameter( PARAMETER_HTMLPAGE_ID ) );
276 HtmlPage htmlPage = HtmlPageHome.findByPrimaryKey( nId, getPlugin( ) );
277
278 Map<String, Object> model = new HashMap<String, Object>( );
279 ReferenceList workgroupsList = AdminWorkgroupService.getUserWorkgroups( getUser( ), getLocale( ) );
280 model.put( MARK_WORKGROUPS_LIST, workgroupsList );
281 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
282 model.put( MARK_PROD_URL, AppPathService.getProdUrl(request) );
283 model.put( MARK_LOCALE, getLocale( ) );
284 model.put( MARK_HTMLPAGE, htmlPage );
285 model.put( MARK_ROLES_LIST, RoleHome.getRolesList( ) );
286 model.put( MARK_STATUS, EnumStatus.getReferenceList( ) );
287
288 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_HTMLPAGE, getLocale( ), model );
289
290 return getAdminPage( template.getHtml( ) );
291 }
292
293
294
295
296
297
298
299
300 public String doModifyHtmlPage( HttpServletRequest request )
301 {
302
303 if ( request.getParameter( PARAMETER_HTMLPAGE_DESCRIPTION ).equals( "" ) || request.getParameter( PARAMETER_HTMLPAGE_HTML_CONTENT ).equals( "" ) )
304 {
305 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
306 }
307
308 int nId = Integer.parseInt( request.getParameter( PARAMETER_HTMLPAGE_ID ) );
309
310 HtmlPage htmlPage = HtmlPageHome.findByPrimaryKey( nId, getPlugin( ) );
311 htmlPage.setDescription( request.getParameter( PARAMETER_HTMLPAGE_DESCRIPTION ) );
312 htmlPage.setHtmlContent( request.getParameter( PARAMETER_HTMLPAGE_HTML_CONTENT ) );
313 htmlPage.setStatus( Integer.parseInt( request.getParameter( PARAMETER_HTMLPAGE_STATUS ) ) );
314 htmlPage.setWorkgroup( request.getParameter( PARAMETER_HTMLPAGE_WORKGROUP ) );
315 htmlPage.setRole( request.getParameter( PARAMETER_HTMLPAGE_ROLE ) );
316
317 String strDateStart = request.getParameter( PARAMETER_HTMLPAGE_DATE_START );
318 String strDateEnd = request.getParameter( PARAMETER_HTMLPAGE_DATE_END );
319
320 Timestamp dateStart = HtmlPageUtil.convertToTimestamp( strDateStart );
321 Timestamp dateEnd = HtmlPageUtil.convertToTimestamp( strDateEnd );
322
323 if ( StringUtils.isNotEmpty( strDateStart ) && dateStart == null )
324 {
325 return AdminMessageService.getMessageUrl( request, MESSAGE_INVALID_DATE_START, AdminMessage.TYPE_STOP );
326 }
327
328 if ( StringUtils.isNotEmpty( strDateEnd ) && dateEnd == null )
329 {
330 return AdminMessageService.getMessageUrl( request, MESSAGE_INVALID_DATE_END, AdminMessage.TYPE_STOP );
331 }
332
333 htmlPage.setDateStart( dateStart );
334 htmlPage.setDateEnd( dateEnd );
335
336 HtmlPageHome.update( htmlPage, getPlugin( ) );
337
338
339 return JSP_REDIRECT_TO_MANAGE_HTMLPAGE;
340 }
341
342
343
344
345
346
347
348
349 public String getConfirmRemoveHtmlPage( HttpServletRequest request )
350 {
351 int nIdHtmlPage = Integer.parseInt( request.getParameter( PARAMETER_HTMLPAGE_ID ) );
352
353 UrlItem url = new UrlItem( JSP_DO_REMOVE_HTMLPAGE );
354 url.addParameter( PARAMETER_HTMLPAGE_ID, nIdHtmlPage );
355 url.addParameter( PARAMETER_ID_HTMLPAGE_LIST, request.getParameter( PARAMETER_ID_HTMLPAGE_LIST ) );
356
357 Object [ ] args = {
358 request.getParameter( PARAMETER_HTMLPAGE_DESCRIPTION )
359 };
360
361 return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_HTMLPAGE, args, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
362 }
363
364
365
366
367
368
369
370
371 public String doRemoveHtmlPage( HttpServletRequest request )
372 {
373 int nIdHtmlPage = Integer.parseInt( request.getParameter( PARAMETER_HTMLPAGE_ID ) );
374
375 HtmlPage htmlPage = HtmlPageHome.findByPrimaryKey( nIdHtmlPage, getPlugin( ) );
376 HtmlPageHome.remove( htmlPage, getPlugin( ) );
377
378
379 return JSP_REDIRECT_TO_MANAGE_HTMLPAGE;
380 }
381 }