Class SyncTask<Projection,​ApiItem,​Model>

  • Type Parameters:
    Projection - The Projection Class Object used for matching the api object to the database object. Typically this Projection Object has fewer properties like id,externalId, or name
    ApiItem - The Class Object representing the individual API result object coming back in the Collection
    Model - The Model Class that the Projection Class is a subset of. This is the Class that needs to be updated with changes

    public class SyncTask<Projection,​ApiItem,​Model>
    extends java.lang.Object
    This Utility Class provides an rxJava compatible means for syncing remote API objects with local/morpheus backed models in a persistent database. This handles an efficeint way to match data projection objects with api objects and batches updates to the backend database for efficient sync. This should be considered the standard method for caching objects within a CloudProvider and many other provider types.


     Observable<NetworkDomainSyncProjection> domainRecords =
     SyncTask<NetworkDomainSyncProjection,Map,NetworkDomain> syncTask = new SyncTask(domainRecords, apiItems as Collection<Map>)
     syncTask.addMatchFunction { NetworkDomainSyncProjection domainObject, Map apiItem ->
         domainObject.externalId == apiItem.'_ref'
     }.addMatchFunction { NetworkDomainSyncProjection domainObject, Map apiItem -> ==
     }.onDelete {removeItems ->, removeItems)
     }.onAdd { itemsToAdd ->
         addMissingZones(poolServer, itemsToAdd)
     }.withLoadObjectDetails { List<SyncTask.UpdateItemDto<NetworkDomainSyncProjection,Map>> updateItems ->
         return{} as Collection<Long>)
     }.onUpdate { List<SyncTask.UpdateItem<NetworkDomain,Map>> updateItems ->
         updateMatchedZones(poolServer, updateItems)