// Create Map separating domains for the email addresses invitations
Map<String, Set<Invitation>> invitationsMap = new HashMap<String, Set<Invitation>>();
for (Invitation invitation : emailMap.get(emailAddress)) {
if (DomainType.ORGANIZATION.equals(invitation.getDomain().getDomainType())) {
if (invitationsMap.get(DomainType.ORGANIZATION.name()) == null) {
invitationsMap.put(DomainType.ORGANIZATION.name(), new TreeSet<Invitation>(new InvitationDomainNameComparator()));
}
invitationsMap.get(DomainType.ORGANIZATION.name()).add(invitation);
parentDomain = (Organization) invitation.getDomain();
} else if (DomainType.GROUP.equals(invitation.getDomain().getDomainType())) {
if (invitationsMap.get(DomainType.GROUP.name()) == null) {
invitationsMap.put(DomainType.GROUP.name(), new TreeSet<Invitation>(new InvitationDomainNameComparator()));
}
invitationsMap.get(DomainType.GROUP.name()).add(invitation);
if(parentDomain == null) {
Group group = (Group) invitation.getDomain();
parentDomain = group.getOrganization();