Search in sources :

Example 16 with ICallerList

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

the class LdapContactsProxy method getContacts.

public synchronized ICallerList getContacts(String category) throws LdapContactsException {
    ICallerList cl = getRuntime().getCallerFactory().createCallerList(getMaxResults());
    String query = "(objectclass=*)";
    if (category != null) {
        String ldapAttrib = LdapMappingManager.getInstance().getLdapAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
        if (ldapAttrib != null && ldapAttrib.trim().length() > 0) {
            query = "(" + ldapAttrib + "=" + category + ")";
        }
    }
    LDAPConnection lc = new LDAPConnection();
    try {
        lc.connect(getServer(), getPort());
        lc.bind(LDAPConnection.LDAP_V3, getLoginUser(), getLoginPassword().getBytes("UTF-8"));
        LDAPSearchConstraints cons = lc.getSearchConstraints();
        cons.setMaxResults(getMaxResults());
        String baseDN = this.getBaseDN();
        String[] bases = null;
        if (baseDN.indexOf("|") > 0) {
            bases = baseDN.split("\\|");
        } else {
            bases = new String[] { baseDN };
        }
        for (int i = 0; i < bases.length; i++) {
            LDAPSearchResults searchResults = lc.search(bases[i], getScope(), query, // return all attributes
            null, // return attrs and values
            false, cons);
            ICaller c = null;
            while (searchResults.hasMore()) {
                LDAPEntry nextEntry = null;
                try {
                    nextEntry = searchResults.next();
                } catch (LDAPException e) {
                    if (e.getResultCode() == LDAPException.LDAP_TIMEOUT || e.getResultCode() == LDAPException.CONNECT_ERROR)
                        break;
                    else
                        continue;
                }
                c = LdapMappingManager.getInstance().mapToJamCaller(nextEntry);
                if (c != null) {
                    cl.add(c);
                }
            }
        }
        // disconnect from the server
        lc.disconnect();
        LdapMappingManager.invalidate();
    } catch (LDAPException e) {
        this.m_logger.log(Level.SEVERE, e.toString(), e);
        throw new LdapContactsException(e.toString(), e);
    } catch (UnsupportedEncodingException e) {
        this.m_logger.log(Level.SEVERE, e.toString(), e);
    }
    if (this.m_dbh != null) {
        try {
            this.m_dbh.deleteAll();
            ICaller c = null;
            for (int i = 0, j = cl.size(); i < j; i++) {
                c = cl.get(i);
                if (c instanceof IMultiPhoneCaller) {
                    List phones = ((IMultiPhoneCaller) c).getPhonenumbers();
                    IPhonenumber pn = null;
                    for (int k = 0; k < phones.size(); k++) {
                        pn = (IPhonenumber) phones.get(k);
                        this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
                    }
                } else {
                    IPhonenumber pn = c.getPhoneNumber();
                    this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
                }
            }
        } catch (SQLException e) {
            throw new LdapContactsException(e.getMessage(), e);
        }
    } else {
        this.m_logger.warning("GoogleContacts proxy datahandler not initialized. Could not insert google contacts...");
    }
    return cl;
}
Also used : SQLException(java.sql.SQLException) LDAPSearchConstraints(com.novell.ldap.LDAPSearchConstraints) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LDAPConnection(com.novell.ldap.LDAPConnection) ICaller(de.janrufmonitor.framework.ICaller) LDAPEntry(com.novell.ldap.LDAPEntry) ICallerList(de.janrufmonitor.framework.ICallerList) LDAPSearchResults(com.novell.ldap.LDAPSearchResults) LDAPException(com.novell.ldap.LDAPException) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 17 with ICallerList

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

the class MacAddressBookManager method getCallers.

