Developer checklist for adding a new entity to be synced to mobile

Assuming that you have defined your JPA Entity and database table; and defined Entity in avni-models. The following is meant to be a checklist and not a complete guide.

Avni Server

  • In simple cases you can extend your EntityRepository from FindByLastModifiedDateTime. You can look at a more complex example here org.avni.web.IndividualController#getIndividualsByOperatingIndividualScope. In a simple case, the sync is performed only based on lastModifiedDateTime. In complex cases there may be additional filters
  • In SyncController add your entity service.

Sync data between Avni Client and Server

Sync between Avni Client and Server is initiated by the Client and could be of following types:

  1. Manual Sync(User triggered, upload and fetch data)

    📘

    As part of manual sync, we'll first replace the "background-sync" job with a "dummy sync" job, perform manual-sync and then, replace the "dummy sync" job again with "background-sync" job.
    In react-native-background-worker, when we schedule a job with same jobKey(Name) as an existing job, it replaces the old one with new one. Therefore, above specified steps are supposed to fulfill our need to NOT run background-sync in parallel with manual-sync.
    This is done, as we do not have a way to cancel jobs by name directly in react-native-background-worker. We could only cancel by id, but we do not want to store job id in db.

  2. Automatic Sync (Periodic trigger)
    1. Complete Sync (upload and fetch data)
    2. Partial Sync (Only upload of data)
Pictorial representation of different Sync workflows in Avni-Client

Pictorial representation of different Sync workflows in Avni-Client