Search in sources :

Example 16 with ContactDetail

use of com.vodafone360.people.datatypes.ContactDetail 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 17 with ContactDetail

use of com.vodafone360.people.datatypes.ContactDetail 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 18 with ContactDetail

use of com.vodafone360.people.datatypes.ContactDetail 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 19 with ContactDetail

use of com.vodafone360.people.datatypes.ContactDetail 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)

Example 20 with ContactDetail

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

the class NowPlusContactsTest method testSyncAddContactDetailList.

@SmallTest
public void testSyncAddContactDetailList() {
    Log.i(LOG_TAG, "***** EXECUTING testSyncAddContactDetailList *****");
    Log.i(LOG_TAG, "Test contact add sync contact detail list");
    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();
    assertEquals(ServiceStatus.SUCCESS, mTestUtility.waitForEvent(WAIT_EVENT_TIMEOUT_MS, DbTestUtility.CONTACTS_INT_EVENT_MASK));
    // add contacts and check if added contacts are the same as fetched 
    Contact addedContact = new Contact();
    assertEquals(ServiceStatus.SUCCESS, mDatabaseHelper.addContact(addedContact));
    ContactDetail cd = new ContactDetail();
    mTestModule.createDummyDetailsData(cd);
    cd.localContactID = addedContact.localContactID;
    cd.nativeContactId = TestModule.generateRandomInt();
    cd.nativeDetailId = TestModule.generateRandomInt();
    cd.nativeVal1 = TestModule.generateRandomString();
    cd.nativeVal2 = TestModule.generateRandomString();
    cd.nativeVal3 = TestModule.generateRandomString();
    List<ContactDetail> detailList = new ArrayList<ContactDetail>();
    detailList.add(cd);
    assertEquals(ServiceStatus.SUCCESS, mDatabaseHelper.syncAddContactDetailList(detailList, false, false));
    Contact modifiedContact = new Contact();
    assertEquals(ServiceStatus.SUCCESS, mDatabaseHelper.fetchContact(addedContact.localContactID, modifiedContact));
    for (ContactDetail fetchedDetail : modifiedContact.details) {
        for (ContactDetail contactDetail : detailList) {
            if (fetchedDetail.key == contactDetail.key) {
                assertEquals(contactDetail.nativeVal1, fetchedDetail.nativeVal1);
                assertEquals(contactDetail.nativeVal2, fetchedDetail.nativeVal2);
                assertEquals(contactDetail.nativeVal3, fetchedDetail.nativeVal3);
            }
        }
    }
    shutdown();
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ArrayList(java.util.ArrayList) Contact(com.vodafone360.people.datatypes.Contact) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

ContactDetail (com.vodafone360.people.datatypes.ContactDetail)109 Contact (com.vodafone360.people.datatypes.Contact)60 ServiceStatus (com.vodafone360.people.service.ServiceStatus)57 ArrayList (java.util.ArrayList)33 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)24 MediumTest (android.test.suitebuilder.annotation.MediumTest)24 Cursor (android.database.Cursor)20 Suppress (android.test.suitebuilder.annotation.Suppress)16 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)15 ContentValues (android.content.ContentValues)11 SmallTest (android.test.suitebuilder.annotation.SmallTest)10 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)10 SQLException (android.database.SQLException)8 Uri (android.net.Uri)7 SQLiteException (android.database.sqlite.SQLiteException)6 ContactsTable (com.vodafone360.people.database.tables.ContactsTable)6 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)6 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)4 ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)4 Date (java.util.Date)4