Class ServerSideColumnPreferenceStorage

java.lang.Object
org.vaadin.addons.antlerflow.grid.columns.storage.ServerSideColumnPreferenceStorage
All Implemented Interfaces:
Serializable, ColumnPreferenceStorage
Direct Known Subclasses:
InMemoryColumnPreferenceStorage, JdbcColumnPreferenceStorage

public abstract class ServerSideColumnPreferenceStorage extends Object implements ColumnPreferenceStorage
Base class for storages that keep preferences on the server, per user (a database, a cache, a REST service). Subclasses implement three synchronous methods; this class resolves the current user and turns failures into a logged warning so the grid falls back to its default columns.

When the user id supplier returns null or blank (an anonymous visitor), nothing is read or written.

See Also:
  • Constructor Details

    • ServerSideColumnPreferenceStorage

      protected ServerSideColumnPreferenceStorage(com.vaadin.flow.function.SerializableSupplier<String> userIdSupplier)
      Parameters:
      userIdSupplier - returns the current user's stable id (for example the login name); called on the UI thread while handling a request
  • Method Details

    • requestPrincipalName

      public static com.vaadin.flow.function.SerializableSupplier<String> requestPrincipalName()
      Returns a user id supplier reading the authenticated principal of the current Vaadin request (HttpServletRequest#getUserPrincipal()), which Spring Security and servlet container security both populate. Anonymous requests yield null.
    • read

      protected abstract Optional<Map<String,Boolean>> read(String userId, String key)
      Reads the stored preference; empty when none is stored.
    • write

      protected abstract void write(String userId, String key, Map<String,Boolean> visibility)
      Inserts or replaces the preference.
    • delete

      protected abstract void delete(String userId, String key)
      Deletes the preference; a missing preference is not an error.
    • load

      public final void load(ColumnPreferenceContext context, com.vaadin.flow.function.SerializableConsumer<Map<String,Boolean>> onLoaded)
      Description copied from interface: ColumnPreferenceStorage
      Loads the preference and passes it to onLoaded, possibly later (for example after a browser round trip). Pass an empty map when nothing is stored. Must be called on the UI thread (with the session locked), as the grid applies the result directly.
      Specified by:
      load in interface ColumnPreferenceStorage
    • save

      public final void save(ColumnPreferenceContext context, Map<String,Boolean> visibility)
      Description copied from interface: ColumnPreferenceStorage
      Stores the preference, replacing any previous one under the same key.
      Specified by:
      save in interface ColumnPreferenceStorage
    • clear

      public final void clear(ColumnPreferenceContext context)
      Description copied from interface: ColumnPreferenceStorage
      Removes the preference stored under the context's key, if any.
      Specified by:
      clear in interface ColumnPreferenceStorage