public void acceptInvitation(String invitationActionToken) throws GroupNotFoundException, TokenNotFoundException,
AlreadyGroupMemberException {
try {
GroupInvitation invitation = em
.createQuery("SELECT i FROM GroupInvitation i WHERE i.invitationActionToken = :invitationActionToken",
GroupInvitation.class).setParameter("invitationActionToken", invitationActionToken)
.getSingleResult();
em.remove(invitation);
if (invitation.getInvitedGroup() == null) {
throw new GroupNotFoundException();
}
if (invitation.getInvitedGroup().getId() == user.getUserGroup().getId()) {
throw new AlreadyGroupMemberException();
}
switchGroup(user, invitation.getInvitedGroup());
save();
log.info("Invitation to group " + user.getUserGroup().getName() + " accepted by user " + user.getUsername());
} catch (NoResultException e) {