Search in sources :

Example 46 with IPhonenumber

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

the class GoogleContactsProxy method preload.

public void preload() throws GoogleContactsException {
    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());
    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());
        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);
                }
            }
        }
    } 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 {
            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;
                    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();
                    this.m_dbh.delete(c.getUUID());
                    this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
                }
            }
            this.m_dbh.commit();
        } catch (SQLException e) {
            throw new GoogleContactsException(e.getMessage(), e);
        }
    } else {
        this.m_logger.warning("GoogleContacts proxy datahandler not initialized. Could not insert google contacts...");
    }
}
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 47 with IPhonenumber

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

the class XMLCallerHandler method startElement.

public void startElement(String uri, String name, String qname, Attributes attributes) throws SAXException {
    if (this.m_multi && qname.equalsIgnoreCase(TAG_CALLERLIST)) {
        this.m_callerList = this.getRuntime().getCallerFactory().createCallerList();
    }
    if (qname.equalsIgnoreCase(TAG_CALLER)) {
        this.m_caller = this.getRuntime().getCallerFactory().createCaller(this.getRuntime().getCallerFactory().createName("", ""), this.getRuntime().getCallerFactory().createPhonenumber(false));
    }
    if (qname.equalsIgnoreCase(TAG_UUID)) {
        this.m_caller.setUUID(attributes.getValue(ATTRIBUTE_VALUE));
    }
    if (qname.equalsIgnoreCase(TAG_FIRSTNAME)) {
        IName cname = this.m_caller.getName();
        cname.setFirstname(decode(attributes.getValue(ATTRIBUTE_VALUE)));
        this.m_caller.setName(cname);
    }
    if (qname.equalsIgnoreCase(TAG_LASTNAME)) {
        IName cname = this.m_caller.getName();
        cname.setLastname(decode(attributes.getValue(ATTRIBUTE_VALUE)));
        this.m_caller.setName(cname);
    }
    if (qname.equalsIgnoreCase(TAG_ADDITIONAL)) {
        IName cname = this.m_caller.getName();
        cname.setAdditional(decode(attributes.getValue(ATTRIBUTE_VALUE)));
        this.m_caller.setName(cname);
    }
    if (qname.equalsIgnoreCase(TAG_INTAREA)) {
        IPhonenumber pn = this.m_caller.getPhoneNumber();
        pn.setIntAreaCode(attributes.getValue(ATTRIBUTE_VALUE));
        this.m_caller.setPhoneNumber(pn);
    }
    if (qname.equalsIgnoreCase(TAG_AREA)) {
        IPhonenumber pn = this.m_caller.getPhoneNumber();
        pn.setAreaCode(attributes.getValue(ATTRIBUTE_VALUE));
        this.m_caller.setPhoneNumber(pn);
    }
    if (qname.equalsIgnoreCase(TAG_CALLNUMBER)) {
        IPhonenumber pn = this.m_caller.getPhoneNumber();
        pn.setCallNumber(attributes.getValue(ATTRIBUTE_VALUE));
        this.m_caller.setPhoneNumber(pn);
    }
    if (qname.equalsIgnoreCase(TAG_TELEPHONENUMBER)) {
        IPhonenumber pn = this.m_caller.getPhoneNumber();
        pn.setTelephoneNumber(attributes.getValue(ATTRIBUTE_VALUE));
        this.m_caller.setPhoneNumber(pn);
    }
    if (qname.equalsIgnoreCase(TAG_ATTRIBUTE)) {
        IAttribute att = this.getRuntime().getCallerFactory().createAttribute(attributes.getValue(ATTRIBUTE_NAME), decode(attributes.getValue(ATTRIBUTE_VALUE)));
        this.m_caller.setAttribute(att);
    }
}
Also used : IAttribute(de.janrufmonitor.framework.IAttribute) IName(de.janrufmonitor.framework.IName) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 48 with IPhonenumber

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

the class OutgoingCall method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    IPhonenumber pn = null;
    try {
        String phone = req.getParameter(OutgoingCall.PARAMETER_NUMBER);
        if (phone == null || phone.length() == 0)
            pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true);
        else
            pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(phone);
        IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
        ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(name, pn);
        ICip cip = PIMRuntime.getInstance().getCallFactory().createCip(req.getParameter(OutgoingCall.PARAMETER_CIP), "");
        IMsn msn = PIMRuntime.getInstance().getCallFactory().createMsn(req.getParameter(OutgoingCall.PARAMETER_MSN), "");
        Date date = new Date(Long.parseLong(req.getParameter(OutgoingCall.PARAMETER_DATE)));
        ICall call = PIMRuntime.getInstance().getCallFactory().createCall(c, msn, cip, date);
        call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STARTRING, Long.toString(new Date().getTime())));
        call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_OUTGOING));
        ClientCallMap.getInstance().setCall((pn.isClired() ? IJAMConst.CLIRED_CALL : pn.getTelephoneNumber()) + "/" + msn.getMSN(), call);
        Thread sender = new Thread(new HandlerThread(call, this));
        sender.start();
        resp.getContentStreamForWrite().close();
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICip(de.janrufmonitor.framework.ICip) ICall(de.janrufmonitor.framework.ICall) IName(de.janrufmonitor.framework.IName) IMsn(de.janrufmonitor.framework.IMsn) Date(java.util.Date) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 49 with IPhonenumber

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

the class OutlookTransformer method createBusinessCallerList.

