com.vodafone360.people.engine.contactsync
Class UploadServerContacts

java.lang.Object
  extended by com.vodafone360.people.engine.contactsync.BaseSyncProcessor
      extended by com.vodafone360.people.engine.contactsync.UploadServerContacts

public class UploadServerContacts
extends BaseSyncProcessor

Processor handling upload of contacts to the People server.


Nested Class Summary
protected static class UploadServerContacts.InternalState
          Internal states supported by the processor.
 
Field Summary
private  java.lang.Long mActiveGroupId
          Contains the server ID of the group being associated with a contact.
private static int MAX_PROGESS
          Maximum progress percentage value.
protected static int MAX_UP_PAGE_SIZE
          Maximum number of contacts to send to the server in a request.
private  java.util.List<ContactChangeLogTable.ContactChangeInfo> mContactChangeInfoList
          Contains the next page of changes from the server change log.
private  java.util.List<Contact> mContactChangeList
          Contains the next page of contacts being sent to the server which have either been added or changed.
private  java.util.List<java.lang.Long> mContactIdList
          List of server IDs which is sent to the server by the DeleteContacts API.
private  Cursor mContactsCursor
          Cursor used for fetching new/modified contacts from the NowPlus database.
private  long mDbSyncTime
          Used for debug to monitor the database read/write time during a sync.
private  Contact mDeleteDetailContact
          Contains the main contact during the contact detail deletion process.
private  java.util.List<GroupItem> mGroupList
          Current list of groups being added to the contacts listed in the mContactIdList.
private  UploadServerContacts.InternalState mInternalState
          Current internal state of the processor.
private  int mItemsDone
          Total number of contacts sync'ed so far.
private  long mNoOfItemsSent
          No of items which were sent in the current batch, used for updating the progress bar once a particular call is complete.
private  int mTotalNoOfItems
          Total number of items which need to be sync'ed to the server (includes all types of updates).
private static long NANOSECONDS_IN_MS
          Used for converting between nanoseconds and milliseconds.
 
Fields inherited from class com.vodafone360.people.engine.contactsync.BaseSyncProcessor
mCallback, mDb, mFailureList
 
Constructor Summary
UploadServerContacts(IContactSyncCallback callback, DatabaseHelper db)
          Processor constructor.
 
Method Summary
protected  void doCancel()
          Called by framework to cancel contact sync.
protected  void doStart()
          Called by framework to start the processor running.
 java.lang.Long getActiveGroupId()
          Returns the server ID of the group being associated with a contact (for testing only).
 java.util.List<Contact> getContactChangeList()
          Returns the next page of contacts being sent to the server which have either been added or changed (for testing only).
 java.util.List<java.lang.Long> getContactIdList()
          Returns a list of server IDs which is sent to the server by the DeleteContacts API (for testing only).
 Contact getDeleteDetailContact()
          Returns the main contact during the contact detail deletion process (for testing only).
 java.util.List<GroupItem> getGroupList()
          Return the current list of groups being added to the contacts listed in the mContactIdList.
 UploadServerContacts.InternalState getInternalState()
          Returns the current internal state of the processor (for testing only).
private  ServiceStatus handleUploadDetailChanges(Contact contactSrc, Contact contactDest, java.util.List<DatabaseHelper.ServerIdInfo> detailServerIdList)
          Called when handling the server response from a new contact or modify contact sync.
private  void moveToNextState()
          Changes the state of the processor to the next internal state.
 void processCommsResponse(ResponseQueue.Response resp)
          Called by framework when a response to a server request is received.
private  void processDeletedContactsResp(ResponseQueue.Response resp)
          Called when a server response is received during a deleted contact sync.
private  void processDeletedDetailsResp(ResponseQueue.Response resp)
          Called when a server response is received during a deleted contact detail sync.
private  void processGroupAdditionsResp(ResponseQueue.Response resp)
          Called when a server response is received during a group/contact add relation sync.
private  void processGroupDeletionsResp(ResponseQueue.Response resp)
          Called when a server response is received during a group/contact delete relation sync.
private  void processModifiedDetailsResp(ResponseQueue.Response resp)
          Called when a server response is received during a modified contact sync.
private  void processNewContactsResp(ResponseQueue.Response resp)
          Called when a server response is received during a new contact sync.
private  void sendNextAddGroupRelationsPage()
          Sends next add contact/group relation request to the server.
private  void sendNextContactAdditionsPage()
          Sends the next page of new contacts to the server.
private  void sendNextDeleteContactsPage()
          Sends the next page of deleted contacts to the server.
