Search in sources :

Example 1 with Organisation

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

the class FetchNativeContactsTest method testRunWithOneModifiedContact.

@MediumTest
@Suppress
public // Breaks tests.
void testRunWithOneModifiedContact() {
    final String fnName = "testRunWithOneModifiedContact";
    Log.i(LOG_TAG, "***** EXECUTING " + fnName + " *****");
    mTestStep = 1;
    startSubTest(fnName, "Checking people database is empty");
    Cursor peopleCursor = mDb.openContactSummaryCursor(null, null);
    assertEquals(0, peopleCursor.getCount());
    assertTrue(Settings.ENABLE_UPDATE_NATIVE_CONTACTS);
    startSubTest(fnName, "Checking native database is empty");
    Cursor nativeCursor = mCr.query(People.CONTENT_URI, new String[] { People._ID, People.NAME, People.NOTES }, null, null, null);
    assertEquals(0, nativeCursor.getCount());
    startSubTest(fnName, "Add one dummy native contact");
    ContentValues peopleValues = new ContentValues();
    peopleValues.put(Contacts.People.NAME, ADD_CONTACT_TEST_NAME);
    peopleValues.put(Contacts.People.NOTES, ADD_CONTACT_TEST_NOTE);
    Uri personUri1 = mCr.insert(Contacts.People.CONTENT_URI, peopleValues);
    assertTrue("Unable to insert contact into native people table", personUri1 != null);
    final long personId = ContentUris.parseId(personUri1);
    ContentValues phoneValues = new ContentValues();
    phoneValues.put(Contacts.Phones.PERSON_ID, personId);
    phoneValues.put(Contacts.Phones.NUMBER, ADD_PHONE_TEST1);
    phoneValues.put(Contacts.Phones.TYPE, ADD_PHONE_TYPE_TEST1);
    Uri phoneUri1 = mCr.insert(Contacts.Phones.CONTENT_URI, phoneValues);
    assertTrue("Unable to insert contact into native phone table 1", phoneUri1 != null);
    final long phoneId1 = (int) ContentUris.parseId(phoneUri1);
    ContentValues cmValues = new ContentValues();
    cmValues.put(Contacts.ContactMethods.PERSON_ID, personId);
    cmValues.put(Contacts.ContactMethods.DATA, ADD_CM_TEST1);
    cmValues.put(Contacts.ContactMethods.TYPE, ADD_CM_TYPE_TEST1);
    cmValues.put(Contacts.ContactMethods.KIND, ADD_CM_KIND_TEST1);
    cmValues.put(Contacts.ContactMethods.ISPRIMARY, 1);
    Uri cmUri1 = mCr.insert(Contacts.ContactMethods.CONTENT_URI, cmValues);
    assertTrue("Unable to insert contact into native contact methods table 1", cmUri1 != null);
    final long cmId1 = ContentUris.parseId(cmUri1);
    ContentValues orgValues = new ContentValues();
    orgValues.put(Contacts.Organizations.PERSON_ID, personId);
    orgValues.put(Contacts.Organizations.COMPANY, ADD_ORG_COMPANY_TEST1);
    orgValues.put(Contacts.Organizations.TITLE, ADD_ORG_TITLE_TEST1);
    orgValues.put(Contacts.Organizations.TYPE, ADD_ORG_TYPE_TEST1);
    orgValues.put(Contacts.Organizations.LABEL, ADD_ORG_LABEL_TEST1);
    Uri orgUri = mCr.insert(Contacts.Organizations.CONTENT_URI, orgValues);
    assertTrue("Unable to insert contact into native organizations table 1", orgUri != null);
    final long orgId1 = ContentUris.parseId(orgUri);
    startSubTest(fnName, "Running processor");
    runProcessor();
    startSubTest(fnName, "Checking contact has been synced to people");
    peopleCursor.requery();
    assertEquals(1, peopleCursor.getCount());
    startSubTest(fnName, "Modifying name");
    peopleValues.clear();
    peopleValues.put(Contacts.People.NAME, MODIFY_CONTACT_TEST_NAME);
    int rowsUpdated = mCr.update(personUri1, peopleValues, null, null);
    assertEquals(1, rowsUpdated);
    startSubTest(fnName, "Modifying phone number");
    phoneValues.clear();
    phoneValues.put(Contacts.Phones.NUMBER, MODIFY_PHONE_TEST1);
    rowsUpdated = mCr.update(phoneUri1, phoneValues, null, null);
    assertEquals(1, rowsUpdated);
    startSubTest(fnName, "Modifying email address");
    cmValues.clear();
    cmValues.put(Contacts.ContactMethods.DATA, MODIFY_EMAIL_TEST1);
    rowsUpdated = mCr.update(cmUri1, cmValues, null, null);
    assertEquals(1, rowsUpdated);
    startSubTest(fnName, "Modifying organization");
    orgValues.clear();
    orgValues.put(Contacts.Organizations.COMPANY, MODIFY_COMPANY_TEST1);
    rowsUpdated = mCr.update(orgUri, orgValues, null, null);
    assertEquals(1, rowsUpdated);
    startSubTest(fnName, "Adding phone number");
    phoneValues.clear();
    phoneValues.put(Contacts.Phones.PERSON_ID, personId);
    phoneValues.put(Contacts.Phones.NUMBER, MODIFY_PHONE_TEST2);
    phoneValues.put(Contacts.Phones.TYPE, MODIFY_PHONE_TYPE_TEST2);
    phoneValues.put(Contacts.Phones.ISPRIMARY, 1);
    Uri phoneUri2 = mCr.insert(Contacts.Phones.CONTENT_URI, phoneValues);
    assertTrue("Unable to insert contact into native phone table 2", phoneUri2 != null);
    final long phoneId2 = (int) ContentUris.parseId(phoneUri2);
    startSubTest(fnName, "Adding email address");
    cmValues.clear();
    cmValues.put(Contacts.ContactMethods.PERSON_ID, personId);
    cmValues.put(Contacts.ContactMethods.DATA, MODIFY_EMAIL_TEST2);
    cmValues.put(Contacts.ContactMethods.TYPE, MODIFY_EMAIL_TYPE_TEST2);
    cmValues.put(Contacts.ContactMethods.KIND, MODIFY_EMAIL_KIND_TEST2);
    Uri cmUri2 = mCr.insert(Contacts.ContactMethods.CONTENT_URI, cmValues);
    assertTrue("Unable to insert contact into native contact methods table 1", cmUri2 != null);
    final long cmId2 = (int) ContentUris.parseId(cmUri2);
    startSubTest(fnName, "Adding organization");
    orgValues.clear();
    orgValues.put(Contacts.Organizations.PERSON_ID, personId);
    orgValues.put(Contacts.Organizations.COMPANY, MODIFY_COMPANY_TEST2);
    orgValues.put(Contacts.Organizations.TITLE, MODIFY_TITLE_TEST2);
    orgValues.put(Contacts.Organizations.TYPE, MODIFY_COMPANY_TYPE_TEST2);
    orgValues.put(Contacts.Organizations.ISPRIMARY, 1);
    Uri orgUri2 = mCr.insert(Contacts.Organizations.CONTENT_URI, orgValues);
    assertTrue("Unable to insert contact into native contact methods table 1", orgUri2 != null);
    final long orgId2 = (int) ContentUris.parseId(orgUri2);
    startSubTest(fnName, "Running processor");
    runProcessor();
    startSubTest(fnName, "Checking still 1 contact");
    peopleCursor.requery();
    assertEquals(1, peopleCursor.getCount());
    assertTrue(peopleCursor.moveToFirst());
    ContactSummary summary = ContactSummaryTable.getQueryData(peopleCursor);
    assertTrue(summary != null);
    Contact newContact = new Contact();
    ServiceStatus status = mDb.fetchContact(summary.localContactID, newContact);
    assertEquals(ServiceStatus.SUCCESS, status);
    boolean doneName = false;
    boolean doneNickname = false;
    boolean doneNote = false;
    boolean donePhone1 = false;
    boolean donePhone2 = false;
    boolean doneCm1 = false;
    boolean doneCm2 = false;
    boolean doneOrg1 = false;
    boolean doneOrg2 = false;
    boolean doneTitle1 = false;
    boolean doneTitle2 = false;
    assertTrue(newContact.synctophone);
    assertEquals(personId, newContact.nativeContactId.longValue());
    assertEquals(personId, summary.nativeContactId.longValue());
    for (ContactDetail detail : newContact.details) {
        assertEquals(Integer.valueOf((int) personId), detail.nativeContactId);
        detail.syncNativeContactId = fetchSyncNativeId(detail.localDetailID);
        assertEquals("No sync marker, ID = " + detail.nativeDetailId + ", key = " + detail.key, Integer.valueOf(-1), detail.syncNativeContactId);
        Integer detailId = detail.nativeDetailId;
        assertTrue(detailId != null);
        switch(detail.key) {
            case VCARD_NAME:
                assertEquals(personId, detailId.longValue());
                assertEquals(MODIFY_CONTACT_TEST_NAME, detail.nativeVal1);
                VCardHelper.Name name = detail.getName();
                assertTrue(name != null);
                assertEquals(MODIFY_CONTACT_TEST_NAME, name.toString());
                doneName = true;
                break;
            case VCARD_NICKNAME:
                assertEquals(personId, detailId.longValue());
                assertEquals(MODIFY_CONTACT_TEST_NAME, detail.nativeVal1);
                assertEquals(MODIFY_CONTACT_TEST_NAME, detail.getValue());
                doneNickname = true;
                break;
            case VCARD_NOTE:
                assertEquals(personId, detailId.longValue());
                assertEquals(ADD_CONTACT_TEST_NOTE, detail.nativeVal1);
                assertEquals(ADD_CONTACT_TEST_NOTE, detail.getValue());
                doneNote = true;
                break;
            case VCARD_PHONE:
                if (detailId.longValue() == phoneId1) {
                    donePhone1 = true;
                    assertEquals(MODIFY_PHONE_TEST1, detail.nativeVal1);
                    assertEquals(MODIFY_PHONE_TEST1, detail.getValue());
                    assertEquals(ADD_PHONE_PEOPLE_TYPE_TEST1, detail.keyType);
                    assertEquals(Integer.valueOf(ContactDetail.ORDER_NORMAL), detail.order);
                } else if (detailId.longValue() == phoneId2) {
                    donePhone2 = true;
                    assertEquals(MODIFY_PHONE_TEST2, detail.nativeVal1);
                    assertEquals(MODIFY_PHONE_TEST2, detail.getValue());
                    assertEquals(MODIFY_PHONE_PEOPLE_TYPE_TEST2, detail.keyType);
                    assertEquals(Integer.valueOf(ContactDetail.ORDER_PREFERRED), detail.order);
                } else {
                    fail("Unknown phone number in people contact: ID:" + detailId + " does not match " + phoneId1 + "," + phoneId2);
                }
                break;
            case VCARD_EMAIL:
                assertTrue(detailId != null);
                if (detailId.longValue() == cmId1) {
                    doneCm1 = true;
                    assertEquals(MODIFY_EMAIL_TEST1, detail.nativeVal1);
                    assertEquals(MODIFY_EMAIL_TEST1, detail.getValue());
                    assertEquals(String.valueOf(ADD_CM_TYPE_TEST1), detail.nativeVal2);
                    assertEquals(String.valueOf(ADD_CM_KIND_TEST1), detail.nativeVal3);
                    assertEquals(ADD_CM_PEOPLE_TYPE_TEST1, detail.keyType);
                    assertEquals(Integer.valueOf(ContactDetail.ORDER_PREFERRED), detail.order);
                } else if (detailId.longValue() == cmId2) {
                    doneCm2 = true;
                    assertEquals(MODIFY_EMAIL_TEST2, detail.nativeVal1);
                    assertEquals(MODIFY_EMAIL_TEST2, detail.getValue());
                    assertEquals(String.valueOf(MODIFY_EMAIL_KIND_TEST2), detail.nativeVal2);
                    assertEquals(String.valueOf(MODIFY_EMAIL_TYPE_TEST2), detail.nativeVal3);
                    assertEquals(MODIFY_EMAIL_PEOPLE_TYPE_TEST2, detail.keyType);
                    assertEquals(Integer.valueOf(ContactDetail.ORDER_NORMAL), detail.order);
                } else {
                    fail("Unknown email in people contact: ID:" + detailId + " does not match " + phoneId1 + "," + phoneId2);
                }
                break;
            case VCARD_ORG:
                assertTrue(detailId != null);
                if (detailId.longValue() == orgId1) {
                    doneOrg1 = true;
                    assertEquals(MODIFY_COMPANY_TEST1, detail.nativeVal1);
                    assertEquals(String.valueOf(ADD_ORG_TYPE_TEST1), detail.nativeVal3);
                    VCardHelper.Organisation org = detail.getOrg();
                    assertTrue(org != null);
                    assertEquals(0, org.unitNames.size());
                    assertEquals(MODIFY_COMPANY_TEST1, org.name);
                    assertEquals(ADD_ORG_PEOPLE_TYPE_TEST1, detail.keyType);
                    assertEquals(Integer.valueOf(ContactDetail.ORDER_NORMAL), detail.order);
                } else if (detailId.longValue() == orgId2) {
                    doneOrg2 = true;
                    assertEquals(MODIFY_COMPANY_TEST2, detail.nativeVal1);
                    assertEquals(String.valueOf(MODIFY_COMPANY_TYPE_TEST2), detail.nativeVal3);
                    VCardHelper.Organisation org = detail.getOrg();
                    assertTrue(org != null);
                    assertEquals(0, org.unitNames.size());
                    assertEquals(MODIFY_COMPANY_TEST2, org.name);
                    assertEquals(MODIFY_COMPANY_PEOPLE_TYPE_TEST2, detail.keyType);
                    assertEquals(Integer.valueOf(ContactDetail.ORDER_PREFERRED), detail.order);
                } else {
                    fail("Unknown organisation in people contact");
                }
                break;
            case VCARD_TITLE:
                assertTrue(detailId != null);
                if (detailId.longValue() == orgId1) {
                    doneTitle1 = true;
                    assertEquals(ADD_ORG_TITLE_TEST1, detail.nativeVal1);
                    assertEquals(ADD_ORG_TITLE_TEST1, detail.getValue());
                } else if (detailId.longValue() == orgId2) {
                    doneTitle2 = true;
                    assertEquals(MODIFY_TITLE_TEST2, detail.nativeVal1);
                    assertEquals(MODIFY_TITLE_TEST2, detail.getValue());
                } else {
                    fail("Unknown title in people contact");
                }
                break;
            default:
                fail("Unexpected detail in people contact: " + detail.key);
        }
    }
    assertTrue("Name was missing", doneName);
    assertTrue("Nickname was missing", doneNickname);
    assertTrue("Note was missing", doneNote);
    assertTrue("Phone1 was missing", donePhone1);
    assertTrue("Phone2 was missing", donePhone2);
    assertTrue("Email1 was missing", doneCm1);
    assertTrue("Email2 was missing", doneCm2);
    assertTrue("Organisation1 was missing", doneOrg1);
    assertTrue("Organisation2 was missing", doneOrg2);
    assertTrue("Title1 was missing", doneTitle1);
    assertTrue("Title2 was missing", doneTitle2);
    nativeCursor.close();
    peopleCursor.close();
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, fnName + " has completed successfully");
    Log.i(LOG_TAG, "*************************************************************************");
    Log.i(LOG_TAG, "");
}
Also used : ContentValues(android.content.ContentValues) ContactSummary(com.vodafone360.people.datatypes.ContactSummary) Cursor(android.database.Cursor) Uri(android.net.Uri) Contact(com.vodafone360.people.datatypes.Contact) ContactDetail(com.vodafone360.people.datatypes.ContactDetail) ServiceStatus(com.vodafone360.people.service.ServiceStatus) VCardHelper(com.vodafone360.people.datatypes.VCardHelper) Suppress(android.test.suitebuilder.annotation.Suppress) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 2 with Organisation

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