public ICallerList getCallers(IFilter[] filters, ISearchTerm[] searchTerms) {
    try {
        String searchTerm = "";
        if (searchTerms != null) {
            for (int i = 0; i < searchTerms.length; i++) {
                searchTerm += " " + searchTerms[i].getSearchTerm();
            }
        }
        if (filters != null && filters[0] != null && searchTerm.trim().length() > 0) {
            ICallerList cl = getRuntime().getCallerFactory().createCallerList();
            cl.add(getProxy().findContacts(searchTerm.trim()));
            this.applyFilters(cl, filters);
            return cl;
        }
        if (searchTerm.trim().length() == 0)
            return this.getCallers(filters);
        return getProxy().findContacts(searchTerm.trim());
    } catch (MacAddressBookProxyException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    return getRuntime().getCallerFactory().createCallerList();
}
Also used : ICallerList(de.janrufmonitor.framework.ICallerList)

Example 18 with ICallerList

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

the class ThunderbirdTransformer method parseContacts.

private void parseContacts(ICallerList cl, List rawData) {
    Map m = null;
    ICallerList c = null;
    for (int i = 0, j = rawData.size(); i < j; i++) {
        m = (Map) rawData.get(i);
        if (this.checkPhone(m)) {
            c = parseMap(m);
            if (c != null && c.size() > 0)
                cl.add(c);
        }
    }
}
Also used : ICallerList(de.janrufmonitor.framework.ICallerList) HashMap(java.util.HashMap) Map(java.util.Map) IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

Example 19 with ICallerList

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

the class ThunderbirdTransformer method getCallers.

public ICallerList getCallers() {
    ICallerList cl = PIMRuntime.getInstance().getCallerFactory().createCallerList();
    if (this.m_filename == null)
        return cl;
    File f = new File(this.m_filename);
    if (!f.exists() || !f.isFile()) {
        this.m_logger.warning("Mozilla Thunderbird file " + this.m_filename + " does not exists.");
        PropagationFactory.getInstance().fire(new Message(Message.INFO, ThunderbirdCallerManager.NAMESPACE, "nofile", new Exception("Sync Mozilla Thunderbird Adressbook...")));
        return cl;
    }
    if (this.m_sync)
        PropagationFactory.getInstance().fire(new Message(Message.INFO, ThunderbirdCallerManager.NAMESPACE, "sync", new Exception("Sync Mozilla Thunderbird Adressbook...")));
    try {
        List rawData = new ArrayList();
        FileInputStream fis = new FileInputStream(f);
        MorkDocument md = new MorkDocument(new InputStreamReader(fis));
        List l = md.getRows();
        Row r = null;
        for (int i = 0, j = l.size(); i < j; i++) {
            r = (Row) l.get(i);
            rawData.add(r.getAliases());
        }
        l = md.getTables();
        Table t = null;
        for (int i = 0, j = l.size(); i < j; i++) {
            t = (Table) l.get(i);
            for (int k = 0; k < t.getRows().size(); k++) {
                r = (Row) t.getRows().get(k);
                rawData.add(r.getAliases());
            }
        }
        fis.close();
        this.m_total = rawData.size();
        if (rawData.size() > 0) {
            this.m_logger.info("Found " + rawData.size() + " Mozilla Thunderbird contacts.");
            this.parseContacts(cl, rawData);
        }
    } catch (FileNotFoundException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (IOException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    this.m_logger.info(cl.size() + " contacts from Mozilla Thunderbird available.");
    return cl;
}
Also used : Table(mork.Table) Message(de.janrufmonitor.exception.Message) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) MorkDocument(mork.MorkDocument) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) ICallerList(de.janrufmonitor.framework.ICallerList) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) Row(mork.Row) File(java.io.File)

Example 20 with ICallerList

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

the class ThunderbirdTransformer method parseMap.

private ICallerList parseMap(Map mx) {
    this.m_current++;
    Map m = new HashMap();
    m.putAll(mx);
    ICallerList cl = PIMRuntime.getInstance().getCallerFactory().createCallerList(2);
    ICaller c = null;
    if (this.checkWork(m)) {
        c = buildWorkContact(m);
        if (c != null)
            cl.add(c);
    }
    if (this.checkHome(m)) {
        c = buildHomeContact(m);
        if (c != null)
            cl.add(c);
    }
    return cl;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

Aggregations

ICallerList (de.janrufmonitor.framework.ICallerList)81 ICaller (de.janrufmonitor.framework.ICaller)40 List (java.util.List)36 ArrayList (java.util.ArrayList)32 IAttribute (de.janrufmonitor.framework.IAttribute)24 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)24 SQLException (java.sql.SQLException)24 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)18 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)17 IOException (java.io.IOException)15 Message (de.janrufmonitor.exception.Message)14 Iterator (java.util.Iterator)11 Map (java.util.Map)11 File (java.io.File)10 HashMap (java.util.HashMap)10 Viewer (org.eclipse.jface.viewers.Viewer)10 ICallerManager (de.janrufmonitor.repository.ICallerManager)9 ComFailException (com.jacob.com.ComFailException)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)7