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