Tools.logMethodIn(log, LogLevel.TRACE, "removeMembership", new Object[] { "id", id, "broadcast", broadcast });
}
orgService.flush();
Membership m = null;
try {
m = new MembershipImpl(id);
} catch (ArrayIndexOutOfBoundsException e) {
//If MembershipID is not valid with format 'membershipType:username:groupId'
//It is seemed as membership not exist
return null;
}
String plGroupName = getPLIDMGroupName(getGroupNameFromId(m.getGroupId()));
String groupId = getIdentitySession().getPersistenceManager().createGroupKey(plGroupName,
getGroupTypeFromId(m.getGroupId()));
boolean hasRole = false;
try {
hasRole = getIdentitySession().getRoleManager().hasRole(m.getUserName(), groupId, m.getMembershipType());
} catch (Exception e) {
// TODO:
handleException("Identity operation error: ", e);
}
boolean associated = false;
try {
associated = getIdentitySession().getRelationshipManager().isAssociatedByKeys(groupId, m.getUserName());
} catch (Exception e) {
// TODO:
handleException("Identity operation error: ", e);
}
if (!hasRole && !(isAssociationMapped() && getAssociationMapping().equals(m.getMembershipType()) && associated)) {
//As test case expect, if meembership does not exist
//This method should return null
return null;
//return m;
}
if (broadcast) {
preDelete(m);
}
if (isCreateMembership(m.getMembershipType(), m.getGroupId())) {
try {
getIdentitySession().getRoleManager().removeRole(m.getMembershipType(), m.getUserName(), groupId);
} catch (Exception e) {
// TODO:
handleException("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) {
// TODO:
handleException("Identity operation error: ", e);