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