Class SyncTask<Projection,ApiItem,Model>

java.lang.Object
com.morpheusdata.core.util.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 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.

Example:


 Observable<NetworkDomainSyncProjection> domainRecords = morpheusContext.network.listNetworkDomainSyncMatch(poolServer.integration.id)

 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 ->
     domainObject.name == apiItem.name
 }.onDelete {removeItems ->
     morpheusContext.network.removeMissingZones(poolServer.integration.id, removeItems)
 }.onAdd { itemsToAdd ->
     addMissingZones(poolServer, itemsToAdd)
 }.withLoadObjectDetails { List<SyncTask.UpdateItemDto<NetworkDomainSyncProjection,Map>> updateItems ->
     return morpheusContext.network.listNetworkDomainsById(updateItems.collect{it.existingItem.id} as Collection<Long>)
 }.onUpdate { List<SyncTask.UpdateItem<NetworkDomain,Map>> updateItems ->
     updateMatchedZones(poolServer, updateItems)
 }.start()