the class NativeContactsApi2 method updateOrganization.

/**
     * Updates the Organization detail in the context of a Contact Update
     * operation. The end of result of this is that the Organization may be
     * inserted, updated or deleted depending on the update data. For example,
     * if the title is deleted but there is also a company name then the
     * Organization is just updated. However, if there was no company name then
     * the detail should be deleted altogether.
     * 
     * @param ccList {@link ContactChange} list where Organization and Title may
     *            be found
     * @param nabContactId The NAB ID of the Contact
     */
private void updateOrganization(ContactChange[] ccList, long nabContactId) {
    if (mMarkedOrganizationIndex < 0 && mMarkedTitleIndex < 0) {
        // no organization or title to update - do nothing
        return;
    }
    // First we check if there is an existing Organization detail in NAB
    final Uri uri = Uri.withAppendedPath(ContentUris.withAppendedId(RawContacts.CONTENT_URI, nabContactId), RawContacts.Data.CONTENT_DIRECTORY);
    Cursor cursor = mCr.query(uri, null, ORGANIZATION_DETAIL_WHERE_CLAUSE, null, RawContacts.Data._ID);
    String company = null;
    String department = null;
    String title = null;
    int flags = ContactChange.FLAG_NONE;
    try {
        if (cursor != null && cursor.moveToNext()) {
            // Found an organization detail
            company = CursorUtils.getString(cursor, Organization.COMPANY);
            department = CursorUtils.getString(cursor, Organization.DEPARTMENT);
            title = CursorUtils.getString(cursor, Organization.TITLE);
            flags = mapFromNabOrganizationType(CursorUtils.getInt(cursor, Organization.TYPE));
            final boolean isPrimary = CursorUtils.getInt(cursor, Organization.IS_PRIMARY) > 0;
            if (isPrimary) {
                flags |= ContactChange.FLAG_PREFERRED;
            }
            mExistingOrganizationId = CursorUtils.getLong(cursor, Organization._ID);
        }
    } finally {
        CursorUtils.closeCursor(cursor);
        // make it a candidate for the GC
        cursor = null;
    }
    if (mMarkedOrganizationIndex >= 0) {
        // Have an Organization (Company + Department) to update
        final ContactChange cc = ccList[mMarkedOrganizationIndex];
        if (cc.getType() != ContactChange.TYPE_DELETE_DETAIL) {
            final String value = cc.getValue();
            if (value != null) {
                final Organisation organization = VCardHelper.getOrg(value);
                company = organization.name;
                if (organization.unitNames.size() > 0) {
                    department = organization.unitNames.get(0);
                }
            }
            flags = cc.getFlags();
        } else {
            // Delete case
            company = null;
            department = null;
        }
    }
    if (mMarkedTitleIndex >= 0) {
        // Have a Title to update
        final ContactChange cc = ccList[mMarkedTitleIndex];
        title = cc.getValue();
        if (cc.getType() != ContactChange.TYPE_UPDATE_DETAIL) {
            flags = cc.getFlags();
        }
    }
    if (company != null || department != null || title != null) {
        /*
             * If any of the above are present we assume a insert or update is
             * needed.
             */
        mValues.clear();
        mValues.put(Organization.LABEL, (String) null);
        mValues.put(Organization.COMPANY, company);
        mValues.put(Organization.DEPARTMENT, department);
        mValues.put(Organization.TITLE, title);
        mValues.put(Organization.TYPE, mapToNabOrganizationType(flags));
        mValues.put(Organization.IS_PRIMARY, flags & ContactChange.FLAG_PREFERRED);
        mValues.put(Organization.MIMETYPE, Organization.CONTENT_ITEM_TYPE);
        if (mExistingOrganizationId != ContactChange.INVALID_ID) {
            // update is needed
            addUpdateValuesToBatch(mExistingOrganizationId);
        } else {
            // insert is needed
            // not a new contact
            addValuesToBatch(nabContactId);
        }
    } else if (mExistingOrganizationId != ContactChange.INVALID_ID) {
        /*
             * Had an Organization but now all values are null, delete is in
             * order.
             */
        addDeleteDetailToBatch(mExistingOrganizationId);
    }
}
Also used : Organisation(com.vodafone360.people.datatypes.VCardHelper.Organisation) Cursor(android.database.Cursor) Uri(android.net.Uri)

