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 | |
public static final String DERIVED_INITIATOR_ROLE_NAME = "Derived Role: Initiator"; |
46 | |
public static final String DERIVED_INITIATOR_OR_REVIEWER_ROLE_NAME = "Derived Role: Initiator or Reviewer"; |
47 | |
public static final String DERIVED_ROUTER_ROLE_NAME = "Derived Role: Router"; |
48 | |
|
49 | 0 | private boolean checkFutureRequests = false; |
50 | 0 | protected Set<List<String>> newRequiredAttributes = new HashSet<List<String>>(); |
51 | |
|
52 | |
{ |
53 | 0 | checkRequiredAttributes = true; |
54 | |
|
55 | 0 | List<String> listOne = new ArrayList<String>(); |
56 | 0 | listOne.add( KimAttributes.DOCUMENT_NUMBER ); |
57 | 0 | newRequiredAttributes.add(listOne); |
58 | |
|
59 | 0 | List<String> listTwo = new ArrayList<String>(); |
60 | 0 | listTwo.add( KimAttributes.DOCUMENT_TYPE_NAME ); |
61 | 0 | listTwo.add( StudentIdentityConstants.QUALIFICATION_KEW_OBJECT_ID ); |
62 | 0 | newRequiredAttributes.add(listTwo); |
63 | |
|
64 | 0 | List<String> listThree = new ArrayList<String>(); |
65 | 0 | listThree.add( StudentIdentityConstants.QUALIFICATION_KEW_OBJECT_ID ); |
66 | 0 | listThree.add( StudentIdentityConstants.QUALIFICATION_KEW_OBJECT_TYPE ); |
67 | 0 | newRequiredAttributes.add(listThree); |
68 | |
|
69 | 0 | for (String proposalReferenceType : StudentIdentityConstants.QUALIFICATION_PROPOSAL_ID_REF_TYPES) { |
70 | 0 | List<String> tempList = new ArrayList<String>(); |
71 | 0 | tempList.add( proposalReferenceType ); |
72 | 0 | newRequiredAttributes.add(tempList); |
73 | 0 | } |
74 | 0 | } |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
@Override |
82 | |
protected void validateRequiredAttributesAgainstReceived(AttributeSet receivedAttributes){ |
83 | 0 | KimQualificationHelper.validateRequiredAttributesAgainstReceived(newRequiredAttributes, receivedAttributes, isCheckFutureRequests(), COMMA_SEPARATOR); |
84 | 0 | super.validateRequiredAttributesAgainstReceived(receivedAttributes); |
85 | 0 | } |
86 | |
|
87 | |
@Override |
88 | |
public AttributeSet translateInputAttributeSet(AttributeSet qualification) { |
89 | 0 | return KimQualificationHelper.translateInputAttributeSet(super.translateInputAttributeSet(qualification)); |
90 | |
} |
91 | |
|
92 | |
protected Long getDocumentNumber(AttributeSet qualification) throws WorkflowException { |
93 | |
|
94 | 0 | String documentId = qualification.get( KimAttributes.DOCUMENT_NUMBER ); |
95 | 0 | if (StringUtils.isNotEmpty(documentId)) { |
96 | 0 | return Long.valueOf(documentId); |
97 | |
} else { |
98 | 0 | LOG.warn("Could not find workflow document id in qualification list:"); |
99 | 0 | LOG.warn(qualification.formattedDump(20)); |
100 | 0 | return null; |
101 | |
} |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
} |
121 | |
|
122 | |
public boolean isCheckFutureRequests() { |
123 | 0 | return checkFutureRequests; |
124 | |
} |
125 | |
|
126 | |
public void setCheckFutureRequests(boolean checkFutureRequests) { |
127 | 0 | this.checkFutureRequests = checkFutureRequests; |
128 | 0 | } |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
@Override |
142 | |
public List<RoleMembershipInfo> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, AttributeSet paramQualification) { |
143 | 0 | List<RoleMembershipInfo> members = new ArrayList<RoleMembershipInfo>(); |
144 | 0 | validateRequiredAttributesAgainstReceived(paramQualification); |
145 | 0 | AttributeSet qualification = translateInputAttributeSet(paramQualification); |
146 | 0 | Long documentNumber = null; |
147 | |
try { |
148 | 0 | documentNumber = getDocumentNumber(qualification); |
149 | 0 | if (documentNumber != null) { |
150 | 0 | if (INITIATOR_ROLE_NAME.equals(roleName)||DERIVED_INITIATOR_ROLE_NAME.equals(roleName)) { |
151 | 0 | String principalId = getWorkflowUtility().getDocumentInitiatorPrincipalId(documentNumber); |
152 | 0 | members.add( new RoleMembershipInfo(null, null, principalId, Role.PRINCIPAL_MEMBER_TYPE, null) ); |
153 | 0 | } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)||DERIVED_INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)) { |
154 | 0 | String[] ids = getWorkflowUtility().getPrincipalIdsInRouteLog(documentNumber, isCheckFutureRequests()); |
155 | 0 | if (ids != null) { |
156 | 0 | for ( String id : ids ) { |
157 | 0 | if ( StringUtils.isNotBlank(id) ) { |
158 | 0 | members.add( new RoleMembershipInfo(null, null, id, Role.PRINCIPAL_MEMBER_TYPE, null) ); |
159 | |
} |
160 | |
} |
161 | |
} |
162 | 0 | } else if(ROUTER_ROLE_NAME.equals(roleName)||DERIVED_ROUTER_ROLE_NAME.equals(roleName)) { |
163 | 0 | String principalId = getWorkflowUtility().getDocumentRoutedByPrincipalId(documentNumber); |
164 | 0 | members.add( new RoleMembershipInfo(null, null, principalId, Role.PRINCIPAL_MEMBER_TYPE, null) ); |
165 | |
} |
166 | |
} |
167 | 0 | } catch (WorkflowException wex) { |
168 | 0 | LOG.error("Workflow Error: " + wex.getLocalizedMessage(),wex); |
169 | 0 | throw new RuntimeException("Error in getting principal Ids in route log for document number: "+documentNumber+" :"+wex.getLocalizedMessage(),wex); |
170 | 0 | } |
171 | 0 | return members; |
172 | |
} |
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
@Override |
178 | |
public boolean hasApplicationRole( |
179 | |
String principalId, List<String> groupIds, String namespaceCode, String roleName, AttributeSet paramQualification){ |
180 | 0 | validateRequiredAttributesAgainstReceived(paramQualification); |
181 | 0 | AttributeSet qualification = translateInputAttributeSet(paramQualification); |
182 | 0 | boolean isUserInRouteLog = false; |
183 | 0 | Long documentNumber = null; |
184 | |
try { |
185 | 0 | documentNumber = getDocumentNumber(qualification); |
186 | 0 | if (documentNumber != null) { |
187 | 0 | if (INITIATOR_ROLE_NAME.equals(roleName)||DERIVED_INITIATOR_ROLE_NAME.equals(roleName)){ |
188 | 0 | isUserInRouteLog = principalId.equals(getWorkflowUtility().getDocumentInitiatorPrincipalId(documentNumber)); |
189 | 0 | } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)||DERIVED_INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)){ |
190 | 0 | isUserInRouteLog = getWorkflowUtility().isUserInRouteLog(documentNumber, principalId, isCheckFutureRequests()); |
191 | 0 | } else if(ROUTER_ROLE_NAME.equals(roleName)||DERIVED_ROUTER_ROLE_NAME.equals(roleName)){ |
192 | 0 | isUserInRouteLog = principalId.equals(getWorkflowUtility().getDocumentRoutedByPrincipalId(documentNumber)); |
193 | |
} |
194 | |
} |
195 | 0 | } catch (WorkflowException wex) { |
196 | 0 | LOG.error("Workflow Error: " + wex.getLocalizedMessage(),wex); |
197 | 0 | throw new RuntimeException("Error in determining whether the principal Id: "+principalId+" is in route log for document number: "+documentNumber+" :"+wex.getLocalizedMessage(),wex); |
198 | 0 | } |
199 | 0 | return isUserInRouteLog; |
200 | |
} |
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
public boolean shouldCacheRoleMembershipResults(String namespaceCode, String roleName) { |
209 | 0 | return false; |
210 | |
} |
211 | |
|
212 | |
protected WorkflowUtility getWorkflowUtility() { |
213 | 0 | return KEWServiceLocator.getWorkflowUtilityService(); |
214 | |
} |
215 | |
|
216 | |
} |