Class CalendarLinkStorage

java.lang.Object
org.exoplatform.agenda.storage.CalendarLinkStorage

@Component public class CalendarLinkStorage extends Object
Maps calendar links between their rows and CalendarLink. No cache: a feed is fetched every few hours per subscriber, and a cached digest would keep a reset link answering until the cache let it go.
  • Constructor Details

    • CalendarLinkStorage

      @Autowired public CalendarLinkStorage(CalendarLinkDAO calendarLinkDAO)
      Builds the storage.
      Parameters:
      calendarLinkDAO - the repository of calendar link rows
  • Method Details

    • getByCalendarId

      public org.exoplatform.agenda.model.CalendarLink getByCalendarId(long calendarId)
      Reads the link of a calendar.
      Parameters:
      calendarId - technical identifier of the calendar
      Returns:
      the link, or null when the calendar has none
    • getByTokenHash

      public org.exoplatform.agenda.model.CalendarLink getByTokenHash(String tokenHash)
      Reads the link a token digest opens.
      Parameters:
      tokenHash - lowercase hexadecimal SHA-256 digest of a token
      Returns:
      the link, or null when no link carries that digest
    • getByCalendarOwnerIds

      public List<org.exoplatform.agenda.model.CalendarLink> getByCalendarOwnerIds(List<Long> ownerIds, int limit)
      Reads the links of the calendars some identities own, in one query.
      Parameters:
      ownerIds - identity identifiers owning the calendars
      limit - most links to read
      Returns:
      the links, newest first, empty when no owner is given
    • save

      public org.exoplatform.agenda.model.CalendarLink save(long calendarId, long creatorId, String tokenHash, String tokenEncrypted, Date createdDate)
      Writes the link of a calendar, creating the row or replacing the one the calendar already has.

      Two managers creating a link for the same calendar at the same moment both find no row, and the unique constraint on the calendar refuses the second insert. That refusal is not an error for the second manager: their link simply replaces the first one, as a reset would, so the insert is retried once as an update of the row that won.

      The insert is flushed, so that the refusal surfaces here on every engine — with a sequence generator the row would otherwise only reach the database at commit, past this method. It is caught both as Spring's translated exception and as the raw JPA one, because whether a repository call is translated depends on the context it runs in; a refusal that is not about the calendar's row is rethrown, since no row is found on the retry.

      Parameters:
      calendarId - technical identifier of the calendar
      creatorId - identity identifier of the user creating the link
      tokenHash - digest of the new token
      tokenEncrypted - the new token encrypted by the platform codec
      createdDate - when the link is created
      Returns:
      the stored link
    • deleteByCalendarId

      public boolean deleteByCalendarId(long calendarId)
      Deletes the link of a calendar.
      Parameters:
      calendarId - technical identifier of the calendar
      Returns:
      true when a link was deleted