Source:
<code>public void linkMembership(User user, Group g, MembershipType mt, boolean broadcast) throws Exception { if (log.isTraceEnabled()) { Tools.logMethodIn(log, LogLevel.TRACE, "linkMembership", new Object[] { "user", user, "group", g, "membershipType", mt, "broadcast", broadcast }); } orgService.flush(); if (g == null) { throw new InvalidNameException("Can not create membership record for " + user.getUserName() + " because group is null"); } if (mt == null) { throw new InvalidNameException("Can not create membership record for " + user.getUserName() + " because membership type is null"); } if (orgService.getMembershipTypeHandler().findMembershipType(mt.getName()) == null) { throw new InvalidNameException("MembershipType doesn't exist: " + mt.getName()); } String plGroupName = getPLIDMGroupName(g.getGroupName()); String groupId = getIdentitySession().getPersistenceManager().createGroupKey(plGroupName, orgService.getConfiguration().getGroupType(g.getParentId())); if (isCreateMembership(mt.getName(), g.getId())) { if (getIdentitySession().getRoleManager().getRoleType(mt.getName()) == null) { getIdentitySession().getRoleManager().createRoleType(mt.getName()); } if (getIdentitySession().getRoleManager().hasRole(user.getUserName(), groupId, mt.getName())) { return; } } <START> <END> if (isAssociationMapped() && getAssociationMapping().equals(mt.getName())) { if (getIdentitySession().getRelationshipManager().isAssociatedByKeys(groupId, user.getUserName())) { return; } getIdentitySession().getRelationshipManager().associateUserByKeys(groupId, user.getUserName()); } MembershipImpl membership = new MembershipImpl(); membership.setMembershipType(mt.getName()); membership.setUserName(user.getUserName()); membership.setGroupId(g.getId()); if (broadcast) { preSave(membership, true); } if (isCreateMembership(mt.getName(), g.getId())) { getIdentitySession().getRoleManager().createRole(mt.getName(), user.getUserName(), groupId); } if (broadcast) { postSave(membership, true); } }</code><technical_language>This block added preSave() postSave()</technical_language>

Target:
public void linkMembership(User user, Group g, MembershipType mt, boolean broadcast) throws Exception { if (log.isTraceEnabled()) { Tools.logMethodIn(log, LogLevel.TRACE, "linkMembership", new Object[] { "user", user, "group", g, "membershipType", mt, "broadcast", broadcast }); } orgService.flush(); if (g == null) { throw new InvalidNameException("Can not create membership record for " + user.getUserName() + " because group is null"); } if (mt == null) { throw new InvalidNameException("Can not create membership record for " + user.getUserName() + " because membership type is null"); } if (orgService.getMembershipTypeHandler().findMembershipType(mt.getName()) == null) { throw new InvalidNameException("MembershipType doesn't exist: " + mt.getName()); } String plGroupName = getPLIDMGroupName(g.getGroupName()); String groupId = getIdentitySession().getPersistenceManager().createGroupKey(plGroupName, orgService.getConfiguration().getGroupType(g.getParentId())); if (isCreateMembership(mt.getName(), g.getId())) { if (getIdentitySession().getRoleManager().getRoleType(mt.getName()) == null) { getIdentitySession().getRoleManager().createRoleType(mt.getName()); } if (getIdentitySession().getRoleManager().hasRole(user.getUserName(), groupId, mt.getName())) { return; } } MembershipImpl membership = new MembershipImpl(); membership.setMembershipType(mt.getName()); membership.setUserName(user.getUserName()); membership.setGroupId(g.getId()); if (broadcast) { preSave(membership, true); } if (isAssociationMapped() && getAssociationMapping().equals(mt.getName())) { if(!getIdentitySession().getRelationshipManager().isAssociatedByKeys(groupId, user.getUserName())) { getIdentitySession().getRelationshipManager().associateUserByKeys(groupId, user.getUserName()); } } if (isCreateMembership(mt.getName(), g.getId())) { getIdentitySession().getRoleManager().createRole(mt.getName(), user.getUserName(), groupId); } if (broadcast) { postSave(membership, true); } }