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