Class SessionStoreBookmarkManager

java.lang.Object
io.goobi.viewer.model.bookmark.SessionStoreBookmarkManager

public class SessionStoreBookmarkManager extends Object
Handles the bookmark list stored in the session store.
Author:
Florian Alpers
  • Field Details

    • BOOKMARK_LIST_ATTRIBUTE_NAME

      public static final String BOOKMARK_LIST_ATTRIBUTE_NAME
      Constant BOOKMARK_LIST_ATTRIBUTE_NAME="bookmarkList".
      See Also:
  • Constructor Details

    • SessionStoreBookmarkManager

      public SessionStoreBookmarkManager()
  • Method Details

    • getBookmarkList

      public Optional<BookmarkList> getBookmarkList(HttpSession session)
      getBookmarkList.
      Parameters:
      session - HTTP session to look up the bookmark list in
      Returns:
      An optional containing the stored bookmark list if one exists
      Throws:
      NullPointerException - if the session is NULL
    • createBookmarkList

      public BookmarkList createBookmarkList(HttpSession session)
      Creates a new BookmarkList and store it in the session store in the attribute "bookmarkList".
      Parameters:
      session - HTTP session to store the new bookmark list in
      Returns:
      the newly created BookmarkList stored in the session
      Throws:
      IllegalArgumentException - if a bookmark list already exists
      IllegalStateException - if the bookmark list could not be stored in the session
      NullPointerException - if the session is NULL
    • getOrCreateBookmarkList

      public BookmarkList getOrCreateBookmarkList(HttpSession session)
      Gets the bookmark list stored in the session. If no bookmark list exists, a new one is created, stored and returned
      Parameters:
      session - HTTP session to retrieve or create the bookmark list in
      Returns:
      the BookmarkList from the session, creating a new one if none exists
      Throws:
      NullPointerException - if the session is NULL
    • addToBookmarkList

      public boolean addToBookmarkList(Bookmark item, HttpSession session)
      Adds the given item to the session bookmark list, creating a new bookmark list if required.
      Parameters:
      item - bookmark to add to the session list
      session - HTTP session holding the bookmark list
      Returns:
      false if the item could not be added (usually because it already exists), true otherwise
      Throws:
      NullPointerException - if the session is NULL
    • removeFromBookself

      public boolean removeFromBookself(Bookmark item, HttpSession session)
      Remove the given item (or one with identical pi, logId and order) from the session bookmark list if it exists If no session bookmark list exists, it doesn't contain the item or the item could not be removed for some other reason, false is returned.
      Parameters:
      item - bookmark to remove from the session list
      session - HTTP session holding the bookmark list
      Returns:
      true if the item was successfully removed from the session bookmark list, false if no session list exists or the item was not found
      Throws:
      NullPointerException - if the session is NULL
    • deleteBookmarkList

      public void deleteBookmarkList(HttpSession session)
      deleteBookmarkList.
      Parameters:
      session - HTTP session whose bookmark list is removed
      Throws:
      NullPointerException - if the session is NULL
    • isInBookmarkList

      public boolean isInBookmarkList(Bookmark item, HttpSession session)
      isInBookmarkList.
      Parameters:
      item - bookmark to look up in the session list
      session - HTTP session holding the bookmark list
      Returns:
      true if the session bookmark list exists and contains the given item, false otherwise
    • addSessionBookmarkListToUser

      public void addSessionBookmarkListToUser(User user, HttpServletRequest request) throws DAOException
      Assigns the current session bookmark list (if any) to the given user and saves the bookmark list to the database The bookmark list gets a newly generated name provided by generateNewBookmarkListName(List).
      Parameters:
      user - user to assign the session bookmark list to
      request - HTTP request providing the current session
      Throws:
      DAOException - if any.
    • generateNewBookmarkListName

      public static String generateNewBookmarkListName(List<BookmarkList> bookmarkLists)
      Returns a String of the pattern "List {n}" where {n} is the lowest positive integer such that no bookmark list named "List {n}" exists in the given list.
      Parameters:
      bookmarkLists - existing bookmark lists used to determine the next available number
      Returns:
      the next available bookmark list name in the format "List {n}"
    • generateBookmarkListInfo

      public static String generateBookmarkListInfo(String text, String itemText, String emptyListText, BookmarkList bookmarkList)
      This embedds the bookmark list items within a text, to be used in autogenerated mails describing the bookmark list The parameter text contains the complete text with a placeholder {0} which is replaced by the text generated from the bookmarks. itemText is the text for each bookmark with placeholder {0} which is replaced by the link to the bookmarked item, and {1} which is replaced by the title of that item.

      The parameter bookmarkList is the bookmark list containing the items to be inserted

      Parameters:
      text - email body template containing placeholder {0} for the item list
      itemText - per-bookmark text template with placeholders {0} (URL) and {1} (title)
      emptyListText - text inserted when the bookmark list is empty
      bookmarkList - bookmark list whose items are rendered into the text
      Returns:
      the email body text with bookmark item links substituted into the template