com.vodafone360.people.engine.contactsync
Class PeopleContactsApi

java.lang.Object
  extended by com.vodafone360.people.engine.contactsync.PeopleContactsApi

public class PeopleContactsApi
extends java.lang.Object

The PeopleContactsApi wrapper class of the People contacts database. Modifying the People database by adding, modifying and deleting contacts should be done via this class to ensure that the database remain consistent across all the tables. Note: this class is an attempt to separate the internal People contacts persistence from other components that need to access it (i.e. hiding its database, SQL tables and internals). It is not yet used by all the code base that would need to.


Field Summary
private  java.util.ArrayList<ContactDetail> mAddedDetails
          Array of added ContactDetail.
private  java.util.List<ContactsTable.ContactIdInfo> mContactIdInfoList
          Array of ContactIdInfo.
private  DatabaseHelper mDbh
          Handler to the DatabaseHelper class.
private  java.util.ArrayList<ContactDetail> mDeletedDetails
          Array of deleted ContactDetail.
private  java.util.ArrayList<ContactDetail> mUpdatedDetails
          Array of updated ContactDetail.
 
Constructor Summary
PeopleContactsApi(DatabaseHelper dbh)
          Constructor.
 
Method Summary
 boolean addNativeContact(ContactChange[] contact)
          Adds a native contact to the people database.
 boolean deleteNativeContact(long nativeId, boolean syncToNative)
          Deletes a Contact in the people database from its native id.
 ContactChange[] getContact(long nativeId)
          Gets a contact from its native id.
 long[] getNativeContactsIds()
          Gets the list of native contacts ids stored in the people database.
 ContactChange[] getNativeSyncableContactChanges(long localId)
          Gets the syncable changes for a contact (i.e. the details not synced yet to native).
 long[] getNativeSyncableContactIds()
          Gets an array of contacts people ids that need to be synced back to native.
private  long[] mergeSortedArrays(long[] array1, long[] array2)
          Merges two sorted arrays in one sorted array.
private  void setNativeContactId(ContactChange[] changes, long nativeContactId)
          Sets the native contact id to the new details.
 boolean syncBackDeletedNativeContact(ContactChange deletedContact)
          Acknowledges the people database that the native side deleted the contact as requested.
 boolean syncBackNewNativeContact(ContactChange[] contact, ContactChange[] nativeIds)
          Sets the native ids to the people database since the contact has been added to native.
 boolean syncBackUpdatedNativeContact(ContactChange[] contact, ContactChange[] nativeIds)
          Sets the native ids to the people database for the added details on native side and removes the deleted details from the people database.
 void updateNativeContact(ContactChange[] contact)
          Updates a native contact in the people database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mDbh

private DatabaseHelper mDbh
Handler to the DatabaseHelper class.


mContactIdInfoList

private java.util.List<ContactsTable.ContactIdInfo> mContactIdInfoList
Array of ContactIdInfo. Used for compatibility reasons with DatabaseHelper method and kept as a class member to avoid frequent allocation.

See Also:
DatabaseHelper.syncDeleteContactList(List, boolean, boolean)

mAddedDetails

private java.util.ArrayList<ContactDetail> mAddedDetails
Array of added ContactDetail. Used for compatibility reasons with DatabaseHelper method and kept as a class member to avoid frequent allocation.

See Also:
DatabaseHelper.syncAddContactDetailList(List, boolean, boolean)

mUpdatedDetails

private java.util.ArrayList<ContactDetail> mUpdatedDetails
Array of updated ContactDetail. Used for compatibility reasons with DatabaseHelper method and kept as a class member to avoid frequent allocation.

See Also:
DatabaseHelper.syncModifyContactDetailList(List, boolean, boolean)

mDeletedDetails

private java.util.ArrayList<ContactDetail> mDeletedDetails
Array of deleted ContactDetail. Used for compatibility reasons with DatabaseHelper method and kept as a class member to avoid frequent allocation.

See Also:
DatabaseHelper#syncDeletedContactDetailList(List, boolean, boolean)
Constructor Detail

PeopleContactsApi

public PeopleContactsApi(DatabaseHelper dbh)
Constructor.

Parameters:
dbh - the DatabaseHelper to access the people database
Method Detail

getNativeContactsIds

public long[] getNativeContactsIds()
Gets the list of native contacts ids stored in the people database. Contacts being deleted but still in the database will also be returned.

Returns:
an array of native contacts ids

getNativeSyncableContactIds

public long[] getNativeSyncableContactIds()
Gets an array of contacts people ids that need to be synced back to native.

Returns:

deleteNativeContact

public boolean deleteNativeContact(long nativeId,
                                   boolean syncToNative)
Deletes a Contact in the people database from its native id. Note: it assumes that the deletion comes from native as it sets flags to prevent syncing back to native

Parameters:
nativeId - the native id of the contact to delete
syncToNative - true if the deletion has to be propagated to native, false otherwise

addNativeContact

public boolean addNativeContact(ContactChange[] contact)
Adds a native contact to the people database. Note: it assumes that the new contact comes from native as it sets flags to prevent syncing back to native

Parameters:
contact - the ContactChange array representing the contact to add
Returns:
true if successful, false otherwise

updateNativeContact

public void updateNativeContact(ContactChange[] contact)
Updates a native contact in the people database. Note: it assumes that the changes come from native as it sets flags to prevent syncing back to native

Parameters:
contact - the contact changes to apply to the contact

getContact

public ContactChange[] getContact(long nativeId)
Gets a contact from its native id.

Parameters:
nativeId - the native id of the contact
Returns:
an array of ContactChange representing the contact, null if not found

getNativeSyncableContactChanges

public ContactChange[] getNativeSyncableContactChanges(long localId)
Gets the syncable changes for a contact (i.e. the details not synced yet to native).

Parameters:
localId - the localId of the contact
Returns:
an array of ContactChange that need to be synced to native

setNativeContactId

private void setNativeContactId(ContactChange[] changes,
                                long nativeContactId)
Sets the native contact id to the new details.

Parameters:
changes - the array of changes where to set missing native contact id
nativeContactId - the native contact id to set

syncBackNewNativeContact

public boolean syncBackNewNativeContact(ContactChange[] contact,
                                        ContactChange[] nativeIds)
Sets the native ids to the people database since the contact has been added to native.

Parameters:
contact - the array of ContactChange representing the new contact the contact
nativeIds - the array of ContactChange containing the native ids for the added contact
Returns:
true if successful, false otherwise

syncBackDeletedNativeContact

public boolean syncBackDeletedNativeContact(ContactChange deletedContact)
Acknowledges the people database that the native side deleted the contact as requested.

Parameters:
deletedContact - the ContactChange of the deleted contact

syncBackUpdatedNativeContact

public boolean syncBackUpdatedNativeContact(ContactChange[] contact,
                                            ContactChange[] nativeIds)
Sets the native ids to the people database for the added details on native side and removes the deleted details from the people database.

Parameters:
contact - the array of ContactChange representing the updates that where performed on the contact
nativeIds - the array of ContactChange containing the native ids for the added details
Returns:
true if successful, false otherwise

mergeSortedArrays

private long[] mergeSortedArrays(long[] array1,
                                 long[] array2)
Merges two sorted arrays in one sorted array.

Parameters:
array1 - the first sorted array
array2 - the second sorted array
Returns:
a sorted array that contains array1 and array2


JavaDoc