Search in sources :

Example 31 with ContactDetail

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

the class SyncMeDbUtils method populateWithDeletedContactDetails.

/**
 * This method adds the deleted details to the detail list sent to server...
 * @param dbHelper DatabaseHelper - database
 * @param contactDetails List<ContactDetail> - the deleted details list
 * @param contactId Long - Me Profile local contact id.
 */
private static void populateWithDeletedContactDetails(final DatabaseHelper dbHelper, final List<ContactDetail> contactDetails, final Long contactId) {
    List<ContactChangeInfo> deletedDetails = new ArrayList<ContactChangeInfo>();
    if (!ContactChangeLogTable.fetchMeProfileChangeLog(deletedDetails, ContactChangeType.DELETE_DETAIL, dbHelper.getReadableDatabase(), contactId)) {
        LogUtils.logE("UploadServerContacts populateWithDeletedContactDetails -" + " Unable to fetch contact changes from database");
        return;
    }
    for (int i = 0; i < deletedDetails.size(); i++) {
        ContactChangeInfo info = deletedDetails.get(i);
        final ContactDetail detail = new ContactDetail();
        detail.localDetailID = info.mLocalDetailId;
        detail.key = info.mServerDetailKey;
        detail.unique_id = info.mServerDetailId;
        detail.deleted = true;
        contactDetails.add(detail);
    }
    dbHelper.deleteContactChanges(deletedDetails);
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ArrayList(java.util.ArrayList)

Example 32 with ContactDetail

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

the class SyncMeDbUtils method processMyContactDetailsChanges.

/**
 * This method stores the getMyChanges() response to database - details part.
 * @param dbHelper DatabaseHelper - database.
 * @param currentMeProfile Contact - me profile contact.
 * @param profileChanges UserProfile - the contact changes.
 * @return ServiceStatus - SUCCESS if the contact changes have been successfully processed stored.
 */
private static String processMyContactDetailsChanges(final DatabaseHelper dbHelper, final Contact currentMeProfile, final UserProfile profileChanges) {
    String ret = null;
    final ArrayList<ContactDetail> modifiedDetailList = new ArrayList<ContactDetail>();
    final ArrayList<ContactDetail> addedDetailList = new ArrayList<ContactDetail>();
    final ArrayList<ContactDetail> deletedDetailList = new ArrayList<ContactDetail>();
    for (ContactDetail newDetail : profileChanges.details) {
        boolean found = false;
        for (int i = 0; i < currentMeProfile.details.size(); i++) {
            ContactDetail oldDetail = currentMeProfile.details.get(i);
            if (DatabaseHelper.doDetailsMatch(newDetail, oldDetail)) {
                found = true;
                if (newDetail.deleted != null && newDetail.deleted.booleanValue()) {
                    deletedDetailList.add(oldDetail);
                } else if (DatabaseHelper.hasDetailChanged(oldDetail, newDetail)) {
                    newDetail.localDetailID = oldDetail.localDetailID;
                    newDetail.localContactID = oldDetail.localContactID;
                    newDetail.nativeContactId = oldDetail.nativeContactId;
                    newDetail.nativeDetailId = oldDetail.nativeDetailId;
                    modifiedDetailList.add(newDetail);
                    if (newDetail.key == DetailKeys.PHOTO) {
                        dbHelper.markMeProfileAvatarChanged();
                        ret = newDetail.value;
                    }
                }
                break;
            }
        }
        // in the response or the deleted flag was false we have to add the new detail to the list
        if ((!found) && ((null == newDetail.deleted) || (!newDetail.deleted.booleanValue()))) {
            newDetail.localContactID = currentMeProfile.localContactID;
            newDetail.nativeContactId = currentMeProfile.nativeContactId;
            if (newDetail.key == DetailKeys.PHOTO) {
                dbHelper.markMeProfileAvatarChanged();
                ret = newDetail.value;
            }
            addedDetailList.add(newDetail);
        }
    }
    if (!addedDetailList.isEmpty()) {
        dbHelper.syncAddContactDetailList(addedDetailList, false, false);
    }
    if (!modifiedDetailList.isEmpty()) {
        dbHelper.syncModifyContactDetailList(modifiedDetailList, false, false);
    }
    if (!deletedDetailList.isEmpty()) {
        dbHelper.syncDeleteContactDetailList(deletedDetailList, false, false);
    }
    return ret;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ArrayList(java.util.ArrayList)

Example 33 with ContactDetail

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

the class SyncMeDbUtils method updateStatus.

/**
 * The utility method to save the status text change to the database...
 * @param dbHelper DatabaseHelper - database
 * @param statusText String - status text
 * @return ContactDetail - the modified or created ContactDetail with key
 *         ContactDetail.DetailKeys.PRESENCE_TEXT
 */
public static ContactDetail updateStatus(final DatabaseHelper dbHelper, final String statusText) {
    Contact meContact = new Contact();
    if (fetchMeProfile(dbHelper, meContact) == ServiceStatus.SUCCESS) {
        // try to modify an existing detail
        for (ContactDetail detail : meContact.details) {
            if (detail.key == ContactDetail.DetailKeys.PRESENCE_TEXT) {
                detail.value = statusText;
                // Currently it's only possible to post a status on
                // Vodafone sns
                detail.alt = ThirdPartyAccount.SNS_TYPE_VODAFONE;
                if (ServiceStatus.SUCCESS == dbHelper.modifyContactDetail(detail)) {
                    return detail;
                }
            }
        }
        // create a new detail instead
        ContactDetail contactDetail = new ContactDetail();
        contactDetail.setValue(statusText, ContactDetail.DetailKeys.PRESENCE_TEXT, null);
        contactDetail.alt = ThirdPartyAccount.SNS_TYPE_VODAFONE;
        contactDetail.localContactID = meContact.localContactID;
        if (ServiceStatus.SUCCESS == dbHelper.addContactDetail(contactDetail)) {
            return contactDetail;
        }
    }
    return null;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) Contact(com.vodafone360.people.datatypes.Contact)

Example 34 with ContactDetail

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

the class SyncMeDbUtils method updateMeProfileDbDetailIds.

/**
 * The utility method to save Contacts/setMe() response to the database...
 * @param dbHelper Database - database
 * @param uploadedMeProfile Contact - me profile which has been uploaded in
 *            Contacts/setMe() call
 * @param result ContactChanges - the contents of response Contacts/setMe().
 *            The contact details in response need to be in the same order
 *            as they were in setMe() request
 */
public static void updateMeProfileDbDetailIds(final DatabaseHelper dbHelper, final ArrayList<ContactDetail> uploadedDetails, final ContactChanges result) {
    Contact uploadedMeProfile = new Contact();
    SyncMeDbUtils.fetchMeProfile(dbHelper, uploadedMeProfile);
    boolean changed = false;
    if (result.mUserProfile.userID != null && !result.mUserProfile.userID.equals(uploadedMeProfile.userID)) {
        uploadedMeProfile.userID = result.mUserProfile.userID;
        changed = true;
    }
    if (result.mUserProfile.contactID != null && !result.mUserProfile.contactID.equals(uploadedMeProfile.contactID)) {
        uploadedMeProfile.contactID = result.mUserProfile.contactID;
        changed = true;
    }
    if (changed) {
        dbHelper.modifyContactServerId(uploadedMeProfile.localContactID, uploadedMeProfile.contactID, uploadedMeProfile.userID);
    }
    ListIterator<ContactDetail> destIt = uploadedDetails.listIterator();
    for (ContactDetail srcDetail : result.mUserProfile.details) {
        if (!destIt.hasNext()) {
            LogUtils.logE("SyncMeDbUtils updateProfileDbDetailsId() - # of details in response > # in request");
            return;
        }
        final ContactDetail destDetail = destIt.next();
        if (srcDetail.key == null || !srcDetail.key.equals(destDetail.key)) {
            LogUtils.logE("SyncMeDbUtils updateProfileDbDetailsId() - details order is wrong");
            break;
        }
        destDetail.unique_id = srcDetail.unique_id;
        dbHelper.syncContactDetail(destDetail.localDetailID, destDetail.unique_id);
    }
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) Contact(com.vodafone360.people.datatypes.Contact)

Example 35 with ContactDetail

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

the class NowPlusContactDetailsTableTest method testFetchContactDetailsForNative.

public void testFetchContactDetailsForNative() {
    final String fnName = "testFetchContactDetailsForNative";
    mTestStep = 1;
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + "*****");
    SQLiteDatabase writeableDb = mTestDatabase.getWritableDatabase();
    SQLiteDatabase readableDb = mTestDatabase.getReadableDatabase();
    startSubTest(fnName, "Creating table");
    createTable();
    Contact contact = new Contact();
    contact.localContactID = TestModule.generateRandomLong();
    // create and add NameDetail
    ContactDetail nameDetail = mTestModule.createDummyDetailsName();
    ContactDetail nicknameDetail = mTestModule.createDummyDetailsNickname(nameDetail);
    nicknameDetail.localContactID = contact.localContactID;
    nicknameDetail.nativeContactId = TestModule.generateRandomInt();
    ServiceStatus status = ContactDetailsTable.addContactDetail(nicknameDetail, true, true, writeableDb);
    assertEquals(ServiceStatus.SUCCESS, status);
    List<ContactDetail> addedDetails = new ArrayList<ContactDetail>();
    addedDetails.add(nicknameDetail);
    // create and add phoneDetail
    ContactDetail phoneDetail = new ContactDetail();
    phoneDetail.localContactID = contact.localContactID;
    phoneDetail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    String number = "07967 123456";
    phoneDetail.setTel(number, ContactDetail.DetailKeyTypes.CELL);
    // phoneDetail.nativeContactId = mTestModule.GenerateRandomInt();
    phoneDetail.nativeContactId = nicknameDetail.nativeContactId;
    status = ContactDetailsTable.addContactDetail(phoneDetail, true, true, writeableDb);
    assertEquals(ServiceStatus.SUCCESS, status);
    addedDetails.add(phoneDetail);
    // create and add phoneDetail
    ContactDetail emailDetail = new ContactDetail();
    emailDetail.localContactID = contact.localContactID;
    emailDetail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
    emailDetail.setEmail(TestModule.generateRandomString() + "@mail.co.uk", ContactDetail.DetailKeyTypes.HOME);
    // emailDetail.nativeContactId = mTestModule.GenerateRandomInt();
    emailDetail.nativeContactId = nicknameDetail.nativeContactId;
    status = ContactDetailsTable.addContactDetail(emailDetail, true, true, writeableDb);
    assertEquals(ServiceStatus.SUCCESS, status);
    addedDetails.add(emailDetail);
    ContactDetail.DetailKeys[] keyList = { ContactDetail.DetailKeys.VCARD_NICKNAME, ContactDetail.DetailKeys.VCARD_PHONE, ContactDetail.DetailKeys.VCARD_EMAIL };
    List<ContactDetail> detailList = new ArrayList<ContactDetail>();
    assertTrue(ContactDetailsTable.fetchContactDetailsForNative(detailList, keyList, false, 0, MAX_MODIFY_NOWPLUS_DETAILS_COUNT, readableDb));
    for (int i = 0; i < detailList.size(); i++) {
        assertTrue(DatabaseHelper.doDetailsMatch(detailList.get(i), addedDetails.get(i)));
    }
    Log.i(LOG_TAG, "***********************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "***********************************************");
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ServiceStatus(com.vodafone360.people.service.ServiceStatus) ArrayList(java.util.ArrayList) Contact(com.vodafone360.people.datatypes.Contact)

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