1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.service.impl; |
17 | |
|
18 | |
import org.apache.commons.collections.CollectionUtils; |
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.apache.log4j.Logger; |
21 | |
import org.kuali.rice.core.util.AttributeSet; |
22 | |
import org.kuali.rice.kim.bo.Role; |
23 | |
import org.kuali.rice.kim.bo.impl.RoleImpl; |
24 | |
import org.kuali.rice.kim.bo.role.dto.RoleMemberCompleteInfo; |
25 | |
import org.kuali.rice.kim.bo.role.impl.KimDelegationImpl; |
26 | |
import org.kuali.rice.kim.bo.role.impl.KimDelegationMemberAttributeDataImpl; |
27 | |
import org.kuali.rice.kim.bo.role.impl.KimDelegationMemberImpl; |
28 | |
import org.kuali.rice.kim.bo.role.impl.RoleMemberAttributeDataImpl; |
29 | |
import org.kuali.rice.kim.bo.role.impl.RoleMemberImpl; |
30 | |
import org.kuali.rice.kim.bo.role.impl.RolePermissionImpl; |
31 | |
import org.kuali.rice.kim.bo.role.impl.RoleResponsibilityActionImpl; |
32 | |
import org.kuali.rice.kim.service.RoleUpdateService; |
33 | |
import org.kuali.rice.kim.util.KIMWebServiceConstants; |
34 | |
import org.kuali.rice.kim.util.KimConstants; |
35 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
36 | |
import org.kuali.rice.kns.service.SequenceAccessorService; |
37 | |
|
38 | |
import javax.jws.WebService; |
39 | |
import java.sql.Date; |
40 | |
import java.util.ArrayList; |
41 | |
import java.util.HashMap; |
42 | |
import java.util.List; |
43 | |
import java.util.Map; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
@WebService(endpointInterface = KIMWebServiceConstants.RoleUpdateService.INTERFACE_CLASS, serviceName = KIMWebServiceConstants.RoleUpdateService.WEB_SERVICE_NAME, portName = KIMWebServiceConstants.RoleUpdateService.WEB_SERVICE_PORT, targetNamespace = KIMWebServiceConstants.MODULE_TARGET_NAMESPACE) |
51 | 0 | public class RoleUpdateServiceImpl extends RoleServiceBase implements RoleUpdateService { |
52 | 0 | private static final Logger LOG = Logger.getLogger( RoleUpdateServiceImpl.class ); |
53 | |
|
54 | |
public void assignGroupToRole(String groupId, String namespaceCode, String roleName, AttributeSet qualifier) { |
55 | |
|
56 | 0 | RoleImpl role = getRoleImplByName( namespaceCode, roleName ); |
57 | |
|
58 | 0 | if ( doAnyMemberRecordsMatch( role.getMembers(), groupId, Role.GROUP_MEMBER_TYPE, qualifier ) ) { |
59 | 0 | return; |
60 | |
} |
61 | |
|
62 | 0 | RoleMemberImpl newRoleMember = new RoleMemberImpl(); |
63 | |
|
64 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
65 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
66 | |
KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S, RoleMemberImpl.class); |
67 | 0 | newRoleMember.setRoleMemberId( nextSeq.toString() ); |
68 | |
|
69 | 0 | newRoleMember.setRoleId( role.getRoleId() ); |
70 | 0 | newRoleMember.setMemberId( groupId ); |
71 | 0 | newRoleMember.setMemberTypeCode( Role.GROUP_MEMBER_TYPE ); |
72 | |
|
73 | |
|
74 | 0 | addMemberAttributeData( newRoleMember, qualifier, role.getKimTypeId() ); |
75 | |
|
76 | |
|
77 | 0 | getResponsibilityInternalService().saveRoleMember(newRoleMember); |
78 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
79 | 0 | } |
80 | |
|
81 | |
public void assignPrincipalToRole(String principalId, String namespaceCode, String roleName, AttributeSet qualifier) { |
82 | |
|
83 | 0 | RoleImpl role = getRoleImplByName( namespaceCode, roleName ); |
84 | 0 | role.refreshReferenceObject("members"); |
85 | |
|
86 | |
|
87 | 0 | if ( doAnyMemberRecordsMatch( role.getMembers(), principalId, Role.PRINCIPAL_MEMBER_TYPE, qualifier ) ) { |
88 | 0 | return; |
89 | |
} |
90 | |
|
91 | 0 | RoleMemberImpl newRoleMember = new RoleMemberImpl(); |
92 | |
|
93 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
94 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
95 | |
KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S, RoleMemberImpl.class ); |
96 | 0 | newRoleMember.setRoleMemberId( nextSeq.toString() ); |
97 | |
|
98 | 0 | newRoleMember.setRoleId( role.getRoleId() ); |
99 | 0 | newRoleMember.setMemberId( principalId ); |
100 | 0 | newRoleMember.setMemberTypeCode( Role.PRINCIPAL_MEMBER_TYPE ); |
101 | |
|
102 | |
|
103 | 0 | addMemberAttributeData( newRoleMember, qualifier, role.getKimTypeId() ); |
104 | |
|
105 | |
|
106 | |
|
107 | 0 | getResponsibilityInternalService().saveRoleMember(newRoleMember); |
108 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
109 | 0 | } |
110 | |
|
111 | |
public void assignRoleToRole(String roleId, String namespaceCode, String roleName, AttributeSet qualifier) { |
112 | |
|
113 | 0 | RoleImpl role = getRoleImplByName( namespaceCode, roleName ); |
114 | |
|
115 | 0 | if ( doAnyMemberRecordsMatch( role.getMembers(), roleId, Role.ROLE_MEMBER_TYPE, qualifier ) ) { |
116 | 0 | return; |
117 | |
} |
118 | |
|
119 | 0 | if ( !checkForCircularRoleMembership( roleId, role) ){ |
120 | 0 | throw new IllegalArgumentException("Circular role reference."); |
121 | |
} |
122 | |
|
123 | 0 | RoleMemberImpl newRoleMember = new RoleMemberImpl(); |
124 | |
|
125 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
126 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
127 | |
KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S, RoleMemberImpl.class); |
128 | 0 | newRoleMember.setRoleMemberId( nextSeq.toString() ); |
129 | |
|
130 | 0 | newRoleMember.setRoleId( role.getRoleId() ); |
131 | 0 | newRoleMember.setMemberId( roleId ); |
132 | 0 | newRoleMember.setMemberTypeCode( Role.ROLE_MEMBER_TYPE ); |
133 | |
|
134 | 0 | addMemberAttributeData( newRoleMember, qualifier, role.getKimTypeId() ); |
135 | |
|
136 | |
|
137 | 0 | getResponsibilityInternalService().saveRoleMember(newRoleMember); |
138 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
139 | 0 | } |
140 | |
|
141 | |
public void removeGroupFromRole(String groupId, String namespaceCode, String roleName, AttributeSet qualifier) { |
142 | |
|
143 | 0 | RoleImpl role = getRoleImplByName( namespaceCode, roleName ); |
144 | |
|
145 | |
|
146 | 0 | for ( RoleMemberImpl rm : role.getMembers() ) { |
147 | 0 | if ( doesMemberMatch( rm, groupId, Role.GROUP_MEMBER_TYPE, qualifier ) ) { |
148 | |
|
149 | |
|
150 | 0 | getResponsibilityInternalService().removeRoleMember(rm); |
151 | |
} |
152 | |
} |
153 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
154 | 0 | } |
155 | |
|
156 | |
public void removePrincipalFromRole(String principalId, String namespaceCode, String roleName, AttributeSet qualifier ) { |
157 | |
|
158 | 0 | RoleImpl role = getRoleImplByName( namespaceCode, roleName ); |
159 | |
|
160 | 0 | role.refreshReferenceObject("members"); |
161 | |
|
162 | 0 | for ( RoleMemberImpl rm : role.getMembers() ) { |
163 | 0 | if ( doesMemberMatch( rm, principalId, Role.PRINCIPAL_MEMBER_TYPE, qualifier ) ) { |
164 | |
|
165 | |
|
166 | 0 | getResponsibilityInternalService().removeRoleMember(rm); |
167 | |
} |
168 | |
} |
169 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
170 | 0 | } |
171 | |
|
172 | |
public void removeRoleFromRole(String roleId, String namespaceCode, String roleName, AttributeSet qualifier) { |
173 | |
|
174 | 0 | RoleImpl role = getRoleImplByName( namespaceCode, roleName ); |
175 | |
|
176 | |
|
177 | 0 | for ( RoleMemberImpl rm : role.getMembers() ) { |
178 | 0 | if ( doesMemberMatch( rm, roleId, Role.ROLE_MEMBER_TYPE, qualifier ) ) { |
179 | |
|
180 | |
|
181 | 0 | getResponsibilityInternalService().removeRoleMember(rm); |
182 | |
} |
183 | |
} |
184 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
185 | 0 | } |
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
public void saveDelegationMemberForRole(String delegationMemberId, |
194 | |
String roleMemberId, String memberId, String memberTypeCode, String delegationTypeCode, |
195 | |
String roleId, AttributeSet qualifications, Date activeFromDate, Date activeToDate) throws UnsupportedOperationException{ |
196 | 0 | if(StringUtils.isEmpty(delegationMemberId) && StringUtils.isEmpty(memberId) && StringUtils.isEmpty(roleId)){ |
197 | 0 | throw new IllegalArgumentException("Either Delegation member ID or a combination of member ID and role ID must be passed in."); |
198 | |
} |
199 | |
|
200 | 0 | RoleImpl role = getRoleImpl(roleId); |
201 | 0 | KimDelegationImpl delegation = getDelegationOfType(role.getRoleId(), delegationTypeCode); |
202 | |
|
203 | 0 | KimDelegationMemberImpl newDelegationMember = new KimDelegationMemberImpl(); |
204 | |
|
205 | 0 | KimDelegationMemberImpl origDelegationMember = null; |
206 | 0 | if(StringUtils.isNotEmpty(delegationMemberId)){ |
207 | 0 | origDelegationMember = getKimDelegationMemberImpl(delegationMemberId); |
208 | |
} else{ |
209 | 0 | List<KimDelegationMemberImpl> origDelegationMembers = |
210 | |
getKimDelegationMemberImplListByMemberAndDelegationId(memberId, delegation.getDelegationId()); |
211 | 0 | origDelegationMember = |
212 | |
(origDelegationMembers!=null && origDelegationMembers.size()>0) ? origDelegationMembers.get(0) : null; |
213 | |
} |
214 | 0 | if(origDelegationMember!=null){ |
215 | 0 | newDelegationMember.setDelegationMemberId(origDelegationMember.getDelegationMemberId()); |
216 | 0 | newDelegationMember.setVersionNumber(origDelegationMember.getVersionNumber()); |
217 | |
} else{ |
218 | 0 | newDelegationMember.setDelegationMemberId(getNewDelegationMemberId()); |
219 | |
} |
220 | 0 | newDelegationMember.setMemberId(memberId); |
221 | 0 | newDelegationMember.setDelegationId(delegation.getDelegationId()); |
222 | 0 | newDelegationMember.setRoleMemberId(roleMemberId); |
223 | 0 | newDelegationMember.setMemberTypeCode(memberTypeCode); |
224 | 0 | if (activeFromDate != null) { |
225 | 0 | newDelegationMember.setActiveFromDate(new java.sql.Timestamp(activeFromDate.getTime())); |
226 | |
} |
227 | 0 | if (activeToDate != null) { |
228 | 0 | newDelegationMember.setActiveToDate(new java.sql.Timestamp(activeToDate.getTime())); |
229 | |
} |
230 | |
|
231 | |
|
232 | 0 | addDelegationMemberAttributeData( newDelegationMember, qualifications, role.getKimTypeId() ); |
233 | |
|
234 | 0 | List<KimDelegationMemberImpl> delegationMembers = new ArrayList<KimDelegationMemberImpl>(); |
235 | 0 | delegationMembers.add(newDelegationMember); |
236 | 0 | delegation.setMembers(delegationMembers); |
237 | |
|
238 | 0 | getBusinessObjectService().save(delegation); |
239 | 0 | for(KimDelegationMemberImpl delegationMember: delegation.getMembers()){ |
240 | 0 | deleteNullDelegationMemberAttributeData(delegationMember.getAttributes()); |
241 | |
} |
242 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
243 | 0 | } |
244 | |
|
245 | |
public RoleMemberCompleteInfo saveRoleMemberForRole(String roleMemberId, String memberId, String memberTypeCode, String roleId, |
246 | |
AttributeSet qualifications, Date activeFromDate, Date activeToDate) throws UnsupportedOperationException{ |
247 | 0 | if(StringUtils.isEmpty(roleMemberId) && StringUtils.isEmpty(memberId) && StringUtils.isEmpty(roleId)){ |
248 | 0 | throw new IllegalArgumentException("Either Role member ID or a combination of member ID and role ID must be passed in."); |
249 | |
} |
250 | 0 | RoleMemberImpl origRoleMember = null; |
251 | |
RoleImpl role; |
252 | |
|
253 | 0 | RoleMemberImpl newRoleMember = new RoleMemberImpl(); |
254 | 0 | if(StringUtils.isEmpty(roleMemberId)){ |
255 | |
|
256 | 0 | role = getRoleImpl(roleId); |
257 | |
|
258 | 0 | origRoleMember = matchingMemberRecord( role.getMembers(), memberId, memberTypeCode, qualifications ); |
259 | |
} else{ |
260 | 0 | origRoleMember = getRoleMemberImpl(roleMemberId); |
261 | 0 | role = getRoleImpl(origRoleMember.getRoleId()); |
262 | |
} |
263 | |
|
264 | 0 | if(origRoleMember !=null){ |
265 | 0 | newRoleMember.setRoleMemberId(origRoleMember.getRoleMemberId()); |
266 | 0 | newRoleMember.setVersionNumber(origRoleMember.getVersionNumber()); |
267 | |
} else { |
268 | |
|
269 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
270 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
271 | |
KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S, RoleMemberImpl.class); |
272 | 0 | newRoleMember.setRoleMemberId( nextSeq.toString() ); |
273 | |
} |
274 | 0 | newRoleMember.setRoleId(role.getRoleId()); |
275 | 0 | newRoleMember.setMemberId( memberId ); |
276 | 0 | newRoleMember.setMemberTypeCode( memberTypeCode ); |
277 | 0 | if (activeFromDate != null) { |
278 | 0 | newRoleMember.setActiveFromDate(new java.sql.Timestamp(activeFromDate.getTime())); |
279 | |
} |
280 | 0 | if (activeToDate != null) { |
281 | 0 | newRoleMember.setActiveToDate(new java.sql.Timestamp(activeToDate.getTime())); |
282 | |
} |
283 | |
|
284 | 0 | addMemberAttributeData( newRoleMember, qualifications, role.getKimTypeId() ); |
285 | |
|
286 | |
|
287 | 0 | getResponsibilityInternalService().saveRoleMember(newRoleMember); |
288 | 0 | deleteNullMemberAttributeData(newRoleMember.getAttributes()); |
289 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
290 | |
|
291 | 0 | return findRoleMemberCompleteInfo(newRoleMember.getRoleMemberId()); |
292 | |
} |
293 | |
|
294 | |
public void saveRoleRspActions(String roleResponsibilityActionId, String roleId, String roleResponsibilityId, String roleMemberId, |
295 | |
String actionTypeCode, String actionPolicyCode, Integer priorityNumber, Boolean forceAction){ |
296 | 0 | RoleResponsibilityActionImpl newRoleRspAction = new RoleResponsibilityActionImpl(); |
297 | 0 | newRoleRspAction.setActionPolicyCode(actionPolicyCode); |
298 | 0 | newRoleRspAction.setActionTypeCode(actionTypeCode); |
299 | 0 | newRoleRspAction.setPriorityNumber(priorityNumber); |
300 | 0 | newRoleRspAction.setForceAction(forceAction); |
301 | 0 | newRoleRspAction.setRoleMemberId(roleMemberId); |
302 | 0 | newRoleRspAction.setRoleResponsibilityId(roleResponsibilityId); |
303 | 0 | if(StringUtils.isEmpty(roleResponsibilityActionId)){ |
304 | |
|
305 | 0 | Map<String, String> criteria = new HashMap<String, String>(1); |
306 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.ROLE_RESPONSIBILITY_ID, roleResponsibilityId); |
307 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID, roleMemberId); |
308 | 0 | List<RoleResponsibilityActionImpl> roleResponsibilityActionImpls = (List<RoleResponsibilityActionImpl>) |
309 | |
getBusinessObjectService().findMatching(RoleResponsibilityActionImpl.class, criteria); |
310 | 0 | if(roleResponsibilityActionImpls!=null && roleResponsibilityActionImpls.size()>0){ |
311 | 0 | newRoleRspAction.setRoleResponsibilityActionId(roleResponsibilityActionImpls.get(0).getRoleResponsibilityActionId()); |
312 | 0 | newRoleRspAction.setVersionNumber(roleResponsibilityActionImpls.get(0).getVersionNumber()); |
313 | |
} else{ |
314 | |
|
315 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
316 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
317 | |
KimConstants.SequenceNames.KRIM_ROLE_RSP_ACTN_ID_S, RoleResponsibilityActionImpl.class); |
318 | 0 | newRoleRspAction.setRoleResponsibilityActionId(nextSeq.toString()); |
319 | |
} |
320 | 0 | } else{ |
321 | 0 | Map<String, String> criteria = new HashMap<String, String>(1); |
322 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.ROLE_RESPONSIBILITY_ACTION_ID, roleResponsibilityActionId); |
323 | 0 | List<RoleResponsibilityActionImpl> roleResponsibilityActionImpls = (List<RoleResponsibilityActionImpl>) |
324 | |
getBusinessObjectService().findMatching(RoleResponsibilityActionImpl.class, criteria); |
325 | 0 | if(CollectionUtils.isNotEmpty(roleResponsibilityActionImpls) && roleResponsibilityActionImpls.size()>0){ |
326 | 0 | newRoleRspAction.setRoleResponsibilityActionId(roleResponsibilityActionImpls.get(0).getRoleResponsibilityActionId()); |
327 | 0 | newRoleRspAction.setVersionNumber(roleResponsibilityActionImpls.get(0).getVersionNumber()); |
328 | |
} |
329 | |
} |
330 | 0 | getBusinessObjectService().save(newRoleRspAction); |
331 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
332 | 0 | } |
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
private void deleteNullMemberAttributeData(List<RoleMemberAttributeDataImpl> attributes) { |
339 | 0 | List<RoleMemberAttributeDataImpl> attributesToDelete = new ArrayList<RoleMemberAttributeDataImpl>(); |
340 | 0 | for(RoleMemberAttributeDataImpl attribute: attributes){ |
341 | 0 | if(attribute.getAttributeValue()==null){ |
342 | 0 | attributesToDelete.add(attribute); |
343 | |
} |
344 | |
} |
345 | 0 | getBusinessObjectService().delete(attributesToDelete); |
346 | 0 | } |
347 | |
|
348 | |
private void deleteNullDelegationMemberAttributeData(List<KimDelegationMemberAttributeDataImpl> attributes) { |
349 | 0 | List<KimDelegationMemberAttributeDataImpl> attributesToDelete = new ArrayList<KimDelegationMemberAttributeDataImpl>(); |
350 | 0 | for(KimDelegationMemberAttributeDataImpl attribute: attributes){ |
351 | 0 | if(attribute.getAttributeValue()==null){ |
352 | 0 | attributesToDelete.add(attribute); |
353 | |
} |
354 | |
} |
355 | 0 | getBusinessObjectService().delete(attributesToDelete); |
356 | 0 | } |
357 | |
|
358 | |
protected void addMemberAttributeData( RoleMemberImpl roleMember, AttributeSet qualifier, String kimTypeId ) { |
359 | 0 | List<RoleMemberAttributeDataImpl> attributes = new ArrayList<RoleMemberAttributeDataImpl>(); |
360 | 0 | for ( String attributeName : qualifier.keySet() ) { |
361 | 0 | RoleMemberAttributeDataImpl a = new RoleMemberAttributeDataImpl(); |
362 | 0 | a.setAttributeValue( qualifier.get( attributeName ) ); |
363 | 0 | a.setKimTypeId( kimTypeId ); |
364 | 0 | a.setAssignedToId(roleMember.getRoleMemberId()); |
365 | |
|
366 | 0 | a.setKimAttributeId( getKimAttributeId( attributeName ) ); |
367 | |
|
368 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
369 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.KIM_ATTRIBUTE_ID, a.getKimAttributeId()); |
370 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.ROLE_MEMBER_ID, roleMember.getRoleMemberId()); |
371 | 0 | List<RoleMemberAttributeDataImpl> origRoleMemberAttributes = |
372 | |
(List<RoleMemberAttributeDataImpl>)getBusinessObjectService().findMatching(RoleMemberAttributeDataImpl.class, criteria); |
373 | 0 | RoleMemberAttributeDataImpl origRoleMemberAttribute = |
374 | |
(origRoleMemberAttributes!=null && origRoleMemberAttributes.size()>0) ? origRoleMemberAttributes.get(0) : null; |
375 | 0 | if(origRoleMemberAttribute!=null){ |
376 | 0 | a.setId(origRoleMemberAttribute.getId()); |
377 | 0 | a.setVersionNumber(origRoleMemberAttribute.getVersionNumber()); |
378 | |
} else{ |
379 | |
|
380 | 0 | a.setId(getNewAttributeDataId()); |
381 | |
} |
382 | 0 | attributes.add( a ); |
383 | 0 | } |
384 | 0 | roleMember.setAttributes( attributes ); |
385 | 0 | } |
386 | |
|
387 | |
protected void addDelegationMemberAttributeData( KimDelegationMemberImpl delegationMember, AttributeSet qualifier, String kimTypeId ) { |
388 | 0 | List<KimDelegationMemberAttributeDataImpl> attributes = new ArrayList<KimDelegationMemberAttributeDataImpl>(); |
389 | 0 | for ( String attributeName : qualifier.keySet() ) { |
390 | 0 | KimDelegationMemberAttributeDataImpl a = new KimDelegationMemberAttributeDataImpl(); |
391 | 0 | a.setAttributeValue( qualifier.get( attributeName ) ); |
392 | 0 | a.setKimTypeId( kimTypeId ); |
393 | 0 | a.setAssignedToId(delegationMember.getDelegationMemberId()); |
394 | |
|
395 | 0 | a.setKimAttributeId( getKimAttributeId( attributeName ) ); |
396 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
397 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.KIM_ATTRIBUTE_ID, a.getKimAttributeId()); |
398 | 0 | criteria.put(KimConstants.PrimaryKeyConstants.DELEGATION_MEMBER_ID, delegationMember.getDelegationMemberId()); |
399 | 0 | List<KimDelegationMemberAttributeDataImpl> origDelegationMemberAttributes = |
400 | |
(List<KimDelegationMemberAttributeDataImpl>)getBusinessObjectService().findMatching(KimDelegationMemberAttributeDataImpl.class, criteria); |
401 | 0 | KimDelegationMemberAttributeDataImpl origDelegationMemberAttribute = |
402 | |
(origDelegationMemberAttributes!=null && origDelegationMemberAttributes.size()>0) ? origDelegationMemberAttributes.get(0) : null; |
403 | 0 | if(origDelegationMemberAttribute!=null){ |
404 | 0 | a.setId(origDelegationMemberAttribute.getId()); |
405 | 0 | a.setVersionNumber(origDelegationMemberAttribute.getVersionNumber()); |
406 | |
} else{ |
407 | |
|
408 | 0 | a.setId(getNewAttributeDataId()); |
409 | |
} |
410 | 0 | attributes.add( a ); |
411 | 0 | } |
412 | 0 | delegationMember.setAttributes( attributes ); |
413 | 0 | } |
414 | |
|
415 | |
public void saveRole(String roleId, String roleName, String roleDescription, boolean active, String kimTypeId, String namespaceCode) throws UnsupportedOperationException { |
416 | |
|
417 | 0 | RoleImpl role = getBusinessObjectService().findBySinglePrimaryKey(RoleImpl.class, roleId); |
418 | 0 | if (role == null) { |
419 | 0 | role = new RoleImpl(); |
420 | 0 | role.setRoleId(roleId); |
421 | |
} |
422 | |
|
423 | 0 | role.setRoleName(roleName); |
424 | 0 | role.setRoleDescription(roleDescription); |
425 | 0 | role.setActive(active); |
426 | 0 | role.setKimTypeId(kimTypeId); |
427 | 0 | role.setNamespaceCode(namespaceCode); |
428 | |
|
429 | 0 | getBusinessObjectService().save(role); |
430 | 0 | } |
431 | |
|
432 | |
public String getNextAvailableRoleId() throws UnsupportedOperationException { |
433 | 0 | Long nextSeq = KNSServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S, RoleImpl.class); |
434 | |
|
435 | 0 | if (nextSeq == null) { |
436 | 0 | LOG.error("Unable to get new role id from sequence " + KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S); |
437 | 0 | throw new RuntimeException("Unable to get new role id from sequence " + KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S); |
438 | |
} |
439 | |
|
440 | 0 | return nextSeq.toString(); |
441 | |
} |
442 | |
|
443 | |
public void assignPermissionToRole(String permissionId, String roleId) throws UnsupportedOperationException { |
444 | 0 | RolePermissionImpl newRolePermission = new RolePermissionImpl(); |
445 | |
|
446 | 0 | Long nextSeq = KNSServiceLocator.getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_ROLE_PERM_ID_S, RolePermissionImpl.class); |
447 | |
|
448 | 0 | if (nextSeq == null) { |
449 | 0 | LOG.error("Unable to get new role permission id from sequence " + KimConstants.SequenceNames.KRIM_ROLE_PERM_ID_S); |
450 | 0 | throw new RuntimeException("Unable to get new role permission id from sequence " + KimConstants.SequenceNames.KRIM_ROLE_PERM_ID_S); |
451 | |
} |
452 | |
|
453 | 0 | newRolePermission.setRolePermissionId(nextSeq.toString()); |
454 | 0 | newRolePermission.setRoleId(roleId); |
455 | 0 | newRolePermission.setPermissionId(permissionId); |
456 | 0 | newRolePermission.setActive(true); |
457 | |
|
458 | 0 | getBusinessObjectService().save(newRolePermission); |
459 | 0 | getIdentityManagementNotificationService().roleUpdated(); |
460 | 0 | } |
461 | |
} |