private ICallerList createBusinessCallerList(Dispatch contact) throws ComFailException {
    ICallerList callerList = getRuntime().getCallerFactory().createCallerList();
    IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
    IAttribute attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, Dispatch.get(contact, "Firstname").toString().trim());
    if (attribute != null)
        m.add(attribute);
    attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, Dispatch.get(contact, "Lastname").toString().trim());
    if (attribute != null)
        m.add(attribute);
    if (m.size() == 0) {
        attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, Dispatch.get(contact, "CompanyName").toString().trim());
        if (attribute != null)
            m.add(attribute);
    } else {
        attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL, Dispatch.get(contact, "CompanyName").toString().trim());
        if (attribute != null)
            m.add(attribute);
    }
    // check if business caller exists
    if (m.size() > 0) {
        m.addAll(createBusinessAddressAttributes(contact));
        List phones = new ArrayList(businessPhones.length);
        IPhonenumber phone = getRuntime().getCallerFactory().createPhonenumber(false);
        String number = null;
        for (int i = 0; i < businessPhones.length; i++) {
            number = Dispatch.get(contact, businessPhones[i]).toString().trim();
            if (number != null && number.length() > 0) {
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("OutlookTransformer raw number: " + number);
                }
                phone = PhonenumberAnalyzer.getInstance(getRuntime()).toIdentifiedPhonenumber(number);
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("OutlookTransformer identified number: " + phone);
                }
                if (phone != null) {
                    if (phone.getTelephoneNumber().trim().length() > 0 && !phone.isClired()) {
                        m.add(getNumberTypeAttribute(businessPhones[i], phone.getTelephoneNumber()));
                        phones.add(phone);
                    }
                }
            }
        }
        if (phones.size() > 0) {
            ICaller outlookCaller = getRuntime().getCallerFactory().createCaller(null, phones, m);
            // outlookCaller.setAttributes(m);
            outlookCaller.setUUID(outlookCaller.getName().getLastname() + "_" + outlookCaller.getName().getFirstname() + "_" + outlookCaller.getPhoneNumber().getTelephoneNumber());
            this.setPictureAttribute(outlookCaller, contact);
            IAttribute cm = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, ID);
            outlookCaller.setAttribute(cm);
            this.m_logger.fine("Created Outlook contact: " + outlookCaller.toString());
            callerList.add(outlookCaller);
        }
    }
    return callerList;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 50 with IPhonenumber

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

the class OutlookTransformer method createPrivateCallerList.

private ICallerList createPrivateCallerList(Dispatch contact) throws ComFailException {
    ICallerList callerList = getRuntime().getCallerFactory().createCallerList();
    IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
    IAttribute attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, Dispatch.get(contact, "Firstname").toString().trim());
    if (attribute != null)
        m.add(attribute);
    attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, Dispatch.get(contact, "Lastname").toString().trim());
    if (attribute != null)
        m.add(attribute);
    // check if private caller exists
    if (m.size() > 0) {
        m.addAll(createPrivateAddressAttributes(contact));
        List phones = new ArrayList(businessPhones.length);
        IPhonenumber phone = getRuntime().getCallerFactory().createPhonenumber(false);
        String number = null;
        for (int i = 0; i < privatePhones.length; i++) {
            number = Dispatch.get(contact, privatePhones[i]).toString().trim();
            if (number != null && number.length() > 0) {
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("OutlookTransformer raw number: " + number);
                }
                phone = PhonenumberAnalyzer.getInstance(getRuntime()).toIdentifiedPhonenumber(number);
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("OutlookTransformer identified number: " + phone);
                }
                if (phone != null) {
                    if (phone.getTelephoneNumber().trim().length() > 0 && !phone.isClired()) {
                        m.add(getNumberTypeAttribute(privatePhones[i], phone.getTelephoneNumber()));
                        phones.add(phone);
                    }
                }
            }
        }
        if (phones.size() > 0) {
            ICaller outlookCaller = getRuntime().getCallerFactory().createCaller(null, phones, m);
            outlookCaller.setUUID(outlookCaller.getName().getLastname() + "_" + outlookCaller.getName().getFirstname() + "_" + outlookCaller.getPhoneNumber().getTelephoneNumber());
            this.setPictureAttribute(outlookCaller, contact);
            IAttribute cm = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, ID);
            outlookCaller.setAttribute(cm);
            this.m_logger.fine("Created Outlook contact: " + outlookCaller.toString());
            callerList.add(outlookCaller);
        }
    }
    return callerList;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IPhonenumber (de.janrufmonitor.framework.IPhonenumber)99 ICaller (de.janrufmonitor.framework.ICaller)62 List (java.util.List)49 ArrayList (java.util.ArrayList)44 IAttribute (de.janrufmonitor.framework.IAttribute)38 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)37 ICallerList (de.janrufmonitor.framework.ICallerList)36 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)26 ICall (de.janrufmonitor.framework.ICall)19 SQLException (java.sql.SQLException)19 IMsn (de.janrufmonitor.framework.IMsn)17 Date (java.util.Date)17 IOException (java.io.IOException)16 ICip (de.janrufmonitor.framework.ICip)13 IName (de.janrufmonitor.framework.IName)13 File (java.io.File)13 Iterator (java.util.Iterator)13 ITreeItemCallerData (de.janrufmonitor.ui.jface.application.ITreeItemCallerData)9 UUID (de.janrufmonitor.util.uuid.UUID)9 FileInputStream (java.io.FileInputStream)9