}
}
private Page doMovePage(long pageId, long moveAfterPageId) {
// get the logged in user
User user = userService.getAuthenticatedUser();
// get the page to move and the page to move after
Page movingPage = pageRepository.get(pageId);
Page afterPage = null;
int newIndex = 0;
// check to see if we should move the page to beginning
if (moveAfterPageId != MOVE_PAGE_DEFAULT_POSITION_INDEX) {
afterPage = pageRepository.get(moveAfterPageId);
}
// get all of the user's pages
// the pageRepository returns an un-modifiable list
// so we need to create a modifyable arraylist
List<Page> pages = new ArrayList<Page>(pageRepository.getAllPages(user.getEntityId()));
// first remove it from the list
if (!pages.remove(movingPage)) {
throw new RuntimeException("unable to find pageId " + pageId + " attempted to be moved for user " + user);
}