1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.role.service.impl; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.kuali.rice.kew.api.KewApiServiceLocator; |
20 | |
import org.kuali.rice.kew.api.document.WorkflowDocumentService; |
21 | |
import org.kuali.rice.kew.exception.WorkflowException; |
22 | |
import org.kuali.rice.kew.service.WorkflowInfo; |
23 | |
import org.kuali.rice.kim.api.role.Role; |
24 | |
import org.kuali.rice.kim.api.role.RoleMembership; |
25 | |
import org.kuali.rice.kim.framework.type.KimDelegationTypeService; |
26 | |
import org.kuali.rice.kim.framework.type.KimRoleTypeService; |
27 | |
import org.kuali.rice.kim.service.support.impl.KimDerivedRoleTypeServiceBase; |
28 | |
import org.kuali.rice.kim.util.KimConstants; |
29 | |
|
30 | |
import java.util.ArrayList; |
31 | |
import java.util.List; |
32 | |
import java.util.Map; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | 0 | public class RouteLogDerivedRoleTypeServiceImpl extends KimDerivedRoleTypeServiceBase implements KimRoleTypeService, KimDelegationTypeService { |
40 | |
public static final String INITIATOR_ROLE_NAME = "Initiator"; |
41 | |
public static final String INITIATOR_OR_REVIEWER_ROLE_NAME = "Initiator or Reviewer"; |
42 | |
public static final String ROUTER_ROLE_NAME = "Router"; |
43 | |
|
44 | 0 | protected WorkflowInfo workflowInfo = new WorkflowInfo(); |
45 | |
|
46 | |
{ |
47 | |
|
48 | |
|
49 | |
|
50 | 0 | checkRequiredAttributes = true; |
51 | 0 | } |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
@Override |
64 | |
public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) { |
65 | 0 | validateRequiredAttributesAgainstReceived(qualification); |
66 | 0 | List<RoleMembership> members = new ArrayList<RoleMembership>(); |
67 | 0 | if(qualification!=null && !qualification.isEmpty()){ |
68 | 0 | String documentId = qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER); |
69 | 0 | if (StringUtils.isNotBlank(documentId)) { |
70 | |
try{ |
71 | 0 | WorkflowDocumentService workflowDocumentService = KewApiServiceLocator.getWorkflowDocumentService(); |
72 | 0 | if (INITIATOR_ROLE_NAME.equals(roleName)) { |
73 | 0 | String principalId = KewApiServiceLocator.getWorkflowDocumentService().getDocumentInitiatorPrincipalId( |
74 | |
documentId); |
75 | 0 | RoleMembership roleMembership = RoleMembership.Builder.create(null,null,principalId, Role.PRINCIPAL_MEMBER_TYPE,null).build(); |
76 | 0 | members.add(roleMembership); |
77 | 0 | } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)) { |
78 | 0 | List<String> ids = workflowInfo.getPrincipalIdsInRouteLog(documentId, true); |
79 | 0 | for ( String id : ids ) { |
80 | 0 | if ( StringUtils.isNotBlank(id) ) { |
81 | 0 | RoleMembership roleMembership = RoleMembership.Builder.create(null,null,id, Role.PRINCIPAL_MEMBER_TYPE,null).build(); |
82 | 0 | members.add(roleMembership ); |
83 | 0 | } |
84 | |
} |
85 | 0 | } else if(ROUTER_ROLE_NAME.equals(roleName)) { |
86 | 0 | String principalId = workflowDocumentService.getDocumentRoutedByPrincipalId(documentId); |
87 | 0 | RoleMembership roleMembership = RoleMembership.Builder.create(null,null,principalId, Role.PRINCIPAL_MEMBER_TYPE,null).build(); |
88 | 0 | members.add(roleMembership); |
89 | |
} |
90 | 0 | } catch(WorkflowException wex){ |
91 | 0 | throw new RuntimeException( |
92 | |
"Error in getting principal Ids in route log for document id: "+ documentId +" :"+wex.getLocalizedMessage(),wex); |
93 | 0 | } |
94 | |
} |
95 | |
} |
96 | |
|
97 | 0 | return members; |
98 | |
} |
99 | |
|
100 | |
@Override |
101 | |
public boolean hasApplicationRole( |
102 | |
String principalId, List<String> groupIds, String namespaceCode, String roleName, Map<String, String> qualification){ |
103 | 0 | validateRequiredAttributesAgainstReceived(qualification); |
104 | 0 | boolean isUserInRouteLog = false; |
105 | 0 | if(qualification!=null && !qualification.isEmpty()){ |
106 | 0 | String documentId = qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER); |
107 | 0 | WorkflowDocumentService workflowDocumentService = KewApiServiceLocator.getWorkflowDocumentService(); |
108 | |
try { |
109 | 0 | if (INITIATOR_ROLE_NAME.equals(roleName)){ |
110 | 0 | isUserInRouteLog = principalId.equals(workflowDocumentService.getDocumentInitiatorPrincipalId(documentId)); |
111 | 0 | } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)){ |
112 | 0 | isUserInRouteLog = workflowInfo.isUserAuthenticatedByRouteLog(documentId, principalId, true); |
113 | 0 | } else if(ROUTER_ROLE_NAME.equals(roleName)){ |
114 | 0 | isUserInRouteLog = principalId.equals(workflowDocumentService.getDocumentRoutedByPrincipalId(documentId)); |
115 | |
} |
116 | 0 | } catch (WorkflowException wex) { |
117 | 0 | throw new RuntimeException("Error in determining whether the principal Id: " + principalId + " is in route log " + |
118 | |
"for document id: " + documentId + " :"+wex.getLocalizedMessage(),wex); |
119 | 0 | } |
120 | |
} |
121 | 0 | return isUserInRouteLog; |
122 | |
} |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
@Override |
130 | |
public boolean shouldCacheRoleMembershipResults(String namespaceCode, |
131 | |
String roleName) { |
132 | 0 | return false; |
133 | |
} |
134 | |
} |