}
orgService.flush();
if (user == null) {
throw new InvalidNameException("Can not create membership record because user is null");
}
if (orgService.getUserHandler().findUserByName(user.getUserName()) == null) {
throw new InvalidNameException("Can not create membership record because user " + user.getUserName() + " does not exist.");
}
if (g == null) {
throw new InvalidNameException("Can not create membership record for " + user.getUserName()
+ " because group is null");
}
//Check group exist
Group g1 = this.orgService.getGroupHandler().findGroupById(g.getId());
if(g1 == null) {
throw new InvalidNameException("Can not create membership record for " + user.getUserName()
+ " because group " + g.getGroupName() + " is not exist");
}
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,