com.vodafone360.people.database.tables
Class ContactSummaryTable

java.lang.Object
  extended by com.vodafone360.people.database.tables.ContactSummaryTable

public abstract class ContactSummaryTable
extends java.lang.Object

The ContactSummaryTable contains a summary of important contact details for each contact such as name, status and Avatar availability. This data is duplicated here to improve the performance of the main contact list in the UI (otherwise the a costly inner join between the contact and contact details table would be needed). This class is never instantiated hence all methods must be static.

Version:
%I%, %G%

Nested Class Summary
static class ContactSummaryTable.Field
          An enumeration of all the field names in the database.
 
Field Summary
private static int ALTDETAIL_TYPE
           
private static int ALTFIELD_TYPE
           
private static int FORMATTED_NAME
           
private static int FRIEND_MINE
           
private static int LOCALCONTACT_ID
           
private static int NATIVE_CONTACTID
           
private static int ONLINE_STATUS
          Deprecated. 
private static int PICTURE_LOADED
           
private static int SNS
           
private static java.util.HashMap<java.lang.Long,java.lang.Integer> sPresenceMap
          This holds the presence information for each contact in the ContactSummaryTable
private static java.lang.String SQL_STRING_LOCAL_ID_EQUAL_QUESTION_MARK
          LocalId = ?
private static int STATUS_TEXT
           
private static int SUMMARY_ID
          Column indices which match the query string returned by getFullQueryList().
private static int SYNCTOPHONE
           
static java.lang.String TABLE_INDEX_NAME
           
static java.lang.String TABLE_NAME
          The name of the table as it appears in the database.
 
Constructor Summary
ContactSummaryTable()
           
 
Method Summary
static ServiceStatus addContact(Contact contact, SQLiteDatabase writableDb)
          Adds contact summary information to the table for a new contact.
private static void addToPresenceMap(java.lang.Long localContactID)
          This API should be called whenever a contact is added.
private static void clearPresenceMap()
          Clears the Presence Map table.
static void create(SQLiteDatabase writeableDb)
          Creates ContactSummary Table.
static ServiceStatus deleteContact(java.lang.Long localContactId, SQLiteDatabase writableDb)
          Deletes a contact summary record
private static void deleteFromPresenceMap(java.lang.Long localContactId)
          This API should be called whenever a contact is deleted from teh ContactSUmmaryTable.
static boolean fetchNativeContactIdList(java.util.List<java.lang.Integer> summaryList, SQLiteDatabase readableDb)
          Fetches a list of native contact IDs from the summary table (in ascending order)
static ServiceStatus fetchSummaryItem(long localContactId, ContactSummary summary, SQLiteDatabase readableDb)
          Fetches the contact summary for a particular contact
private static ContactDetail findAlternativeNameContactDetail(ContentValues values, java.util.List<ContactDetail> details)
          This method returns the most preferred contact detail to be displayed instead of the contact name when vcard.name is missing.
private static boolean getContactValuesFromDetail(ContentValues contactValues, ContactDetail newDetail)
          Adds suitable entries to a ContentValues objects for inserting or updating the contact summary table, from a contact detail.
private static java.lang.String getFullQueryList()
          Fetches the list of table fields that can be injected into an SQL query statement.
private static java.lang.String getGroupConstraint(java.lang.Long groupFilterId)
          Get a group constraint for SQL query depending on the group type.
private static java.lang.String getOnlineWhereClause()
          This API creates the string to be used in the IN clause when getting the list of all online contacts.
private static java.lang.String getOrderedQueryStringSql()
          Returns a full SQL query statement to fetch the contact summary information.
private static java.lang.String getOrderedQueryStringSql(java.lang.String whereClause)
          Returns a full SQL query statement to fetch the contact summary information in alphabetical order of contact name.
private static ContactSummary.OnlineStatus getPresence(java.lang.Long localContactID)
          Fetches the presence of the contact with localContactID
static ContactSummary getQueryData(Cursor c)
          Fetches the contact summary data from the current record of the given cursor.
private static java.lang.String getQueryStringSql(java.lang.String whereClause)
          Returns a full SQL query statement to fetch the contact summary information.
private static boolean isEmpty(java.lang.String string)
           
private static boolean isPreferredAltDetail(ContactDetail newDetail, ContactDetail currentDetail)
          Determines if a contact detail should be used in preference to the current alternative detail (the alternative detail is one that is shown when a contact has no name or no status).
static ServiceStatus modifyContact(Contact contact, SQLiteDatabase writableDb)
          Modifies contact parameters.
static ServiceStatus modifyPictureLoadedFlag(java.lang.Long localContactId, java.lang.Boolean value, SQLiteDatabase writeableDb)
          Modifies the avatar loaded flag for a particular contact
