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.core.xml.dto.AttributeSet; |
23 | |
import org.kuali.rice.kew.exception.WorkflowException; |
24 | |
import org.kuali.rice.kew.service.WorkflowInfo; |
25 | |
import org.kuali.rice.kim.bo.Role; |
26 | |
import org.kuali.rice.kim.bo.role.dto.RoleMembershipInfo; |
27 | |
import org.kuali.rice.kim.service.support.KimDelegationTypeService; |
28 | |
import org.kuali.rice.kim.service.support.KimRoleTypeService; |
29 | |
import org.kuali.rice.kim.service.support.impl.KimDerivedRoleTypeServiceBase; |
30 | |
import org.kuali.rice.kim.util.KimConstants; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class RouteLogDerivedRoleTypeServiceImpl extends KimDerivedRoleTypeServiceBase implements KimRoleTypeService, KimDelegationTypeService { |
38 | |
public static final String INITIATOR_ROLE_NAME = "Initiator"; |
39 | |
public static final String INITIATOR_OR_REVIEWER_ROLE_NAME = "Initiator or Reviewer"; |
40 | |
public static final String ROUTER_ROLE_NAME = "Router"; |
41 | |
|
42 | 0 | protected WorkflowInfo workflowInfo = new WorkflowInfo(); |
43 | |
|
44 | |
{ |
45 | |
|
46 | |
|
47 | |
|
48 | 0 | checkRequiredAttributes = true; |
49 | 0 | } |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
@Override |
63 | |
public List<RoleMembershipInfo> getRoleMembersFromApplicationRole(String namespaceCode, String roleName, AttributeSet qualification) { |
64 | 0 | validateRequiredAttributesAgainstReceived(qualification); |
65 | 0 | List<RoleMembershipInfo> members = new ArrayList<RoleMembershipInfo>(); |
66 | 0 | if(qualification!=null && !qualification.isEmpty()){ |
67 | 0 | String documentNumber = qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER); |
68 | 0 | if (StringUtils.isNotBlank(documentNumber)) { |
69 | 0 | Long documentNumberLong = Long.parseLong(documentNumber); |
70 | |
try{ |
71 | 0 | if (INITIATOR_ROLE_NAME.equals(roleName)) { |
72 | 0 | String principalId = workflowInfo.getDocumentInitiatorPrincipalId(documentNumberLong); |
73 | 0 | members.add( new RoleMembershipInfo(null, null, principalId, Role.PRINCIPAL_MEMBER_TYPE, null) ); |
74 | 0 | } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)) { |
75 | 0 | List<String> ids = workflowInfo.getPrincipalIdsInRouteLog(documentNumberLong, true); |
76 | 0 | for ( String id : ids ) { |
77 | 0 | if ( StringUtils.isNotBlank(id) ) { |
78 | 0 | members.add( new RoleMembershipInfo(null, null, id, Role.PRINCIPAL_MEMBER_TYPE, null) ); |
79 | |
} |
80 | |
} |
81 | 0 | } else if(ROUTER_ROLE_NAME.equals(roleName)) { |
82 | 0 | String principalId = workflowInfo.getDocumentRoutedByPrincipalId(documentNumberLong); |
83 | 0 | members.add( new RoleMembershipInfo(null, null, principalId, Role.PRINCIPAL_MEMBER_TYPE, null) ); |
84 | |
} |
85 | 0 | } catch(WorkflowException wex){ |
86 | 0 | throw new RuntimeException( |
87 | |
"Error in getting principal Ids in route log for document number: "+documentNumber+" :"+wex.getLocalizedMessage(),wex); |
88 | 0 | } |
89 | |
} |
90 | |
} |
91 | 0 | return members; |
92 | |
} |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
@Override |
98 | |
public boolean hasApplicationRole( |
99 | |
String principalId, List<String> groupIds, String namespaceCode, String roleName, AttributeSet qualification){ |
100 | 0 | validateRequiredAttributesAgainstReceived(qualification); |
101 | 0 | boolean isUserInRouteLog = false; |
102 | 0 | if(qualification!=null && !qualification.isEmpty()){ |
103 | 0 | String documentNumber = qualification.get(KimConstants.AttributeConstants.DOCUMENT_NUMBER); |
104 | |
try { |
105 | 0 | Long documentNumberLong = Long.parseLong(documentNumber); |
106 | 0 | if (INITIATOR_ROLE_NAME.equals(roleName)){ |
107 | 0 | isUserInRouteLog = principalId.equals(workflowInfo.getDocumentInitiatorPrincipalId(documentNumberLong)); |
108 | 0 | } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)){ |
109 | 0 | isUserInRouteLog = workflowInfo.isUserAuthenticatedByRouteLog(documentNumberLong, principalId, true); |
110 | 0 | } else if(ROUTER_ROLE_NAME.equals(roleName)){ |
111 | 0 | isUserInRouteLog = principalId.equals(workflowInfo.getDocumentRoutedByPrincipalId(documentNumberLong)); |
112 | |
} |
113 | 0 | } catch (NumberFormatException e) { |
114 | 0 | throw new RuntimeException("Invalid (non-numeric) document number: "+documentNumber,e); |
115 | 0 | } catch (WorkflowException wex) { |
116 | 0 | throw new RuntimeException("Error in determining whether the principal Id: "+principalId+" is in route log " + |
117 | |
"for document number: "+documentNumber+" :"+wex.getLocalizedMessage(),wex); |
118 | 0 | } |
119 | |
} |
120 | 0 | return isUserInRouteLog; |
121 | |
} |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
@Override |
129 | |
public boolean shouldCacheRoleMembershipResults(String namespaceCode, |
130 | |
String roleName) { |
131 | 0 | return false; |
132 | |
} |
133 | |
} |