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 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.core.api.mo.common.Attributes; |
27 | |
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
28 | |
import org.kuali.rice.kew.messaging.MessageServiceNames; |
29 | |
import org.kuali.rice.kew.responsibility.ResponsibilityChangeProcessor; |
30 | |
import org.kuali.rice.kim.api.responsibility.Responsibility; |
31 | |
import org.kuali.rice.kim.api.responsibility.ResponsibilityService; |
32 | |
import org.kuali.rice.kim.bo.role.dto.RoleResponsibilityInfo; |
33 | |
import org.kuali.rice.kim.bo.role.impl.RoleMemberImpl; |
34 | |
import org.kuali.rice.kim.bo.role.impl.RoleResponsibilityImpl; |
35 | |
import org.kuali.rice.kim.util.KimConstants; |
36 | |
import org.kuali.rice.kns.service.BusinessObjectService; |
37 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
38 | |
import org.kuali.rice.ksb.api.KsbApiServiceLocator; |
39 | |
import org.kuali.rice.ksb.messaging.service.KSBXMLService; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 0 | public class ResponsibilityInternalServiceImpl implements ResponsibilityInternalService { |
48 | |
|
49 | |
private BusinessObjectService businessObjectService; |
50 | |
private ResponsibilityService responsibilityService; |
51 | |
|
52 | |
public void saveRoleMember(RoleMemberImpl roleMember){ |
53 | |
|
54 | |
|
55 | 0 | List<RoleResponsibilityInfo> oldRoleResp = getRoleResponsibilities(roleMember.getRoleId()); |
56 | |
|
57 | |
|
58 | 0 | getBusinessObjectService().save( roleMember ); |
59 | |
|
60 | |
|
61 | |
|
62 | 0 | List<RoleResponsibilityInfo> newRoleResp = getRoleResponsibilities(roleMember.getRoleId()); |
63 | |
|
64 | 0 | updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(oldRoleResp, newRoleResp)); |
65 | 0 | } |
66 | |
|
67 | |
public void removeRoleMember(RoleMemberImpl roleMember){ |
68 | |
|
69 | 0 | List<RoleResponsibilityInfo> oldRoleResp = getRoleResponsibilities(roleMember.getRoleId()); |
70 | |
|
71 | |
|
72 | 0 | getBusinessObjectService().delete( roleMember ); |
73 | |
|
74 | |
|
75 | |
|
76 | 0 | List<RoleResponsibilityInfo> newRoleResp = getRoleResponsibilities(roleMember.getRoleId()); |
77 | |
|
78 | 0 | updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(oldRoleResp, newRoleResp)); |
79 | 0 | } |
80 | |
|
81 | |
@SuppressWarnings("unchecked") |
82 | |
public void updateActionRequestsForRoleChange(String roleId) { |
83 | 0 | List<RoleResponsibilityInfo> newRoleResp = getRoleResponsibilities(roleId); |
84 | |
|
85 | 0 | updateActionRequestsForResponsibilityChange(getChangedRoleResponsibilityIds(Collections.EMPTY_LIST, newRoleResp)); |
86 | 0 | } |
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
public void updateActionRequestsForResponsibilityChange(Set<String> responsibilityIds) { |
95 | |
|
96 | 0 | KSBXMLService responsibilityChangeProcessor = (KSBXMLService) KsbApiServiceLocator.getMessageHelper() |
97 | |
.getServiceAsynchronously(new QName(MessageServiceNames.RESPONSIBILITY_CHANGE_SERVICE)); |
98 | |
try { |
99 | 0 | responsibilityChangeProcessor.invoke(ResponsibilityChangeProcessor.getResponsibilityChangeContents(responsibilityIds)); |
100 | |
|
101 | 0 | } catch (Exception e) { |
102 | 0 | throw new WorkflowRuntimeException(e); |
103 | 0 | } |
104 | |
|
105 | 0 | } |
106 | |
|
107 | |
@SuppressWarnings("unchecked") |
108 | |
public List<RoleResponsibilityInfo> getRoleResponsibilities(String roleId){ |
109 | 0 | List<RoleResponsibilityImpl> roleResponsibilities = |
110 | |
(List<RoleResponsibilityImpl>)getBusinessObjectService() |
111 | |
.findMatching(RoleResponsibilityImpl.class, Collections.singletonMap(KimConstants.PrimaryKeyConstants.ROLE_ID, roleId)); |
112 | 0 | List<RoleResponsibilityInfo> result = new ArrayList<RoleResponsibilityInfo>( roleResponsibilities.size() ); |
113 | 0 | for ( RoleResponsibilityImpl roleResp : roleResponsibilities ) { |
114 | 0 | result.add( roleResp.toSimpleInfo() ); |
115 | |
} |
116 | |
|
117 | 0 | return result; |
118 | |
} |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
protected Set<String> getChangedRoleResponsibilityIds( |
129 | |
List<RoleResponsibilityInfo> oldRespList, |
130 | |
List<RoleResponsibilityInfo> newRespList) { |
131 | 0 | Set<String> lRet = new HashSet<String>(); |
132 | |
|
133 | 0 | for (RoleResponsibilityInfo resp : oldRespList) { |
134 | 0 | lRet.add(resp.getResponsibilityId()); |
135 | |
} |
136 | 0 | for (RoleResponsibilityInfo resp : newRespList) { |
137 | 0 | lRet.add(resp.getResponsibilityId()); |
138 | |
} |
139 | |
|
140 | 0 | return lRet; |
141 | |
} |
142 | |
|
143 | |
protected BusinessObjectService getBusinessObjectService() { |
144 | 0 | if ( businessObjectService == null ) { |
145 | 0 | businessObjectService = KNSServiceLocator.getBusinessObjectService(); |
146 | |
} |
147 | 0 | return businessObjectService; |
148 | |
} |
149 | |
|
150 | |
public boolean areActionsAtAssignmentLevel(Responsibility responsibility ) { |
151 | 0 | Attributes details = responsibility.getAttributes(); |
152 | 0 | if ( details == null ) { |
153 | 0 | return false; |
154 | |
} |
155 | 0 | String actionDetailsAtRoleMemberLevel = details.get( KimConstants.AttributeConstants.ACTION_DETAILS_AT_ROLE_MEMBER_LEVEL ); |
156 | 0 | return Boolean.valueOf(actionDetailsAtRoleMemberLevel); |
157 | |
} |
158 | |
|
159 | |
public boolean areActionsAtAssignmentLevelById( String responsibilityId ) { |
160 | 0 | Responsibility responsibility = responsibilityService.getResponsibility(responsibilityId); |
161 | 0 | if ( responsibility == null ) { |
162 | 0 | return false; |
163 | |
} |
164 | 0 | return areActionsAtAssignmentLevel(responsibility); |
165 | |
} |
166 | |
|
167 | |
} |