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