private static Cursor openContactSummaryCursor(java.lang.CharSequence constraint, java.lang.Long meProfileId, SQLiteDatabase readableDb)
          Fetches a contact list cursor for a given search constraint
static Cursor openContactSummaryCursor(java.lang.Long groupFilterId, java.lang.CharSequence constraint, java.lang.Long meProfileId, SQLiteDatabase readableDb)
          Fetches a contact list cursor for a given filter and search constraint
private static Cursor openContactSummaryCursor(java.lang.Long groupFilterId, java.lang.Long meProfileId, SQLiteDatabase readableDb)
          Fetches a contact list cursor for a given filter
static boolean setNativeContactId(long localContactId, long nativeContactId, SQLiteDatabase writableDb)
           
static ServiceStatus setOfflineStatus()
           
static ServiceStatus setOfflineStatusExceptForMe(long localContactIdOfMe)
           
static ServiceStatus syncSetNativeIds(java.util.List<ContactsTable.ContactIdInfo> contactIdList, SQLiteDatabase writableDb)
          Updates the native IDs for a list of contacts.
private static void updateAltValues(ContentValues values, ContactDetail altDetail)
          Processes a ContentValues object to handle a missing name or missing status.
static ServiceStatus updateNameAndStatus(Contact contact, SQLiteDatabase writableDb)
          Updates the summary for a contact Replaces the complex logic of updating the summary with a new contactdetail.
static ServiceStatus updateOnlineStatus(User user)
          TODO: be careful
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TABLE_NAME

public static final java.lang.String TABLE_NAME
The name of the table as it appears in the database.

See Also:
Constant Field Values

TABLE_INDEX_NAME

public static final java.lang.String TABLE_INDEX_NAME
See Also:
Constant Field Values

sPresenceMap

private static java.util.HashMap<java.lang.Long,java.lang.Integer> sPresenceMap
This holds the presence information for each contact in the ContactSummaryTable


SUMMARY_ID

private static final int SUMMARY_ID
Column indices which match the query string returned by getFullQueryList().

See Also:
Constant Field Values

LOCALCONTACT_ID

private static final int LOCALCONTACT_ID
See Also:
Constant Field Values

FORMATTED_NAME

private static final int FORMATTED_NAME
See Also:
Constant Field Values

STATUS_TEXT

private static final int STATUS_TEXT
See Also:
Constant Field Values

ONLINE_STATUS

@Deprecated
private static final int ONLINE_STATUS
Deprecated. 
See Also:
Constant Field Values

NATIVE_CONTACTID

private static final int NATIVE_CONTACTID
See Also:
Constant Field Values

FRIEND_MINE

private static final int FRIEND_MINE
See Also:
Constant Field Values

PICTURE_LOADED

private static final int PICTURE_LOADED
See Also:
Constant Field Values

SNS

private static final int SNS
See Also:
Constant Field Values

SYNCTOPHONE

private static final int SYNCTOPHONE
See Also:
Constant Field Values

ALTFIELD_TYPE

private static final int ALTFIELD_TYPE
See Also:
Constant Field Values

ALTDETAIL_TYPE

private static final int ALTDETAIL_TYPE
See Also:
Constant Field Values

SQL_STRING_LOCAL_ID_EQUAL_QUESTION_MARK

private static final java.lang.String SQL_STRING_LOCAL_ID_EQUAL_QUESTION_MARK
LocalId = ?

Constructor Detail

ContactSummaryTable

public ContactSummaryTable()
Method Detail

create

public static void create(SQLiteDatabase writeableDb)
                   throws SQLException
Creates ContactSummary Table.

Parameters:
writeableDb - A writable SQLite database
Throws:
SQLException - If an SQL compilation error occurs

getFullQueryList

private static java.lang.String getFullQueryList()
Fetches the list of table fields that can be injected into an SQL query statement. The getQueryData(Cursor) method can be used to obtain the data from the query.

Returns:
The query string
See Also:
getQueryData(Cursor).

getOrderedQueryStringSql

private static java.lang.String getOrderedQueryStringSql()
Returns a full SQL query statement to fetch the contact summary information. The getQueryData(Cursor) method can be used to obtain the data from the query.

Returns:
The query string
See Also:
getQueryData(Cursor).

getQueryStringSql

private static java.lang.String getQueryStringSql(java.lang.String whereClause)
Returns a full SQL query statement to fetch the contact summary information. The getQueryData(Cursor) method can be used to obtain the data from the query.

Parameters:
whereClause - An SQL where clause (without the "WHERE"). Cannot be null.
Returns:
The query string
See Also:
getQueryData(Cursor).

getOrderedQueryStringSql

