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.action.ActionRequest; |
23 | |
import org.kuali.rice.kew.api.action.ActionRequestStatus; |
24 | |
import org.kuali.rice.kew.api.KewApiConstants; |
25 | |
import org.kuali.rice.kim.api.KimConstants; |
26 | |
import org.kuali.rice.kim.api.role.Role; |
27 | |
import org.kuali.rice.kim.api.role.RoleMembership; |
28 | |
import org.kuali.rice.kim.framework.common.delegate.DelegationTypeService; |
29 | |
import org.kuali.rice.kim.framework.role.RoleTypeService; |
30 | |
import org.kuali.rice.kns.kim.role.DerivedRoleTypeServiceBase; |
31 | |
|
32 | |
import java.util.ArrayList; |
33 | |
import java.util.Collections; |
34 | |
import java.util.List; |
35 | |
import java.util.Map; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class ActionRequestDerivedRoleTypeServiceImpl extends DerivedRoleTypeServiceBase implements RoleTypeService, DelegationTypeService { |
43 | |
private static final String NON_AD_HOC_APPROVE_REQUEST_RECIPIENT_ROLE_NAME = "Non-Ad Hoc Approve Request Recipient"; |
44 | |
private static final String APPROVE_REQUEST_RECIPIENT_ROLE_NAME = "Approve Request Recipient"; |
45 | |
private static final String ACKNOWLEDGE_REQUEST_RECIPIENT_ROLE_NAME = "Acknowledge Request Recipient"; |
46 | |
private static final String FYI_REQUEST_RECIPIENT_ROLE_NAME = "FYI Request Recipient"; |
47 | |
|
48 | |
@Override |
49 | |
protected List<String> getRequiredAttributes() { |
50 | 0 | final List<String> attrs = new ArrayList<String>(super.getRequiredAttributes()); |
51 | 0 | attrs.add(KimConstants.AttributeConstants.DOCUMENT_NUMBER); |
52 | 0 | return Collections.unmodifiableList(attrs); |
53 | |
} |
54 | |
|
55 | |
@Override |
56 | |
protected boolean isCheckRequiredAttributes() { |
57 | 0 | return true; |
58 | |
} |
59 | |
|
60 | |
@Override |
61 | |
public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) { |
62 | 0 | if (StringUtils.isBlank(namespaceCode)) { |
63 | 0 | throw new RiceIllegalArgumentException("namespaceCode was null or blank"); |
64 | |
} |
65 | |
|
66 | 0 | if (StringUtils.isBlank(roleName)) { |
67 | 0 | throw new RiceIllegalArgumentException("roleName was null"); |
68 | |
} |
69 | 0 | List<RoleMembership> members = new ArrayList<RoleMembership>(); |
70 | 0 | if ( qualification != null && !qualification.isEmpty() ) { |
71 | 0 | String principalId = qualification.get(KimConstants.AttributeConstants.PRINCIPAL_ID); |
72 | 0 | if (qualification.containsKey(KimConstants.AttributeConstants.PRINCIPAL_ID) |
73 | |
&& hasApplicationRole(principalId, null, namespaceCode, |
74 | |
roleName, qualification)) { |
75 | 0 | members.add(RoleMembership.Builder.create(null, null, principalId, MemberType.PRINCIPAL, null).build()); |
76 | |
} |
77 | |
} |
78 | 0 | return members; |
79 | |
} |
80 | |
|
81 | |
@Override |
82 | |
public boolean hasApplicationRole(String principalId, |
83 | |
List<String> groupIds, String namespaceCode, String roleName, |
84 | |
Map<String, String> qualification) { |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | 0 | if (StringUtils.isBlank(roleName)) { |
98 | 0 | throw new RiceIllegalArgumentException("roleName was null or blank"); |
99 | |
} |
100 | |
|
101 | 0 | if (qualification == null) { |
102 | 0 | throw new RiceIllegalArgumentException("qualification was null"); |
103 | |
} |
104 | |
|
105 | 0 | validateRequiredAttributesAgainstReceived(qualification); |
106 | |
try { |
107 | 0 | if ( (qualification != null && !qualification.isEmpty())) { |
108 | 0 | List<ActionRequest> actionRequests = KewApiServiceLocator.getWorkflowDocumentService().getActionRequestsForPrincipalAtNode( |
109 | |
qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER), null, principalId); |
110 | 0 | if (APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName) || NON_AD_HOC_APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName)) { |
111 | 0 | for ( ActionRequest ar : actionRequests ) { |
112 | 0 | if ( ar.getActionRequested().getCode().equals( KewApiConstants.ACTION_REQUEST_APPROVE_REQ ) |
113 | |
&& ar.getStatus().getCode().equals( ActionRequestStatus.ACTIVATED.getCode() ) ) { |
114 | 0 | return APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName) || (NON_AD_HOC_APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName) && !ar.isAdHocRequest()); |
115 | |
} |
116 | |
} |
117 | 0 | return false; |
118 | |
} |
119 | 0 | if (ACKNOWLEDGE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName)) { |
120 | 0 | for ( ActionRequest ar : actionRequests ) { |
121 | 0 | if ( ar.getActionRequested().getCode().equals( KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ ) |
122 | |
&& ar.getStatus().getCode().equals( ActionRequestStatus.ACTIVATED.getCode() ) ) { |
123 | 0 | return true; |
124 | |
} |
125 | |
} |
126 | 0 | return false; |
127 | |
} |
128 | 0 | if (FYI_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName)) { |
129 | 0 | for ( ActionRequest ar : actionRequests ) { |
130 | 0 | if ( ar.getActionRequested().getCode().equals( KewApiConstants.ACTION_REQUEST_FYI_REQ ) |
131 | |
&& ar.getStatus().getCode().equals( ActionRequestStatus.ACTIVATED.getCode() ) ) { |
132 | 0 | return true; |
133 | |
} |
134 | |
} |
135 | 0 | return false; |
136 | |
} |
137 | |
} |
138 | 0 | return false; |
139 | 0 | } catch (RiceIllegalArgumentException e) { |
140 | 0 | throw new RuntimeException("Unable to load route header", e); |
141 | |
} |
142 | |
} |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
@Override |
150 | |
public boolean dynamicRoleMembership(String namespaceCode, String roleName) { |
151 | 0 | if (StringUtils.isBlank(namespaceCode)) { |
152 | 0 | throw new RiceIllegalArgumentException("namespaceCode was null or blank"); |
153 | |
} |
154 | |
|
155 | 0 | if (StringUtils.isBlank(roleName)) { |
156 | 0 | throw new RiceIllegalArgumentException("roleName was null or blank"); |
157 | |
} |
158 | |
|
159 | 0 | return false; |
160 | |
} |
161 | |
|
162 | |
} |