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.workflow.service;
35
36 import fr.paris.lutece.plugins.workflow.utils.WorkflowUtils;
37 import fr.paris.lutece.plugins.workflowcore.business.action.Action;
38 import fr.paris.lutece.plugins.workflowcore.business.action.ActionFilter;
39 import fr.paris.lutece.plugins.workflowcore.business.state.State;
40 import fr.paris.lutece.plugins.workflowcore.service.action.ActionService;
41 import fr.paris.lutece.plugins.workflowcore.service.action.IActionService;
42 import fr.paris.lutece.plugins.workflowcore.service.state.IStateService;
43 import fr.paris.lutece.plugins.workflowcore.service.state.StateService;
44 import fr.paris.lutece.plugins.workflowcore.service.workflow.IWorkflowService;
45 import fr.paris.lutece.plugins.workflowcore.service.workflow.WorkflowService;
46 import fr.paris.lutece.portal.service.rbac.Permission;
47 import fr.paris.lutece.portal.service.rbac.ResourceIdService;
48 import fr.paris.lutece.portal.service.rbac.ResourceType;
49 import fr.paris.lutece.portal.service.rbac.ResourceTypeManager;
50 import fr.paris.lutece.portal.service.spring.SpringContextService;
51 import fr.paris.lutece.util.ReferenceList;
52
53 import java.util.List;
54 import java.util.Locale;
55
56
57
58
59
60
61 public class ActionResourceIdService extends ResourceIdService
62 {
63
64 public static final String PERMISSION_VIEW = "VIEW";
65
66
67 public static final String PERMISSION_MANAGE_ADVANCED_PARAMETERS = "MANAGE_ADVANCED_PARAMETERS";
68 private static final String PROPERTY_LABEL_RESOURCE_TYPE = "workflow.permission.label.resource_type_action";
69 private static final String PROPERTY_LABEL_VIEW = "workflow.permission.label.view_action";
70 private static final String PROPERTY_LABEL_MANAGE_ADVANCED_PARAMETERS = "workflow.permission.label.manage_advanced_parameters";
71
72
73 public ActionResourceIdService( )
74 {
75 setPluginName( WorkflowPlugin.PLUGIN_NAME );
76 }
77
78
79
80
81 @Override
82 public void register( )
83 {
84 ResourceType rt = new ResourceType( );
85 rt.setResourceIdServiceClass( ActionResourceIdService.class.getName( ) );
86 rt.setPluginName( WorkflowPlugin.PLUGIN_NAME );
87 rt.setResourceTypeKey( Action.RESOURCE_TYPE );
88 rt.setResourceTypeLabelKey( PROPERTY_LABEL_RESOURCE_TYPE );
89
90 Permission p = new Permission( );
91 p.setPermissionKey( PERMISSION_VIEW );
92 p.setPermissionTitleKey( PROPERTY_LABEL_VIEW );
93 rt.registerPermission( p );
94
95 p = new Permission( );
96 p.setPermissionKey( PERMISSION_MANAGE_ADVANCED_PARAMETERS );
97 p.setPermissionTitleKey( PROPERTY_LABEL_MANAGE_ADVANCED_PARAMETERS );
98 rt.registerPermission( p );
99
100 ResourceTypeManager.registerResourceType( rt );
101 }
102
103
104
105
106
107
108
109
110 public ReferenceList getResourceIdList( Locale locale )
111 {
112 IActionService actionService = SpringContextService.getBean( ActionService.BEAN_SERVICE );
113 ActionFilter actionFilter = new ActionFilter( );
114 actionFilter.setAutomaticReflexiveAction( false );
115
116 List<Action> listAction = actionService.getListActionByFilter( actionFilter );
117 ReferenceList reflistAction = new ReferenceList( );
118
119 for ( Action action : listAction )
120 {
121 reflistAction.addItem( action.getId( ), getActionLabel( action ) );
122 }
123
124 return reflistAction;
125 }
126
127
128
129
130
131
132
133
134
135
136 public String getTitle( String strId, Locale locale )
137 {
138 IActionService actionService = SpringContextService.getBean( ActionService.BEAN_SERVICE );
139 int nId = WorkflowUtils.convertStringToInt( strId );
140 Action action = actionService.findByPrimaryKey( nId );
141
142 if ( action == null )
143 {
144 return null;
145 }
146
147 return getActionLabel( action );
148 }
149
150 private String getActionLabel( Action action )
151 {
152 IWorkflowService workflowService = SpringContextService.getBean( WorkflowService.BEAN_SERVICE );
153 IStateService stateService = SpringContextService.getBean( StateService.BEAN_SERVICE );
154
155 action.setWorkflow( workflowService.findByPrimaryKey( action.getWorkflow( ).getId( ) ) );
156 action.setStateAfter( stateService.findByPrimaryKey( action.getStateAfter( ).getId( ) ) );
157
158 StringBuilder sbTitle = new StringBuilder( );
159 sbTitle.append( action.getWorkflow( ).getName( ) );
160 sbTitle.append( "/" );
161 sbTitle.append( action.getName( ) );
162 sbTitle.append( " ( " );
163 for ( Integer idStateBefore : action.getListIdStateBefore( ) )
164 {
165 State stateBefore = stateService.findByPrimaryKey( idStateBefore );
166 sbTitle.append( stateBefore.getName( ) );
167 sbTitle.append( " " );
168 }
169 sbTitle.append( " -> " );
170 sbTitle.append( action.getStateAfter( ).getName( ) );
171 sbTitle.append( " ) " );
172
173 return sbTitle.toString( );
174 }
175 }