private  void sendNextDeleteDetailsPage()
          Sends the next deleted details to the server.
private  void sendNextDelGroupRelationsPage()
          Sends next delete contact/group relation request to the server.
private  void sendNextDetailChangesPage()
          Sends the next page of new/modified details to the server.
private  void startProcessDeletedContacts()
          Sends the first page of deleted contacts to the server.
private  void startProcessDeletedDetails()
          Sends the deleted details of the first contact to the server.
private  void startProcessGroupAdditions()
          Sends the first contact/group relation addition request to the server.
private  void startProcessGroupDeletions()
          Sends the first contact/group relation deletion request to the server.
private  void startProcessModifiedDetails()
          Sends the first page of contact modifications (includes new and modified details) to the server.
private  void startProcessNewContacts()
          Sends the first page of new contacts to the server.
private  void updateProgress()
          Helper method to update the progress UI.
 
Methods inherited from class com.vodafone360.people.engine.contactsync.BaseSyncProcessor
cancel, complete, getEngine, markDbChanged, onComplete, onTimeoutEvent, setReqId, setSyncStatus, setTimeout, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_PROGESS

private static final int MAX_PROGESS
Maximum progress percentage value.

See Also:
Constant Field Values

NANOSECONDS_IN_MS

private static final long NANOSECONDS_IN_MS
Used for converting between nanoseconds and milliseconds.

See Also:
Constant Field Values

MAX_UP_PAGE_SIZE

protected static final int MAX_UP_PAGE_SIZE
Maximum number of contacts to send to the server in a request.

See Also:
Constant Field Values

mNoOfItemsSent

private long mNoOfItemsSent
No of items which were sent in the current batch, used for updating the progress bar once a particular call is complete.


mTotalNoOfItems

private int mTotalNoOfItems
Total number of items which need to be sync'ed to the server (includes all types of updates). Used for updating the progress.


mItemsDone

private int mItemsDone
Total number of contacts sync'ed so far.


mContactChangeInfoList

private final java.util.List<ContactChangeLogTable.ContactChangeInfo> mContactChangeInfoList
Contains the next page of changes from the server change log.


mContactChangeList

private final java.util.List<Contact> mContactChangeList
Contains the next page of contacts being sent to the server which have either been added or changed.


mInternalState

private UploadServerContacts.InternalState mInternalState
Current internal state of the processor.


mDbSyncTime

private long mDbSyncTime
Used for debug to monitor the database read/write time during a sync.


mContactsCursor

private Cursor mContactsCursor
Cursor used for fetching new/modified contacts from the NowPlus database.


mContactIdList

private final java.util.List<java.lang.Long> mContactIdList
List of server IDs which is sent to the server by the DeleteContacts API.


mGroupList

private final java.util.List<GroupItem> mGroupList
Current list of groups being added to the contacts listed in the mContactIdList. Will only contain a single group (list is needed for the GroupPrivacy.addContactGroupRelations(BaseEngine, List, List) API).


mDeleteDetailContact

private Contact mDeleteDetailContact
Contains the main contact during the contact detail deletion process.


mActiveGroupId

private java.lang.Long mActiveGroupId
Contains the server ID of the group being associated with a contact.

Constructor Detail

UploadServerContacts

public UploadServerContacts(IContactSyncCallback callback,
                            DatabaseHelper db)
Processor constructor.

Parameters:
callback - Provides access to contact sync engine callback functions.
db - NowPlus Database needed for reading contact and group information
Method Detail

doStart

protected final void doStart()
Called by framework to start the processor running. First sends all the new contacts to the server.

Specified by:
doStart in class BaseSyncProcessor

startProcessNewContacts

private void startProcessNewContacts()
Sends the first page of new contacts to the server.


startProcessModifiedDetails

private void startProcessModifiedDetails()
Sends the first page of contact modifications (includes new and modified details) to the server.


startProcessDeletedContacts

private void startProcessDeletedContacts()
Sends the first page of deleted contacts to the server.


startProcessDeletedDetails

private void startProcessDeletedDetails()
Sends the deleted details of the first contact to the server.


startProcessGroupAdditions

private void startProcessGroupAdditions()
Sends the first contact/group relation addition request to the server.


startProcessGroupDeletions

private void startProcessGroupDeletions()
Sends the first contact/group relation deletion request to the server.


sendNextContactAdditionsPage

private void sendNextContactAdditionsPage()
Sends the next page of new contacts to the server.


sendNextDetailChangesPage

