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.core.api.exception.RiceIllegalArgumentException; |
20 | |
import org.kuali.rice.core.api.membership.MemberType; |
21 | |
import org.kuali.rice.kew.api.KewApiServiceLocator; |
22 | |
import org.kuali.rice.kew.api.document.WorkflowDocumentService; |
23 | |
import org.kuali.rice.kim.api.KimConstants; |
24 | |
import org.kuali.rice.kim.api.role.Role; |
25 | |
import org.kuali.rice.kim.api.role.RoleMembership; |
26 | |
import org.kuali.rice.kim.framework.common.delegate.DelegationTypeService; |
27 | |
import org.kuali.rice.kim.framework.role.RoleTypeService; |
28 | |
import org.kuali.rice.kns.kim.role.DerivedRoleTypeServiceBase; |
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 DerivedRoleTypeServiceBase implements RoleTypeService, DelegationTypeService { |
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 | |
@Override |
45 | |
protected boolean isCheckRequiredAttributes() { |
46 | 0 | return true; |
47 | |
} |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
@Override |
60 | |
public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) { |
61 | 0 | if (StringUtils.isBlank(namespaceCode)) { |
62 | 0 | throw new RiceIllegalArgumentException("namespaceCode was null or blank"); |
63 | |
} |
64 | |
|
65 | 0 | if (roleName == null) { |
66 | 0 | throw new RiceIllegalArgumentException("roleName was null"); |
67 | |
} |
68 | |
|
69 | 0 | validateRequiredAttributesAgainstReceived(qualification); |
70 | 0 | List<RoleMembership> members = new ArrayList<RoleMembership>(); |
71 | 0 | if(qualification!=null && !qualification.isEmpty()){ |
72 | 0 | String documentId = qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER); |
73 | 0 | if (StringUtils.isNotBlank(documentId)) { |
74 | |
try{ |
75 | 0 | WorkflowDocumentService workflowDocumentService = KewApiServiceLocator.getWorkflowDocumentService(); |
76 | 0 | if (INITIATOR_ROLE_NAME.equals(roleName)) { |
77 | 0 | String principalId = KewApiServiceLocator.getWorkflowDocumentService().getDocumentInitiatorPrincipalId( |
78 | |
documentId); |
79 | 0 | RoleMembership roleMembership = RoleMembership.Builder.create(null,null,principalId, MemberType.PRINCIPAL, null).build(); |
80 | 0 | members.add(roleMembership); |
81 | 0 | } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)) { |
82 | 0 | List<String> ids = KewApiServiceLocator.getWorkflowDocumentActionsService().getPrincipalIdsInRouteLog( |
83 | |
documentId, true); |
84 | 0 | for ( String id : ids ) { |
85 | 0 | if ( StringUtils.isNotBlank(id) ) { |
86 | 0 | RoleMembership roleMembership = RoleMembership.Builder.create(null,null,id, MemberType.PRINCIPAL, null).build(); |
87 | 0 | members.add(roleMembership ); |
88 | 0 | } |
89 | |
} |
90 | 0 | } else if(ROUTER_ROLE_NAME.equals(roleName)) { |
91 | 0 | String principalId = workflowDocumentService.getRoutedByPrincipalIdByDocumentId(documentId); |
92 | 0 | RoleMembership roleMembership = RoleMembership.Builder.create(null,null,principalId, MemberType.PRINCIPAL, null).build(); |
93 | 0 | members.add(roleMembership); |
94 | |
} |
95 | 0 | } catch(Exception wex){ |
96 | 0 | throw new RuntimeException( |
97 | |
"Error in getting principal Ids in route log for document id: "+ documentId +" :"+wex.getLocalizedMessage(),wex); |
98 | 0 | } |
99 | |
} |
100 | |
} |
101 | |
|
102 | 0 | return members; |
103 | |
} |
104 | |
|
105 | |
@Override |
106 | |
public boolean hasApplicationRole( |
107 | |
String principalId, List<String> groupIds, String namespaceCode, String roleName, Map<String, String> qualification){ |
108 | 0 | if (StringUtils.isBlank(principalId)) { |
109 | 0 | throw new RiceIllegalArgumentException("principalId was null or blank"); |
110 | |
} |
111 | |
|
112 | 0 | if (groupIds == null) { |
113 | 0 | throw new RiceIllegalArgumentException("groupIds was null or blank"); |
114 | |
} |
115 | |
|
116 | 0 | if (StringUtils.isBlank(namespaceCode)) { |
117 | 0 | throw new RiceIllegalArgumentException("namespaceCode was null or blank"); |
118 | |
} |
119 | |
|
120 | 0 | if (StringUtils.isBlank(roleName)) { |
121 | 0 | throw new RiceIllegalArgumentException("roleName was null or blank"); |
122 | |
} |
123 | |
|
124 | 0 | if (qualification == null) { |
125 | 0 | throw new RiceIllegalArgumentException("qualification was null"); |
126 | |
} |
127 | |
|
128 | |
|
129 | 0 | validateRequiredAttributesAgainstReceived(qualification); |
130 | 0 | boolean isUserInRouteLog = false; |
131 | 0 | if(qualification!=null && !qualification.isEmpty()){ |
132 | 0 | String documentId = qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER); |
133 | 0 | WorkflowDocumentService workflowDocumentService = KewApiServiceLocator.getWorkflowDocumentService(); |
134 | |
try { |
135 | 0 | if (INITIATOR_ROLE_NAME.equals(roleName)){ |
136 | 0 | isUserInRouteLog = principalId.equals(workflowDocumentService.getDocumentInitiatorPrincipalId(documentId)); |
137 | 0 | } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)){ |
138 | 0 | isUserInRouteLog = KewApiServiceLocator.getWorkflowDocumentActionsService().isUserInRouteLog( |
139 | |
documentId, principalId, true); |
140 | 0 | } else if(ROUTER_ROLE_NAME.equals(roleName)){ |
141 | 0 | isUserInRouteLog = principalId.equals(workflowDocumentService.getRoutedByPrincipalIdByDocumentId( |
142 | |
documentId)); |
143 | |
} |
144 | 0 | } catch (Exception wex) { |
145 | 0 | throw new RuntimeException("Error in determining whether the principal Id: " + principalId + " is in route log " + |
146 | |
"for document id: " + documentId + " :"+wex.getLocalizedMessage(),wex); |
147 | 0 | } |
148 | |
} |
149 | 0 | return isUserInRouteLog; |
150 | |
} |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
@Override |
158 | |
public boolean dynamicRoleMembership(String namespaceCode, String roleName) { |
159 | 0 | if (StringUtils.isBlank(namespaceCode)) { |
160 | 0 | throw new RiceIllegalArgumentException("namespaceCode was null or blank"); |
161 | |
} |
162 | |
|
163 | 0 | if (StringUtils.isBlank(roleName)) { |
164 | 0 | throw new RiceIllegalArgumentException("roleName was null or blank"); |
165 | |
} |
166 | |
|
167 | 0 | return false; |
168 | |
} |
169 | |
} |