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.state.State;
38 import fr.paris.lutece.plugins.workflowcore.business.state.StateFilter;
39 import fr.paris.lutece.plugins.workflowcore.service.state.IStateService;
40 import fr.paris.lutece.plugins.workflowcore.service.state.StateService;
41 import fr.paris.lutece.plugins.workflowcore.service.workflow.IWorkflowService;
42 import fr.paris.lutece.plugins.workflowcore.service.workflow.WorkflowService;
43 import fr.paris.lutece.portal.service.rbac.Permission;
44 import fr.paris.lutece.portal.service.rbac.ResourceIdService;
45 import fr.paris.lutece.portal.service.rbac.ResourceType;
46 import fr.paris.lutece.portal.service.rbac.ResourceTypeManager;
47 import fr.paris.lutece.portal.service.spring.SpringContextService;
48 import fr.paris.lutece.util.ReferenceList;
49
50 import java.util.List;
51 import java.util.Locale;
52
53
54
55
56
57
58 public class StateResourceIdService extends ResourceIdService
59 {
60
61 public static final String PERMISSION_VIEW = "VIEW";
62
63
64
65
66 public static final String PERMISSION_VIEW_ALL_WORKGROUP = "VIEW_ALL_WORKGROUP";
67 private static final String PROPERTY_LABEL_RESOURCE_TYPE = "workflow.permission.label.resource_type_state";
68 private static final String PROPERTY_LABEL_VIEW = "workflow.permission.label.view_state";
69 private static final String PROPERTY_LABEL_VIEW_ALL_WORKGROUP = "workflow.permission.label.view_all_workgroup";
70
71
72 public StateResourceIdService( )
73 {
74 setPluginName( WorkflowPlugin.PLUGIN_NAME );
75 }
76
77
78
79
80 @Override
81 public void register( )
82 {
83 ResourceType rt = new ResourceType( );
84 rt.setResourceIdServiceClass( StateResourceIdService.class.getName( ) );
85 rt.setPluginName( WorkflowPlugin.PLUGIN_NAME );
86 rt.setResourceTypeKey( State.RESOURCE_TYPE );
87 rt.setResourceTypeLabelKey( PROPERTY_LABEL_RESOURCE_TYPE );
88
89 Permission p = new Permission( );
90 p.setPermissionKey( PERMISSION_VIEW );
91 p.setPermissionTitleKey( PROPERTY_LABEL_VIEW );
92 rt.registerPermission( p );
93
94 p = new Permission( );
95 p.setPermissionKey( PERMISSION_VIEW_ALL_WORKGROUP );
96 p.setPermissionTitleKey( PROPERTY_LABEL_VIEW_ALL_WORKGROUP );
97 rt.registerPermission( p );
98
99 ResourceTypeManager.registerResourceType( rt );
100 }
101
102
103
104
105 @Override
106 public ReferenceList getResourceIdList( Locale locale )
107 {
108 IStateService stateService = SpringContextService.getBean( StateService.BEAN_SERVICE );
109 IWorkflowService workflowService = SpringContextService.getBean( WorkflowService.BEAN_SERVICE );
110 List<State> listState = stateService.getListStateByFilter( new StateFilter( ) );
111
112 ReferenceList reflistState = new ReferenceList( );
113
114 for ( State state : listState )
115 {
116 state.setWorkflow( workflowService.findByPrimaryKey( state.getWorkflow( ).getId( ) ) );
117 reflistState.addItem( state.getId( ), state.getWorkflow( ).getName( ) + "/" + state.getName( ) );
118 }
119
120 return reflistState;
121 }
122
123
124
125
126 @Override
127 public String getTitle( String strId, Locale locale )
128 {
129 IStateService stateService = SpringContextService.getBean( StateService.BEAN_SERVICE );
130 IWorkflowService workflowService = SpringContextService.getBean( WorkflowService.BEAN_SERVICE );
131 int nId = WorkflowUtils.convertStringToInt( strId );
132 State state = stateService.findByPrimaryKey( nId );
133
134 if ( state != null )
135 {
136 state.setWorkflow( workflowService.findByPrimaryKey( state.getWorkflow( ).getId( ) ) );
137 }
138
139 return ( state != null ) ? ( state.getWorkflow( ).getName( ) + "/" + state.getName( ) ) : null;
140 }
141 }