Example 3 with Organisation

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

the class NativeContactsApi2 method putOrganization.

// PHOTO NOT USED
// /**
// * Do a GET request and retrieve up to maxBytes bytes
// *
// * @param url
// * @param maxBytes
// * @return
// * @throws IOException
// */
// public static byte[] doGetAndReturnBytes(URL url, int maxBytes) throws
// IOException {
// HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// conn.setRequestMethod("GET");
// InputStream istr = null;
// try {
// int rc = conn.getResponseCode();
// if (rc != 200) {
// throw new IOException("code " + rc + " '" + conn.getResponseMessage() +
// "'");
// }
// istr = new BufferedInputStream(conn.getInputStream(), 512);
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// copy(istr, baos, maxBytes);
// return baos.toByteArray();
// } finally {
// if (istr != null) {
// istr.close();
// }
// }
// }
//    
// /**
// * Copy maxBytes from an input stream to an output stream.
// * @param in
// * @param out
// * @param maxBytes
// * @return
// * @throws IOException
// */
// private static int copy(InputStream in, OutputStream out, int maxBytes)
// throws IOException {
// byte[] buf = new byte[512];
// int bytesRead = 1;
// int totalBytes = 0;
// while (bytesRead > 0) {
// bytesRead = in.read(buf, 0, Math.min(512, maxBytes - totalBytes));
// if (bytesRead > 0) {
// out.write(buf, 0, bytesRead);
// totalBytes += bytesRead;
// }
// }
// return totalBytes;
// }
//  
// /**
// * Put Photo detail into the values
// * @param cc {@link ContactChange} to read values from
// */
// private void putPhoto(ContactChange cc) {
// try {
// // File file = new File(cc.getValue());
// // InputStream is = new FileInputStream(file);
// // byte[] bytes = new byte[(int) file.length()];
// // is.read(bytes);
// // is.close();
// final URL url = new URL(cc.getValue());
// byte[] bytes = doGetAndReturnBytes(url, 1024 * 100);
// mValues.put(Photo.PHOTO, bytes);
// mValues.put(Photo.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
// } catch(Exception ex) {
// LogUtils.logE("Unable to put Photo detail because of exception:"+ex);
// }
// }
/**
     * Put Organization detail into the values
     * 
     * @param cc {@link ContactChange} to read values from
     */
