Search in sources :

Example 1 with ICaller

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

the class GenericWebAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null) {
        IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            Object o = selection.getFirstElement();
            if (o instanceof ICall || o instanceof ICaller) {
                Properties configuration = getRuntime().getConfigManagerFactory().getConfigManager().getProperties(this.getNamespace());
                if (configuration != null) {
                    String url = configuration.getProperty("url");
                    if (url != null && url.trim().length() > 0) {
                        this.m_logger.info("Found valid web url to execute: " + url);
                        Formatter f = Formatter.getInstance(this.getRuntime());
                        url = f.parse(url, o);
                        this.m_logger.info("Parsed web url to execute: " + url);
                        Program.launch(url);
                    }
                } else {
                    this.m_logger.warning("Found invalid configuration for namespace: " + this.getNamespace());
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICall(de.janrufmonitor.framework.ICall) Formatter(de.janrufmonitor.util.formatter.Formatter) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Properties(java.util.Properties)

Example 2 with ICaller

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

the class GoogleContactsProxy method getContacts.

public synchronized ICallerList getContacts(String category) throws GoogleContactsException {
    this.m_current = 0;
    this.m_total = 0;
    try {
        fetchCategories();
    } catch (IOException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    } catch (ServiceException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    }
    ICallerList cl = getRuntime().getCallerFactory().createCallerList(getMaxResults());
    if (category != null && !this.m_reverseCategories.containsKey(category))
        return cl;
    ContactsService cs = login();
    try {
        URL feedUrl = new URL("http://www.google.com/m8/feeds/contacts/" + getLoginUser() + "/full");
        Query q = new Query(feedUrl);
        q.setMaxResults(getMaxResults());
        if (category != null)
            q.setStringCustomParameter("group", (String) this.m_reverseCategories.get(category));
        ContactFeed resultFeed = (ContactFeed) cs.getFeed(q, ContactFeed.class);
        List entries = resultFeed.getEntries();
        this.m_total = entries.size();
        this.m_logger.info("Fetched " + entries.size() + " entries from google account " + getLoginUser());
        Object o = null;
        for (int i = 0, j = entries.size(); i < j; i++) {
            o = entries.get(i);
            if (o instanceof ContactEntry) {
                // && (category==null || matchCategory(category, (ContactEntry) o))) {
                ICaller c = this.parse(cs, (ContactEntry) o);
                if (c != null) {
                    cl.add(c);
                    this.m_current++;
                }
            }
        }
    } catch (MalformedURLException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    } catch (IOException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    } catch (ServiceException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    }
    // 
    if (this.m_dbh != null) {
        try {
            if (category == null)
                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;
                    if (category != null)
                        this.m_dbh.delete(c.getUUID());
                    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();
                    if (category != null)
                        this.m_dbh.delete(c.getUUID());
                    this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
                }
            }
        } catch (SQLException e) {
            throw new GoogleContactsException(e.getMessage(), e);
        }
    } else {
        this.m_logger.warning("GoogleContacts proxy datahandler not initialized. Could not insert google contacts...");
    }
    return cl;
}
Also used : MalformedURLException(java.net.MalformedURLException) Query(com.google.gdata.client.Query) SQLException(java.sql.SQLException) IOException(java.io.IOException) ContactFeed(com.google.gdata.data.contacts.ContactFeed) URL(java.net.URL) ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) ServiceException(com.google.gdata.util.ServiceException) ContactsService(com.google.gdata.client.contacts.ContactsService) ContactEntry(com.google.gdata.data.contacts.ContactEntry) List(java.util.List) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 3 with ICaller

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

the class GoogleContactsProxy method deleteContacts.

public synchronized void deleteContacts(ICallerList cl) throws GoogleContactsException {
    this.m_current = 0;
    this.m_total = 0;
    this.m_total = cl.size();
    try {
        fetchCategories();
    } catch (IOException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    } catch (ServiceException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    }
    ContactsService cs = login();
    ICaller c = null;
    for (int i = 0, j = cl.size(); i < j; i++) {
        c = cl.get(i);
        try {
            if (c.getAttributes().contains("entryUrl")) {
                String entryUrl = c.getAttribute("entryUrl").getValue();
                if (entryUrl.length() > 0) {
                    ContactEntry entry = (ContactEntry) cs.getEntry(new URL(entryUrl), ContactEntry.class);
                    if (entry != null) {
                        this.m_logger.info("Deleting google contact: " + entry.getEtag());
                        entry.delete();
                        this.m_current++;
                    }
                }
            }
            if (this.m_dbh != null) {
                try {
                    this.m_dbh.delete(c.getUUID());
                } catch (SQLException e) {
                    throw new GoogleContactsException(e.getMessage(), e);
                }
            } else {
                this.m_logger.warning("GoogleContacts proxy datahandler not initialized. Could not insert google contacts...");
            }
        } catch (MalformedURLException e) {
            this.m_logger.log(Level.SEVERE, e.toString(), e);
        } catch (IOException e) {
            this.m_logger.log(Level.SEVERE, e.toString(), e);
        } catch (ServiceException e) {
            this.m_logger.log(Level.SEVERE, e.toString(), e);
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) MalformedURLException(java.net.MalformedURLException) ServiceException(com.google.gdata.util.ServiceException) ContactsService(com.google.gdata.client.contacts.ContactsService) SQLException(java.sql.SQLException) ContactEntry(com.google.gdata.data.contacts.ContactEntry) IOException(java.io.IOException) URL(java.net.URL)

Example 4 with ICaller

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

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

the class HttpCallerManager method getCaller.

public ICaller getCaller(IPhonenumber number) throws CallerNotFoundException {
    if (!this.isConnected()) {
        this.m_logger.warning("Client is not yet connected with the server.");
        throw new CallerNotFoundException("No caller found. Client is not yet connected with the server.");
    }
    IRequester r = this.getRequester(new CallerGetHandler(number, this.getCallerManager()));
    IHttpResponse resp = r.request();
    String xml = this.getXmlContent(resp);
    this.handleRequester(resp, r);
    ICaller c = XMLSerializer.toCaller(xml);
    if (c != null) {
        return c;
    }
    throw new CallerNotFoundException("no caller found.");
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) IRequester(de.janrufmonitor.service.commons.http.IRequester) CallerGetHandler(de.janrufmonitor.service.client.request.handler.CallerGetHandler) IHttpResponse(de.janrufmonitor.service.commons.http.IHttpResponse)

Aggregations

ICaller (de.janrufmonitor.framework.ICaller)144 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)62 ICallerList (de.janrufmonitor.framework.ICallerList)49 List (java.util.List)46 IAttribute (de.janrufmonitor.framework.IAttribute)42 ICall (de.janrufmonitor.framework.ICall)41 ArrayList (java.util.ArrayList)40 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)32 SQLException (java.sql.SQLException)26 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)25 IOException (java.io.IOException)25 Viewer (org.eclipse.jface.viewers.Viewer)24 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 File (java.io.File)20 Date (java.util.Date)17 Iterator (java.util.Iterator)17 Shell (org.eclipse.swt.widgets.Shell)17 IMsn (de.janrufmonitor.framework.IMsn)16 Properties (java.util.Properties)15 ICip (de.janrufmonitor.framework.ICip)14