Class CaldavSyncStorage

java.lang.Object
org.exoplatform.caldav.storage.CaldavSyncStorage

@Component public class CaldavSyncStorage extends Object
Maps calendar pairs and their object mappings between their JPA entities and the service-layer DTOs, and is the single place hrefs are made canonical.

No business logic: what a pair means, when it may be created, whether a deletion propagates — all of that belongs to the service. What lives here is the mechanical part the service should not have to remember, above all that an href is stored decoded and without its trailing slash. A binding that compared raw hrefs would lose its pair the first time a server answered a differently-escaped one, and that is not a decision, it is an invariant.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    An href reduced to what identifies the resource: its percent-decoded path, without a trailing slash.
    long
    countObjects(long calendarSyncId)
    How many objects a pair maps.
    int
    deleteObjects(long calendarSyncId)
    Drops every object mapping of a pair, leaving the pair itself in place.
    void
    deletePair(long id)
    Removes a pair and, by the foreign key, its object mappings.
    org.springframework.data.domain.Page<org.exoplatform.caldav.model.CalendarSync>
    getDuePairs(org.exoplatform.caldav.model.CalendarSyncStatus status, Date before, int offset, int limit)
    One page of pairs in a given state whose last synchronisation ended before a cutoff, or has never ended.
    org.exoplatform.caldav.model.ObjectSync
    getObjectByEvent(long calendarSyncId, long localEventId)
    The mapping for one eXo event inside a pair.
    org.exoplatform.caldav.model.ObjectSync
    getObjectByUid(long calendarSyncId, String icsUid)
    The mapping for one iCalendar object inside a pair.
    org.springframework.data.domain.Page<org.exoplatform.caldav.model.ObjectSync>
    getObjects(long calendarSyncId, int offset, int limit)
    One page of a pair's object mappings.
    org.exoplatform.caldav.model.CalendarSync
    getPairByLocalCalendar(long userIdentityId, long serverId, String localCalendarSyncUid)
    The pair bound to one local calendar.
    org.exoplatform.caldav.model.CalendarSync
    getPairByRemoteHref(long userIdentityId, long serverId, String remoteHref)
    The pair bound to one remote collection, matched on the canonical path.
    List<org.exoplatform.caldav.model.CalendarSync>
    getPairs(long userIdentityId, long serverId)
    Every pair a user holds on one server.
    List<org.exoplatform.caldav.model.CalendarSync>
    getPairsByOrigin(long userIdentityId, long serverId, org.exoplatform.caldav.model.SyncOrigin origin)
    The pairs of one origin a user holds on a server.
    boolean
    isEventMapped(long localEventId)
    Whether an eXo event is already mapped.
    org.exoplatform.caldav.model.ObjectSync
    saveObject(org.exoplatform.caldav.model.ObjectSync object)
    Creates or updates an object mapping, canonicalising its href on the way in.
    org.exoplatform.caldav.model.CalendarSync
    savePair(org.exoplatform.caldav.model.CalendarSync pair)
    Creates or updates a pair, canonicalising its href on the way in.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CaldavSyncStorage

      public CaldavSyncStorage()
  • Method Details

    • getPairs

      public List<org.exoplatform.caldav.model.CalendarSync> getPairs(long userIdentityId, long serverId)
      Every pair a user holds on one server.
      Parameters:
      userIdentityId - identity of the user
      serverId - declared server registration
      Returns:
      the user's pairs on that server
    • getPairByLocalCalendar

      public org.exoplatform.caldav.model.CalendarSync getPairByLocalCalendar(long userIdentityId, long serverId, String localCalendarSyncUid)
      The pair bound to one local calendar.
      Parameters:
      userIdentityId - identity of the user
      serverId - declared server registration
      localCalendarSyncUid - agenda's immutable calendar anchor
      Returns:
      the pair, or null when the calendar is not bound
    • getPairByRemoteHref

      public org.exoplatform.caldav.model.CalendarSync getPairByRemoteHref(long userIdentityId, long serverId, String remoteHref)
      The pair bound to one remote collection, matched on the canonical path.

      Resolved in memory over the user's own pairs rather than by a query: the href column is too long to index on MySQL under utf8mb4, and a person's pairs are few. Querying it would have meant either a scan or a schema contortion, for a set that fits in a handful of rows.

      Parameters:
      userIdentityId - identity of the user
      serverId - declared server registration
      remoteHref - the collection href, in any spelling
      Returns:
      the pair, or null when the collection is not bound
    • getPairsByOrigin

      public List<org.exoplatform.caldav.model.CalendarSync> getPairsByOrigin(long userIdentityId, long serverId, org.exoplatform.caldav.model.SyncOrigin origin)
      The pairs of one origin a user holds on a server. A list even for SyncOrigin.MIRROR, which should be single: the database cannot enforce that uniqueness, so the caller is given what is actually there rather than the first of several.
      Parameters:
      userIdentityId - identity of the user
      serverId - declared server registration
      origin - which side created the collection
      Returns:
      the matching pairs
    • getDuePairs

      public org.springframework.data.domain.Page<org.exoplatform.caldav.model.CalendarSync> getDuePairs(org.exoplatform.caldav.model.CalendarSyncStatus status, Date before, int offset, int limit)
      One page of pairs in a given state whose last synchronisation ended before a cutoff, or has never ended.
      Parameters:
      status - the state to select
      before - pairs last synchronised strictly before this instant
      offset - page offset, in pages
      limit - page size
      Returns:
      one page of due pairs, oldest synchronisation first
    • savePair

      @Transactional public org.exoplatform.caldav.model.CalendarSync savePair(org.exoplatform.caldav.model.CalendarSync pair)
      Creates or updates a pair, canonicalising its href on the way in.
      Parameters:
      pair - the pair to persist
      Returns:
      the persisted pair, carrying its identifier
    • deletePair

      @Transactional public void deletePair(long id)
      Removes a pair and, by the foreign key, its object mappings.
      Parameters:
      id - technical identifier of the pair
    • getObjectByUid

      public org.exoplatform.caldav.model.ObjectSync getObjectByUid(long calendarSyncId, String icsUid)
      The mapping for one iCalendar object inside a pair.
      Parameters:
      calendarSyncId - the pair
      icsUid - the iCalendar UID
      Returns:
      the mapping, or null when the object is unknown
    • getObjectByEvent

      public org.exoplatform.caldav.model.ObjectSync getObjectByEvent(long calendarSyncId, long localEventId)
      The mapping for one eXo event inside a pair.
      Parameters:
      calendarSyncId - the pair
      localEventId - the eXo event
      Returns:
      the mapping, or null when the event has never been pushed
    • getObjects

      public org.springframework.data.domain.Page<org.exoplatform.caldav.model.ObjectSync> getObjects(long calendarSyncId, int offset, int limit)
      One page of a pair's object mappings.
      Parameters:
      calendarSyncId - the pair
      offset - page offset, in pages
      limit - page size
      Returns:
      one page of mappings, by identifier
    • countObjects

      public long countObjects(long calendarSyncId)
      How many objects a pair maps.
      Parameters:
      calendarSyncId - the pair
      Returns:
      the mapping count
    • isEventMapped

      public boolean isEventMapped(long localEventId)
      Whether an eXo event is already mapped. The question the backfill asks before creating a row, and the reason re-running it creates nothing.
      Parameters:
      localEventId - the eXo event
      Returns:
      true when a mapping exists
    • saveObject

      @Transactional public org.exoplatform.caldav.model.ObjectSync saveObject(org.exoplatform.caldav.model.ObjectSync object)
      Creates or updates an object mapping, canonicalising its href on the way in.
      Parameters:
      object - the mapping to persist
      Returns:
      the persisted mapping, carrying its identifier
    • deleteObjects

      @Transactional public int deleteObjects(long calendarSyncId)
      Drops every object mapping of a pair, leaving the pair itself in place.
      Parameters:
      calendarSyncId - the pair
      Returns:
      how many mappings were removed
    • canonicalHref

      public static String canonicalHref(String href)
      An href reduced to what identifies the resource: its percent-decoded path, without a trailing slash.

      The Java counterpart of the browser connector's collectionPath. The same collection is written %40 by one server and @ by a client, reported with and without a trailing slash, and reached through more than one host — none of which makes it a different collection. An href that cannot be parsed is returned trimmed rather than rejected: this is a normalisation, not a validation, and refusing to store an odd href would lose the binding rather than protect it.

      Parameters:
      href - a collection or object href, absolute or relative
      Returns:
      the canonical path, or the trimmed input when it cannot be parsed