Search in sources :

Example 26 with Contact

use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.

the class ContactDetailsTable method modifyDetail.

/**
     * Updates an existing contact detail in the table.
     * 
     * @param detail The modified detail.
     * @param syncToServer Mark the new detail so it will be synced to the
     *            server
     * @param syncToNative Mark the new detail so it will be synced to the
     *            native database
     * @param writeableDb A writable SQLite database object.
     * @return SUCCESS or a suitable error code.
     * @note If any given field values in the contact detail are NULL they will
     *       NOT be modified in the database.
     */
public static ServiceStatus modifyDetail(ContactDetail detail, boolean syncToServer, boolean syncToNative, SQLiteDatabase writeableDb) {
    try {
        // back to server if we change anything
        if (VersionUtils.is2XPlatform() == false && detail.key == DetailKeys.VCARD_NAME) {
            Name name = VCardHelper.getName(detail.value);
            if (name.surname.length() > 0) {
                name.firstname = name.firstname.replace(name.surname, "").trim();
                name.midname = name.midname.replace(name.surname, "").trim();
            }
            String vcardName = VCardHelper.makeName(name);
            if (!detail.value.equals(vcardName)) {
                syncToServer = true;
                detail.value = vcardName;
            }
        }
        ContentValues contactDetailValues = fillUpdateData(detail, syncToServer, syncToNative);
        if (writeableDb.update(TABLE_NAME, contactDetailValues, Field.DETAILLOCALID + " = " + detail.localDetailID, null) <= 0) {
            LogUtils.logE("ContactDetailsTable.modifyDetail() Unable to update contact detail , localDetailID[" + detail.localDetailID + "]");
            return ServiceStatus.ERROR_NOT_FOUND;
        }
    } catch (SQLException e) {
        LogUtils.logE("ContactDetailsTable.modifyDetail() SQLException - Unable to modify contact detail", e);
        return ServiceStatus.ERROR_DATABASE_CORRUPT;
    }
    DatabaseHelper.trace(true, "ContactDetailsTable.modifyDetail() localContactID[" + detail.localContactID + "] localDetailID[" + detail.localDetailID + "]");
    return ServiceStatus.SUCCESS;
}
Also used : ContentValues(android.content.ContentValues) SQLException(android.database.SQLException) Name(com.vodafone360.people.datatypes.VCardHelper.Name)

Example 27 with Contact

use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.

the class ContactDetailsTable method syncServerGetNextNewContactDetails.

/**
     * Returns the next batch of contacts which need to be added on the server.
     * The {@link #syncServerFetchContactChanges(SQLiteDatabase, boolean)}
     * method is used to retrieve the cursor initially, then this function can
     * be called many times until all the contacts have been fetched. When the
     * list returned from this method is empty the cursor has reached the end
     * and the sync is complete.
     * 
     * @param c The cursor (see description above)
     * @param contactList Will be filled with contacts that need to be added to
     *            the server
     * @param maxContactsToFetch Maximum number of contacts to return in the
     *            list. The function can be called in a loop until all the
     *            contacts have been retrieved.
     */
public static void syncServerGetNextNewContactDetails(Cursor c, List<Contact> contactList, int maxContactsToFetch) {
    final int QUERY_COLUMN_LOCALCONTACTID = 0;
    final int QUERY_COLUMN_SERVERSYNCCONTACTID = 1;
    final int QUERY_COLUMN_LOCALDETAILID = 2;
    final int QUERY_COLUMN_SERVERDETAILID = 3;
    final int QUERY_COLUMN_KEY = 4;
    final int QUERY_COLUMN_KEYTYPE = 5;
    final int QUERY_COLUMN_VAL = 6;
    final int QUERY_COLUMN_ORDER = 7;
    final int QUERY_COLUMN_PHOTOURL = 8;
    contactList.clear();
    Contact currentContact = null;
    while (c.moveToNext()) {
        final ContactDetail detail = new ContactDetail();
        if (!c.isNull(QUERY_COLUMN_LOCALCONTACTID)) {
            detail.localContactID = c.getLong(QUERY_COLUMN_LOCALCONTACTID);
        }
        if (!c.isNull(QUERY_COLUMN_SERVERSYNCCONTACTID)) {
            detail.serverContactId = c.getLong(QUERY_COLUMN_SERVERSYNCCONTACTID);
        }
        if (currentContact == null || !currentContact.localContactID.equals(detail.localContactID)) {
            if (contactList.size() >= maxContactsToFetch) {
                if (currentContact != null) {
                    c.moveToPrevious();
                }
                break;
            }
            currentContact = new Contact();
            currentContact.localContactID = detail.localContactID;
            if (detail.serverContactId == null) {
                currentContact.synctophone = true;
            }
            currentContact.contactID = detail.serverContactId;
            contactList.add(currentContact);
        }
        if (!c.isNull(QUERY_COLUMN_LOCALDETAILID)) {
            detail.localDetailID = c.getLong(QUERY_COLUMN_LOCALDETAILID);
        }
        if (!c.isNull(QUERY_COLUMN_SERVERDETAILID)) {
            detail.unique_id = c.getLong(QUERY_COLUMN_SERVERDETAILID);
        }
        detail.key = ContactDetail.DetailKeys.values()[c.getInt(QUERY_COLUMN_KEY)];
        if (!c.isNull(QUERY_COLUMN_KEYTYPE)) {
            detail.keyType = ContactDetail.DetailKeyTypes.values()[c.getInt(QUERY_COLUMN_KEYTYPE)];
        }
        detail.value = c.getString(QUERY_COLUMN_VAL);
        if (!c.isNull(QUERY_COLUMN_ORDER)) {
            detail.order = c.getInt(QUERY_COLUMN_ORDER);
        }
        if (!c.isNull(QUERY_COLUMN_PHOTOURL)) {
            detail.photo_url = c.getString(QUERY_COLUMN_PHOTOURL);
        }
        currentContact.details.add(detail);
    }
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) Contact(com.vodafone360.people.datatypes.Contact)

