Search in sources :

Example 1 with StructuredPostalAddress

use of com.google.gdata.data.extensions.StructuredPostalAddress in project janrufmonitor by tbrandt77.

the class GoogleContactsProxy method parse.

private synchronized ICaller parse(ContactsService cs, ContactEntry e) {
    if (e == null)
        return null;
    if (e.getPhoneNumbers().size() == 0)
        return null;
    String uuid = parseUUID(e);
    IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
    m.addAll(parseName(e));
    if (e.hasStructuredPostalAddresses()) {
        StructuredPostalAddress pa = (StructuredPostalAddress) e.getStructuredPostalAddresses().get(0);
        m.addAll(parseAddress(pa));
    }
    // 2012/10/20: added email support
    if (e.hasEmailAddresses()) {
        List emaillist = e.getEmailAddresses();
        if (emaillist.size() > 0) {
            Email email = (Email) emaillist.get(0);
            m.add(parseEmail(email));
        }
    }
    List gphones = e.getPhoneNumbers();
    List pl = new ArrayList(gphones.size());
    PhoneNumber p = null;
    IPhonenumber pn = null;
    for (int i = 0, j = gphones.size(); i < j; i++) {
        p = (PhoneNumber) gphones.get(i);
        pn = PhonenumberAnalyzer.getInstance(getRuntime()).toIdentifiedPhonenumber(p.getPhoneNumber());
        if (pn != null) {
            pl.add(pn);
            m.add(parseNumberType(pn, p));
        }
    }
    if (pl.size() == 0)
        return null;
    if (e.getExtendedProperties() != null) {
        ExtendedProperty exp = null;
        for (int i = 0, j = e.getExtendedProperties().size(); i < j; i++) {
            exp = (ExtendedProperty) e.getExtendedProperties().get(i);
            if (exp.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_GEO_ACC) && exp.getValue().length() > 0) {
                m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_ACC, exp.getValue()));
            }
            if (exp.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_GEO_LNG) && exp.getValue().length() > 0) {
                m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG, exp.getValue()));
            }
            if (exp.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_GEO_LAT) && exp.getValue().length() > 0) {
                m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT, exp.getValue()));
            }
        }
    }
    m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, GoogleContactsCallerManager.ID));
    m.add(getRuntime().getCallerFactory().createAttribute("entryUrl", e.getSelfLink().getHref()));
    IAttribute a = parseCategory(e);
    if (a != null)
        m.add(a);
    try {
        a = parseImage(cs, e);
        if (a != null) {
            m.add(a);
        }
    } catch (GoogleContactsException ex) {
        this.m_logger.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return getRuntime().getCallerFactory().createCaller(uuid, null, pl, m);
}
Also used : Email(com.google.gdata.data.extensions.Email) ArrayList(java.util.ArrayList) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) PhoneNumber(com.google.gdata.data.extensions.PhoneNumber) List(java.util.List) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) StructuredPostalAddress(com.google.gdata.data.extensions.StructuredPostalAddress) ExtendedProperty(com.google.gdata.data.extensions.ExtendedProperty) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 2 with StructuredPostalAddress

use of com.google.gdata.data.extensions.StructuredPostalAddress in project janrufmonitor by tbrandt77.

the class GoogleContactsProxy method createPostalAddress.

private StructuredPostalAddress createPostalAddress(IAttributeMap m) {
    StructuredPostalAddress pa = new StructuredPostalAddress();
    StringBuffer tmp = new StringBuffer(256);
    if (m.contains(IJAMConst.ATTRIBUTE_NAME_STREET)) {
        tmp.append(m.get(IJAMConst.ATTRIBUTE_NAME_STREET).getValue());
        if (m.contains(IJAMConst.ATTRIBUTE_NAME_STREET_NO)) {
            tmp.append(" ");
            tmp.append(m.get(IJAMConst.ATTRIBUTE_NAME_STREET_NO).getValue());
        }
        tmp.append("\n");
    }
    if (m.contains(IJAMConst.ATTRIBUTE_NAME_CITY)) {
        if (m.contains(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE)) {
            tmp.append(m.get(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue());
            tmp.append(" ");
        }
        tmp.append(m.get(IJAMConst.ATTRIBUTE_NAME_CITY).getValue());
    }
    if (m.contains(IJAMConst.ATTRIBUTE_NAME_COUNTRY)) {
        tmp.append("\n");
        tmp.append(m.get(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue());
    }
    if (tmp.length() == 0)
        tmp.append(" ");
    pa.setFormattedAddress(new FormattedAddress(tmp.toString()));
    pa.setRel(PostalAddress.Rel.HOME);
    pa.setPrimary(Boolean.TRUE);
    return pa;
}
Also used : FormattedAddress(com.google.gdata.data.extensions.FormattedAddress) StructuredPostalAddress(com.google.gdata.data.extensions.StructuredPostalAddress)

Aggregations

StructuredPostalAddress (com.google.gdata.data.extensions.StructuredPostalAddress)2 Email (com.google.gdata.data.extensions.Email)1 ExtendedProperty (com.google.gdata.data.extensions.ExtendedProperty)1 FormattedAddress (com.google.gdata.data.extensions.FormattedAddress)1 PhoneNumber (com.google.gdata.data.extensions.PhoneNumber)1 IAttribute (de.janrufmonitor.framework.IAttribute)1 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)1 ICallerList (de.janrufmonitor.framework.ICallerList)1 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1