private static java.lang.String getOrderedQueryStringSql(java.lang.String whereClause)
Returns a full SQL query statement to fetch the contact summary information in alphabetical order of contact name. The getQueryData(Cursor) method can be used to obtain the data from the query.

Parameters:
whereClause - An SQL where clause (without the "WHERE"). Cannot be null.
Returns:
The query string
See Also:
getQueryData(Cursor).

getQueryData

public static ContactSummary getQueryData(Cursor c)
Fetches the contact summary data from the current record of the given cursor.

Parameters:
c - Cursor returned by one of the getFullQueryList() based query methods.
Returns:
Filled in ContactSummary object

fetchSummaryItem

public static ServiceStatus fetchSummaryItem(long localContactId,
                                             ContactSummary summary,
                                             SQLiteDatabase readableDb)
Fetches the contact summary for a particular contact

Parameters:
localContactID - The primary key ID of the contact to find
summary - A new ContactSummary object to be filled in
readableDb - Readable SQLite database
Returns:
SUCCESS or a suitable error code

updateAltValues

private static void updateAltValues(ContentValues values,
                                    ContactDetail altDetail)
Processes a ContentValues object to handle a missing name or missing status.
  1. If the name is missing it will be replaced using the alternative detail.
  2. If the name is present, but status is missing the status will be replaced using the alternative detail
  3. Otherwise, the althernative detail is not used
In any case the ContactSummaryTable.Field.ALTFIELDTYPE value will be updated to reflect how the alternative detail is being used.