private void putOrganization(ContactChange[] ccList) {
    mValues.clear();
    int flags = ContactChange.FLAG_NONE;
    if (mMarkedOrganizationIndex > -1) {
        final ContactChange cc = ccList[mMarkedOrganizationIndex];
        flags |= cc.getFlags();
        final Organisation organization = VCardHelper.getOrg(cc.getValue());
        if (organization != null) {
            mValues.put(Organization.COMPANY, organization.name);
            if (organization.unitNames.size() > 0) {
                // Only considering one unit name (department) as that's all
                // we support
                mValues.put(Organization.DEPARTMENT, organization.unitNames.get(0));
            } else {
                mValues.putNull(Organization.DEPARTMENT);
            }
        }
    }
    if (mMarkedTitleIndex > -1) {
        final ContactChange cc = ccList[mMarkedTitleIndex];
        flags |= cc.getFlags();
        // No need to check for empty values as there is only one
        mValues.put(Organization.TITLE, cc.getValue());
    }
    if (mValues.size() > 0) {
        mValues.put(Organization.LABEL, (String) null);
        mValues.put(Organization.TYPE, mapToNabOrganizationType(flags));
        mValues.put(Organization.IS_PRIMARY, flags & ContactChange.FLAG_PREFERRED);
        mValues.put(Organization.MIMETYPE, Organization.CONTENT_ITEM_TYPE);
    }
}
Also used : Organisation(com.vodafone360.people.datatypes.VCardHelper.Organisation)

