Search in sources :

Example 16 with Person

use of sqlite.feature.many2many.case5.model.Person in project google-services by googlesamples.

the class RestApiActivity method onConnectionsLoadFinished.

protected void onConnectionsLoadFinished(@Nullable List<Person> connections) {
    hideProgressDialog();
    if (connections == null) {
        Log.d(TAG, "getContacts:connections: null");
        mDetailTextView.setText(getString(R.string.connections_fmt, "None"));
        return;
    }
    Log.d(TAG, "getContacts:connections: size=" + connections.size());
    // Get names of all connections
    StringBuilder msg = new StringBuilder();
    for (int i = 0; i < connections.size(); i++) {
        Person person = connections.get(i);
        if (person.getNames() != null && person.getNames().size() > 0) {
            msg.append(person.getNames().get(0).getDisplayName());
            if (i < connections.size() - 1) {
                msg.append(",");
            }
        }
    }
    // Display names
    mDetailTextView.setText(getString(R.string.connections_fmt, msg.toString()));
}
Also used : Person(com.google.api.services.people.v1.model.Person)

Example 17 with Person

use of sqlite.feature.many2many.case5.model.Person in project kripton by xcesco.

the class PersonDaoImpl method selectById.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, name, age FROM person WHERE id = ${id}</pre>
 *
 * <h2>Projected columns:</h2>
 * <dl>
 * 	<dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
 * 	<dt>name</dt><dd>is associated to bean's property <strong>name</strong></dd>
 * 	<dt>age</dt><dd>is associated to bean's property <strong>age</strong></dd>
 * </dl>
 *
 * <h2>Query's parameters:</h2>
 * <dl>
 * 	<dt>${id}</dt><dd>is binded to method's parameter <strong>id</strong></dd>
 * </dl>
 *
 * @param id
 * 	is binded to <code>${id}</code>
 * @return selected bean or <code>null</code>.
 */
@Override
public Person selectById(long id) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_BY_ID_SQL10;
    // add where arguments
    _contentValues.addWhereArgs(String.valueOf(id));
    String[] _sqlArgs = _contentValues.whereArgsAsArray();
    // log section BEGIN
    if (_context.isLogEnabled()) {
        // manage log
        Logger.info(_sql);
        // log for where parameters -- BEGIN
        int _whereParamCounter = 0;
        for (String _whereParamItem : _contentValues.whereArgs()) {
            Logger.info("==> param%s: '%s'", (_whereParamCounter++), StringUtils.checkSize(_whereParamItem));
        }
    // log for where parameters -- END
    }
    // log section END
    try (Cursor _cursor = database().rawQuery(_sql, _sqlArgs)) {
        // log section BEGIN
        if (_context.isLogEnabled()) {
            Logger.info("Rows found: %s", _cursor.getCount());
        }
        // log section END
        Person resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("name");
            int index2 = _cursor.getColumnIndex("age");
            resultBean = new Person();
            resultBean.id = _cursor.getLong(index0);
            if (!_cursor.isNull(index1)) {
                resultBean.name = _cursor.getString(index1);
            }
            if (!_cursor.isNull(index2)) {
                resultBean.age = _cursor.getInt(index2);
            }
        }
        return resultBean;
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) Cursor(android.database.Cursor) Person(sqlite.feature.many2many.case4.model.Person)

Example 18 with Person

use of sqlite.feature.many2many.case5.model.Person in project kripton by xcesco.

the class PersonDaoImpl method selectById.

/**
 * <h2>Select SQL:</h2>
 *
 * <pre>SELECT id, name, age FROM person WHERE id = ${id}</pre>
 *
 * <h2>Projected columns:</h2>
 * <dl>
 * 	<dt>id</dt><dd>is associated to bean's property <strong>id</strong></dd>
 * 	<dt>name</dt><dd>is associated to bean's property <strong>name</strong></dd>
 * 	<dt>age</dt><dd>is associated to bean's property <strong>age</strong></dd>
 * </dl>
 *
 * <h2>Query's parameters:</h2>
 * <dl>
 * 	<dt>${id}</dt><dd>is binded to method's parameter <strong>id</strong></dd>
 * </dl>
 *
 * @param id
 * 	is binded to <code>${id}</code>
 * @return selected bean or <code>null</code>.
 */
