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.managewferror.web;
35
36
37 import fr.paris.lutece.plugins.managewferror.business.Config;
38 import fr.paris.lutece.plugins.managewferror.business.ConfigHome;
39 import fr.paris.lutece.plugins.managewferror.business.MappingAction;
40 import fr.paris.lutece.plugins.managewferror.business.service.ConfigService;
41 import fr.paris.lutece.plugins.workflowcore.business.action.ActionFilter;
42 import fr.paris.lutece.plugins.workflowcore.service.action.ActionService;
43 import fr.paris.lutece.plugins.workflowcore.service.action.IActionService;
44 import fr.paris.lutece.portal.business.rbac.RBAC;
45 import fr.paris.lutece.portal.service.admin.AccessDeniedException;
46 import fr.paris.lutece.portal.service.admin.AdminUserService;
47 import fr.paris.lutece.portal.service.message.AdminMessage;
48 import fr.paris.lutece.portal.service.message.AdminMessageService;
49 import fr.paris.lutece.portal.service.rbac.RBACService;
50 import fr.paris.lutece.portal.service.spring.SpringContextService;
51 import fr.paris.lutece.portal.service.workflow.WorkflowService;
52 import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
53 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
54 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
55 import fr.paris.lutece.util.url.UrlItem;
56
57 import java.util.ArrayList;
58 import java.util.Collection;
59 import java.util.List;
60 import java.util.Locale;
61 import java.util.Map;
62
63 import javax.servlet.http.HttpServletRequest;
64
65 import org.apache.commons.lang.StringUtils;
66
67
68
69
70 @Controller( controllerJsp = "ManageConfigs.jsp", controllerPath = "jsp/admin/plugins/managewferror/", right = "WFERROR_MANAGEMENT" )
71 public class ConfigJspBean extends ConfigurationJspBean
72 {
73
74
75
76 private static final long serialVersionUID = 3371104954947583628L;
77
78 private static final String TEMPLATE_MANAGE_CONFIGS = "/admin/plugins/managewferror/manage_configs.html";
79 private static final String TEMPLATE_CREATE_CONFIG = "/admin/plugins/managewferror/create_config.html";
80 private static final String TEMPLATE_MODIFY_CONFIG = "/admin/plugins/managewferror/modify_config.html";
81
82
83 private static final String PARAMETER_ID_CONFIG = "id";
84 private static final String PARAMETER_ID_WORKFLOW = "idWorkflow";
85 private static final String PARAMETER_ID_WORKFLOW_BEGIN = "idWorkflowBegin";
86 private static final String PARAMETER_REMOVED_ACTION = "removedAction";
87
88 private static final String PROPERTY_PAGE_TITLE_MANAGE_CONFIGS = "managewferror.manage_configs.pageTitle";
89 private static final String PROPERTY_PAGE_TITLE_MODIFY_CONFIG = "managewferror.modify_config.pageTitle";
90 private static final String PROPERTY_PAGE_TITLE_CREATE_CONFIG = "managewferror.create_config.pageTitle";
91
92
93 private static final String MARK_CONFIG_LIST = "config_list";
94 private static final String MARK_CONFIG = "config";
95
96 private static final String JSP_MANAGE_CONFIGS = "jsp/admin/plugins/managewferror/ManageConfigs.jsp";
97
98
99 private static final String MESSAGE_CONFIRM_REMOVE_CONFIG = "managewferror.message.confirmRemoveConfig";
100
101
102 private static final String VALIDATION_ATTRIBUTES_PREFIX = "managewferror.model.entity.config.attribute.";
103
104
105 private static final String VIEW_MANAGE_CONFIGS = "manageConfigs";
106 private static final String VIEW_CREATE_CONFIG = "createConfig";
107 private static final String VIEW_MODIFY_CONFIG = "modifyConfig";
108
109
110 private static final String ACTION_CREATE_CONFIG = "createConfig";
111 private static final String ACTION_MODIFY_CONFIG = "modifyConfig";
112 private static final String ACTION_REMOVE_CONFIG = "removeConfig";
113 private static final String ACTION_CONFIRM_REMOVE_CONFIG = "confirmRemoveConfig";
114 private static final String ACTION_REMOVE_CONFIG_MAPPING = "removeMaping";
115 private static final String ACTION_ADD__MAPPING = "addMaping";
116 private static final String ACTION_SELECT_WF = "selectWorkflow";
117
118 private static final String INFO_CONFIG_CREATED = "managewferror.info.config.created";
119 private static final String INFO_CONFIG_UPDATED = "managewferror.info.config.updated";
120 private static final String INFO_CONFIG_REMOVED = "managewferror.info.config.removed";
121
122 private static final String MARK_RESOURCEFORM_LIST = "resourceform_list";
123 private static final String MARK_RESOURCEFORM_CONFIG_LIST = "resourceform_configlist";
124 private static final String MARK_LIST_WORKFLOWS = "listWorkflows";
125 private static final String MARK_ACTION_LIST_BEGIN = "listActionsBegin";
126 private static final String MARK_ACTION_LIST_RELAUNCH = "listActionsRelaunch";
127 private static final String MARK_ID_WORKFLOW = "idWorkflow";
128 private static final String MARK_ID_WORKFLOW_BEGIN = "idWorkflowBegin";
129 private static final String MARK_REMOVED_LIST_ACTION_BEGIN = "removedListActionsBegin";
130 private static final String MARK_REMOVED_LIST_ACTION_RELAUNCH = "removedListActionsRelaunch";
131
132
133 private Config _config;
134 private MappingAction _mapping;
135 private IActionService _actionService = SpringContextService.getBean( ActionService.BEAN_SERVICE );
136
137
138
139
140
141
142
143
144
145 @View( value = VIEW_MANAGE_CONFIGS, defaultView = true )
146 public String getManageConfigs( HttpServletRequest request ) throws AccessDeniedException
147 {
148 _config = null;
149 if ( !RBACService.isAuthorized( Config.CONFIG_RESOURCE, RBAC.WILDCARD_RESOURCES_ID, Config.PERMISSION_MANAGE, getUser( ) ) )
150 {
151 throw new AccessDeniedException( );
152
153 }
154 List<Config> listConfigs = ConfigHome.getConfigsList( );
155 listConfigs = (List<Config>) RBACService.getAuthorizedCollection( listConfigs, Config.PERMISSION_MANAGE, getUser( ) );
156
157 Map<String, Object> model = getPaginatedListModel( request, MARK_CONFIG_LIST, listConfigs, JSP_MANAGE_CONFIGS );
158
159 return getPage( PROPERTY_PAGE_TITLE_MANAGE_CONFIGS, TEMPLATE_MANAGE_CONFIGS, model );
160 }
161
162
163
164
165
166
167
168
169
170 @View( VIEW_CREATE_CONFIG )
171 public String getCreateConfig( HttpServletRequest request ) throws AccessDeniedException
172 {
173 if ( !RBACService.isAuthorized( Config.CONFIG_RESOURCE, RBAC.WILDCARD_RESOURCES_ID, Config.PERMISSION_MANAGE, getUser( ) ) )
174 {
175 throw new AccessDeniedException( );
176
177 }
178
179 _config = ( _config != null ) ? _config : new Config( );
180 MappingAction mapping = new MappingAction( );
181 String idWorkflowBegin = request.getParameter( PARAMETER_ID_WORKFLOW_BEGIN );
182 String idWorkflow = request.getParameter( PARAMETER_ID_WORKFLOW );
183 String action = request.getParameter( "view_createConfig" );
184 String removedAction = request.getParameter( PARAMETER_REMOVED_ACTION );
185
186 Map<String, Object> model = getModel( );
187 model.put( MARK_ID_WORKFLOW_BEGIN, idWorkflowBegin );
188 model.put( MARK_ID_WORKFLOW, idWorkflow );
189
190 if ( action != null && action.equals( ACTION_ADD__MAPPING ) )
191 {
192 populate( mapping, request );
193 if ( !contain( mapping, _config.getListActionMapping( ) ) )
194 _config.addActionMapping( mapping );
195
196 }
197 else
198 if ( action != null && action.equals( ACTION_REMOVE_CONFIG_MAPPING ) )
199 {
200
201 _config.removeActionMapping( Integer.parseInt( removedAction ) );
202 }
203 else
204 if ( action != null && action.equals( ACTION_SELECT_WF ) )
205 {
206
207 _config.getListActionMapping( ).clear( );
208
209 }
210
211 if ( idWorkflowBegin != null && StringUtils.isNotEmpty( idWorkflowBegin ) && Integer.parseInt( idWorkflowBegin ) != -1 )
212 {
213
214 List<fr.paris.lutece.plugins.workflowcore.business.action.Action> listAction = getAction( Integer.parseInt( idWorkflowBegin ) );
215 List<fr.paris.lutece.plugins.workflowcore.business.action.Action> removedListAction = new ArrayList<fr.paris.lutece.plugins.workflowcore.business.action.Action>( );
216 for ( fr.paris.lutece.plugins.workflowcore.business.action.Action act : listAction )
217 {
218 for ( MappingAction mpg : _config.getListActionMapping( ) )
219 {
220 if ( act.getId( ) == mpg.getIdActionBegin( ) )
221 {
222
223 removedListAction.add( act );
224 }
225 }
226
227 }
228
229 model.put( MARK_ACTION_LIST_BEGIN, listAction );
230 model.put( MARK_REMOVED_LIST_ACTION_BEGIN, removedListAction );
231
232 }
233 if ( idWorkflow != null && StringUtils.isNotEmpty( idWorkflow ) && Integer.parseInt( idWorkflow ) != -1 )
234 {
235 List<fr.paris.lutece.plugins.workflowcore.business.action.Action> listAction = getAction( Integer.parseInt( idWorkflow ) );
236 List<fr.paris.lutece.plugins.workflowcore.business.action.Action> removedListAction = new ArrayList<fr.paris.lutece.plugins.workflowcore.business.action.Action>( );
237
238 for ( fr.paris.lutece.plugins.workflowcore.business.action.Action act : listAction )
239 {
240 for ( MappingAction mpg : _config.getListActionMapping( ) )
241 {
242 if ( act.getId( ) == mpg.getIdActionRelaunch( ) )
243 {
244
245 removedListAction.add( act );
246 }
247 }
248
249 }
250
251 model.put( MARK_ACTION_LIST_RELAUNCH, listAction );
252 model.put( MARK_REMOVED_LIST_ACTION_RELAUNCH, removedListAction );
253
254 }
255
256 populate( _config, request );
257 model.put( MARK_CONFIG, _config );
258 addElementsToModelForLeftColumn( request, request.getLocale( ), model );
259
260 return getPage( PROPERTY_PAGE_TITLE_CREATE_CONFIG, TEMPLATE_CREATE_CONFIG, model );
261 }
262
263
264
265
266
267
268
269
270
271 @Action( ACTION_CREATE_CONFIG )
272 public String doCreateConfig( HttpServletRequest request ) throws AccessDeniedException
273 {
274 if ( !RBACService.isAuthorized( Config.CONFIG_RESOURCE, RBAC.WILDCARD_RESOURCES_ID, Config.PERMISSION_MANAGE, getUser( ) ) )
275 {
276 throw new AccessDeniedException( );
277
278 }
279 populate( _config, request );
280
281 if ( !validateBean( _config, VALIDATION_ATTRIBUTES_PREFIX ) )
282 {
283 return redirectView( request, VIEW_CREATE_CONFIG );
284 }
285
286 ConfigService.getService( ).createConfig( _config );
287 addInfo( INFO_CONFIG_CREATED, getLocale( ) );
288
289 return redirectView( request, VIEW_MANAGE_CONFIGS );
290 }
291
292
293
294
295
296
297
298
299
300 @Action( ACTION_CONFIRM_REMOVE_CONFIG )
301 public String getConfirmRemoveConfig( HttpServletRequest request ) throws AccessDeniedException
302 {
303
304 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CONFIG ) );
305 if ( !RBACService.isAuthorized( Config.CONFIG_RESOURCE, String.valueOf( nId ), Config.PERMISSION_MANAGE, getUser( ) ) )
306 {
307 throw new AccessDeniedException( );
308
309 }
310 UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_CONFIG ) );
311 url.addParameter( PARAMETER_ID_CONFIG, nId );
312
313 String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_CONFIG, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
314
315 return redirect( request, strMessageUrl );
316 }
317
318
319
320
321
322
323
324
325
326 @Action( ACTION_REMOVE_CONFIG )
327 public String doRemoveConfig( HttpServletRequest request ) throws AccessDeniedException
328 {
329 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CONFIG ) );
330 if ( !RBACService.isAuthorized( Config.CONFIG_RESOURCE, String.valueOf( nId ), Config.PERMISSION_MANAGE, getUser( ) ) )
331 {
332 throw new AccessDeniedException( );
333
334 }
335 ConfigService.getService( ).removeConfig( nId );
336 addInfo( INFO_CONFIG_REMOVED, getLocale( ) );
337
338 return redirectView( request, VIEW_MANAGE_CONFIGS );
339 }
340
341
342
343
344
345
346
347
348
349 @View( VIEW_MODIFY_CONFIG )
350 public String getModifyConfig( HttpServletRequest request ) throws AccessDeniedException
351 {
352
353 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CONFIG ) );
354 _mapping = ( _mapping != null ) ? _mapping : new MappingAction( );
355 String idWorkflowBegin = request.getParameter( PARAMETER_ID_WORKFLOW_BEGIN );
356 String idWorkflow = request.getParameter( PARAMETER_ID_WORKFLOW );
357 String action = request.getParameter( "view_modifyConfig" );
358 String removedAction = request.getParameter( PARAMETER_REMOVED_ACTION );
359
360 MappingAction mapping = new MappingAction( );
361 if ( !RBACService.isAuthorized( Config.CONFIG_RESOURCE, request.getParameter( PARAMETER_ID_CONFIG ), Config.PERMISSION_MANAGE, getUser( ) ) )
362 {
363 throw new AccessDeniedException( );
364
365 }
366
367 if ( _config == null || ( _config.getId( ) != nId ) )
368 {
369 _config = ConfigService.getService( ).findConfigByID( nId );
370 }
371
372 Map<String, Object> model = getModel( );
373
374
375 if ( action != null && action.equals( ACTION_ADD__MAPPING ) )
376 {
377 populate( mapping, request );
378 mapping.setIdConfig(nId);
379 if ( !contain( mapping, _config.getListActionMapping( ) ) )
380 _config.addActionMapping( mapping );
381 }
382 else
383 if ( action != null && action.equals( ACTION_REMOVE_CONFIG_MAPPING ) )
384 {
385 populate( mapping, request );
386 mapping.setIdConfig(nId);
387 _config.removeActionMapping( mapping );
388 List<fr.paris.lutece.plugins.workflowcore.business.action.Action> listActionBegin = new ArrayList<fr.paris.lutece.plugins.workflowcore.business.action.Action>( );
389 for ( MappingAction mp : _config.getListActionMapping( ) )
390 {
391 fr.paris.lutece.plugins.workflowcore.business.action.Action act = _actionService.findByPrimaryKey( mp.getIdActionBegin( ) );
392 if ( act != null )
393 {
394 listActionBegin.add( act );
395 }
396
397 }
398 model.put( MARK_REMOVED_LIST_ACTION_BEGIN, listActionBegin );
399 }
400
401 else
402 if ( action != null && action.equals( ACTION_SELECT_WF ) )
403 {
404
405 if ( _config.getListActionMapping( ).size( ) != 0 && _config.getListActionMapping( ) != null )
406 {
407 for ( MappingAction MapAction : _config.getListActionMapping( ) )
408 {
409 fr.paris.lutece.plugins.workflowcore.business.action.Action actionBegin = _actionService.findByPrimaryKey( MapAction
410 .getIdActionBegin( ) );
411 fr.paris.lutece.plugins.workflowcore.business.action.Action actionRelanch = _actionService.findByPrimaryKey( MapAction
412 .getIdActionRelaunch( ) );
413
414 if ( idWorkflowBegin == null
415 || idWorkflow == null
416 || ( actionBegin.getWorkflow( ).getId( ) != Integer.parseInt( idWorkflowBegin ) || actionRelanch.getWorkflow( ).getId( ) != Integer
417 .parseInt( idWorkflow ) ) )
418 {
419 _config.getListActionMapping( ).clear( );
420 }
421 break;
422 }
423 }
424
425 }
426 else
427 {
428 List<fr.paris.lutece.plugins.workflowcore.business.action.Action> listActionBegin = new ArrayList<fr.paris.lutece.plugins.workflowcore.business.action.Action>( );
429 List<fr.paris.lutece.plugins.workflowcore.business.action.Action> listActionRelaunch = getAction( _config.getIdWorkflow( ) );
430
431 for ( MappingAction mp : _config.getListActionMapping( ) )
432 {
433 fr.paris.lutece.plugins.workflowcore.business.action.Action act = _actionService.findByPrimaryKey( mp.getIdActionBegin( ) );
434 if ( act != null )
435 {
436 listActionBegin.add( act );
437 idWorkflowBegin= String.valueOf( act.getWorkflow().getId());
438 }
439
440 }
441 model.put( MARK_REMOVED_LIST_ACTION_BEGIN, listActionBegin );
442 model.put( MARK_REMOVED_LIST_ACTION_RELAUNCH, listActionRelaunch );
443
444 }
445 if ( idWorkflowBegin != null && StringUtils.isNotEmpty( idWorkflowBegin ) && Integer.parseInt( idWorkflowBegin ) != -1 )
446 {
447
448 List<fr.paris.lutece.plugins.workflowcore.business.action.Action> listAction = getAction( Integer.parseInt( idWorkflowBegin ) );
449 List<fr.paris.lutece.plugins.workflowcore.business.action.Action> removedListAction = new ArrayList<fr.paris.lutece.plugins.workflowcore.business.action.Action>( );
450
451 for ( fr.paris.lutece.plugins.workflowcore.business.action.Action act : listAction )
452 {
453 for ( MappingAction mpg : _config.getListActionMapping( ) )
454 {
455 if ( act.getId( ) == mpg.getIdActionBegin( ) )
456 {
457
458 removedListAction.add( act );
459 }
460 }
461
462 }
463
464 model.put( MARK_ACTION_LIST_BEGIN, listAction );
465 model.put( MARK_REMOVED_LIST_ACTION_BEGIN, removedListAction );
466
467 }
468 if ( idWorkflow != null && StringUtils.isNotEmpty( idWorkflow ) && Integer.parseInt( idWorkflow ) != -1 )
469 {
470 List<fr.paris.lutece.plugins.workflowcore.business.action.Action> listAction = getAction( Integer.parseInt( idWorkflow ) );
471 List<fr.paris.lutece.plugins.workflowcore.business.action.Action> removedListAction = new ArrayList<fr.paris.lutece.plugins.workflowcore.business.action.Action>( );
472
473 for ( fr.paris.lutece.plugins.workflowcore.business.action.Action act : listAction )
474 {
475 for ( MappingAction mpg : _config.getListActionMapping( ) )
476 {
477 if ( act.getId( ) == mpg.getIdActionRelaunch( ) )
478 {
479
480 removedListAction.add( act );
481 }
482 }
483
484 }
485
486 model.put( MARK_ACTION_LIST_RELAUNCH, listAction );
487 model.put( MARK_REMOVED_LIST_ACTION_RELAUNCH, removedListAction );
488
489 }
490
491 populate( _config, request );
492 model.put( MARK_CONFIG, _config );
493 model.put( MARK_ID_WORKFLOW_BEGIN, idWorkflowBegin );
494 model.put( MARK_ID_WORKFLOW, idWorkflow );
495
496 addElementsToModelForLeftColumn( request, request.getLocale( ), model );
497
498 return getPage( PROPERTY_PAGE_TITLE_MODIFY_CONFIG, TEMPLATE_MODIFY_CONFIG, model );
499 }
500
501
502
503
504
505
506
507
508
509 @Action( ACTION_MODIFY_CONFIG )
510 public String doModifyConfig( HttpServletRequest request ) throws AccessDeniedException
511 {
512 populate( _config, request );
513
514 if ( !RBACService.isAuthorized( Config.CONFIG_RESOURCE, String.valueOf( _config.getId( ) ), Config.PERMISSION_MANAGE, getUser( ) ) )
515 {
516 throw new AccessDeniedException( );
517
518 }
519
520 if ( !validateBean( _config, VALIDATION_ATTRIBUTES_PREFIX ) )
521 {
522 return redirect( request, VIEW_MODIFY_CONFIG, PARAMETER_ID_CONFIG, _config.getId( ) );
523 }
524
525 ConfigService.getService( ).updateConfig( _config );
526 addInfo( INFO_CONFIG_UPDATED, getLocale( ) );
527
528 return redirectView( request, VIEW_MANAGE_CONFIGS );
529 }
530
531
532
533
534
535
536
537
538 @Action( ACTION_REMOVE_CONFIG_MAPPING )
539 public String doRemoveConfigMapping( HttpServletRequest request )
540 {
541 populate( _mapping, request );
542 ConfigHome.removeMapping( _mapping );
543
544 return redirect( request, VIEW_MODIFY_CONFIG, PARAMETER_ID_CONFIG, _config.getId( ) );
545 }
546
547
548
549
550
551
552
553 public static void addElementsToModelForLeftColumn( HttpServletRequest request, Locale locale, Map<String, Object> model )
554 {
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573 model.put( MARK_LIST_WORKFLOWS, WorkflowService.getInstance( ).getWorkflowsEnabled( AdminUserService.getAdminUser( request ), locale ) );
574
575 }
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601 public List<fr.paris.lutece.plugins.workflowcore.business.action.Action> getAction( int nIdWorkflow )
602 {
603
604 ActionFilter actionFilter = new ActionFilter( );
605 actionFilter.setIdWorkflow( nIdWorkflow );
606 List<fr.paris.lutece.plugins.workflowcore.business.action.Action> actionsList = _actionService.getListActionByFilter( actionFilter );
607
608 return actionsList;
609 }
610
611 public boolean contain( MappingAction mapping, Collection<MappingAction> collection )
612 {
613
614 for ( MappingAction mpg : collection )
615 {
616 if ( mpg.getIdActionRelaunch( ) == mapping.getIdActionRelaunch( ) && mapping.getIdActionBegin( ) == mpg.getIdActionBegin( ) )
617 return true;
618
619 }
620 return false;
621 }
622
623 }