View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kim.document;
17  
18  import java.util.ArrayList;
19  import java.util.Comparator;
20  import java.util.List;
21  
22  import javax.persistence.CascadeType;
23  import javax.persistence.Column;
24  import javax.persistence.Convert;
25  import javax.persistence.Entity;
26  import javax.persistence.JoinColumn;
27  import javax.persistence.OneToMany;
28  import javax.persistence.Table;
29  import javax.persistence.Transient;
30  
31  import org.apache.commons.lang.StringUtils;
32  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
33  import org.kuali.rice.kim.api.KimConstants;
34  import org.kuali.rice.kim.api.responsibility.ResponsibilityService;
35  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
36  import org.kuali.rice.kim.api.type.KimAttributeField;
37  import org.kuali.rice.kim.api.type.KimType;
38  import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember;
39  import org.kuali.rice.kim.bo.ui.KimDocumentRolePermission;
40  import org.kuali.rice.kim.bo.ui.KimDocumentRoleQualifier;
41  import org.kuali.rice.kim.bo.ui.KimDocumentRoleResponsibility;
42  import org.kuali.rice.kim.bo.ui.KimDocumentRoleResponsibilityAction;
43  import org.kuali.rice.kim.bo.ui.RoleDocumentDelegation;
44  import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMember;
45  import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMemberQualifier;
46  import org.kuali.rice.kim.impl.responsibility.ResponsibilityInternalService;
47  import org.kuali.rice.kim.impl.services.KimImplServiceLocator;
48  import org.kuali.rice.kim.impl.type.IdentityManagementTypeAttributeTransactionalDocument;
49  import org.kuali.rice.kim.service.KIMServiceLocatorInternal;
50  import org.kuali.rice.kim.web.struts.form.IdentityManagementRoleDocumentForm;
51  import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
52  import org.kuali.rice.krad.data.platform.MaxValueIncrementerFactory;
53  import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
54  import org.springframework.util.AutoPopulatingList;
55  
56  /**
57   * This is a description of what this class does - bhargavp don't forget to fill this in.
58   *
59   * @author Kuali Rice Team (rice.collab@kuali.org)
60   *
61   */
62  @Entity
63  @Table(name = "KRIM_ROLE_DOCUMENT_T")
64  public class IdentityManagementRoleDocument extends IdentityManagementTypeAttributeTransactionalDocument {
65  
66      private static final long serialVersionUID = 1L;
67  
68      // principal data
69      @Column(name = "ROLE_ID")
70      protected String roleId;
71  
72      @Column(name = "ROLE_TYP_ID")
73      protected String roleTypeId;
74  
75      @Transient
76      protected String roleTypeName;
77  
78      @Column(name = "ROLE_NMSPC")
79      protected String roleNamespace = "";
80  
81      @Column(name = "ROLE_NM")
82      protected String roleName = "";
83  
84      @Column(name = "DESC_TXT")
85      protected String roleDescription = "";
86  
87      @Column(name = "ACTV_IND")
88      @Convert(converter = BooleanYNConverter.class)
89      protected boolean active = true;
90  
91      @Transient
92      protected boolean editing;
93  
94      @OneToMany(targetEntity = KimDocumentRolePermission.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST })
95      @JoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR", insertable = false, updatable = false)
96      protected List<KimDocumentRolePermission> permissions = new AutoPopulatingList<KimDocumentRolePermission>(KimDocumentRolePermission.class);
97  
98      @OneToMany(targetEntity = KimDocumentRoleResponsibility.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST })
99      @JoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR", insertable = false, updatable = false)
100     protected List<KimDocumentRoleResponsibility> responsibilities = new AutoPopulatingList<KimDocumentRoleResponsibility>(KimDocumentRoleResponsibility.class);
101 
102     @OneToMany(targetEntity = KimDocumentRoleMember.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST })
103     @JoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR", insertable = false, updatable = false)
104     protected List<KimDocumentRoleMember> modifiedMembers = new AutoPopulatingList<KimDocumentRoleMember>(KimDocumentRoleMember.class);
105 
106     @Transient
107     private List<RoleDocumentDelegationMember> delegationMembers = new AutoPopulatingList<RoleDocumentDelegationMember>(RoleDocumentDelegationMember.class);
108 
109     @OneToMany(targetEntity = RoleDocumentDelegation.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST })
110     @JoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR", insertable = false, updatable = false)
111     private List<RoleDocumentDelegation> delegations = new AutoPopulatingList<RoleDocumentDelegation>(RoleDocumentDelegation.class);
112 
113     @Transient
114     protected List<KimDocumentRoleMember> searchResultMembers = new AutoPopulatingList<KimDocumentRoleMember>(KimDocumentRoleMember.class);
115 
116     @Transient
117     protected List<KimDocumentRoleMember> members = new AutoPopulatingList<KimDocumentRoleMember>(KimDocumentRoleMember.class);
118 
119     @Transient
120     private transient ResponsibilityService responsibilityService;
121 
122     @Transient
123     private transient ResponsibilityInternalService responsibilityInternalService;
124 
125     public IdentityManagementRoleDocument() {
126     }
127 
128     /**
129 	 * @return the active
130 	 */
131     public boolean isActive() {
132         return this.active;
133     }
134 
135     /**
136 	 * @param active the active to set
137 	 */
138     public void setActive(boolean active) {
139         this.active = active;
140     }
141 
142     /**
143 	 * @param roleId the roleId to set
144 	 */
145     public void setRoleId(String roleId) {
146         this.roleId = roleId;
147     }
148 
149     /**
150 	 * @return the roleName
151 	 */
152     public String getRoleName() {
153         return this.roleName;
154     }
155 
156     /**
157 	 * @param roleName the roleName to set
158 	 */
159     public void setRoleName(String roleName) {
160         this.roleName = roleName;
161     }
162 
163     /**
164 	 * @return the roleDescription
165 	 */
166     public String getRoleDescription() {
167         return this.roleDescription;
168     }
169 
170     /**
171 	 * @param roleDescription the roleDescription to set
172 	 */
173     public void setRoleDescription(String roleDescription) {
174         this.roleDescription = roleDescription;
175     }
176 
177     /**
178 	 * @return the roleNamespace
179 	 */
180     public String getRoleNamespace() {
181         return this.roleNamespace;
182     }
183 
184     /**
185 	 * @param roleNamespace the roleNamespace to set
186 	 */
187     public void setRoleNamespace(String roleNamespace) {
188         this.roleNamespace = roleNamespace;
189     }
190 
191     /**
192 	 * @return the roleTypeId
193 	 */
194     public String getRoleTypeId() {
195         return this.roleTypeId;
196     }
197 
198     /**
199 	 * @param roleTypeId the roleTypeId to set
200 	 */
201     public void setRoleTypeId(String roleTypeId) {
202         this.roleTypeId = roleTypeId;
203     }
204 
205     /**
206 	 * @return the roleTypeName
207 	 */
208     public String getRoleTypeName() {
209         if (roleTypeName == null) {
210             if (kimType != null) {
211                 roleTypeName = kimType.getName();
212             } else if (roleTypeId != null) {
213                 setKimType(KimApiServiceLocator.getKimTypeInfoService().getKimType(roleTypeId));
214                 if (kimType != null) {
215                     roleTypeName = kimType.getName();
216                 }
217             }
218         }
219         return this.roleTypeName;
220     }
221 
222     /**
223 	 * @param roleTypeName the roleTypeName to set
224 	 */
225     public void setRoleTypeName(String roleTypeName) {
226         this.roleTypeName = roleTypeName;
227     }
228 
229     /**
230 	 * @return the delegationMembers
231 	 */
232     @Override
233     public List<RoleDocumentDelegationMember> getDelegationMembers() {
234         return this.delegationMembers;
235     }
236 
237     /**
238 	 * @param delegationMembers the delegationMembers to set
239 	 */
240     @Override
241     public void setDelegationMembers(List<RoleDocumentDelegationMember> delegationMembers) {
242         this.delegationMembers = delegationMembers;
243     }
244 
245     /**
246 	 * @return the permissions
247 	 */
248     public List<KimDocumentRolePermission> getPermissions() {
249         return this.permissions;
250     }
251 
252     /**
253 	 * @param permissions the permissions to set
254 	 */
255     public void setPermissions(List<KimDocumentRolePermission> permissions) {
256         this.permissions = permissions;
257     }
258 
259     /**
260 	 * @return the responsibilities
261 	 */
262     public List<KimDocumentRoleResponsibility> getResponsibilities() {
263         return this.responsibilities;
264     }
265 
266     /**
267 	 * @param responsibilities the responsibilities to set
268 	 */
269     public void setResponsibilities(List<KimDocumentRoleResponsibility> responsibilities) {
270         this.responsibilities = responsibilities;
271     }
272 
273     /**
274 	 * @return the members
275 	 */
276     public List<KimDocumentRoleMember> getMembers() {
277         return this.members;
278     }
279 
280     public enum RoleMemberMetaDataType implements Comparator<KimDocumentRoleMember> {
281 
282         MEMBER_ID("memberId"), MEMBER_NAME("memberName"), FULL_MEMBER_NAME("memberFullName");
283 
284         private final String attributeName;
285 
286         RoleMemberMetaDataType(String anAttributeName) {
287             this.attributeName = anAttributeName;
288         }
289 
290         public String getAttributeName() {
291             return attributeName;
292         }
293 
294         @Override
295         public int compare(KimDocumentRoleMember m1, KimDocumentRoleMember m2) {
296             if (m1 == null && m2 == null) {
297                 return 0;
298             } else if (m1 == null) {
299                 return -1;
300             } else if (m2 == null) {
301                 return 1;
302             }
303             if (this.getAttributeName().equals(MEMBER_ID.getAttributeName())) {
304                 return m1.getMemberId().compareToIgnoreCase(m2.getMemberId());
305             } else if (this.getAttributeName().equals(FULL_MEMBER_NAME.getAttributeName())) {
306                 return m1.getMemberFullName().compareToIgnoreCase(m2.getMemberFullName());
307             }
308             return m1.getMemberName().compareToIgnoreCase(m2.getMemberName());
309         }
310     }
311 
312     public void setMemberMetaDataTypeToSort(Integer columnNumber) {
313         switch(columnNumber) {
314             case 1:
315                 this.memberMetaDataType = RoleMemberMetaDataType.MEMBER_ID;
316                 break;
317             case 2:
318                 this.memberMetaDataType = RoleMemberMetaDataType.MEMBER_NAME;
319                 break;
320             case 3:
321                 this.memberMetaDataType = RoleMemberMetaDataType.FULL_MEMBER_NAME;
322                 break;
323             default:
324                 this.memberMetaDataType = RoleMemberMetaDataType.MEMBER_NAME;
325                 break;
326         }
327     }
328 
329     @Transient
330     protected RoleMemberMetaDataType memberMetaDataType = RoleMemberMetaDataType.MEMBER_NAME;
331 
332     public RoleMemberMetaDataType getMemberMetaDataType() {
333         return memberMetaDataType;
334     }
335 
336     public void setMemberMetaDataType(RoleMemberMetaDataType memberMetaDataType) {
337         this.memberMetaDataType = memberMetaDataType;
338     }
339 
340     /**
341 	 * @return the members
342 	 */
343     public KimDocumentRoleMember getMember(String roleMemberId) {
344         if (StringUtils.isEmpty(roleMemberId)) {
345             return null;
346         }
347         for (KimDocumentRoleMember roleMember : getMembers()) {
348             if (roleMemberId.equals(roleMember.getRoleMemberId())) {
349                 return roleMember;
350             }
351         }
352         return null;
353     }
354 
355     /**
356      * @param members the members to set
357      */
358     public void setMembers(List<KimDocumentRoleMember> members) {
359         this.members = members;
360     }
361 
362     /**
363      * @return the modifiedMembers
364      */
365     public List<KimDocumentRoleMember> getModifiedMembers() {
366         return this.modifiedMembers;
367     }
368 
369     /**
370      * @param modifiedMembers the modifiedMembers to set
371      */
372     public void setModifiedMembers(List<KimDocumentRoleMember> modifiedMembers) {
373         this.modifiedMembers = modifiedMembers;
374     }
375 
376     /**
377      * @return the searchResultMembers
378      */
379     public List<KimDocumentRoleMember> getSearchResultMembers() {
380         return this.searchResultMembers;
381     }
382 
383     /**
384      * @param searchResultMembers the searchResultMembers to set
385      */
386     public void setSearchResultMembers(List<KimDocumentRoleMember> searchResultMembers) {
387         this.searchResultMembers = searchResultMembers;
388     }
389 
390     public void addResponsibility(KimDocumentRoleResponsibility roleResponsibility) {
391         if (!getResponsibilityInternalService().areActionsAtAssignmentLevelById(roleResponsibility.getResponsibilityId())) {
392             roleResponsibility.getRoleRspActions().add(getNewRespAction(roleResponsibility));
393         }
394         getResponsibilities().add(roleResponsibility);
395     }
396 
397     protected KimDocumentRoleResponsibilityAction getNewRespAction(KimDocumentRoleResponsibility roleResponsibility) {
398         KimDocumentRoleResponsibilityAction roleRspAction = new KimDocumentRoleResponsibilityAction();
399         roleRspAction.setKimResponsibility(roleResponsibility.getKimResponsibility());
400         roleRspAction.setRoleResponsibilityId(roleResponsibility.getRoleResponsibilityId());
401         return roleRspAction;
402     }
403 
404     public void addDelegationMember(RoleDocumentDelegationMember newDelegationMember) {
405         getDelegationMembers().add(newDelegationMember);
406     }
407 
408     public void addMember(KimDocumentRoleMember member) {
409         DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S);
410         member.setRoleMemberId(incrementer.nextStringValue());
411         setupMemberRspActions(member);
412         getModifiedMembers().add(member);
413     }
414 
415     public KimDocumentRoleMember getBlankMember() {
416         KimDocumentRoleMember member = new KimDocumentRoleMember();
417         KimDocumentRoleQualifier qualifier;
418         if (getDefinitions() != null) {
419             for (KimAttributeField key : getDefinitions()) {
420                 qualifier = new KimDocumentRoleQualifier();
421                 qualifier.setKimAttrDefnId(getKimAttributeDefnId(key));
422                 member.getQualifiers().add(qualifier);
423             }
424         }
425         setupMemberRspActions(member);
426         return member;
427     }
428 
429     public RoleDocumentDelegationMember getBlankDelegationMember() {
430         RoleDocumentDelegationMember member = new RoleDocumentDelegationMember();
431         RoleDocumentDelegationMemberQualifier qualifier;
432         if (getDefinitions() != null) {
433             for (KimAttributeField key : getDefinitions()) {
434                 qualifier = new RoleDocumentDelegationMemberQualifier();
435                 setAttrDefnIdForDelMemberQualifier(qualifier, key);
436                 member.getQualifiers().add(qualifier);
437             }
438         }
439         return member;
440     }
441 
442     public void setupMemberRspActions(KimDocumentRoleMember member) {
443         member.getRoleRspActions().clear();
444         for (KimDocumentRoleResponsibility roleResp : getResponsibilities()) {
445             if (getResponsibilityInternalService().areActionsAtAssignmentLevelById(roleResp.getResponsibilityId())) {
446                 KimDocumentRoleResponsibilityAction action = new KimDocumentRoleResponsibilityAction();
447                 action.setRoleResponsibilityId("*");
448                 action.setRoleMemberId(member.getRoleMemberId());
449                 member.getRoleRspActions().add(action);
450                 break;
451             }
452         }
453     }
454 
455     public void updateMembers(IdentityManagementRoleDocumentForm roleDocumentForm) {
456         for (KimDocumentRoleMember member : roleDocumentForm.getRoleDocument().getMembers()) {
457             roleDocumentForm.getRoleDocument().setupMemberRspActions(member);
458         }
459     }
460 
461     public void updateMembers(KimDocumentRoleResponsibility newResponsibility) {
462         for (KimDocumentRoleMember member : getMembers()) {
463             setupMemberRspActions(newResponsibility, member);
464         }
465     }
466 
467     public void setupMemberRspActions(KimDocumentRoleResponsibility roleResp, KimDocumentRoleMember member) {
468         if ((member.getRoleRspActions() == null || member.getRoleRspActions().size() < 1) && getResponsibilityInternalService().areActionsAtAssignmentLevelById(roleResp.getResponsibilityId())) {
469             KimDocumentRoleResponsibilityAction action = new KimDocumentRoleResponsibilityAction();
470             action.setRoleResponsibilityId("*");
471             action.setRoleMemberId(member.getRoleMemberId());
472             if (member.getRoleRspActions() == null) {
473                 member.setRoleRspActions(new ArrayList<KimDocumentRoleResponsibilityAction>());
474             }
475             member.getRoleRspActions().add(action);
476         }
477     }
478 
479     protected void setAttrDefnIdForDelMemberQualifier(RoleDocumentDelegationMemberQualifier qualifier, KimAttributeField definition) {
480         qualifier.setKimAttrDefnId(definition.getId());
481     }
482 
483     /**
484      * @see org.kuali.rice.krad.document.DocumentBase#doRouteStatusChange(org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange)
485      */
486     @Override
487     public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
488         super.doRouteStatusChange(statusChangeEvent);
489         if (getDocumentHeader().getWorkflowDocument().isProcessed()) {
490             KIMServiceLocatorInternal.getUiDocumentService().saveRole(this);
491         }
492     }
493 
494     public void initializeDocumentForNewRole() {
495         if (StringUtils.isBlank(this.roleId)) {
496             DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), KimConstants.SequenceNames.KRIM_ROLE_ID_S);
497             this.roleId = incrementer.nextStringValue();
498         }
499         if (StringUtils.isBlank(this.roleTypeId)) {
500             this.roleTypeId = "1";
501         }
502     }
503 
504     public String getRoleId() {
505         if (StringUtils.isBlank(this.roleId)) {
506             initializeDocumentForNewRole();
507         }
508         return roleId;
509     }
510 
511     @Override
512     public void prepareForSave() {
513         String roleId;
514         if (StringUtils.isBlank(getRoleId())) {
515             DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), KimConstants.SequenceNames.KRIM_ROLE_ID_S);
516             roleId = incrementer.nextStringValue();
517             setRoleId(roleId);
518         } else {
519             roleId = getRoleId();
520         }
521         if (getPermissions() != null) {
522             for (KimDocumentRolePermission permission : getPermissions()) {
523                 permission.setRoleId(roleId);
524                 permission.setDocumentNumber(getDocumentNumber());
525                 if (StringUtils.isBlank(permission.getRolePermissionId())) {
526                     DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), KimConstants.SequenceNames.KRIM_ROLE_PERM_ID_S);
527                     permission.setRolePermissionId(incrementer.nextStringValue());
528                 }
529             }
530         }
531         if (getResponsibilities() != null) {
532             for (KimDocumentRoleResponsibility responsibility : getResponsibilities()) {
533                 String nextRoleResponsibilityId = null;
534 
535                 if (StringUtils.isBlank(responsibility.getRoleResponsibilityId())) {
536                     DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), KimConstants.SequenceNames.KRIM_ROLE_RSP_ID_S);
537                     nextRoleResponsibilityId = incrementer.nextStringValue();
538                     responsibility.setRoleResponsibilityId(nextRoleResponsibilityId);
539                 } else{
540                     responsibility.setDocumentNumber(getDocumentNumber());
541                     responsibility.setVersionNumber(null);
542                 }
543 
544                 responsibility.setRoleId(roleId);
545                 if (!getResponsibilityInternalService().areActionsAtAssignmentLevelById(responsibility.getResponsibilityId())) {
546                     if (StringUtils.isBlank(responsibility.getRoleRspActions().get(0).getRoleResponsibilityActionId())) {
547                         DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), KimConstants.SequenceNames.KRIM_ROLE_RSP_ACTN_ID_S);
548                         responsibility.getRoleRspActions().get(0).setRoleResponsibilityActionId(incrementer.nextStringValue());
549                     }
550 
551                     if (StringUtils.isBlank(responsibility.getRoleRspActions().get(0).getRoleResponsibilityId())) {
552                         if (StringUtils.isBlank(nextRoleResponsibilityId)) {
553                             responsibility.getRoleRspActions().get(0).setRoleResponsibilityId(responsibility.getRoleResponsibilityId());
554                         } else {
555                             responsibility.getRoleRspActions().get(0).setRoleResponsibilityId(nextRoleResponsibilityId);
556                         }
557                     }
558 
559                     responsibility.getRoleRspActions().get(0).setRoleMemberId("*");
560                     responsibility.getRoleRspActions().get(0).setDocumentNumber(getDocumentNumber());
561                 }
562             }
563         }
564         if (getModifiedMembers() != null) {
565             for (KimDocumentRoleMember member : getModifiedMembers()) {
566                 member.setDocumentNumber(getDocumentNumber());
567                 member.setRoleId(roleId);
568                 if (StringUtils.isBlank(member.getRoleMemberId())) {
569                     DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), KimConstants.SequenceNames.KRIM_ROLE_MBR_ID_S);
570                     member.setRoleMemberId(incrementer.nextStringValue());
571                 }
572                 for (KimDocumentRoleQualifier qualifier : member.getQualifiers()) {
573                     qualifier.setDocumentNumber(getDocumentNumber());
574                     qualifier.setKimTypId(getKimType().getId());
575                 }
576                 for (KimDocumentRoleResponsibilityAction roleRespAction : member.getRoleRspActions()) {
577                     if (StringUtils.isBlank(roleRespAction.getRoleResponsibilityActionId())) {
578                         DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), KimConstants.SequenceNames.KRIM_ROLE_RSP_ACTN_ID_S);
579                         roleRespAction.setRoleResponsibilityActionId(incrementer.nextStringValue());
580                     }
581                     roleRespAction.setRoleMemberId(member.getRoleMemberId());
582                     roleRespAction.setDocumentNumber(getDocumentNumber());
583                     if (!StringUtils.equals(roleRespAction.getRoleResponsibilityId(), "*")) {
584                         for (KimDocumentRoleResponsibility responsibility : getResponsibilities()) {
585                             if (StringUtils.equals(roleRespAction.getKimResponsibility().getId(), responsibility.getResponsibilityId())) {
586                                 roleRespAction.setRoleResponsibilityId(responsibility.getRoleResponsibilityId());
587                             }
588                         }
589                     }
590                     // This will cause a problem with JPA
591 //                    if (roleRespAction.getVersionNumber() == null) {
592 //                        roleRespAction.setVersionNumber(new Long(1));
593 //                    }
594                 }
595             }
596         }
597         if (getDelegationMembers() != null) {
598             for (RoleDocumentDelegationMember delegationMember : getDelegationMembers()) {
599                 delegationMember.setDocumentNumber(getDocumentNumber());
600                 addDelegationMemberToDelegation(delegationMember);
601             }
602             for (RoleDocumentDelegation delegation : getDelegations()) {
603                 delegation.setDocumentNumber(getDocumentNumber());
604                 delegation.setKimTypeId(getKimType().getId());
605                 List<RoleDocumentDelegationMember> membersToRemove = new AutoPopulatingList<RoleDocumentDelegationMember>(RoleDocumentDelegationMember.class);
606                 for (RoleDocumentDelegationMember member : delegation.getMembers()) {
607                     if (delegation.getDelegationId().equals(member.getDelegationId()) && delegation.getDelegationTypeCode().equals(member.getDelegationTypeCode())) {
608                         for (RoleDocumentDelegationMemberQualifier qualifier : member.getQualifiers()) {
609                             qualifier.setKimTypId(getKimType().getId());
610                         }
611                     } else {
612                         membersToRemove.add(member);
613                     }
614                 }
615                 if (!membersToRemove.isEmpty()) {
616                     for (RoleDocumentDelegationMember member : membersToRemove) {
617                         delegation.getMembers().remove(member);
618                     }
619                 }
620                 delegation.setRoleId(roleId);
621             }
622         }
623     }
624 
625     public ResponsibilityService getResponsibilityService() {
626         if (responsibilityService == null) {
627             responsibilityService = KimApiServiceLocator.getResponsibilityService();
628         }
629         return responsibilityService;
630     }
631 
632     public ResponsibilityInternalService getResponsibilityInternalService() {
633         if (responsibilityInternalService == null) {
634             responsibilityInternalService = KimImplServiceLocator.getResponsibilityInternalService();
635         }
636         return responsibilityInternalService;
637     }
638 
639     /**
640 	 * @return the editing
641 	 */
642     public boolean isEditing() {
643         return this.editing;
644     }
645 
646     /**
647 	 * @param editing the editing to set
648 	 */
649     public void setEditing(boolean editing) {
650         this.editing = editing;
651     }
652 
653     /**
654 	 * @return the delegations
655 	 */
656     @Override
657     public List<RoleDocumentDelegation> getDelegations() {
658         return this.delegations;
659     }
660 
661     /**
662 	 * @param delegations the delegations to set
663 	 */
664     @Override
665     public void setDelegations(List<RoleDocumentDelegation> delegations) {
666         this.delegations = delegations;
667     }
668 
669     @Override
670     public void setKimType(KimType kimType) {
671         super.setKimType(kimType);
672         if (kimType != null) {
673             setRoleTypeId(kimType.getId());
674             setRoleTypeName(kimType.getName());
675         }
676     }
677 }