Source:
public Response mergeUserAccounts(@Context final HttpServletRequest httpServletRequest, final UserIdMergeDTO userIdMergeDTO) { try { RegisteredUserDTO currentlyLoggedInUser = this.userManager.getCurrentRegisteredUser(httpServletRequest); if (!isUserAnAdmin(userManager, currentlyLoggedInUser)) { return new SegueErrorResponse(Status.FORBIDDEN, "You must be logged in as an admin to access this function.").toResponse(); } if (currentlyLoggedInUser.getId().equals(userIdMergeDTO.getSourceId())) { return new SegueErrorResponse(Status.BAD_REQUEST, "You are not allowed to be the merge source.") .toResponse(); } RegisteredUserDTO targetUser = this.userManager.getUserDTOById(userIdMergeDTO.getTargetId()); RegisteredUserDTO sourceUser = this.userManager.getUserDTOById(userIdMergeDTO.getSourceId()); this.userManager.mergeUserAccounts(targetUser, sourceUser); getLogManager().logEvent(currentlyLoggedInUser, httpServletRequest, SegueLogType.MERGE_USER, ImmutableMap.of(USER_ID_FKEY_FIELDNAME, targetUser.getId(), OLD_USER_ID_FKEY_FIELDNAME, sourceUser.getId())); log.info("Admin User: " + currentlyLoggedInUser.getEmail() + " has just merged the target user account with id: " + userIdMergeDTO.getTargetId() + " with the source user account" + userIdMergeDTO.getSourceId()); return Response.noContent().build(); } catch (NoUserLoggedInException e) { return SegueErrorResponse.getNotLoggedInResponse(); } catch (SegueDatabaseException e) { log.error("Unable to merge accounts", e); return new SegueErrorResponse(Status.INTERNAL_SERVER_ERROR, "Database error while looking up user information.").toResponse(); } catch (NoUserException e) { return new SegueErrorResponse(Status.NOT_FOUND, "Unable to locate the users with the requested ids: " + userIdMergeDTO.getTargetId() + ", " + userIdMergeDTO.getSourceId()).toResponse(); } }

Target:
public Response mergeUserAccounts(@Context final HttpServletRequest httpServletRequest, final UserIdMergeDTO userIdMergeDTO) { try { RegisteredUserDTO currentlyLoggedInUser = this.userManager.getCurrentRegisteredUser(httpServletRequest); if (!isUserAnAdmin(userManager, currentlyLoggedInUser)) { return new SegueErrorResponse(Status.FORBIDDEN, "You must be logged in as an admin to access this function.").toResponse(); } if (currentlyLoggedInUser.getId().equals(userIdMergeDTO.getSourceId())) { return new SegueErrorResponse(Status.BAD_REQUEST, "You are not allowed to be the merge source.") .toResponse(); } RegisteredUserDTO targetUser = this.userManager.getUserDTOById(userIdMergeDTO.getTargetId()); RegisteredUserDTO sourceUser = this.userManager.getUserDTOById(userIdMergeDTO.getSourceId()); this.userManager.mergeUserAccounts(targetUser, sourceUser); getLogManager().logEvent(currentlyLoggedInUser, httpServletRequest, SegueLogType.ADMIN_MERGE_USER, ImmutableMap.of(USER_ID_FKEY_FIELDNAME, targetUser.getId(), OLD_USER_ID_FKEY_FIELDNAME, sourceUser.getId())); log.info("Admin User: " + currentlyLoggedInUser.getEmail() + " has just merged the target user account with id: " + userIdMergeDTO.getTargetId() + " with the source user account with id: " + userIdMergeDTO.getSourceId()); return Response.noContent().build(); } catch (NoUserLoggedInException e) { return SegueErrorResponse.getNotLoggedInResponse(); } catch (SegueDatabaseException e) { log.error("Unable to merge accounts", e); return new SegueErrorResponse(Status.INTERNAL_SERVER_ERROR, "Database error while looking up user information.").toResponse(); } catch (NoUserException e) { return new SegueErrorResponse(Status.NOT_FOUND, "Unable to locate the users with the requested ids: " + userIdMergeDTO.getTargetId() + ", " + userIdMergeDTO.getSourceId()).toResponse(); } }