}
public Membership removeMembership(String id, boolean broadcast) throws Exception
{
Membership m = new MembershipImpl(id);
String groupId =
getIdentitySession().getPersistenceManager().
createGroupKey(getGroupNameFromId(m.getGroupId()), getGroupTypeFromId(m.getGroupId()));
boolean hasRole = false;
try
{
hasRole = getIdentitySession().getRoleManager().hasRole(m.getUserName(), groupId, m.getMembershipType());
}
catch (Exception e)
{
//TODO:
log.info("Identity operation error: ", e);
}
boolean associated = false;
try
{
associated = getIdentitySession().getRelationshipManager().isAssociatedByKeys(groupId, m.getUserName());
}
catch (Exception e)
{
//TODO:
log.info("Identity operation error: ", e);
}
if (!hasRole &&
!(isAssociationMapped() && getAssociationMapping().equals(m.getMembershipType()) && associated))
{
return m;
}
if (broadcast)
{
preDelete(m);
}
if (isCreateMembership(m.getMembershipType()))
{
try
{
getIdentitySession().getRoleManager().removeRole(m.getMembershipType(), m.getUserName(), groupId);
}
catch (Exception e)
{
//TODO:
log.info("Identity operation error: ", e);
}
}
if (isAssociationMapped() && getAssociationMapping().equals(m.getMembershipType()) && associated)
{
Set<String> keys = new HashSet<String>();
keys.add(m.getUserName());
try
{
getIdentitySession().getRelationshipManager().disassociateUsersByKeys(groupId, keys);
}
catch (Exception e)