Interface ViewDraftService

All Known Implementing Classes:
ViewDraftServiceImpl

@NullMarked public interface ViewDraftService
Manages ViewDraft entities on behalf of the current authenticated user.

Every method operates strictly on the drafts belonging to the current authenticated user (as reported by CurrentAuthentication), except deleteExpired() which clears expired drafts of all users. When there is no authenticated user - neither an authentication at all, nor an anonymous one - every other method is a silent no-op returning an empty result.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    delete(String viewId, @Nullable String entityId)
    Deletes the current user's draft for the given view and entity identifier, if any.
    int
    Deletes drafts of all users older than the configured retention period.
    find(String viewId, @Nullable String entityId)
    Finds the current user's draft for the given view and entity identifier.
    Returns all drafts of the current user, newest first.
    void
    save(String viewId, @Nullable String entityId, String payload)
    Saves a draft for the current user, creating or updating it.
  • Method Details

    • find

      Optional<ViewDraft> find(String viewId, @Nullable String entityId)
      Finds the current user's draft for the given view and entity identifier.

      If a matching draft exists but is older than the configured retention period, it is deleted as a side effect and an empty result is returned (opportunistic cleanup).

      Parameters:
      viewId - view identifier
      entityId - entity identifier the draft is associated with, or null for a draft not tied to a specific entity instance
      Returns:
      the current user's draft, or empty if none exists, it has expired, or there is no authenticated user
    • findAll

      List<ViewDraft> findAll()
      Returns all drafts of the current user, newest first.

      Drafts older than the configured retention period are deleted as a side effect and are not returned (opportunistic cleanup), just as in find(String, String).

      Returns:
      the current user's drafts ordered by creation date descending, or an empty list if there are none or there is no authenticated user
    • save

      void save(String viewId, @Nullable String entityId, String payload)
      Saves a draft for the current user, creating or updating it.

      This is an upsert: there is at most one draft per (username, viewId, entityId) combination. If a draft for this key already exists, it is updated in place; otherwise a new one is created.

      Does nothing if there is no authenticated user.

      Parameters:
      viewId - view identifier
      entityId - entity identifier the draft is associated with, or null for a draft not tied to a specific entity instance
      payload - serialized draft content
    • delete

      void delete(String viewId, @Nullable String entityId)
      Deletes the current user's draft for the given view and entity identifier, if any.

      Does nothing if there is no authenticated user or no matching draft exists.

      Parameters:
      viewId - view identifier
      entityId - entity identifier the draft is associated with, or null for a draft not tied to a specific entity instance
    • deleteExpired

      int deleteExpired()
      Deletes drafts of all users older than the configured retention period.

      Unlike the other methods, this is not scoped to the current user and does not require an authenticated user, so a scheduled cleanup job can call it directly.

      Returns:
      the number of deleted drafts