Search in sources :

Example 1 with ContactIdInfo

use of com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo in project 360-Engine-for-Android by 360.

the class FetchNativeContactsTest method checkContacts.

private void checkContacts(List<NativeContactDetails> nativeContactList) {
    for (int i = 0; i < nativeContactList.size(); i++) {
        NativeContactDetails ncd = nativeContactList.get(i);
        ContactIdInfo info = ContactsTable.fetchContactIdFromNative(ncd.mId, mDb.getReadableDatabase());
        Contact contact = new Contact();
        ServiceStatus status = mDb.fetchContact(info.localId, contact);
        assertEquals(ServiceStatus.SUCCESS, status);
        LogUtils.logI("Checking contact local ID " + info.localId + ", native ID " + ncd.mId);
        boolean nameDone = false;
        boolean nicknameDone = false;
        boolean noteDone = false;
        int phonesDone = 0;
        int emailsDone = 0;
        int addressesDone = 0;
        int orgsDone = 0;
        int titlesDone = 0;
        for (ContactDetail detail : contact.details) {
            assertEquals(ncd.mId, detail.nativeContactId);
            detail.syncNativeContactId = fetchSyncNativeId(detail.localDetailID);
            assertEquals("No sync marker, ID = " + detail.nativeDetailId + ", key = " + detail.key, Integer.valueOf(-1), detail.syncNativeContactId);
            switch(detail.key) {
                case VCARD_NAME:
                    nameDone = true;
                    assertEquals(ncd.mName.toString(), detail.nativeVal1);
                    break;
                case VCARD_NICKNAME:
                    nicknameDone = true;
                    assertEquals(ncd.mName.toString(), detail.nativeVal1);
                    break;
                case VCARD_NOTE:
                    noteDone = true;
                    assertEquals(ncd.mNote, detail.nativeVal1);
                    break;
                case VCARD_PHONE:
                    phonesDone++;
                    for (NativeDetail nd : ncd.mPhoneList) {
                        if (nd.mId.equals(detail.localDetailID)) {
                            assertEquals(nd.mValue1, detail.nativeVal1);
                            assertEquals(nd.mValue2, detail.nativeVal2);
                            assertEquals(nd.mValue3, detail.nativeVal3);
                            break;
                        }
                    }
                    break;
                case VCARD_EMAIL:
                    emailsDone++;
                    for (NativeDetail nd : ncd.mEmailList) {
                        if (nd.mId.equals(detail.localDetailID)) {
                            assertEquals(nd.mValue1, detail.nativeVal1);
                            assertEquals(nd.mValue2, detail.nativeVal2);
                            assertEquals(nd.mValue3, detail.nativeVal3);
                            break;
                        }
                    }
                    break;
                case VCARD_ADDRESS:
                    addressesDone++;
                    for (NativeDetail nd : ncd.mAddressList) {
                        if (nd.mId.equals(detail.localDetailID)) {
                            assertEquals(nd.mValue1, detail.nativeVal1);
                            assertEquals(nd.mValue2, detail.nativeVal2);
                            assertEquals(nd.mValue3, detail.nativeVal3);
                            break;
                        }
                    }
                    break;
                case VCARD_ORG:
                    orgsDone++;
                    for (NativeDetail nd : ncd.mOrgList) {
                        if (nd.mId.equals(detail.localDetailID)) {
                            assertEquals(nd.mValue1, detail.nativeVal1);
                            assertEquals(nd.mValue2, detail.nativeVal2);
                            assertEquals(nd.mValue3, detail.nativeVal3);
                            break;
                        }
                    }
                    break;
                case VCARD_TITLE:
                    titlesDone++;
                    for (NativeDetail nd : ncd.mTitleList) {
                        if (nd.mId.equals(detail.localDetailID)) {
                            assertEquals(nd.mValue1, detail.nativeVal1);
                            assertEquals(nd.mValue2, detail.nativeVal2);
                            assertEquals(nd.mValue3, detail.nativeVal3);
                            break;
                        }
                    }
                    break;
                default:
                    fail("Unexpected detail: " + detail.key);
            }
        }
        String nameString = ncd.mName.toString();
        if (nameString.length() > 0) {
            assertTrue("Name was not done", nameDone);
            assertTrue("Nickname was not done", nicknameDone);
        }
        if (ncd.mNote != null && ncd.mNote.length() > 0) {
            assertTrue("Note was not done", noteDone);
        }
        assertEquals(ncd.mPhoneList.size(), phonesDone);
        assertEquals(ncd.mEmailList.size(), emailsDone);
        assertEquals(ncd.mAddressList.size(), addressesDone);
        assertEquals(ncd.mOrgList.size(), orgsDone);
        assertEquals(ncd.mTitleList.size(), titlesDone);
    }
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) NativeContactDetails(com.vodafone360.people.tests.TestModule.NativeContactDetails) ContactIdInfo(com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo) ServiceStatus(com.vodafone360.people.service.ServiceStatus) NativeDetail(com.vodafone360.people.tests.TestModule.NativeDetail) Contact(com.vodafone360.people.datatypes.Contact)