@Override
public Person selectById(long id) {
    KriptonContentValues _contentValues = contentValues();
    // query SQL is statically defined
    String _sql = SELECT_BY_ID_SQL10;
    // add where arguments
    _contentValues.addWhereArgs(String.valueOf(id));
    String[] _sqlArgs = _contentValues.whereArgsAsArray();
    // log section BEGIN
    if (_context.isLogEnabled()) {
        // manage log
        Logger.info(_sql);
        // log for where parameters -- BEGIN
        int _whereParamCounter = 0;
        for (String _whereParamItem : _contentValues.whereArgs()) {
            Logger.info("==> param%s: '%s'", (_whereParamCounter++), StringUtils.checkSize(_whereParamItem));
        }
    // log for where parameters -- END
    }
    // log section END
    try (Cursor _cursor = database().rawQuery(_sql, _sqlArgs)) {
        // log section BEGIN
        if (_context.isLogEnabled()) {
            Logger.info("Rows found: %s", _cursor.getCount());
        }
        // log section END
        Person resultBean = null;
        if (_cursor.moveToFirst()) {
            int index0 = _cursor.getColumnIndex("id");
            int index1 = _cursor.getColumnIndex("name");
            int index2 = _cursor.getColumnIndex("age");
            resultBean = new Person();
            resultBean.id = _cursor.getLong(index0);
            if (!_cursor.isNull(index1)) {
                resultBean.name = _cursor.getString(index1);
            }
            if (!_cursor.isNull(index2)) {
                resultBean.age = _cursor.getInt(index2);
            }
        }
        return resultBean;
    }
}
Also used : KriptonContentValues(com.abubusoft.kripton.android.sqlite.KriptonContentValues) Cursor(android.database.Cursor) Person(sqlite.feature.many2many.case5.model.Person)

Example 19 with Person

use of sqlite.feature.many2many.case5.model.Person in project data-transfer-project by google.

the class GoogleContactsImporter method importItem.

@Override
public ImportResult importItem(UUID jobId, TokensAndUrlAuthData authData, ContactsModelWrapper data) {
    JCardReader reader = new JCardReader(data.getVCards());
    try {
        // TODO(olsona): address any other problems that might arise in conversion
        List<VCard> vCardList = reader.readAll();
        for (VCard vCard : vCardList) {
            Person person = convert(vCard);
            getOrCreatePeopleService(authData).people().createContact(person).execute();
        }
        return ImportResult.OK;
    } catch (IOException e) {
        return new ImportResult(ImportResult.ResultType.ERROR, e.getMessage());
    }
}
Also used : ImportResult(org.dataportabilityproject.spi.transfer.provider.ImportResult) IOException(java.io.IOException) JCardReader(ezvcard.io.json.JCardReader) VCard(ezvcard.VCard) Person(com.google.api.services.people.v1.model.Person)

Example 20 with Person

use of sqlite.feature.many2many.case5.model.Person in project data-transfer-project by google.

the class GoogleContactsImporter method convert.

// TODO(olsona): can we guarantee that <VCARDPROPERTY>.getPref() will always return a value?
@VisibleForTesting
static Person convert(VCard vCard) {
    Person person = new Person();
    Preconditions.checkArgument(atLeastOneNamePresent(vCard), "At least one name must be present");
    person.setNames(Collections.singletonList(getPrimaryGoogleName(vCard.getStructuredNames())));
    if (vCard.getAddresses() != null) {
        person.setAddresses(vCard.getAddresses().stream().map(GoogleContactsImporter::convertToGoogleAddress).collect(Collectors.toList()));
    }
    if (vCard.getTelephoneNumbers() != null) {
        person.setPhoneNumbers(vCard.getTelephoneNumbers().stream().map(GoogleContactsImporter::convertToGooglePhoneNumber).collect(Collectors.toList()));
    }
    if (vCard.getEmails() != null) {
        person.setEmailAddresses(vCard.getEmails().stream().map(GoogleContactsImporter::convertToGoogleEmail).collect(Collectors.toList()));
    }
    return person;
}
Also used : Person(com.google.api.services.people.v1.model.Person) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Person (com.google.api.services.people.v1.model.Person)25 VCard (ezvcard.VCard)20 Test (org.junit.Test)16 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)15 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)13 Email (ezvcard.property.Email)13 Telephone (ezvcard.property.Telephone)13 Person (model.Person)13 List (java.util.List)12 Collectors (java.util.stream.Collectors)12 Name (com.google.api.services.people.v1.model.Name)11 StructuredName (ezvcard.property.StructuredName)11 Truth.assertThat (com.google.common.truth.Truth.assertThat)10 Pair (com.google.gdata.util.common.base.Pair)10 Collections (java.util.Collections)10 Function (java.util.function.Function)10 Address (com.google.api.services.people.v1.model.Address)9 Nullable (com.google.gdata.util.common.base.Nullable)8 Before (org.junit.Before)8 SOURCE_PARAM_NAME_TYPE (org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.SOURCE_PARAM_NAME_TYPE)6