com.vodafone360.people.engine.contactsync
Class NativeExporter

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

public class NativeExporter
extends java.lang.Object


Field Summary
private  NativeContactsApi.Account mAccount
          The Native Account where to write the Contacts.
private static int MAX_CONTACTS_OPERATION_COUNT
          Number of contacts to be processed "per tick".
private  int mCurrentSyncableIdIndex
          The index in the current people id.
private  NativeContactsApi mNativeContactsApi
          Handle to the Native Contacts API.
private  PeopleContactsApi mPeopleContactsApi
          Handler to the People Contacts API.
private  int mProcessedIds
          The current count of processed IDs.
private  int mResult
          The result status.
private  int mState
          The current state.
private  long[] mSyncableContactsIds
          The list of local IDs from people contacts that need to be synced to Native.
private  int mTotalIds
          The total count of IDs to process (Native Database + People Database).
static int RESULT_ERROR
          The undefined result when the NativeImporter has not been run yet.
static int RESULT_OK
          The ok result when the NativeImporter has finished successfully.
static int RESULT_UNDEFINED
          The undefined result when the NativeImporter has not been run yet.
private static int STATE_DONE
          Internal state representing the task to perform: final state, nothing else to perform.
private static int STATE_GET_CONTACT_IDS
          Internal state representing the task to perform: gets the list of local contacts IDs to be synced to Native.
private static int STATE_ITERATE_THROUGH_IDS
          Internal state representing the task to perform: iterates through the list of syncable contacts IDs and sync to Native side.
 
Constructor Summary
NativeExporter(PeopleContactsApi pca, NativeContactsApi nca)
          Constructor.
 
Method Summary
private  void complete(int result)
          Sets the internal state to DONE with the provided result status.
private  void exportContactChanges(ContactChange[] changes)
          Exports the contact changes to the native address book.
private  void getContactIds()
          Gets the list of local contacts IDs that need to be synced to Native.
 int getCount()
          Gets the total number of IDs to process.
 int getPosition()
          Gets the current position in the list of IDs.
 int getResult()
          Gets the Import result.
private  void iterateThroughSyncableIds()
          Iterates through the list of syncable contacts IDs and sync to Native side.
 boolean tick()
          Tick method to call each time there is time for processing the Native Contacts Import.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESULT_UNDEFINED

public static final int RESULT_UNDEFINED
The undefined result when the NativeImporter has not been run yet.

See Also:
getResult(), Constant Field Values

RESULT_OK

public static final int RESULT_OK
The ok result when the NativeImporter has finished successfully.

See Also:
getResult(), Constant Field Values

RESULT_ERROR

public static final int RESULT_ERROR
The undefined result when the NativeImporter has not been run yet.

See Also:
getResult(), Constant Field Values

MAX_CONTACTS_OPERATION_COUNT

private static final int MAX_CONTACTS_OPERATION_COUNT
Number of contacts to be processed "per tick".

See Also:
tick(), Constant Field Values

mPeopleContactsApi

private PeopleContactsApi mPeopleContactsApi
Handler to the People Contacts API.


mNativeContactsApi

private NativeContactsApi mNativeContactsApi
Handle to the Native Contacts API.


STATE_GET_CONTACT_IDS

private static final int STATE_GET_CONTACT_IDS
Internal state representing the task to perform: gets the list of local contacts IDs to be synced to Native.

See Also:
Constant Field Values

STATE_ITERATE_THROUGH_IDS

private static final int STATE_ITERATE_THROUGH_IDS
Internal state representing the task to perform: iterates through the list of syncable contacts IDs and sync to Native side.

See Also:
Constant Field Values

STATE_DONE

private static final int STATE_DONE
Internal state representing the task to perform: final state, nothing else to perform.

See Also:
Constant Field Values

mState

private int mState
The current state.


mSyncableContactsIds

private long[] mSyncableContactsIds
The list of local IDs from people contacts that need to be synced to Native.


mCurrentSyncableIdIndex

private int mCurrentSyncableIdIndex
The index in the current people id.

See Also:
mSyncableContactsIds

mResult

private int mResult
The result status.


mTotalIds

private int mTotalIds
The total count of IDs to process (Native Database + People Database).


mProcessedIds

private int mProcessedIds
The current count of processed IDs.


mAccount

private NativeContactsApi.Account mAccount
The Native Account where to write the Contacts.

Constructor Detail

NativeExporter

public NativeExporter(PeopleContactsApi pca,
                      NativeContactsApi nca)
Constructor.

Parameters:
pca - handler to the People Contacts API
nca - handler to the Native Contacts API
Method Detail

getPosition

public int getPosition()
Gets the current position in the list of IDs. This can be used to track the current progress.

Returns:
the last processed id position in the list of IDs
See Also:
getCount()

getCount

public int getCount()
Gets the total number of IDs to process.

Returns:
the number of IDs to process

complete

private void complete(int result)
Sets the internal state to DONE with the provided result status.

Parameters:
result - the result status to set

tick

public boolean tick()
Tick method to call each time there is time for processing the Native Contacts Import. Note: the method will block for some time to process a certain number of Contacts and then will return. It will have to be called until it returns true meaning that the Import is over.

Returns:
true when the Import Task is finished, false if not

getResult

public int getResult()
Gets the Import result.

Returns:
the Import result
See Also:
RESULT_OK, RESULT_ERROR, RESULT_UNDEFINED

getContactIds

private void getContactIds()
Gets the list of local contacts IDs that need to be synced to Native.


iterateThroughSyncableIds

private void iterateThroughSyncableIds()
Iterates through the list of syncable contacts IDs and sync to Native side.


exportContactChanges

private void exportContactChanges(ContactChange[] changes)
Exports the contact changes to the native address book.

Parameters:
changes - the array of ContactChange that represent a full contact, a deleted contact or an updated contact


JavaDoc