View Javadoc

1   /*
2    * Copyright 2010 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.service.impl;
17  
18  import org.apache.commons.collections.CollectionUtils;
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.rice.kim.api.group.Group;
21  import org.kuali.rice.kim.api.identity.address.EntityAddress;
22  import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
23  import org.kuali.rice.kim.api.identity.email.EntityEmail;
24  import org.kuali.rice.kim.api.identity.employment.EntityEmployment;
25  import org.kuali.rice.kim.api.identity.entity.Entity;
26  import org.kuali.rice.kim.api.identity.name.EntityName;
27  import org.kuali.rice.kim.api.identity.phone.EntityPhone;
28  import org.kuali.rice.kim.api.identity.principal.Principal;
29  import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfo;
30  import org.kuali.rice.kim.api.role.Role;
31  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
32  import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember;
33  import org.kuali.rice.kim.bo.ui.PersonDocumentAddress;
34  import org.kuali.rice.kim.bo.ui.PersonDocumentAffiliation;
35  import org.kuali.rice.kim.bo.ui.PersonDocumentEmail;
36  import org.kuali.rice.kim.bo.ui.PersonDocumentEmploymentInfo;
37  import org.kuali.rice.kim.bo.ui.PersonDocumentName;
38  import org.kuali.rice.kim.bo.ui.PersonDocumentPhone;
39  import org.kuali.rice.kim.document.IdentityManagementPersonDocument;
40  import org.kuali.rice.kim.document.IdentityManagementRoleDocument;
41  import org.kuali.rice.kim.framework.services.KimFrameworkServiceLocator;
42  import org.kuali.rice.kim.framework.type.KimTypeService;
43  import org.kuali.rice.kim.impl.common.delegate.DelegateBo;
44  import org.kuali.rice.kim.impl.group.GroupBo;
45  import org.kuali.rice.kim.impl.group.GroupMemberBo;
46  import org.kuali.rice.kim.impl.identity.entity.EntityBo;
47  import org.kuali.rice.kim.impl.identity.principal.PrincipalBo;
48  import org.kuali.rice.kim.impl.role.RoleBo;
49  import org.kuali.rice.kim.impl.role.RoleMemberAttributeDataBo;
50  import org.kuali.rice.kim.impl.role.RoleMemberBo;
51  import org.kuali.rice.kim.impl.role.RoleResponsibilityActionBo;
52  import org.kuali.rice.kim.util.KimCommonUtilsInternal;
53  import org.kuali.rice.kim.util.KimConstants;
54  import org.kuali.rice.krad.bo.BusinessObject;
55  import org.kuali.rice.krad.bo.PersistableBusinessObject;
56  import org.kuali.rice.krad.document.Document;
57  import org.kuali.rice.krad.util.ObjectUtils;
58  
59  import java.sql.Timestamp;
60  import java.util.ArrayList;
61  import java.util.Collections;
62  import java.util.HashMap;
63  import java.util.List;
64  import java.util.Map;
65  
66  /** 
67   * Customized version of the UiDocumentServiceImpl to support LDAP communcation
68   *
69   * @author Leo Przybylski (przybyls@arizona.edu)
70   */
71  public class LdapUiDocumentServiceImpl extends org.kuali.rice.kim.service.impl.UiDocumentServiceImpl {
72  
73  	/**
74  	 *
75  	 * @see org.kuali.rice.kim.service.UiDocumentService#loadEntityToPersonDoc(IdentityManagementPersonDocument, String)
76  	 */
77  	public void loadEntityToPersonDoc(IdentityManagementPersonDocument identityManagementPersonDocument, String principalId) {
78  		Principal principal = this.getIdentityService().getPrincipal(principalId);
79          if(principal==null) {
80          	throw new RuntimeException("Principal does not exist for principal id:"+principalId);
81          }
82  
83          identityManagementPersonDocument.setPrincipalId(principal.getPrincipalId());
84          identityManagementPersonDocument.setPrincipalName(principal.getPrincipalName());
85          identityManagementPersonDocument.setPassword(principal.getPassword());
86          identityManagementPersonDocument.setActive(principal.isActive());
87          Entity kimEntity = this.getIdentityService().getEntity(principal.getEntityId());
88  		identityManagementPersonDocument.setEntityId(kimEntity.getId());
89  		if ( ObjectUtils.isNotNull( kimEntity.getPrivacyPreferences() ) ) {
90  			identityManagementPersonDocument.setPrivacy(loadPrivacyReferences(kimEntity.getPrivacyPreferences()));
91  		}
92  		//identityManagementPersonDocument.setActive(kimEntity.isActive());
93  		identityManagementPersonDocument.setAffiliations(loadAffiliations(kimEntity.getAffiliations(),kimEntity.getEmploymentInformation()));
94  		identityManagementPersonDocument.setNames(loadNames( identityManagementPersonDocument, principalId, kimEntity.getNames(), identityManagementPersonDocument.getPrivacy().isSuppressName() ));
95  		EntityTypeContactInfo entityType = null;
96  		for (EntityTypeContactInfo type : kimEntity.getEntityTypeContactInfos()) {
97  			if (KimConstants.EntityTypes.PERSON.equals(type.getEntityTypeCode())) {
98  				entityType = EntityTypeContactInfo.Builder.create(type).build();
99  			}
100 		}
101 
102 		if(entityType!=null){
103 			identityManagementPersonDocument.setEmails(loadEmails(identityManagementPersonDocument, principalId, entityType.getEmailAddresses(), identityManagementPersonDocument.getPrivacy().isSuppressEmail()));
104 			identityManagementPersonDocument.setPhones(loadPhones(identityManagementPersonDocument, principalId, entityType.getPhoneNumbers(), identityManagementPersonDocument.getPrivacy().isSuppressPhone()));
105 			identityManagementPersonDocument.setAddrs(loadAddresses(identityManagementPersonDocument, principalId, entityType.getAddresses(), identityManagementPersonDocument.getPrivacy().isSuppressAddress()));
106 		}
107 
108 		List<Group> groups = getGroupService().getGroups(getGroupService().getDirectGroupIdsForPrincipal(identityManagementPersonDocument.getPrincipalId()));
109 		loadGroupToPersonDoc(identityManagementPersonDocument, groups);
110 		loadRoleToPersonDoc(identityManagementPersonDocument);
111 		loadDelegationsToPersonDoc(identityManagementPersonDocument);
112 	}
113 
114 	protected String getInitiatorPrincipalId(Document document){
115 		try{
116 			return document.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
117 		} catch(Exception ex){
118 			return null;
119 		}
120 	}
121 
122 	/**
123 	 * @see org.kuali.rice.kim.service.UiDocumentService#saveEntityPerson(IdentityManagementPersonDocument)
124 	 */
125     public void saveEntityPerson(IdentityManagementPersonDocument identityManagementPersonDocument) {
126         final Entity kimEntity = getIdentityService().getEntity(identityManagementPersonDocument.getEntityId());
127 		boolean creatingNew = false;
128 
129 		String initiatorPrincipalId = getInitiatorPrincipalId(identityManagementPersonDocument);
130 		boolean inactivatingPrincipal = false;
131 
132 		List <GroupMemberBo>  groupPrincipals = populateGroupMembers(identityManagementPersonDocument);
133 		List <RoleMemberBo>  rolePrincipals = populateRoleMembers(identityManagementPersonDocument);
134 		List <DelegateBo> personDelegations = populateDelegations(identityManagementPersonDocument);
135 		List <PersistableBusinessObject> bos = new ArrayList<PersistableBusinessObject>();
136 		List <RoleResponsibilityActionBo> roleRspActions = populateRoleRspActions(identityManagementPersonDocument);
137 		List <RoleMemberAttributeDataBo> blankRoleMemberAttrs = getBlankRoleMemberAttrs(rolePrincipals);
138 		//if(ObjectUtils.isNotNull(kimEntity.getPrivacyPreferences()))
139 		//	bos.add(kimEntity.getPrivacyPreferences());
140 		bos.addAll(groupPrincipals);
141 		bos.addAll(rolePrincipals);
142 		bos.addAll(roleRspActions);
143 		bos.addAll(personDelegations);
144 		// boservice.save(bos) does not handle deleteawarelist
145 		getBusinessObjectService().save(bos);
146 
147 		if (!blankRoleMemberAttrs.isEmpty()) {
148 			getBusinessObjectService().delete(blankRoleMemberAttrs);
149 		}
150 		if ( inactivatingPrincipal ) {
151 			//when a person is inactivated, inactivate their group, role, and delegation memberships
152 			KimApiServiceLocator.getRoleService().principalInactivated(identityManagementPersonDocument.getPrincipalId());
153 		}
154 	}
155 
156     protected boolean setupPrincipal(IdentityManagementPersonDocument identityManagementPersonDocument,EntityBo kimEntity, List<PrincipalBo> origPrincipals) {
157     	boolean inactivatingPrincipal = false;
158 		List<PrincipalBo> principals = new ArrayList<PrincipalBo>();
159 		Principal.Builder principal = Principal.Builder.create(identityManagementPersonDocument.getPrincipalName());
160 		principal.setPrincipalId(identityManagementPersonDocument.getPrincipalId());
161 		principal.setPassword(identityManagementPersonDocument.getPassword());
162 		principal.setActive(identityManagementPersonDocument.isActive());
163 		principal.setEntityId(identityManagementPersonDocument.getEntityId());
164 		if(ObjectUtils.isNotNull(origPrincipals)){
165 			for (PrincipalBo prncpl : origPrincipals) {
166 				if (prncpl.getPrincipalId()!=null && StringUtils.equals(prncpl.getPrincipalId(), principal.getPrincipalId())) {
167 					principal.setVersionNumber(prncpl.getVersionNumber());
168                     principal.setObjectId(prncpl.getObjectId());
169 					// check if inactivating the principal
170 					if ( prncpl.isActive() && !principal.isActive() ) {
171 						inactivatingPrincipal = true;
172 					}
173 				}
174 			}
175 		}
176 		principals.add(PrincipalBo.from(principal.build()));
177 
178 		kimEntity.setPrincipals(principals);
179 		return inactivatingPrincipal;
180 	}
181 
182 	protected List<PersonDocumentAffiliation> loadAffiliations(List <EntityAffiliation> affiliations, List<EntityEmployment> empInfos) {
183 		List<PersonDocumentAffiliation> docAffiliations = new ArrayList<PersonDocumentAffiliation>();
184 		if(ObjectUtils.isNotNull(affiliations)){
185 			for (EntityAffiliation affiliation: affiliations) {
186 				if(affiliation.isActive()){
187 					PersonDocumentAffiliation docAffiliation = new PersonDocumentAffiliation();
188 					docAffiliation.setAffiliationTypeCode(affiliation.getAffiliationType().getCode());
189 					docAffiliation.setCampusCode(affiliation.getCampusCode());
190 					docAffiliation.setActive(affiliation.isActive());
191 					docAffiliation.setDflt(affiliation.isDefaultValue());
192 					docAffiliation.setEntityAffiliationId(affiliation.getId());
193 					docAffiliation.refreshReferenceObject("affiliationType");
194 					// EntityAffiliationImpl does not define empinfos as collection
195 					docAffiliations.add(docAffiliation);
196 					docAffiliation.setEdit(true);
197 					// employment informations
198 					List<PersonDocumentEmploymentInfo> docEmploymentInformations = new ArrayList<PersonDocumentEmploymentInfo>();
199 					if(ObjectUtils.isNotNull(empInfos)){
200 						for (EntityEmployment empInfo: empInfos) {
201 							if (empInfo.isActive()
202                                     && StringUtils.equals(docAffiliation.getEntityAffiliationId(),
203                                                           (empInfo.getEntityAffiliation() != null ? empInfo.getEntityAffiliation().getId() : null))) {
204 								PersonDocumentEmploymentInfo docEmpInfo = new PersonDocumentEmploymentInfo();
205 								docEmpInfo.setEntityEmploymentId(empInfo.getEmployeeId());
206 								docEmpInfo.setEmployeeId(empInfo.getEmployeeId());
207 								docEmpInfo.setEmploymentRecordId(empInfo.getEmploymentRecordId());
208 								docEmpInfo.setBaseSalaryAmount(empInfo.getBaseSalaryAmount());
209 								docEmpInfo.setPrimaryDepartmentCode(empInfo.getPrimaryDepartmentCode());
210 								docEmpInfo.setEmploymentStatusCode(empInfo.getEmployeeStatus() != null ? empInfo.getEmployeeStatus().getCode() : null);
211 								docEmpInfo.setEmploymentTypeCode(empInfo.getEmployeeType() != null ? empInfo.getEmployeeType().getCode() : null);
212 								docEmpInfo.setActive(empInfo.isActive());
213 								docEmpInfo.setPrimary(empInfo.isPrimary());
214 								docEmpInfo.setEntityAffiliationId(empInfo.getEntityAffiliation() != null ? empInfo.getEntityAffiliation().getId() : null);
215 								// there is no version number on KimEntityEmploymentInformationInfo
216 								//docEmpInfo.setVersionNumber(empInfo.getVersionNumber());
217 								docEmpInfo.setEdit(true);
218 								docEmpInfo.refreshReferenceObject("employmentType");
219 								docEmploymentInformations.add(docEmpInfo);
220 							}
221 						}
222 					}
223 					docAffiliation.setEmpInfos(docEmploymentInformations);
224 				}
225 			}
226 		}
227 		return docAffiliations;
228 
229 	}
230 
231     
232     protected List<PersonDocumentName> loadNames( IdentityManagementPersonDocument personDoc, String principalId, List <EntityName> names, boolean suppressDisplay ) {
233 		List<PersonDocumentName> docNames = new ArrayList<PersonDocumentName>();
234 		if(ObjectUtils.isNotNull(names)){
235 			for (EntityName name: names) {
236 				if(name.isActive()){
237 					PersonDocumentName docName = new PersonDocumentName();
238                     if (name.getNameType() != null) {
239 					    docName.setNameCode(name.getNameType().getCode());
240                     }
241 
242 					//We do not need to check the privacy setting here - The UI should care of it
243 					docName.setFirstName(name.getFirstNameUnmasked());
244 					docName.setLastName(name.getLastNameUnmasked());
245 					docName.setMiddleName(name.getMiddleNameUnmasked());
246 					docName.setNamePrefix(name.getNamePrefixUnmasked());
247 					docName.setNameSuffix(name.getNameSuffixUnmasked());
248 
249 					docName.setActive(name.isActive());
250 					docName.setDflt(name.isDefaultValue());
251 					docName.setEdit(true);
252 					docName.setEntityNameId(name.getId());
253 					docNames.add(docName);
254 				}
255 			}
256 		}
257 		return docNames;
258 	}
259 
260     protected List<PersonDocumentAddress> loadAddresses(IdentityManagementPersonDocument identityManagementPersonDocument, String principalId, List<EntityAddress> entityAddresses, boolean suppressDisplay ) {
261 		List<PersonDocumentAddress> docAddresses = new ArrayList<PersonDocumentAddress>();
262 		if(ObjectUtils.isNotNull(entityAddresses)){
263 			for (EntityAddress address: entityAddresses) {
264 				if(address.isActive()){
265 					PersonDocumentAddress docAddress = new PersonDocumentAddress();
266 					docAddress.setEntityTypeCode(address.getEntityTypeCode());
267 					docAddress.setAddressTypeCode(address.getAddressType().getCode());
268 
269 					//We do not need to check the privacy setting here - The UI should care of it
270 					docAddress.setLine1(address.getLine1Unmasked());
271 					docAddress.setLine2(address.getLine2Unmasked());
272 					docAddress.setLine3(address.getLine3Unmasked());
273 					docAddress.setStateCode(address.getStateCodeUnmasked());
274 					docAddress.setPostalCode(address.getPostalCodeUnmasked());
275 					docAddress.setCountryCode(address.getCountryCodeUnmasked());
276 					docAddress.setCity(address.getCityUnmasked());
277 
278 					docAddress.setActive(address.isActive());
279 					docAddress.setDflt(address.isDefaultValue());
280 					docAddress.setEntityAddressId(address.getId());
281 					docAddress.setEdit(true);
282 					docAddresses.add(docAddress);
283 				}
284 			}
285 		}
286 		return docAddresses;
287 	}
288 
289     protected List<PersonDocumentEmail> loadEmails(IdentityManagementPersonDocument identityManagementPersonDocument, String principalId, List<EntityEmail> entityEmails, boolean suppressDisplay ) {
290 		List<PersonDocumentEmail> emails = new ArrayList<PersonDocumentEmail>();
291 		if(ObjectUtils.isNotNull(entityEmails)){
292 			for (EntityEmail email: entityEmails) {
293 				if(email.isActive()){
294 					PersonDocumentEmail docEmail = new PersonDocumentEmail();
295 					//docEmail.setEntityId(email.getEntityId());
296 					docEmail.setEntityTypeCode(email.getEntityTypeCode());
297                     if (email.getEmailType() != null) {
298 					    docEmail.setEmailTypeCode(email.getEmailType().getCode());
299                     }
300 					// EmailType not on info object.
301 					//docEmail.setEmailType(((KimEntityEmailImpl)email).getEmailType());
302 					//We do not need to check the privacy setting here - The UI should care of it
303 					docEmail.setEmailAddress(email.getEmailAddressUnmasked());
304 
305 					docEmail.setActive(email.isActive());
306 					docEmail.setDflt(email.isDefaultValue());
307 					docEmail.setEntityEmailId(email.getId());
308 					docEmail.setEdit(true);
309 					emails.add(docEmail);
310 				}
311 			}
312 		}
313 		return emails;
314 	}
315 
316     protected List<PersonDocumentPhone> loadPhones(IdentityManagementPersonDocument identityManagementPersonDocument, String principalId, List<EntityPhone> entityPhones, boolean suppressDisplay ) {
317 		List<PersonDocumentPhone> docPhones = new ArrayList<PersonDocumentPhone>();
318 		if(ObjectUtils.isNotNull(entityPhones)){
319 			for (EntityPhone phone: entityPhones) {
320 				if(phone.isActive()){
321 					PersonDocumentPhone docPhone = new PersonDocumentPhone();
322                     if (phone.getPhoneType() != null) {
323 					    docPhone.setPhoneTypeCode(phone.getPhoneType().getCode());
324                     }
325 					//docPhone.setPhoneType(((KimEntityPhoneImpl)phone).getPhoneType());
326 					docPhone.setEntityTypeCode(phone.getEntityTypeCode());
327 					//We do not need to check the privacy setting here - The UI should care of it
328 					docPhone.setPhoneNumber(phone.getPhoneNumberUnmasked());
329 					docPhone.setCountryCode(phone.getCountryCodeUnmasked());
330 					docPhone.setExtensionNumber(phone.getExtensionNumberUnmasked());
331 
332 					docPhone.setActive(phone.isActive());
333 					docPhone.setDflt(phone.isDefaultValue());
334 					docPhone.setEntityPhoneId(phone.getId());
335 					docPhone.setEdit(true);
336 					docPhones.add(docPhone);
337 				}
338 			}
339 		}
340 		return docPhones;
341 
342 	}
343 
344     public BusinessObject getMember(String memberTypeCode, String memberId){
345         Class<? extends BusinessObject> roleMemberTypeClass = null;
346         String roleMemberIdName = "";
347     	if(KimConstants.KimUIConstants.MEMBER_TYPE_PRINCIPAL_CODE.equals(memberTypeCode)){
348         	roleMemberTypeClass = PrincipalBo.class;
349         	roleMemberIdName = KimConstants.PrimaryKeyConstants.PRINCIPAL_ID;
350 	 	 	Principal principalInfo = getIdentityService().getPrincipal(memberId);
351 	 	 	if (principalInfo != null) {
352 	 	 		
353 	 	 	}
354         } else if(KimConstants.KimUIConstants.MEMBER_TYPE_GROUP_CODE.equals(memberTypeCode)){
355         	roleMemberTypeClass = GroupBo.class;
356         	roleMemberIdName = KimConstants.PrimaryKeyConstants.GROUP_ID;
357         	Group groupInfo = null;
358 	 	 	groupInfo = getGroupService().getGroup(memberId);
359 	 	 	if (groupInfo != null) {
360 	 	 		
361 	 	 	}
362         } else if(KimConstants.KimUIConstants.MEMBER_TYPE_ROLE_CODE.equals(memberTypeCode)){
363         	roleMemberTypeClass = RoleBo.class;
364         	roleMemberIdName = KimConstants.PrimaryKeyConstants.ROLE_ID;
365 	 	 	Role role = getRoleService().getRole(memberId);
366 	 	 	if (role != null) {
367 	 	 		
368 	 	 	}
369         }
370         Map<String, String> criteria = new HashMap<String, String>();
371         criteria.put(roleMemberIdName, memberId);
372         return getBusinessObjectService().findByPrimaryKey(roleMemberTypeClass, criteria);
373     }
374 
375     /**
376      * Overridden to only check permission - users should not be able to edit themselves.
377      * 
378      * @see org.kuali.rice.kim.service.impl.UiDocumentServiceImpl#canModifyEntity(java.lang.String, java.lang.String)
379      */
380     @Override
381 	public boolean canModifyEntity( String currentUserPrincipalId, String toModifyPrincipalId ){
382 		return (StringUtils.isNotBlank(currentUserPrincipalId) && StringUtils.isNotBlank(toModifyPrincipalId) &&
383 				currentUserPrincipalId.equals(toModifyPrincipalId)) ||
384 				getPermissionService().isAuthorized(
385 						currentUserPrincipalId,
386 						KimConstants.NAMESPACE_CODE,
387 						KimConstants.PermissionNames.MODIFY_ENTITY,
388 						null,
389 						Collections.singletonMap(KimConstants.AttributeConstants.PRINCIPAL_ID, currentUserPrincipalId));
390 	}
391     
392     protected List<RoleMemberBo> getRoleMembers(IdentityManagementRoleDocument identityManagementRoleDocument, List<RoleMemberBo> origRoleMembers){
393         List<RoleMemberBo> roleMembers = new ArrayList<RoleMemberBo>();
394         RoleMemberBo newRoleMember;
395         RoleMemberBo origRoleMemberImplTemp;
396         List<RoleMemberAttributeDataBo> origAttributes;
397         boolean activatingInactive = false;
398         String newRoleMemberIdAssigned = "";
399 
400         identityManagementRoleDocument.setKimType(KimApiServiceLocator.getKimTypeInfoService().getKimType(identityManagementRoleDocument.getRoleTypeId()));
401         KimTypeService kimTypeService = KimFrameworkServiceLocator.getKimTypeService(identityManagementRoleDocument.getKimType());
402 
403         if(CollectionUtils.isNotEmpty(identityManagementRoleDocument.getMembers())){
404             for(KimDocumentRoleMember documentRoleMember: identityManagementRoleDocument.getMembers()){
405                 origRoleMemberImplTemp = null;
406 
407                 newRoleMember = new RoleMemberBo();
408                 KimCommonUtilsInternal.copyProperties(newRoleMember, documentRoleMember);
409                 newRoleMember.setRoleId(identityManagementRoleDocument.getRoleId());
410                 if(ObjectUtils.isNotNull(origRoleMembers)){
411                     for(RoleMemberBo origRoleMemberImpl: origRoleMembers){
412                         if((origRoleMemberImpl.getRoleId()!=null && StringUtils.equals(origRoleMemberImpl.getRoleId(), newRoleMember.getRoleId())) &&
413                             (origRoleMemberImpl.getMemberId()!=null && StringUtils.equals(origRoleMemberImpl.getMemberId(), newRoleMember.getMemberId())) &&
414                             (origRoleMemberImpl.getMemberTypeCode()!=null && StringUtils.equals(origRoleMemberImpl.getMemberTypeCode(), newRoleMember.getMemberTypeCode())) &&
415                             !origRoleMemberImpl.isActive(new Timestamp(System.currentTimeMillis())) &&
416                             !kimTypeService.validateAttributesAgainstExisting(identityManagementRoleDocument.getKimType().getId(),
417                                     documentRoleMember.getQualifierAsMap(), origRoleMemberImpl.getAttributes()).isEmpty()) {
418 
419                             //TODO: verify if you want to add  && newRoleMember.isActive() condition to if...
420 
421                             newRoleMemberIdAssigned = newRoleMember.getRoleMemberId();
422                             newRoleMember.setRoleMemberId(origRoleMemberImpl.getRoleMemberId());
423                             activatingInactive = true;
424                         }
425                         if(origRoleMemberImpl.getRoleMemberId()!=null && StringUtils.equals(origRoleMemberImpl.getRoleMemberId(), newRoleMember.getRoleMemberId())){
426                             newRoleMember.setVersionNumber(origRoleMemberImpl.getVersionNumber());
427                             origRoleMemberImplTemp = origRoleMemberImpl;
428                         }
429                     }
430                 }
431                 origAttributes = (origRoleMemberImplTemp==null || origRoleMemberImplTemp.getAttributes()==null)?
432                                     new ArrayList<RoleMemberAttributeDataBo>():origRoleMemberImplTemp.getAttributeDetails();
433                 newRoleMember.setActiveFromDateValue(documentRoleMember.getActiveFromDate());
434                 newRoleMember.setActiveToDateValue(documentRoleMember.getActiveToDate());
435                 newRoleMember.setAttributeDetails(getRoleMemberAttributeData(documentRoleMember.getQualifiers(), origAttributes, activatingInactive, newRoleMemberIdAssigned));
436                 newRoleMember.setRoleRspActions(getRoleMemberResponsibilityActions(documentRoleMember, origRoleMemberImplTemp, activatingInactive, newRoleMemberIdAssigned));
437                 roleMembers.add(newRoleMember);
438                 activatingInactive = false;
439             }
440         }
441         return roleMembers;
442     }
443 }