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 | |
|
19 | |
import org.kuali.rice.kew.api.action.ActionRequestStatus; |
20 | |
import org.kuali.rice.kew.dto.ActionRequestDTO; |
21 | |
import org.kuali.rice.kew.exception.WorkflowException; |
22 | |
import org.kuali.rice.kew.service.WorkflowInfo; |
23 | |
import org.kuali.rice.kew.util.KEWConstants; |
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.type.KimDelegationTypeService; |
27 | |
import org.kuali.rice.kim.framework.type.KimRoleTypeService; |
28 | |
import org.kuali.rice.kim.service.support.impl.KimDerivedRoleTypeServiceBase; |
29 | |
import org.kuali.rice.kim.util.KimConstants; |
30 | |
|
31 | |
import java.util.ArrayList; |
32 | |
import java.util.List; |
33 | |
import java.util.Map; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 0 | public class ActionRequestDerivedRoleTypeServiceImpl extends |
41 | |
KimDerivedRoleTypeServiceBase implements KimRoleTypeService, KimDelegationTypeService { |
42 | |
private static final String NON_AD_HOC_APPROVE_REQUEST_RECIPIENT_ROLE_NAME = "Non-Ad Hoc Approve Request Recipient"; |
43 | |
private static final String APPROVE_REQUEST_RECIPIENT_ROLE_NAME = "Approve Request Recipient"; |
44 | |
private static final String ACKNOWLEDGE_REQUEST_RECIPIENT_ROLE_NAME = "Acknowledge Request Recipient"; |
45 | |
private static final String FYI_REQUEST_RECIPIENT_ROLE_NAME = "FYI Request Recipient"; |
46 | 0 | protected WorkflowInfo workflowInfo = new WorkflowInfo(); |
47 | |
|
48 | |
{ |
49 | 0 | requiredAttributes.add( KimConstants.AttributeConstants.DOCUMENT_NUMBER ); |
50 | 0 | checkRequiredAttributes = true; |
51 | 0 | } |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
@Override |
57 | |
public List<RoleMembership> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, Map<String, String> qualification) { |
58 | 0 | List<RoleMembership> members = new ArrayList<RoleMembership>(); |
59 | 0 | if ( qualification != null && !qualification.isEmpty() ) { |
60 | 0 | String principalId = qualification.get(KimConstants.AttributeConstants.PRINCIPAL_ID); |
61 | 0 | if (qualification.containsKey(KimConstants.AttributeConstants.PRINCIPAL_ID) |
62 | |
&& hasApplicationRole(principalId, null, namespaceCode, |
63 | |
roleName, qualification)) { |
64 | 0 | members.add(RoleMembership.Builder.create(null, null, principalId, Role.PRINCIPAL_MEMBER_TYPE, null).build()); |
65 | |
} |
66 | |
} |
67 | 0 | return members; |
68 | |
} |
69 | |
|
70 | |
@Override |
71 | |
public boolean hasApplicationRole(String principalId, |
72 | |
List<String> groupIds, String namespaceCode, String roleName, |
73 | |
Map<String, String> qualification) { |
74 | 0 | validateRequiredAttributesAgainstReceived(qualification); |
75 | |
try { |
76 | 0 | if ( (qualification != null && !qualification.isEmpty())) { |
77 | 0 | ActionRequestDTO[] actionRequests = workflowInfo.getActionRequests(qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER), null, principalId); |
78 | 0 | if (APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName) || NON_AD_HOC_APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName)) { |
79 | 0 | for ( ActionRequestDTO ar : actionRequests ) { |
80 | 0 | if ( ar.getActionRequested().equals( KEWConstants.ACTION_REQUEST_APPROVE_REQ ) |
81 | |
&& ar.getStatus().equals( ActionRequestStatus.ACTIVATED.getCode() ) ) { |
82 | 0 | return APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName) || (NON_AD_HOC_APPROVE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName) && !ar.isAdHocRequest()); |
83 | |
} |
84 | |
} |
85 | 0 | return false; |
86 | |
} |
87 | 0 | if (ACKNOWLEDGE_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName)) { |
88 | 0 | for ( ActionRequestDTO ar : actionRequests ) { |
89 | 0 | if ( ar.getActionRequested().equals( KEWConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ ) |
90 | |
&& ar.getStatus().equals( ActionRequestStatus.ACTIVATED.getCode() ) ) { |
91 | 0 | return true; |
92 | |
} |
93 | |
} |
94 | 0 | return false; |
95 | |
} |
96 | 0 | if (FYI_REQUEST_RECIPIENT_ROLE_NAME.equals(roleName)) { |
97 | 0 | for ( ActionRequestDTO ar : actionRequests ) { |
98 | 0 | if ( ar.getActionRequested().equals( KEWConstants.ACTION_REQUEST_FYI_REQ ) |
99 | |
&& ar.getStatus().equals( ActionRequestStatus.ACTIVATED.getCode() ) ) { |
100 | 0 | return true; |
101 | |
} |
102 | |
} |
103 | 0 | return false; |
104 | |
} |
105 | |
} |
106 | 0 | return false; |
107 | 0 | } catch (WorkflowException e) { |
108 | 0 | throw new RuntimeException("Unable to load route header", e); |
109 | |
} |
110 | |
} |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
@Override |
118 | |
public boolean shouldCacheRoleMembershipResults(String namespaceCode, |
119 | |
String roleName) { |
120 | 0 | return false; |
121 | |
} |
122 | |
|
123 | |
} |