private void sendNextDetailChangesPage()
Sends the next page of new/modified details to the server.


sendNextDeleteContactsPage

private void sendNextDeleteContactsPage()
Sends the next page of deleted contacts to the server.


sendNextDeleteDetailsPage

private void sendNextDeleteDetailsPage()
Sends the next deleted details to the server. This has to be done one contact at a time.


sendNextAddGroupRelationsPage

private void sendNextAddGroupRelationsPage()
Sends next add contact/group relation request to the server. Many contacts can be added by a single request.


sendNextDelGroupRelationsPage

private void sendNextDelGroupRelationsPage()
Sends next delete contact/group relation request to the server.


moveToNextState

private void moveToNextState()
Changes the state of the processor to the next internal state. Is called when the current state has finished.


doCancel

protected void doCancel()
Called by framework to cancel contact sync. No implementation required, the server response will be ignored and the contact sync will be repeated if necessary.

Specified by:
doCancel in class BaseSyncProcessor

processCommsResponse

public final void processCommsResponse(ResponseQueue.Response resp)
Called by framework when a response to a server request is received. Processes response based on the current internal state.

Specified by:
processCommsResponse in class BaseSyncProcessor
Parameters:
resp - Response data

processNewContactsResp

private void processNewContactsResp(ResponseQueue.Response resp)
Called when a server response is received during a new contact sync. The server ID, user ID and contact detail unique IDs are extracted from the response and the NowPlus database updated. Possibly server errors are also handled.

Parameters:
resp - Response from server.

processModifiedDetailsResp

private void processModifiedDetailsResp(ResponseQueue.Response resp)
Called when a server response is received during a modified contact sync. The server ID, user ID and contact detail unique IDs are extracted from the response and the NowPlus database updated if necessary. Possibly server errors are also handled.

Parameters:
resp - Response from server.

processDeletedContactsResp

private void processDeletedContactsResp(ResponseQueue.Response resp)
Called when a server response is received during a deleted contact sync. The server change log is updated. Possibly server errors are also handled.

Parameters:
resp - Response from server.

processDeletedDetailsResp

private void processDeletedDetailsResp(ResponseQueue.Response resp)
Called when a server response is received during a deleted contact detail sync. The server change log is updated. Possibly server errors are also handled.

Parameters:
resp - Response from server.

processGroupAdditionsResp

private void processGroupAdditionsResp(ResponseQueue.Response resp)
Called when a server response is received during a group/contact add relation sync. The server change log is updated. Possibly server errors are also handled.

Parameters:
resp - Response from server.

processGroupDeletionsResp

private void processGroupDeletionsResp(ResponseQueue.Response resp)
Called when a server response is received during a group/contact delete relation sync. The server change log is updated. Possibly server errors are also handled.

Parameters:
resp - Response from server.

handleUploadDetailChanges

private ServiceStatus handleUploadDetailChanges(Contact contactSrc,
                                                Contact contactDest,
                                                java.util.List<DatabaseHelper.ServerIdInfo> detailServerIdList)
Called when handling the server response from a new contact or modify contact sync. Updates the unique IDs for all the details if necessary.

Parameters:
contactSrc - Contact received from server.
contactDest - Contact from database.
detailServerIdList - List of contact details with updated unique id.
Returns:
ServiceStatus object.

updateProgress

private void updateProgress()
Helper method to update the progress UI.


getInternalState

public final UploadServerContacts.InternalState getInternalState()
Returns the current internal state of the processor (for testing only).

Returns:
InternalState of processor.

getContactIdList

public final java.util.List<java.lang.Long> getContactIdList()
Returns a list of server IDs which is sent to the server by the DeleteContacts API (for testing only).

Returns:
List of server IDs.

getGroupList

public final java.util.List<GroupItem> getGroupList()
Return the current list of groups being added to the contacts listed in the mContactIdList. Will only contain a single group (list is needed for the GroupPrivacy.addContactGroupRelations(BaseEngine, List, List) API) (for testing only).

Returns:
List of groups.

getContactChangeList

public final java.util.List<Contact> getContactChangeList()
Returns the next page of contacts being sent to the server which have either been added or changed (for testing only).

Returns:
List of contacts.

getDeleteDetailContact

public final Contact getDeleteDetailContact()
Returns the main contact during the contact detail deletion process (for testing only).

Returns:
Main contact.

getActiveGroupId

public final java.lang.Long getActiveGroupId()
Returns the server ID of the group being associated with a contact (for testing only).

Returns:
Server ID.


JavaDoc