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