Parameters:
values - The ContentValues object to be updated
altDetail - The must suitable alternative detail (see #fetchNewAltDetail(long, ContactDetail, SQLiteDatabase)

addContact

public static ServiceStatus addContact(Contact contact,
                                       SQLiteDatabase writableDb)
Adds contact summary information to the table for a new contact. If the contact has no name or no status, an alternative detail will be used such as telephone number or email address.

Parameters:
contact - The new contact
writableDb - Writable SQLite database
Returns:
SUCCESS or a suitable error code

findAlternativeNameContactDetail

private static ContactDetail findAlternativeNameContactDetail(ContentValues values,
                                                              java.util.List<ContactDetail> details)
This method returns the most preferred contact detail to be displayed instead of the contact name when vcard.name is missing.

Parameters:
values - - ContentValues to be stored in the DB for the added contact
details - - the list of all contact details for the contact being added
Returns:
the contact detail most suitable to replace the missing vcard.name. "Value" field may be empty if no suitable contact detail was found.

deleteContact

public static ServiceStatus deleteContact(java.lang.Long localContactId,
                                          SQLiteDatabase writableDb)
Deletes a contact summary record

Parameters:
localContactID - The primary key ID of the contact to delete
writableDb - Writeable SQLite database
Returns:
SUCCESS or a suitable error code

modifyContact

public static ServiceStatus modifyContact(Contact contact,
                                          SQLiteDatabase writableDb)
Modifies contact parameters. Called when fields in the Contacts table have been changed.

Parameters:
contact - The modified contact
writableDb - Writable SQLite database
Returns:
SUCCESS or a suitable error code

getContactValuesFromDetail

private static boolean getContactValuesFromDetail(ContentValues contactValues,
                                                  ContactDetail newDetail)
Adds suitable entries to a ContentValues objects for inserting or updating the contact summary table, from a contact detail.

Parameters:
contactValues - The content values object to update
newDetail - The new or modified detail
Returns:
true if the summary table has been updated, false otherwise

isPreferredAltDetail

private static boolean isPreferredAltDetail(ContactDetail newDetail,
                                            ContactDetail currentDetail)
Determines if a contact detail should be used in preference to the current alternative detail (the alternative detail is one that is shown when a contact has no name or no status).

Parameters:
newDetail - The new detail
currentDetail - The current alternative detail
Returns:
true if the new detail should be used, false otherwise

fetchNativeContactIdList

public static boolean fetchNativeContactIdList(java.util.List<java.lang.Integer> summaryList,
                                               SQLiteDatabase readableDb)
Fetches a list of native contact IDs from the summary table (in ascending order)

Parameters:
summaryList - A list that will be populated by this function
readableDb - Readable SQLite database
Returns:
true if successful, false otherwise

modifyPictureLoadedFlag

public static ServiceStatus modifyPictureLoadedFlag(java.lang.Long localContactId,
                                                    java.lang.Boolean value,
                                                    SQLiteDatabase writeableDb)
Modifies the avatar loaded flag for a particular contact

Parameters:
localContactID - The primary key ID of the contact
value - Can be one of the following values:
  • true - The avatar has been loaded
  • false - There contact has an avatar but it has not yet been loaded
  • null - The contact does not have an avatar
writeableDb - Writable SQLite database
Returns:
SUCCESS or a suitable error code

getGroupConstraint

private static java.lang.String getGroupConstraint(java.lang.Long groupFilterId)
Get a group constraint for SQL query depending on the group type.

Parameters:
groupFilterId - the group id
Returns:
a String containing the corresponding group constraint

openContactSummaryCursor

public static Cursor openContactSummaryCursor(java.lang.Long groupFilterId,
                                              java.lang.CharSequence constraint,
                                              java.lang.Long meProfileId,
                                              SQLiteDatabase readableDb)
Fetches a contact list cursor for a given filter and search constraint

Parameters:
groupFilterId - The server group ID or null to fetch all groups
constraint - A search string or null to fetch without constraint
meProfileId - The current me profile Id which should be excluded from the returned list.
readableDb - Readable SQLite database
Returns:
The cursor or null if an error occurred
See Also:
getQueryData(Cursor)

openContactSummaryCursor

private static Cursor openContactSummaryCursor(java.lang.Long groupFilterId,
                                               java.lang.Long meProfileId,
                                               SQLiteDatabase readableDb)
Fetches a contact list cursor for a given filter

Parameters:
groupFilterId - The server group ID or null to fetch all groups
meProfileId - The current me profile Id which should be excluded from the returned list.
readableDb - Readable SQLite database
Returns:
The cursor or null if an error occurred
See Also:
getQueryData(Cursor)

openContactSummaryCursor

private static Cursor openContactSummaryCursor(java.lang.CharSequence constraint,
                                               java.lang.Long meProfileId,
                                               SQLiteDatabase readableDb)
Fetches a contact list cursor for a given search constraint

Parameters:
constraint - A search string or null to fetch without constraint
meProfileId - The current me profile Id which should be excluded from the returned list.
readableDb - Readable SQLite database
Returns:
The cursor or null if an error occurred
See Also:
getQueryData(Cursor)

updateOnlineStatus

public static ServiceStatus updateOnlineStatus(User user)
TODO: be careful

Parameters:
user -
writableDb -
Returns:

setOfflineStatus

public static ServiceStatus setOfflineStatus()
Parameters:
user -
writableDb -
Returns:

setOfflineStatusExceptForMe

public static ServiceStatus setOfflineStatusExceptForMe(long localContactIdOfMe)
Parameters:
localContactIdOfMe -
writableDb -
Returns:

syncSetNativeIds

public static ServiceStatus syncSetNativeIds(java.util.List<ContactsTable.ContactIdInfo> contactIdList,
                                             SQLiteDatabase writableDb)
Updates the native IDs for a list of contacts.

Parameters:
contactIdList - A list of ContactIdInfo objects. For each object, the local ID must match a local contact ID in the table. The Native ID will be used for the update. Other fields are unused.
writeableDb - Writable SQLite database
Returns:
SUCCESS or a suitable error code

isEmpty

private static boolean isEmpty(java.lang.String string)

updateNameAndStatus

public static ServiceStatus updateNameAndStatus(Contact contact,
                                                SQLiteDatabase writableDb)
Updates the summary for a contact Replaces the complex logic of updating the summary with a new contactdetail. Instead the method gets a whole contact after it has been modified and builds the summary infos.

Parameters:
contact - A Contact object that has been modified
writeableDb - Writable SQLite database
Returns:
SUCCESS or a suitable error code

setNativeContactId

public static boolean setNativeContactId(long localContactId,
                                         long nativeContactId,
                                         SQLiteDatabase writableDb)
Parameters:
localContactId -
writableDb -
Returns:

clearPresenceMap

private static void clearPresenceMap()
Clears the Presence Map table. This needs to be called whenever the ContactSummaryTable is cleared or recreated.


getPresence

private static ContactSummary.OnlineStatus getPresence(java.lang.Long localContactID)
Fetches the presence of the contact with localContactID

Parameters:
localContactID -
Returns:
the presence status of the contact

addToPresenceMap

private static void addToPresenceMap(java.lang.Long localContactID)
This API should be called whenever a contact is added. The presenceMap should be consistent with the ContactSummaryTable. Hence the default status of OFFLINE is set for every contact added

Parameters:
localContactID -

deleteFromPresenceMap

private static void deleteFromPresenceMap(java.lang.Long localContactId)
This API should be called whenever a contact is deleted from teh ContactSUmmaryTable. This API removes the presence information for the given contact

Parameters:
localContactId -

getOnlineWhereClause

private static java.lang.String getOnlineWhereClause()
This API creates the string to be used in the IN clause when getting the list of all online contacts.

Returns:
The list of contacts in the proper format for the IN list


JavaDoc