Example 28 with Contact

use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.

the class ContactDetailsTable method fixPreferredValues.

/**
     * Fixes the phone numbers and emails of a contact to ensure that at least
     * one of each is a preferred detail.
     * 
     * @param localContactId The local Id of the contact
     * @param writableDb A writable SQLite database object
     * @return SUCCESS or a suitable error code.
     */
public static ServiceStatus fixPreferredValues(long localContactId, SQLiteDatabase writableDb) {
    DatabaseHelper.trace(false, "ContactDetailsTable.fixPreferredValues()");
    ServiceStatus status = fixPreferredDetail(localContactId, ContactDetail.DetailKeys.VCARD_PHONE, writableDb);
    if (ServiceStatus.SUCCESS != status) {
        return status;
    }
    return fixPreferredDetail(localContactId, ContactDetail.DetailKeys.VCARD_EMAIL, writableDb);
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Example 29 with Contact

use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.

the class ContactDetailsTable method fetchDetail.

/**
     * Fetches the first contact detail found for a contact and key.
     * 
     * @param localContactId The local contact ID
     * @param key The contact detail key value
     * @param readableDb A readable SQLite database object.
     * @return The contact detail, or NULL if it could not be found.
     */
public static ContactDetail fetchDetail(long localContactId, DetailKeys key, SQLiteDatabase readableDb) {
    DatabaseHelper.trace(false, "ContactDetailsTable.fetchDetail()");
    String[] args = { String.format("%d", localContactId), String.format("%d", key.ordinal()) };
    ContactDetail detail = null;
    Cursor c = null;
    try {
        c = readableDb.rawQuery(getQueryStringSql(Field.LOCALCONTACTID + "=? AND " + Field.KEY + "=?"), args);
        if (c.moveToFirst()) {
            detail = getQueryData(c);
        }
    } catch (SQLiteException e) {
        LogUtils.logE("ContactDetailsTable.fetchDetail() Exception - Unable to fetch contact detail", e);
        return null;
    } finally {
        CloseUtils.close(c);
        c = null;
    }
    return detail;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException)

Example 30 with Contact

use of com.vodafone360.people.datatypes.Contact in project 360-Engine-for-Android by 360.

the class NowPlusContactsTest method testAddDeleteContactsDetails.

@MediumTest
public void testAddDeleteContactsDetails() {
    Log.i(LOG_TAG, "***** EXECUTING testAddDeleteContactsDetails *****");
    Log.i(LOG_TAG, "Test contact functionality (add delete contacts details)");
    Log.i(LOG_TAG, "Test 1a: Initialise test environment and load database");
    assertTrue(initialise());
    Log.i(LOG_TAG, "Test 1b: Remove user data");
    mDatabaseHelper.removeUserData();
    ServiceStatus status = mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK);
    assertEquals(ServiceStatus.SUCCESS, status);
    Log.i(LOG_TAG, "Test 1c: Add " + NUM_OF_CONTACTS + " random contacts");
    // add contacts and check if added contacts are the same as fetched 
    Contact[] inputContacts = new Contact[NUM_OF_CONTACTS];
    Contact addedContact = new Contact();
    for (int i = 0; i < NUM_OF_CONTACTS; i++) {
        inputContacts[i] = mTestModule.createDummyContactData();
        status = mDatabaseHelper.addContact(inputContacts[i]);
        assertEquals(ServiceStatus.SUCCESS, status);
        status = mDatabaseHelper.fetchContact(inputContacts[i].localContactID, addedContact);
        assertEquals(ServiceStatus.SUCCESS, status);
        assertTrue(TestModule.doContactsMatch(addedContact, inputContacts[i]));
    }
    Log.i(LOG_TAG, "Test 1d: Delete contacts detatils and check if deletion was correct");
    for (int i = 0; i < inputContacts.length; i++) {
        for (int j = 0; j < inputContacts[i].details.size(); j++) {
            ContactDetail detail = inputContacts[i].details.get(j);
            status = mDatabaseHelper.deleteContactDetail(detail.localDetailID);
            assertEquals(ServiceStatus.SUCCESS, status);
        }
        // check if deletion works good 
        Contact modifiedContact = new Contact();
        status = mDatabaseHelper.fetchContact(inputContacts[i].localContactID, modifiedContact);
        assertEquals(ServiceStatus.SUCCESS, status);
        assertTrue(TestModule.doContactsMatch(modifiedContact, inputContacts[i]));
    }
    shutdown();
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) Contact(com.vodafone360.people.datatypes.Contact) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

Contact (com.vodafone360.people.datatypes.Contact)109 ServiceStatus (com.vodafone360.people.service.ServiceStatus)107 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)100 ArrayList (java.util.ArrayList)62 MediumTest (android.test.suitebuilder.annotation.MediumTest)50 Suppress (android.test.suitebuilder.annotation.Suppress)39 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)34 Cursor (android.database.Cursor)31 ContactChange (com.vodafone360.people.engine.contactsync.ContactChange)22 SmallTest (android.test.suitebuilder.annotation.SmallTest)19 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)18 SQLException (android.database.SQLException)15 ContentValues (android.content.ContentValues)14 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)13 Uri (android.net.Uri)11 ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)11 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)11 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)11 SQLiteException (android.database.sqlite.SQLiteException)9 ContactsTable (com.vodafone360.people.database.tables.ContactsTable)9