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 public class ResponsibilityInternalServiceImpl implements ResponsibilityInternalService {
46
47 private BusinessObjectService businessObjectService;
48
49 public void saveRoleMember(RoleMemberImpl roleMember){
50
51
52 List<RoleResponsibilityInfo> oldRoleResp = getRoleResponsibilities(roleMember.getRoleId());
53
54
55 getBusinessObjectService().save( roleMember );
56
57
58
59 List<RoleResponsibilityInfo> newRoleResp = getRoleResponsibilities(roleMember.getRoleId());
60
61 updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(oldRoleResp, newRoleResp));
62 }
63
64 public void removeRoleMember(RoleMemberImpl roleMember){
65
66 List<RoleResponsibilityInfo> oldRoleResp = getRoleResponsibilities(roleMember.getRoleId());
67
68
69 getBusinessObjectService().delete( roleMember );
70
71
72
73 List<RoleResponsibilityInfo> newRoleResp = getRoleResponsibilities(roleMember.getRoleId());
74
75 updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(oldRoleResp, newRoleResp));
76 }
77
78 @SuppressWarnings("unchecked")
79 public void updateActionRequestsForRoleChange(String roleId) {
80 List<RoleResponsibilityInfo> newRoleResp = getRoleResponsibilities(roleId);
81
82 updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(Collections.EMPTY_LIST, newRoleResp));
83 }
84
85
86
87
88
89
90
91 public void updateActionRequestsForResponsibilityChange(Set<String> responsibilityIds) {
92
93 KSBXMLService responsibilityChangeProcessor = (KSBXMLService) KSBServiceLocator.getMessageHelper()
94 .getServiceAsynchronously(new QName(MessageServiceNames.RESPONSIBILITY_CHANGE_SERVICE));
95 try {
96 responsibilityChangeProcessor.invoke(ResponsibilityChangeProcessor.getResponsibilityChangeContents(responsibilityIds));
97
98 } catch (Exception e) {
99 throw new WorkflowRuntimeException(e);
100 }
101
102 }
103
104 @SuppressWarnings("unchecked")
105 public List<RoleResponsibilityInfo> getRoleResponsibilities(String roleId){
106 List<RoleResponsibilityImpl> roleResponsibilities =
107 (List<RoleResponsibilityImpl>)getBusinessObjectService()
108 .findMatching(RoleResponsibilityImpl.class, Collections.singletonMap(KimConstants.PrimaryKeyConstants.ROLE_ID, roleId));
109 List<RoleResponsibilityInfo> result = new ArrayList<RoleResponsibilityInfo>( roleResponsibilities.size() );
110 for ( RoleResponsibilityImpl roleResp : roleResponsibilities ) {
111 result.add( roleResp.toSimpleInfo() );
112 }
113
114 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 Set<String> lRet = new HashSet<String>();
129
130 for (RoleResponsibilityInfo resp : oldRespList) {
131 lRet.add(resp.getResponsibilityId());
132 }
133 for (RoleResponsibilityInfo resp : newRespList) {
134 lRet.add(resp.getResponsibilityId());
135 }
136
137 return lRet;
138 }
139
140 protected BusinessObjectService getBusinessObjectService() {
141 if ( businessObjectService == null ) {
142 businessObjectService = KNSServiceLocator.getBusinessObjectService();
143 }
144 return businessObjectService;
145 }
146
147 }