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