Example 2 with ContactIdInfo

use of com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo in project 360-Engine-for-Android by 360.

the class NowPlusContactsTableTest method testServerSyncMethods.

@MediumTest
public void testServerSyncMethods() {
    final String fnName = "testServerSyncMethods";
    mTestStep = 1;
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
    Log.i(LOG_TAG, "Validates server sync methods");
    SQLiteDatabase writeableDb = mTestDatabase.getWritableDatabase();
    SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
    startSubTest(fnName, "Creating table");
    createTable();
    // add contacts and populate contactServerIdList
    List<ServerIdInfo> contactServerIdList = new ArrayList<ServerIdInfo>();
    final long contactIdBase = TestModule.generateRandomLong();
    for (int i = 0; i < NUM_OF_CONTACTS; i++) {
        Contact c = mTestModule.createDummyContactData();
        if (i == 2) {
            // Add duplicate server ID in database
            c.contactID = contactIdBase;
        }
        c.userID = TestModule.generateRandomLong();
        ServiceStatus status = ContactsTable.addContact(c, writeableDb);
        assertEquals(ServiceStatus.SUCCESS, status);
        ServerIdInfo serverInfo = new ServerIdInfo();
        serverInfo.localId = c.localContactID;
        serverInfo.serverId = contactIdBase + i;
        serverInfo.userId = c.userID;
        contactServerIdList.add(serverInfo);
    }
    // Add duplicate server ID in list from server
    Contact duplicateContact = mTestModule.createDummyContactData();
    duplicateContact.userID = TestModule.generateRandomLong();
    ServiceStatus status = ContactsTable.addContact(duplicateContact, writeableDb);
    assertEquals(ServiceStatus.SUCCESS, status);
    ServerIdInfo serverInfo = new ServerIdInfo();
    serverInfo.localId = duplicateContact.localContactID;
    serverInfo.serverId = contactIdBase + 1;
    serverInfo.userId = duplicateContact.userID;
    contactServerIdList.add(serverInfo);
    List<ContactIdInfo> dupList = new ArrayList<ContactIdInfo>();
    status = ContactsTable.syncSetServerIds(contactServerIdList, dupList, writeableDb);
    assertEquals(ServiceStatus.SUCCESS, status);
    // fetch server ids
    HashSet<Long> serverIds = new HashSet<Long>();
    status = ContactsTable.fetchContactServerIdList(serverIds, readableDb);
    assertEquals(ServiceStatus.SUCCESS, status);
    // validate if lists have the same sizes
    assertEquals(2, dupList.size());
    assertEquals(contactServerIdList.size() - 2, serverIds.size());
    assertEquals(Long.valueOf(dupList.get(0).localId), contactServerIdList.get(0).localId);
    assertEquals(contactServerIdList.get(0).serverId, dupList.get(0).serverId);
    assertEquals(duplicateContact.localContactID, Long.valueOf(dupList.get(1).localId));
    assertEquals(Long.valueOf(contactIdBase + 1), dupList.get(1).serverId);
    // Need to convert HashSet into an Arraylist, otherwise it's not possible to compare
    // HashSet is not sorted!
    ArrayList<Long> serverIdsArrayList = new ArrayList<Long>(serverIds);
    Collections.sort(serverIdsArrayList);
    final Iterator<Long> serverIdsIt = serverIdsArrayList.iterator();
    for (int i = 1; i < contactServerIdList.size() - 1; i++) {
        Long actServerId = serverIdsIt.next();
        assertEquals(contactServerIdList.get(i).serverId, actServerId);
    }
    Log.i(LOG_TAG, "***********************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "***********************************************");
    Log.i(LOG_TAG, "");
}
Also used : ContactIdInfo(com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo) ArrayList(java.util.ArrayList) ServerIdInfo(com.vodafone360.people.database.DatabaseHelper.ServerIdInfo) Contact(com.vodafone360.people.datatypes.Contact) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ServiceStatus(com.vodafone360.people.service.ServiceStatus) HashSet(java.util.HashSet) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 3 with ContactIdInfo

use of com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo in project 360-Engine-for-Android by 360.

the class NowPlusContactsTableTest method testFetchContactFormNativeId.

@MediumTest
public void testFetchContactFormNativeId() {
    final String fnName = "testFetchContactFormNativeId";
    mTestStep = 1;
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
    Log.i(LOG_TAG, "tests fetchContactFormNativeId a contact id");
    SQLiteDatabase writableDb = mTestDatabase.getWritableDatabase();
    startSubTest(fnName, "Creating table");
    createTable();
    startSubTest(fnName, "Add Contact");
    Contact contact = mTestModule.createDummyContactData();
    contact.userID = TestModule.generateRandomLong();
    contact.nativeContactId = TestModule.generateRandomInt();
    Long serverId = TestModule.generateRandomLong();
    ServiceStatus status = ContactsTable.addContact(contact, writableDb);
    assertEquals(ServiceStatus.SUCCESS, status);
    assertTrue(ContactsTable.modifyContactServerId(contact.localContactID, serverId, contact.userID, writableDb));
    ContactIdInfo idInfo = ContactsTable.fetchContactIdFromNative(contact.nativeContactId, writableDb);
    assertTrue(idInfo.localId == contact.localContactID);
    assertEquals(serverId, idInfo.serverId);
    Log.i(LOG_TAG, "***********************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "***********************************************");
    Log.i(LOG_TAG, "");
}
Also used : ContactIdInfo(com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ServiceStatus(com.vodafone360.people.service.ServiceStatus) Contact(com.vodafone360.people.datatypes.Contact) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 4 with ContactIdInfo

use of com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo in project 360-Engine-for-Android by 360.

the class SyncMeDbUtils method setMeProfile.

/**
 * This method create a Me Profile contact in the database.
 * @param dbHelper DatabaseHelper - the database.
 * @param meProfile Contact - the Me Profile contact
 * @return ServiceStatus - ServiceStatus.SUCCESS when the new contact is
 *         successfully created.
 */
public static ServiceStatus setMeProfile(final DatabaseHelper dbHelper, Contact meProfile) {
    ServiceStatus status = ServiceStatus.ERROR_DATABASE_CORRUPT;
    // the contact didn't exist before
    if (sMeProfileLocalContactId == null) {
        List<Contact> contactList = new ArrayList<Contact>();
        contactList.add(meProfile);
        status = dbHelper.syncAddContactList(contactList, false, false);
        if (ServiceStatus.SUCCESS == status) {
            sMeProfileLocalContactId = meProfile.localContactID;
            status = StateTable.modifyMeProfileID(sMeProfileLocalContactId, dbHelper.getWritableDatabase());
            PresenceDbUtils.resetMeProfileIds();
            if (ServiceStatus.SUCCESS != status) {
                List<ContactsTable.ContactIdInfo> idList = new ArrayList<ContactsTable.ContactIdInfo>();
                ContactsTable.ContactIdInfo contactIdInfo = new ContactsTable.ContactIdInfo();
                contactIdInfo.localId = meProfile.localContactID;
                contactIdInfo.serverId = meProfile.contactID;
                contactIdInfo.nativeId = meProfile.nativeContactId;
                idList.add(contactIdInfo);
                dbHelper.syncDeleteContactList(idList, false, false);
            }
        }
    }
    return status;
}
Also used : ServiceStatus(com.vodafone360.people.service.ServiceStatus) ContactsTable(com.vodafone360.people.database.tables.ContactsTable) ArrayList(java.util.ArrayList) Contact(com.vodafone360.people.datatypes.Contact)

Example 5 with ContactIdInfo

use of com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo in project 360-Engine-for-Android by 360.

the class DatabaseHelper method syncDeleteContactList.

/**
 * Function used by the contact sync engine to delete a list of contacts
 * from the database.
 *
 * @param contactIdList The list of contact IDs received from the server (at
 *            least localId should be set)
 * @param syncToServer true if the contacts need to be deleted from the
 *            server
 * @param syncToNative true if the contacts need to be deleted from the
 *            native phonebook
 * @return SUCCESS or a suitable error code
 * @see #deleteContact(long)
 */
public ServiceStatus syncDeleteContactList(List<ContactsTable.ContactIdInfo> contactIdList, boolean syncToServer, boolean syncToNative) {
    if (Settings.ENABLED_DATABASE_TRACE)
        trace(false, "DatabaseHelper.syncDeleteContactList() syncToServer[" + syncToServer + "] syncToNative[" + syncToNative + "]");
    if (!Settings.ENABLE_SERVER_CONTACT_SYNC) {
        syncToServer = false;
    }
    if (!Settings.ENABLE_UPDATE_NATIVE_CONTACTS) {
        syncToNative = false;
    }
    SQLiteDatabase writableDb = getWritableDatabase();
    for (ContactsTable.ContactIdInfo contactIdInfo : contactIdList) {
        try {
            writableDb.beginTransaction();
            if (syncToNative && contactIdInfo.mergedLocalId == null) {
                if (!NativeChangeLogTable.addDeletedContactChange(contactIdInfo.localId, contactIdInfo.nativeId, writableDb)) {
                    return ServiceStatus.ERROR_DATABASE_CORRUPT;
                }
            }
            if (syncToServer) {
                if (!ContactChangeLogTable.addDeletedContactChange(contactIdInfo.localId, contactIdInfo.serverId, syncToServer, writableDb)) {
                    return ServiceStatus.ERROR_DATABASE_CORRUPT;
                }
            }
            if (!ContactGroupsTable.deleteContact(contactIdInfo.localId, writableDb)) {
                return ServiceStatus.ERROR_DATABASE_CORRUPT;
            }
            if (SyncMeDbUtils.getMeProfileLocalContactId(this) != null && SyncMeDbUtils.getMeProfileLocalContactId(this).longValue() == contactIdInfo.localId) {
                ServiceStatus status = StateTable.modifyMeProfileID(null, writableDb);
                if (ServiceStatus.SUCCESS != status) {
                    return status;
                }
                SyncMeDbUtils.setMeProfileId(null);
                PresenceDbUtils.resetMeProfileIds();
            }
            ServiceStatus status = ContactSummaryTable.deleteContact(contactIdInfo.localId, writableDb);
            if (ServiceStatus.SUCCESS != status) {
                return status;
            }
            status = ContactDetailsTable.deleteDetailByContactId(contactIdInfo.localId, writableDb);
            if (ServiceStatus.SUCCESS != status && ServiceStatus.ERROR_NOT_FOUND != status) {
                return status;
            }
            status = ContactsTable.deleteContact(contactIdInfo.localId, writableDb);
            if (ServiceStatus.SUCCESS != status) {
                return status;
            }
            if (!deleteThumbnail(contactIdInfo.localId))
                LogUtils.logE("Not able to delete thumbnail for: " + contactIdInfo.localId);
            // timeline
            ActivitiesTable.removeTimelineContactData(contactIdInfo.localId, writableDb);
            writableDb.setTransactionSuccessful();
        } finally {
            writableDb.endTransaction();
        }
    }
    return ServiceStatus.SUCCESS;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ContactsTable(com.vodafone360.people.database.tables.ContactsTable) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Aggregations

ServiceStatus (com.vodafone360.people.service.ServiceStatus)13 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)11 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)10 ArrayList (java.util.ArrayList)9 ContactsTable (com.vodafone360.people.database.tables.ContactsTable)7 Contact (com.vodafone360.people.datatypes.Contact)7 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)7 SQLiteStatement (android.database.sqlite.SQLiteStatement)5 MediumTest (android.test.suitebuilder.annotation.MediumTest)4 SQLException (android.database.SQLException)3 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)3 Cursor (android.database.Cursor)2 ContentValues (android.content.ContentValues)1 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)1 SQLiteException (android.database.sqlite.SQLiteException)1 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)1 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)1 ContactChange (com.vodafone360.people.engine.contactsync.ContactChange)1 PeopleContactsApi (com.vodafone360.people.engine.contactsync.PeopleContactsApi)1 NativeContactDetails (com.vodafone360.people.tests.TestModule.NativeContactDetails)1