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.wrapper.web;
35
36 import fr.paris.lutece.plugins.wrapper.business.Wrapper;
37 import fr.paris.lutece.plugins.wrapper.business.WrapperHome;
38 import fr.paris.lutece.portal.business.role.RoleHome;
39 import fr.paris.lutece.portal.service.message.AdminMessage;
40 import fr.paris.lutece.portal.service.message.AdminMessageService;
41 import fr.paris.lutece.portal.service.template.AppTemplateService;
42 import fr.paris.lutece.portal.service.util.AppPropertiesService;
43 import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService;
44 import fr.paris.lutece.portal.web.admin.PluginAdminPageJspBean;
45 import fr.paris.lutece.portal.web.constants.Messages;
46 import fr.paris.lutece.util.ReferenceList;
47 import fr.paris.lutece.util.html.HtmlTemplate;
48 import fr.paris.lutece.util.html.Paginator;
49 import fr.paris.lutece.util.url.UrlItem;
50
51 import java.util.Collection;
52 import java.util.HashMap;
53 import java.util.List;
54 import java.util.Map;
55
56 import javax.servlet.http.HttpServletRequest;
57
58
59
60
61
62
63 public class WrapperJspBean extends PluginAdminPageJspBean
64 {
65
66 public static final String RIGHT_MANAGE_WRAPPER = "WRAPPER_MANAGEMENT";
67
68
69 private static final String PROPERTY_PAGE_TITLE_WRAPPER_LIST = "wrapper.manage_wrapper.pageTitle";
70 private static final String PROPERTY_PAGE_TITLE_MODIFY = "wrapper.modify_wrapper.pageTitle";
71 private static final String PROPERTY_PAGE_TITLE_CREATE = "wrapper.create_wrapper.pageTitle";
72
73
74 private static final String PROPERTY_DEFAULT_WRAPPER_LIST_PER_PAGE = "wrapper.wrapperList.itemsPerPage";
75
76
77 private static final String MESSAGE_CONFIRM_REMOVE_WRAPPER = "wrapper.message.confirmRemoveWrapper";
78
79
80 private static final String MARK_LIST_WRAPPER_LIST = "wrapper_list";
81 private static final String MARK_NB_ITEMS_PER_PAGE = "nb_items_per_page";
82 private static final String MARK_WORKGROUPS_LIST = "workgroups_list";
83 private static final String MARK_LOCALE = "locale";
84 private static final String MARK_WRAPPER = "wrapper";
85 private static final String MARK_ROLES_LIST = "roles_list";
86 private static final String MARK_PAGINATOR = "paginator";
87
88
89 private static final String PARAMETER_WRAPPER_ID = "id_wrapper";
90 private static final String PARAMETER_WRAPPER_DESCRIPTION = "description";
91 private static final String PARAMETER_WRAPPER_STATUS = "status";
92 private static final String PARAMETER_WRAPPER_WORKGROUP = "workgroup";
93 private static final String PARAMETER_WRAPPER_URL = "wrapper_url";
94 private static final String PARAMETER_WRAPPER_STYLES = "wrapper_styles";
95 private static final String PARAMETER_ID_WRAPPER_LIST = "wrapper_list_id";
96 private static final String PARAMETER_WRAPPER_ROLE = "role";
97 private static final String PARAMETER_PAGE_INDEX = "page_index";
98
99
100 private static final String TEMPLATE_MANAGE_WRAPPER = "/admin/plugins/wrapper/manage_wrapper.html";
101 private static final String TEMPLATE_CREATE_WRAPPER = "/admin/plugins/wrapper/create_wrapper.html";
102 private static final String TEMPLATE_MODIFY_WRAPPER = "/admin/plugins/wrapper/modify_wrapper.html";
103
104
105 private static final String JSP_DO_REMOVE_WRAPPER = "jsp/admin/plugins/wrapper/DoRemoveWrapper.jsp";
106 private static final String JSP_REDIRECT_TO_MANAGE_WRAPPER = "ManageWrapper.jsp";
107
108
109 private int _nDefaultItemsPerPage;
110 private String _strCurrentPageIndex;
111 private int _nItemsPerPage;
112
113
114
115
116
117
118 public String getManageWrapper( HttpServletRequest request )
119 {
120 setPageTitleProperty( PROPERTY_PAGE_TITLE_WRAPPER_LIST );
121
122 _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
123 _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( PROPERTY_DEFAULT_WRAPPER_LIST_PER_PAGE, 50 );
124 _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage,
125 _nDefaultItemsPerPage );
126
127 Collection<Wrapper> listWrapperList = WrapperHome.findAll( getPlugin( ) );
128 listWrapperList = AdminWorkgroupService.getAuthorizedCollection( listWrapperList, getUser( ) );
129
130 Paginator paginator = new Paginator( (List<Wrapper>) listWrapperList, _nItemsPerPage, getHomeUrl( request ),
131 PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
132
133 Map<String, Object> model = new HashMap<String, Object>( );
134 model.put( MARK_NB_ITEMS_PER_PAGE, "" + _nItemsPerPage );
135 model.put( MARK_PAGINATOR, paginator );
136 model.put( MARK_LIST_WRAPPER_LIST, paginator.getPageItems( ) );
137
138 HtmlTemplate templateList = AppTemplateService.getTemplate( TEMPLATE_MANAGE_WRAPPER, getLocale( ), model );
139
140 return getAdminPage( templateList.getHtml( ) );
141 }
142
143
144
145
146
147
148
149 public String getCreateWrapper( HttpServletRequest request )
150 {
151 setPageTitleProperty( PROPERTY_PAGE_TITLE_CREATE );
152
153 Map<String, Object> model = new HashMap<String, Object>( );
154 ReferenceList workgroupsList = AdminWorkgroupService.getUserWorkgroups( getUser( ), getLocale( ) );
155 model.put( MARK_WORKGROUPS_LIST, workgroupsList );
156 model.put( MARK_LOCALE, getLocale( ) );
157 model.put( MARK_ROLES_LIST, RoleHome.getRolesList( ) );
158
159 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_WRAPPER, getLocale( ), model );
160
161 return getAdminPage( template.getHtml( ) );
162 }
163
164
165
166
167
168
169
170 public String doCreateWrapper( HttpServletRequest request )
171 {
172 String strDescription = request.getParameter( PARAMETER_WRAPPER_DESCRIPTION );
173 String strWrapperUrl = request.getParameter( PARAMETER_WRAPPER_URL );
174 String strWrapperStyles = request.getParameter( PARAMETER_WRAPPER_STYLES );
175 String strStatus = request.getParameter( PARAMETER_WRAPPER_STATUS );
176 String strWorkgroup = request.getParameter( PARAMETER_WRAPPER_WORKGROUP );
177 String strRole = request.getParameter( PARAMETER_WRAPPER_ROLE );
178
179
180 if ( ( strDescription == null ) || strDescription.trim( ).equals( "" ) )
181 {
182 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
183 }
184
185 Wrapper wrapper = new Wrapper( );
186
187 wrapper.setDescription( strDescription );
188 wrapper.setWrapperUrl( strWrapperUrl );
189 wrapper.setWrapperStyles( strWrapperStyles );
190 wrapper.setStatus( Integer.parseInt( strStatus ) );
191 wrapper.setWorkgroup( strWorkgroup );
192 wrapper.setRole( strRole );
193
194 WrapperHome.create( wrapper, getPlugin( ) );
195
196
197 return JSP_REDIRECT_TO_MANAGE_WRAPPER;
198 }
199
200
201
202
203
204
205
206 public String doDuplicateWrapper( HttpServletRequest request )
207 {
208 int nId = Integer.parseInt( request.getParameter( PARAMETER_WRAPPER_ID ) );
209
210 Wrapper wrapper = WrapperHome.findByPrimaryKey( nId, getPlugin( ) );
211
212 Wrapper duplicateWrapper = new Wrapper( );
213 duplicateWrapper.setDescription( wrapper.getDescription( ) );
214 duplicateWrapper.setWrapperUrl( wrapper.getWrapperUrl( ) );
215 duplicateWrapper.setWrapperStyles( wrapper.getWrapperStyles( ) );
216 duplicateWrapper.setStatus( wrapper.getStatus( ) );
217 duplicateWrapper.setWorkgroup( wrapper.getWorkgroup( ) );
218 duplicateWrapper.setRole( wrapper.getRole( ) );
219
220 WrapperHome.create( duplicateWrapper, getPlugin( ) );
221
222
223 return JSP_REDIRECT_TO_MANAGE_WRAPPER;
224 }
225
226
227
228
229
230
231
232 public String getModifyWrapper( HttpServletRequest request )
233 {
234 setPageTitleProperty( PROPERTY_PAGE_TITLE_MODIFY );
235
236 int nId = Integer.parseInt( request.getParameter( PARAMETER_WRAPPER_ID ) );
237 Wrapper wrapper = WrapperHome.findByPrimaryKey( nId, getPlugin( ) );
238
239 Map<String, Object> model = new HashMap<String, Object>( );
240 ReferenceList workgroupsList = AdminWorkgroupService.getUserWorkgroups( getUser( ), getLocale( ) );
241 model.put( MARK_WORKGROUPS_LIST, workgroupsList );
242 model.put( MARK_LOCALE, getLocale( ) );
243 model.put( MARK_WRAPPER, wrapper );
244 model.put( MARK_ROLES_LIST, RoleHome.getRolesList( ) );
245
246 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_WRAPPER, getLocale( ), model );
247
248 return getAdminPage( template.getHtml( ) );
249 }
250
251
252
253
254
255
256
257 public String doModifyWrapper( HttpServletRequest request )
258 {
259
260 if ( request.getParameter( PARAMETER_WRAPPER_DESCRIPTION ).equals( "" ) ||
261 request.getParameter( PARAMETER_WRAPPER_URL ).equals( "" ) )
262 {
263 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
264 }
265
266 int nId = Integer.parseInt( request.getParameter( PARAMETER_WRAPPER_ID ) );
267
268 Wrapper wrapper = WrapperHome.findByPrimaryKey( nId, getPlugin( ) );
269 wrapper.setDescription( request.getParameter( PARAMETER_WRAPPER_DESCRIPTION ) );
270 wrapper.setWrapperUrl( request.getParameter( PARAMETER_WRAPPER_URL ) );
271 wrapper.setWrapperStyles( request.getParameter( PARAMETER_WRAPPER_STYLES ) );
272 wrapper.setStatus( Integer.parseInt( request.getParameter( PARAMETER_WRAPPER_STATUS ) ) );
273 wrapper.setWorkgroup( request.getParameter( PARAMETER_WRAPPER_WORKGROUP ) );
274 wrapper.setRole( request.getParameter( PARAMETER_WRAPPER_ROLE ) );
275
276 WrapperHome.update( wrapper, getPlugin( ) );
277
278
279 return JSP_REDIRECT_TO_MANAGE_WRAPPER;
280 }
281
282
283
284
285
286
287
288 public String getConfirmRemoveWrapper( HttpServletRequest request )
289 {
290 int nIdWrapper = Integer.parseInt( request.getParameter( PARAMETER_WRAPPER_ID ) );
291
292 UrlItem url = new UrlItem( JSP_DO_REMOVE_WRAPPER );
293 url.addParameter( PARAMETER_WRAPPER_ID, nIdWrapper );
294 url.addParameter( PARAMETER_ID_WRAPPER_LIST, request.getParameter( PARAMETER_ID_WRAPPER_LIST ) );
295
296 Object[] args = { request.getParameter( PARAMETER_WRAPPER_DESCRIPTION ) };
297
298 return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_WRAPPER, args, url.getUrl( ),
299 AdminMessage.TYPE_CONFIRMATION );
300 }
301
302
303
304
305
306
307
308 public String doRemoveWrapper( HttpServletRequest request )
309 {
310 int nIdWrapper = Integer.parseInt( request.getParameter( PARAMETER_WRAPPER_ID ) );
311
312 Wrapper wrapper = WrapperHome.findByPrimaryKey( nIdWrapper, getPlugin( ) );
313 WrapperHome.remove( wrapper, getPlugin( ) );
314
315
316 return JSP_REDIRECT_TO_MANAGE_WRAPPER;
317 }
318 }