Class ViewDraftServiceImpl

java.lang.Object
io.jmix.uirecovery.impl.ViewDraftServiceImpl
All Implemented Interfaces:
ViewDraftService

@NullMarked @Component("uirec_ViewDraftService") public class ViewDraftServiceImpl extends Object implements ViewDraftService
  • Field Details

  • Constructor Details

    • ViewDraftServiceImpl

      public ViewDraftServiceImpl()
  • Method Details

    • setTransactionManager

      @Autowired protected void setTransactionManager(org.springframework.transaction.PlatformTransactionManager transactionManager)
      Every write runs in its own transaction, so a draft write never joins - or is rolled back by - a surrounding business transaction.
    • find

      public Optional<ViewDraft> find(String viewId, @Nullable String entityId)
      Description copied from interface: ViewDraftService
      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).

      Specified by:
      find in interface ViewDraftService
      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

      public List<ViewDraft> findAll()
      Description copied from interface: ViewDraftService
      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 ViewDraftService.find(String, String).

      Specified by:
      findAll in interface ViewDraftService
      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

      public void save(String viewId, @Nullable String entityId, String payload)
      Description copied from interface: ViewDraftService
      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.

      Specified by:
      save in interface ViewDraftService
      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

      public void delete(String viewId, @Nullable String entityId)
      Description copied from interface: ViewDraftService
      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.

      Specified by:
      delete in interface ViewDraftService
      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

      public int deleteExpired()
      Description copied from interface: ViewDraftService
      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.

      Specified by:
      deleteExpired in interface ViewDraftService
      Returns:
      the number of deleted drafts
    • findDraft

      protected @Nullable ViewDraft findDraft(String viewId, @Nullable String entityId)
    • isExpired

      protected boolean isExpired(ViewDraft draft)
    • expiryThreshold

      protected OffsetDateTime expiryThreshold()
    • notAuthenticated

      protected boolean notAuthenticated()
      An anonymous authentication is set while nobody is logged in, and its principal is not a UserDetails, so it does not count as an authenticated user here.