Example 4 with Organisation

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

the class NativeContactsApi2 method readOrganization.

/**
     * Reads an organization detail as a {@link ContactChange} from the provided
     * cursor. For this type of detail we need to use a VCARD (semicolon
     * separated) value. In reality two different changes may be read if a title
     * is also present.
     * 
     * @param cursor Cursor to read from
     * @param ccList List of Contact Changes to add read detail data
     * @param nabContactId ID of the NAB Contact
     */
private void readOrganization(Cursor cursor, List<ContactChange> ccList, long nabContactId) {
    final int type = CursorUtils.getInt(cursor, Organization.TYPE);
    int flags = mapFromNabOrganizationType(type);
    final boolean isPrimary = CursorUtils.getInt(cursor, Organization.IS_PRIMARY) != 0;
    if (isPrimary) {
        flags |= ContactChange.FLAG_PREFERRED;
    }
    final long nabDetailId = CursorUtils.getLong(cursor, Organization._ID);
    if (!mHaveReadOrganization) {
        // VCard Helper data type (CAB)
        final Organisation organization = new Organisation();
        // Company
        organization.name = CursorUtils.getString(cursor, Organization.COMPANY);
        // Department
        final String department = CursorUtils.getString(cursor, Organization.DEPARTMENT);
        if (!TextUtils.isEmpty(department)) {
            organization.unitNames.add(department);
        }
        if ((organization.unitNames != null && organization.unitNames.size() > 0) || !TextUtils.isEmpty(organization.name)) {
            final ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_ORG, VCardHelper.makeOrg(organization), flags);
            cc.setNabContactId(nabContactId);
            cc.setNabDetailId(nabDetailId);
            ccList.add(cc);
            mHaveReadOrganization = true;
        }
        // Title
        final String title = CursorUtils.getString(cursor, Organization.TITLE);
        if (!TextUtils.isEmpty(title)) {
            final ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_TITLE, title, flags);
            cc.setNabContactId(nabContactId);
            cc.setNabDetailId(nabDetailId);
            ccList.add(cc);
            mHaveReadOrganization = true;
        }
    }
}
Also used : Organisation(com.vodafone360.people.datatypes.VCardHelper.Organisation)

