Search in sources :

Example 1 with IAttributeMap

use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.

the class GoogleContactsCallerManager method getCallers.

public ICallerList getCallers(IFilter filter) {
    try {
        if (filter != null && filter.getType().equals(FilterType.ATTRIBUTE)) {
            IAttributeMap m = ((AttributeFilter) filter).getAttributeMap();
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
                IAttribute a = m.get(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
                return getProxy().getContacts(a.getValue());
            }
        }
        if (filter != null && filter.getType().equals(FilterType.CHARACTER)) {
            ICallerList cl = getProxy().getContacts(null);
            this.applyFilters(cl, new IFilter[] { filter });
            return cl;
        }
        return getProxy().getContacts(null);
    } catch (GoogleContactsException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "loginerror", e));
    }
    return getRuntime().getCallerFactory().createCallerList();
}
Also used : ICallerList(de.janrufmonitor.framework.ICallerList) Message(de.janrufmonitor.exception.Message) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

Example 2 with IAttributeMap

use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.

the class GoogleContactsProxy method parseName.

private IAttributeMap parseName(ContactEntry e) {
    IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
    if (e.getName() != null && e.getName().getFamilyName() != null && e.getName().getGivenName() != null) {
        m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, e.getName().getFamilyName().getValue()));
        m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, e.getName().getGivenName().getValue()));
        return m;
    }
    String name = e.getTitle().getPlainText();
    // test name splitting
    String[] tmp = name.split(" ");
    if (tmp.length == 1 || tmp.length > 2) {
        m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, name));
    }
    // case: Brandt, Thilo
    if (tmp.length == 2) {
        if (tmp[0].length() < 3 || tmp[1].length() < 3) {
            m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, name));
        } else {
            if (tmp[0].endsWith(",")) {
                m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, tmp[0].substring(0, tmp[0].length() - 1)));
                m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, tmp[1]));
            } else {
                m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, tmp[1]));
                m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, tmp[0]));
            }
        }
    }
    if (e.getOrganizations().size() > 0) {
        Organization o = (Organization) e.getOrganizations().get(0);
        if (o != null && o.getOrgName() != null) {
            m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL, ((Organization) e.getOrganizations().get(0)).getOrgName().getValue()));
        }
    }
    return m;
}
Also used : Organization(com.google.gdata.data.extensions.Organization) IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

Example 3 with IAttributeMap

use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.

the class GoogleContactsProxy method parseAddress.

/**
 * Parsing the address field
 *
 * Street no.1 12345 city
 *
 * @param pa
 * @return
 */
private IAttributeMap parseAddress(StructuredPostalAddress pa) {
    IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
    if (pa == null)
        return m;
    if (pa.hasCity()) {
        m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CITY, pa.getCity().getValue()));
    }
    if (pa.hasPostcode()) {
        m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, pa.getPostcode().getValue()));
    }
    if (pa.hasStreet()) {
        String[] street = splitStreet(pa.getStreet().getValue());
        m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET, street[0]));
        m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET_NO, street[1]));
    }
    if (pa.hasCountry()) {
        m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, pa.getCountry().getValue()));
    }
    return m;
}
Also used : IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

Example 4 with IAttributeMap

use of de.janrufmonitor.framework.IAttributeMap 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 5 with IAttributeMap

use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.

the class LdapMappingManager method mapAttributes.

private IAttributeMap mapAttributes(LDAPEntry entry) {
    IAttributeMap attributes = getRuntime().getCallerFactory().createAttributeMap();
    LDAPAttributeSet attributeSet = entry.getAttributeSet();
    Iterator allAttributes = attributeSet.iterator();
    while (allAttributes.hasNext()) {
        LDAPAttribute attribute = (LDAPAttribute) allAttributes.next();
        if (m_attributeMappings.values().contains(attribute.getName())) {
            String value = attribute.getStringValue();
            if (m_logger.isLoggable(Level.INFO)) {
                m_logger.info("Adding LDAP attribute: " + attribute.getName() + ", value: " + value);
            }
            if (!m_inversAttributeMappings.getProperty(attribute.getName()).equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH)) {
                attributes.add(getRuntime().getCallerFactory().createAttribute(m_inversAttributeMappings.getProperty(attribute.getName()), value));
            } else {
                try {
                    addImage(attributes, attribute.getByteValue(), entry);
                } catch (IOException e) {
                    m_logger.log(Level.SEVERE, e.toString(), e);
                }
            }
        }
    }
    return attributes;
}
Also used : LDAPAttribute(com.novell.ldap.LDAPAttribute) LDAPAttributeSet(com.novell.ldap.LDAPAttributeSet) Iterator(java.util.Iterator) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IOException(java.io.IOException)

Aggregations

IAttributeMap (de.janrufmonitor.framework.IAttributeMap)64 IAttribute (de.janrufmonitor.framework.IAttribute)37 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)36 ICaller (de.janrufmonitor.framework.ICaller)31 List (java.util.List)24 ICallerList (de.janrufmonitor.framework.ICallerList)23 ArrayList (java.util.ArrayList)21 Iterator (java.util.Iterator)17 IOException (java.io.IOException)14 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)13 Date (java.util.Date)12 IMsn (de.janrufmonitor.framework.IMsn)11 File (java.io.File)10 ICip (de.janrufmonitor.framework.ICip)8 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)8 Message (de.janrufmonitor.exception.Message)6 ICall (de.janrufmonitor.framework.ICall)6 SimpleDateFormat (java.text.SimpleDateFormat)6 StringTokenizer (java.util.StringTokenizer)6 IFilter (de.janrufmonitor.repository.filter.IFilter)5