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