Example 5 with Organisation

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

the class UpdateNativeContactsTest method feedOneSyncableContact.

/**
     * Feeds the People database with a contact containing all the possible details
     * that can be synced on native side.
     * 
     * @return the created Contact
     */
private Contact feedOneSyncableContact() {
    final Contact contact = new Contact();
    // set it syncable to native side
    contact.synctophone = true;
    contact.aboutMe = "xxx xxyyyy";
    contact.friendOfMine = false;
    contact.gender = 1;
    // add a VCARD_NAME
    ContactDetail detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_NAME;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    Name name = new Name();
    name.firstname = "Firstname";
    name.midname = "Midname";
    name.surname = "Surname";
    name.suffixes = "Suffixes";
    name.title = "Title";
    // a VCARD_NAME
    detail.value = VCardHelper.makeName(name);
    contact.details.add(detail);
    // add a VCARD_NICKNAME
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_NICKNAME;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "My Nickname";
    contact.details.add(detail);
    // add a birthday VCARD_DATE + BIRTHDAY type 
    detail = new ContactDetail();
    detail.order = ContactDetail.ORDER_NORMAL;
    Time time = new Time();
    time.set(1, 1, 2010);
    detail.setDate(time, ContactDetail.DetailKeyTypes.BIRTHDAY);
    contact.details.add(detail);
    // add emails (Work, Home, Other)
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
    detail.keyType = ContactDetail.DetailKeyTypes.HOME;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "email@home.test";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
    detail.keyType = ContactDetail.DetailKeyTypes.WORK;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "email@work.test";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_EMAIL;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "email@other.test";
    contact.details.add(detail);
    // add phones VCARD_PHONE (Home, Cell, Work, Fax, Other)
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.HOME;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "+33111111";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.CELL;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "+33222222";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.WORK;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "+33333333";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.FAX;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "+33444444";
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "+33555555";
    contact.details.add(detail);
    // add a preferred detail since all the others are set to normal
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_PHONE;
    detail.keyType = ContactDetail.DetailKeyTypes.HOME;
    detail.order = ContactDetail.ORDER_PREFERRED;
    detail.value = "+33666666";
    contact.details.add(detail);
    // add VCARD_ADDRESS (Home, Work, Other)
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_ADDRESS;
    detail.keyType = ContactDetail.DetailKeyTypes.HOME;
    detail.order = ContactDetail.ORDER_NORMAL;
    PostalAddress address = new PostalAddress();
    address.addressLine1 = "home address line 1";
    address.addressLine2 = "home address line 2";
    address.city = "home city";
    address.country = "home country";
    address.county = "home county";
    address.postCode = "home postcode";
    address.postOfficeBox = "home po box";
    detail.value = VCardHelper.makePostalAddress(address);
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_ADDRESS;
    detail.keyType = ContactDetail.DetailKeyTypes.WORK;
    detail.order = ContactDetail.ORDER_NORMAL;
    address = new PostalAddress();
    address.addressLine1 = "work address line 1";
    address.addressLine2 = "work address line 2";
    address.city = "work city";
    address.country = "work country";
    address.county = "work county";
    address.postCode = "work postcode";
    address.postOfficeBox = "work po box";
    detail.value = VCardHelper.makePostalAddress(address);
    contact.details.add(detail);
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_ADDRESS;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    address = new PostalAddress();
    address.addressLine1 = "other address line 1";
    address.addressLine2 = "other address line 2";
    address.city = "other city";
    address.country = "other country";
    address.county = "other county";
    address.postCode = "other postcode";
    address.postOfficeBox = "other po box";
    detail.value = VCardHelper.makePostalAddress(address);
    contact.details.add(detail);
    // add a VCARD_URL
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_URL;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "http://myurl.test";
    contact.details.add(detail);
    // add a VCARD_NOTE
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_NOTE;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "a note";
    contact.details.add(detail);
    // add a VCARD_ORG
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_ORG;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    Organisation org = new Organisation();
    org.name = "company name";
    org.unitNames.add("department");
    detail.value = VCardHelper.makeOrg(org);
    contact.details.add(detail);
    // add a VCARD_TITLE
    detail = new ContactDetail();
    detail.key = ContactDetail.DetailKeys.VCARD_TITLE;
    detail.keyType = ContactDetail.DetailKeyTypes.UNKNOWN;
    detail.order = ContactDetail.ORDER_NORMAL;
    detail.value = "title";
    contact.details.add(detail);
    mDatabaseHelper.addContact(contact);
    return contact;
}
Also used : ContactDetail(com.vodafone360.people.datatypes.ContactDetail) PostalAddress(com.vodafone360.people.datatypes.VCardHelper.PostalAddress) Organisation(com.vodafone360.people.datatypes.VCardHelper.Organisation) Time(android.text.format.Time) Contact(com.vodafone360.people.datatypes.Contact) Name(com.vodafone360.people.datatypes.VCardHelper.Name)

Aggregations

Organisation (com.vodafone360.people.datatypes.VCardHelper.Organisation)9 Uri (android.net.Uri)5 Contact (com.vodafone360.people.datatypes.Contact)5 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)5 Cursor (android.database.Cursor)4 VCardHelper (com.vodafone360.people.datatypes.VCardHelper)4 ContentValues (android.content.ContentValues)3 MediumTest (android.test.suitebuilder.annotation.MediumTest)3 Suppress (android.test.suitebuilder.annotation.Suppress)3 ContactSummary (com.vodafone360.people.datatypes.ContactSummary)3 ServiceStatus (com.vodafone360.people.service.ServiceStatus)3 Time (android.text.format.Time)2 Name (com.vodafone360.people.datatypes.VCardHelper.Name)2 PostalAddress (com.vodafone360.people.datatypes.VCardHelper.PostalAddress)2