1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.responsibility; |
17 | |
|
18 | |
import org.kuali.rice.kew.api.WorkflowRuntimeException; |
19 | |
import org.kuali.rice.kew.messaging.MessageServiceNames; |
20 | |
import org.kuali.rice.kew.responsibility.ResponsibilityChangeProcessor; |
21 | |
import org.kuali.rice.kew.util.KEWConstants; |
22 | |
import org.kuali.rice.kim.api.responsibility.Responsibility; |
23 | |
import org.kuali.rice.kim.api.responsibility.ResponsibilityService; |
24 | |
import org.kuali.rice.kim.api.role.RoleResponsibility; |
25 | |
import org.kuali.rice.kim.impl.role.RoleMemberBo; |
26 | |
import org.kuali.rice.kim.impl.role.RoleResponsibilityBo; |
27 | |
import org.kuali.rice.kim.util.KimConstants; |
28 | |
import org.kuali.rice.krad.service.BusinessObjectService; |
29 | |
import org.kuali.rice.krad.service.KRADServiceLocator; |
30 | |
import org.kuali.rice.ksb.api.KsbApiServiceLocator; |
31 | |
import org.kuali.rice.ksb.messaging.service.KSBXMLService; |
32 | |
|
33 | |
import javax.xml.namespace.QName; |
34 | |
import java.util.ArrayList; |
35 | |
import java.util.Collections; |
36 | |
import java.util.HashSet; |
37 | |
import java.util.List; |
38 | |
import java.util.Map; |
39 | |
import java.util.Set; |
40 | |
|
41 | 0 | public class ResponsibilityInternalServiceImpl implements ResponsibilityInternalService { |
42 | |
|
43 | |
private BusinessObjectService businessObjectService; |
44 | |
private ResponsibilityService responsibilityService; |
45 | |
|
46 | |
public void saveRoleMember(RoleMemberBo roleMember){ |
47 | |
|
48 | |
|
49 | 0 | List<RoleResponsibility> oldRoleResp = getRoleResponsibilities(roleMember.getRoleId()); |
50 | |
|
51 | |
|
52 | 0 | getBusinessObjectService().save( roleMember ); |
53 | |
|
54 | |
|
55 | |
|
56 | 0 | List<RoleResponsibility> newRoleResp = getRoleResponsibilities(roleMember.getRoleId()); |
57 | |
|
58 | 0 | updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(oldRoleResp, newRoleResp)); |
59 | 0 | } |
60 | |
|
61 | |
public void removeRoleMember(RoleMemberBo roleMember){ |
62 | |
|
63 | 0 | List<RoleResponsibility> oldRoleResp = getRoleResponsibilities(roleMember.getRoleId()); |
64 | |
|
65 | |
|
66 | 0 | getBusinessObjectService().delete( roleMember ); |
67 | |
|
68 | |
|
69 | |
|
70 | 0 | List<RoleResponsibility> newRoleResp = getRoleResponsibilities(roleMember.getRoleId()); |
71 | |
|
72 | 0 | updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(oldRoleResp, newRoleResp)); |
73 | 0 | } |
74 | |
|
75 | |
@SuppressWarnings("unchecked") |
76 | |
public void updateActionRequestsForRoleChange(String roleId) { |
77 | 0 | List<RoleResponsibility> newRoleResp = getRoleResponsibilities(roleId); |
78 | |
|
79 | 0 | updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(Collections.EMPTY_LIST, newRoleResp)); |
80 | 0 | } |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public void updateActionRequestsForResponsibilityChange(Set<String> responsibilityIds) { |
89 | |
|
90 | 0 | KSBXMLService responsibilityChangeProcessor = (KSBXMLService) KsbApiServiceLocator.getMessageHelper() |
91 | |
.getServiceAsynchronously(new QName(KEWConstants.KEW_MODULE_NAMESPACE, MessageServiceNames.RESPONSIBILITY_CHANGE_SERVICE)); |
92 | |
try { |
93 | 0 | responsibilityChangeProcessor.invoke(ResponsibilityChangeProcessor.getResponsibilityChangeContents(responsibilityIds)); |
94 | |
|
95 | 0 | } catch (Exception e) { |
96 | 0 | throw new WorkflowRuntimeException(e); |
97 | 0 | } |
98 | |
|
99 | 0 | } |
100 | |
|
101 | |
@SuppressWarnings("unchecked") |
102 | |
public List<RoleResponsibility> getRoleResponsibilities(String roleId){ |
103 | 0 | List<RoleResponsibilityBo> rrBoList = |
104 | |
(List<RoleResponsibilityBo>)getBusinessObjectService() |
105 | |
.findMatching(RoleResponsibilityBo.class, Collections.singletonMap(KimConstants.PrimaryKeyConstants.ROLE_ID, roleId)); |
106 | 0 | List<RoleResponsibility> result = new ArrayList<RoleResponsibility>( rrBoList.size() ); |
107 | 0 | for ( RoleResponsibilityBo bo : rrBoList ) { |
108 | 0 | result.add( RoleResponsibilityBo.to(bo) ); |
109 | |
} |
110 | 0 | return result; |
111 | |
} |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
protected Set<String> getChangedRoleResponsibilityIds( |
122 | |
List<RoleResponsibility> oldRespList, |
123 | |
List<RoleResponsibility> newRespList) { |
124 | 0 | Set<String> lRet = new HashSet<String>(); |
125 | |
|
126 | 0 | for (RoleResponsibility resp : oldRespList) { |
127 | 0 | lRet.add(resp.getResponsibilityId()); |
128 | |
} |
129 | 0 | for (RoleResponsibility resp : newRespList) { |
130 | 0 | lRet.add(resp.getResponsibilityId()); |
131 | |
} |
132 | |
|
133 | 0 | return lRet; |
134 | |
} |
135 | |
|
136 | |
protected BusinessObjectService getBusinessObjectService() { |
137 | 0 | if ( businessObjectService == null ) { |
138 | 0 | businessObjectService = KRADServiceLocator.getBusinessObjectService(); |
139 | |
} |
140 | 0 | return businessObjectService; |
141 | |
} |
142 | |
|
143 | |
public boolean areActionsAtAssignmentLevel(Responsibility responsibility ) { |
144 | 0 | Map<String, String> details = responsibility.getAttributes(); |
145 | 0 | if ( details == null ) { |
146 | 0 | return false; |
147 | |
} |
148 | 0 | String actionDetailsAtRoleMemberLevel = details.get( KimConstants.AttributeConstants.ACTION_DETAILS_AT_ROLE_MEMBER_LEVEL ); |
149 | 0 | return Boolean.valueOf(actionDetailsAtRoleMemberLevel); |
150 | |
} |
151 | |
|
152 | |
public boolean areActionsAtAssignmentLevelById( String responsibilityId ) { |
153 | 0 | Responsibility responsibility = responsibilityService.getResponsibility(responsibilityId); |
154 | 0 | if ( responsibility == null ) { |
155 | 0 | return false; |
156 | |
} |
157 | 0 | return areActionsAtAssignmentLevel(responsibility); |
158 | |
} |
159 | |
|
160 | |
} |