Search in sources :

Example 1 with IAttribute

use of de.janrufmonitor.framework.IAttribute 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 IAttribute

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

the class GoogleContactsProxy method identify.

public synchronized ICaller identify(IPhonenumber pn) throws GoogleContactsException {
    ICaller c = Identifier.identifyDefault(getRuntime(), pn);
    if (c != null) {
        pn = c.getPhoneNumber();
        try {
            List uuids = this.m_dbh.select(pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
            if (this.m_logger.isLoggable(Level.INFO)) {
                this.m_logger.info("List of found UUIDs: " + uuids);
            }
            if (uuids.size() > 0) {
                String uuid = null;
                ICaller contact = null;
                for (int k = 0; k < uuids.size(); k++) {
                    uuid = (String) uuids.get(k);
                    try {
                        contact = this.identifyByUUID(uuid);
                        if (contact != null) {
                            if (this.m_logger.isLoggable(Level.INFO)) {
                                this.m_logger.info("Google contact found for UUID: " + uuid);
                            }
                            contact.setUUID(new UUID().toString());
                            if (contact instanceof IMultiPhoneCaller) {
                                ((IMultiPhoneCaller) contact).getPhonenumbers().clear();
                            }
                            contact.setPhoneNumber(pn);
                            contact.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION, pn.getTelephoneNumber()));
                            return contact;
                        }
                    } catch (GoogleContactsException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                    }
                }
            } else {
                Properties config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(GoogleContactsCallerManager.NAMESPACE);
                if (config.getProperty(CFG_GOOGLE_KEEPEXT, "false").equalsIgnoreCase("true")) {
                    // iterate down
                    String callnumber = pn.getCallNumber();
                    if (callnumber.length() > 1) {
                        pn.setCallNumber(callnumber.substring(0, callnumber.length() - 1));
                        ICaller ca = this.identify(pn);
                        if (ca != null) {
                            pn.setCallNumber(callnumber);
                            if (ca instanceof IMultiPhoneCaller) {
                                ((IMultiPhoneCaller) ca).getPhonenumbers().clear();
                            }
                            ca.setPhoneNumber(pn);
                            // set extension
                            if (ca.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION)) {
                                String centralnumber = ca.getAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION).getValue();
                                if (pn.getTelephoneNumber().length() > centralnumber.length()) {
                                    IAttribute att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EXTENSION, pn.getTelephoneNumber().substring(centralnumber.length()));
                                    ca.setAttribute(att);
                                }
                            }
                            if (this.m_logger.isLoggable(Level.INFO)) {
                                this.m_logger.info("Caller match by central number: " + ca.toString());
                            }
                            return ca;
                        }
                    }
                }
            }
        } catch (SQLException e) {
            this.m_logger.log(Level.SEVERE, e.toString(), e);
        }
    }
    this.m_logger.info("Caller not identified: " + pn.getTelephoneNumber());
    return null;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) SQLException(java.sql.SQLException) IAttribute(de.janrufmonitor.framework.IAttribute) List(java.util.List) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) UUID(de.janrufmonitor.util.uuid.UUID) Properties(java.util.Properties)

Example 3 with IAttribute

use of de.janrufmonitor.framework.IAttribute 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 4 with IAttribute

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

the class HttpCallerManager method addCallerManagerAttribute.

private void addCallerManagerAttribute(ICallerList l) {
    // add caller manager attribute to callers
    for (int i = 0; i < l.size(); i++) {
        ICaller c = (ICaller) l.get(i);
        if (c != null) {
            IAttribute cm = this.getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, this.getID());
            c.setAttribute(cm);
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) IAttribute(de.janrufmonitor.framework.IAttribute)

Example 5 with IAttribute

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

the class GoogleMapsLocalize method buildRequestParameters.

private String buildRequestParameters(ICaller c) {
    StringBuffer params = new StringBuffer();
    IAttribute att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_STREET);
    if (att != null) {
        params.append("+");
        params.append(encode(att.getValue()));
    }
    att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_STREET_NO);
    if (att != null) {
        params.append("+");
        params.append(encode(att.getValue()));
    }
    att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE);
    if (att != null) {
        params.append("+");
        params.append(encode(att.getValue()));
    }
    att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CITY);
    if (att != null) {
        params.append("+");
        params.append(encode(att.getValue()));
    }
    att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY);
    if (att != null) {
        params.append("+");
        params.append(encode(att.getValue()));
    }
    return params.toString();
}
Also used : IAttribute(de.janrufmonitor.framework.IAttribute)

Aggregations

IAttribute (de.janrufmonitor.framework.IAttribute)111 ICaller (de.janrufmonitor.framework.ICaller)44 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)40 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)39 List (java.util.List)34 ICallerList (de.janrufmonitor.framework.ICallerList)31 ArrayList (java.util.ArrayList)29 Iterator (java.util.Iterator)25 ICall (de.janrufmonitor.framework.ICall)19 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)15 SQLException (java.sql.SQLException)15 File (java.io.File)14 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)12 IOException (java.io.IOException)12 Message (de.janrufmonitor.exception.Message)11 ComFailException (com.jacob.com.ComFailException)10 Date (java.util.Date)10 IMsn (de.janrufmonitor.framework.IMsn)9 Dispatch (com.jacob.com.Dispatch)8 UUID (de.janrufmonitor.util.uuid.UUID)8