1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.lum.kim.role.type; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.HashSet; |
20 | |
import java.util.List; |
21 | |
import java.util.Set; |
22 | |
|
23 | |
import org.apache.commons.lang.StringUtils; |
24 | |
import org.kuali.rice.kew.exception.WorkflowException; |
25 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
26 | |
import org.kuali.rice.kew.service.WorkflowUtility; |
27 | |
import org.kuali.rice.kim.bo.Role; |
28 | |
import org.kuali.rice.kim.bo.impl.KimAttributes; |
29 | |
import org.kuali.rice.kim.bo.role.dto.RoleMembershipInfo; |
30 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
31 | |
import org.kuali.rice.kim.service.support.impl.KimDerivedRoleTypeServiceBase; |
32 | |
import org.kuali.student.common.rice.StudentIdentityConstants; |
33 | |
import org.kuali.student.lum.kim.KimQualificationHelper; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | public class KSRouteLogDerivedRoleTypeServiceImpl extends KimDerivedRoleTypeServiceBase { |
39 | 0 | private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KSRouteLogDerivedRoleTypeServiceImpl.class); |
40 | |
|
41 | |
public static final String INITIATOR_ROLE_NAME = "Initiator"; |
42 | |
public static final String INITIATOR_OR_REVIEWER_ROLE_NAME = "Initiator or Reviewer"; |
43 | |
public static final String ROUTER_ROLE_NAME = "Router"; |
44 | |
|
45 | 0 | private boolean checkFutureRequests = false; |
46 | 0 | protected Set<List<String>> newRequiredAttributes = new HashSet<List<String>>(); |
47 | |
|
48 | |
{ |
49 | 0 | checkRequiredAttributes = true; |
50 | |
|
51 | 0 | List<String> listOne = new ArrayList<String>(); |
52 | 0 | listOne.add( KimAttributes.DOCUMENT_NUMBER ); |
53 | 0 | newRequiredAttributes.add(listOne); |
54 | |
|
55 | 0 | List<String> listTwo = new ArrayList<String>(); |
56 | 0 | listTwo.add( KimAttributes.DOCUMENT_TYPE_NAME ); |
57 | 0 | listTwo.add( StudentIdentityConstants.QUALIFICATION_KEW_OBJECT_ID ); |
58 | 0 | newRequiredAttributes.add(listTwo); |
59 | |
|
60 | 0 | List<String> listThree = new ArrayList<String>(); |
61 | 0 | listThree.add( StudentIdentityConstants.QUALIFICATION_KEW_OBJECT_ID ); |
62 | 0 | listThree.add( StudentIdentityConstants.QUALIFICATION_KEW_OBJECT_TYPE ); |
63 | 0 | newRequiredAttributes.add(listThree); |
64 | |
|
65 | 0 | for (String proposalReferenceType : StudentIdentityConstants.QUALIFICATION_PROPOSAL_ID_REF_TYPES) { |
66 | 0 | List<String> tempList = new ArrayList<String>(); |
67 | 0 | tempList.add( proposalReferenceType ); |
68 | 0 | newRequiredAttributes.add(tempList); |
69 | 0 | } |
70 | 0 | } |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
@Override |
78 | |
protected void validateRequiredAttributesAgainstReceived(AttributeSet receivedAttributes){ |
79 | 0 | KimQualificationHelper.validateRequiredAttributesAgainstReceived(newRequiredAttributes, receivedAttributes, isCheckFutureRequests(), COMMA_SEPARATOR); |
80 | 0 | super.validateRequiredAttributesAgainstReceived(receivedAttributes); |
81 | 0 | } |
82 | |
|
83 | |
@Override |
84 | |
public AttributeSet translateInputAttributeSet(AttributeSet qualification) { |
85 | 0 | return KimQualificationHelper.translateInputAttributeSet(super.translateInputAttributeSet(qualification)); |
86 | |
} |
87 | |
|
88 | |
protected Long getDocumentNumber(AttributeSet qualification) throws WorkflowException { |
89 | |
|
90 | 0 | String documentId = qualification.get( KimAttributes.DOCUMENT_NUMBER ); |
91 | 0 | if (StringUtils.isNotEmpty(documentId)) { |
92 | 0 | return Long.valueOf(documentId); |
93 | |
} else { |
94 | 0 | LOG.warn("Could not find workflow document id in qualification list:"); |
95 | 0 | LOG.warn(qualification.formattedDump(20)); |
96 | 0 | return null; |
97 | |
} |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
} |
117 | |
|
118 | |
public boolean isCheckFutureRequests() { |
119 | 0 | return checkFutureRequests; |
120 | |
} |
121 | |
|
122 | |
public void setCheckFutureRequests(boolean checkFutureRequests) { |
123 | 0 | this.checkFutureRequests = checkFutureRequests; |
124 | 0 | } |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
@Override |
138 | |
public List<RoleMembershipInfo> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, AttributeSet paramQualification) { |
139 | 0 | List<RoleMembershipInfo> members = new ArrayList<RoleMembershipInfo>(); |
140 | 0 | validateRequiredAttributesAgainstReceived(paramQualification); |
141 | 0 | AttributeSet qualification = translateInputAttributeSet(paramQualification); |
142 | 0 | Long documentNumber = null; |
143 | |
try { |
144 | 0 | documentNumber = getDocumentNumber(qualification); |
145 | 0 | if (documentNumber != null) { |
146 | 0 | if (INITIATOR_ROLE_NAME.equals(roleName)) { |
147 | 0 | String principalId = getWorkflowUtility().getDocumentInitiatorPrincipalId(documentNumber); |
148 | 0 | members.add( new RoleMembershipInfo(null, null, principalId, Role.PRINCIPAL_MEMBER_TYPE, null) ); |
149 | 0 | } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)) { |
150 | 0 | String[] ids = getWorkflowUtility().getPrincipalIdsInRouteLog(documentNumber, isCheckFutureRequests()); |
151 | 0 | if (ids != null) { |
152 | 0 | for ( String id : ids ) { |
153 | 0 | if ( StringUtils.isNotBlank(id) ) { |
154 | 0 | members.add( new RoleMembershipInfo(null, null, id, Role.PRINCIPAL_MEMBER_TYPE, null) ); |
155 | |
} |
156 | |
} |
157 | |
} |
158 | 0 | } else if(ROUTER_ROLE_NAME.equals(roleName)) { |
159 | 0 | String principalId = getWorkflowUtility().getDocumentRoutedByPrincipalId(documentNumber); |
160 | 0 | members.add( new RoleMembershipInfo(null, null, principalId, Role.PRINCIPAL_MEMBER_TYPE, null) ); |
161 | |
} |
162 | |
} |
163 | 0 | } catch (WorkflowException wex) { |
164 | 0 | LOG.error("Workflow Error: " + wex.getLocalizedMessage(),wex); |
165 | 0 | throw new RuntimeException("Error in getting principal Ids in route log for document number: "+documentNumber+" :"+wex.getLocalizedMessage(),wex); |
166 | 0 | } |
167 | 0 | return members; |
168 | |
} |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
@Override |
174 | |
public boolean hasApplicationRole( |
175 | |
String principalId, List<String> groupIds, String namespaceCode, String roleName, AttributeSet paramQualification){ |
176 | 0 | validateRequiredAttributesAgainstReceived(paramQualification); |
177 | 0 | AttributeSet qualification = translateInputAttributeSet(paramQualification); |
178 | 0 | boolean isUserInRouteLog = false; |
179 | 0 | Long documentNumber = null; |
180 | |
try { |
181 | 0 | documentNumber = getDocumentNumber(qualification); |
182 | 0 | if (documentNumber != null) { |
183 | 0 | if (INITIATOR_ROLE_NAME.equals(roleName)){ |
184 | 0 | isUserInRouteLog = principalId.equals(getWorkflowUtility().getDocumentInitiatorPrincipalId(documentNumber)); |
185 | 0 | } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)){ |
186 | 0 | isUserInRouteLog = getWorkflowUtility().isUserInRouteLog(documentNumber, principalId, isCheckFutureRequests()); |
187 | 0 | } else if(ROUTER_ROLE_NAME.equals(roleName)){ |
188 | 0 | isUserInRouteLog = principalId.equals(getWorkflowUtility().getDocumentRoutedByPrincipalId(documentNumber)); |
189 | |
} |
190 | |
} |
191 | 0 | } catch (WorkflowException wex) { |
192 | 0 | LOG.error("Workflow Error: " + wex.getLocalizedMessage(),wex); |
193 | 0 | throw new RuntimeException("Error in determining whether the principal Id: "+principalId+" is in route log for document number: "+documentNumber+" :"+wex.getLocalizedMessage(),wex); |
194 | 0 | } |
195 | 0 | return isUserInRouteLog; |
196 | |
} |
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
public boolean shouldCacheRoleMembershipResults(String namespaceCode, String roleName) { |
205 | 0 | return false; |
206 | |
} |
207 | |
|
208 | |
protected WorkflowUtility getWorkflowUtility() { |
209 | 0 | return KEWServiceLocator.getWorkflowUtilityService(); |
210 | |
} |
211 | |
|
212 | |
} |