Search in sources :

Example 11 with IMultiPhoneCaller

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

the class OutlookMappingManager method mapToOutlookCaller.

public void mapToOutlookCaller(Dispatch oCaller, ICaller jamCaller, IOutlookMapping om) {
    if (this.m_logger.isLoggable(Level.INFO)) {
        this.m_logger.info("Appliing mapping: " + om.toString());
    }
    // clear all supported fields in outlook
    List outlookContacFieldMappings = om.getSupportedContactFields();
    String field = null;
    for (int i = 0, j = outlookContacFieldMappings.size(); i < j; i++) {
        field = (String) outlookContacFieldMappings.get(i);
        Dispatch.put(oCaller, field, "");
    }
    // clear all supported numbers in outlook
    List outlookNumberMappings = om.getSupportedNumbers();
    String numbertype = null;
    for (int i = 0, j = outlookNumberMappings.size(); i < j; i++) {
        numbertype = (String) outlookNumberMappings.get(i);
        Dispatch.put(oCaller, numbertype, "");
    }
    // set address data
    Dispatch.put(oCaller, OutlookContactConst.User1, jamCaller.getUUID());
    Dispatch.put(oCaller, OutlookContactConst.User2, jamCaller.getPhoneNumber().getIntAreaCode() + jamCaller.getPhoneNumber().getAreaCode());
    String jamField = null;
    IAttribute a = null;
    for (int i = 0, j = outlookContacFieldMappings.size(); i < j; i++) {
        field = (String) outlookContacFieldMappings.get(i);
        jamField = om.mapToJamField(field);
        if (jamField != null) {
            a = jamCaller.getAttribute(jamField);
            if (a != null) {
                // TODO: 2008/08/13 - Hack for street no
                if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_STREET)) {
                    if (jamCaller.getAttributes().contains((IJAMConst.ATTRIBUTE_NAME_STREET_NO))) {
                        Dispatch.put(oCaller, field, a.getValue() + " " + jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_STREET_NO).getValue());
                    } else {
                        Dispatch.put(oCaller, field, a.getValue());
                    }
                } else if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_GEO_ACC) || a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_GEO_LNG) || a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_GEO_LAT)) {
                    StringBuffer geodata = new StringBuffer();
                    geodata.append(jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_ACC).getValue());
                    geodata.append(",");
                    geodata.append(jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG).getValue());
                    geodata.append(",");
                    geodata.append(jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT).getValue());
                    Dispatch.put(oCaller, field, geodata.toString());
                } else {
                    Dispatch.put(oCaller, field, a.getValue());
                }
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("Setting attribute: " + a.toString());
                }
            }
        }
    }
    // set phone numbers
    if (jamCaller instanceof IMultiPhoneCaller) {
        List pns = ((IMultiPhoneCaller) jamCaller).getPhonenumbers();
        IPhonenumber pn = null;
        IAttributeMap m = jamCaller.getAttributes();
        for (int k = 0; k < pns.size(); k++) {
            pn = (IPhonenumber) pns.get(k);
            this.setContactPhone(oCaller, pn, m, om);
        }
    } else {
        this.setContactPhone(oCaller, jamCaller.getPhoneNumber(), jamCaller.getAttributes(), om);
    }
    Dispatch.call(oCaller, "RemovePicture");
    if (this.getAttribute(jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH)).length() > 0) {
        try {
            Dispatch.call(oCaller, "AddPicture", PathResolver.getInstance().resolve(this.getAttribute(jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH))));
        } catch (ComFailException e) {
            this.m_logger.log(Level.WARNING, e.getMessage(), e);
        }
    }
    Dispatch.call(oCaller, "Save");
}
Also used : IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) List(java.util.List) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) ComFailException(com.jacob.com.ComFailException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 12 with IMultiPhoneCaller

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

the class OutlookContactProxy method updateProxyDatabase.

private void updateProxyDatabase(ICallerList callers) {
    ICaller c = null;
    for (int i = 0, j = callers.size(); i < j; i++) {
        c = callers.get(i);
        if (c instanceof IMultiPhoneCaller) {
            try {
                // clean up cache
                if (this.m_dbh != null)
                    this.m_dbh.delete(c.getUUID());
            } catch (SQLException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
    for (int i = 0, j = callers.size(); i < j; i++) {
        c = callers.get(i);
        if (c instanceof IMultiPhoneCaller) {
            List pns = ((IMultiPhoneCaller) c).getPhonenumbers();
            IPhonenumber pn = null;
            for (int k = 0, l = pns.size(); k < l; k++) {
                pn = (IPhonenumber) pns.get(k);
                if (this.m_dbh != null) {
                    try {
                        this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
                    } catch (SQLException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                    }
                }
            }
        } else {
            if (this.m_dbh != null) {
                try {
                    this.m_dbh.delete(c.getUUID());
                    this.m_dbh.insert(c.getUUID(), c.getPhoneNumber().getIntAreaCode(), c.getPhoneNumber().getAreaCode(), c.getPhoneNumber().getCallNumber());
                } catch (SQLException e) {
                    this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) SQLException(java.sql.SQLException) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 13 with IMultiPhoneCaller

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

the class OutlookContactProxy method getCallerListFromSingleContact.

private ICallerList getCallerListFromSingleContact(Dispatch contact) throws ComFailException {
    ICallerList callers = getRuntime().getCallerFactory().createCallerList();
    try {
        Properties config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(NAMESPACE);
        if (config.getProperty("split", "true").equalsIgnoreCase("true")) {
            ICaller privateCaller = createPrivateCaller(contact);
            ICaller businessCaller = createBusinessCaller(contact);
            if (privateCaller == null && businessCaller != null) {
                callers.add(businessCaller);
            }
            if (privateCaller != null && businessCaller == null) {
                callers.add(privateCaller);
            }
            if (privateCaller != null && businessCaller != null) {
                if (((IMultiPhoneCaller) businessCaller).getPhonenumbers().size() == 1) {
                    // only one entry available
                    IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) businessCaller).getPhonenumbers().get(0);
                    IAttribute numbertype = businessCaller.getAttribute(IOutlookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
                    if (numbertype != null && numbertype.getValue().equalsIgnoreCase(OutlookContactConst.MobileTelephoneNumber)) {
                        this.m_logger.info("Bussiness caller will be dropped. Only mobile number available, but still in private contact: " + businessCaller);
                        businessCaller = null;
                    }
                }
                if (((IMultiPhoneCaller) privateCaller).getPhonenumbers().size() == 1 && businessCaller != null) {
                    // only one entry available
                    IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) privateCaller).getPhonenumbers().get(0);
                    IAttribute numbertype = privateCaller.getAttribute(IOutlookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
                    if (numbertype != null && numbertype.getValue().equalsIgnoreCase(OutlookContactConst.MobileTelephoneNumber)) {
                        this.m_logger.info("Private caller will be dropped. Only mobile number available, but still in business contact: " + privateCaller);
                        privateCaller = null;
                    }
                }
                if (privateCaller != null) {
                    callers.add(privateCaller);
                }
                if (businessCaller != null) {
                    callers.add(businessCaller);
                }
            }
        } else {
            ICaller c = OutlookMappingManager.getInstance().mapToJamCaller(contact, new DefaultOutlookMapping());
            if (c != null)
                callers.add(c);
        }
        updateProxyDatabase(callers);
    } catch (ComFailException ex) {
        this.m_logger.warning("1 item (e.g. distribution list) was ignored on loading.");
        if (ex.toString().indexOf("Can't get object clsid from progid") > -1) {
            this.m_logger.log(Level.SEVERE, ex.toString(), ex);
            PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "olstarterror", ex));
        } else
            this.m_logger.warning(ex.toString() + ", " + ex.getMessage());
    } catch (Exception ex) {
        this.m_logger.warning(ex.getMessage() + ", " + ex.toString());
    } finally {
        // added 2006/02/05: clean outlook references
        if (contact != null)
            contact.safeRelease();
    }
    return callers;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) DefaultOutlookMapping(de.janrufmonitor.repository.mapping.DefaultOutlookMapping) ICallerList(de.janrufmonitor.framework.ICallerList) Message(de.janrufmonitor.exception.Message) IAttribute(de.janrufmonitor.framework.IAttribute) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) Properties(java.util.Properties) ComFailException(com.jacob.com.ComFailException) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) SQLException(java.sql.SQLException) ComFailException(com.jacob.com.ComFailException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 14 with IMultiPhoneCaller

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

the class OutlookContactProxy method findContact.

public synchronized ICaller findContact(IPhonenumber pn) throws OutlookContactProxyException {
    ICaller c = Identifier.identifyDefault(getRuntime(), pn);
    if (c == null && PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(pn.getTelephoneNumber())) {
        pn = getRuntime().getCallerFactory().createInternalPhonenumber(pn.getTelephoneNumber());
        c = getRuntime().getCallerFactory().createCaller(pn);
    }
    if (c != null) {
        if (PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(pn)) {
            IPhonenumber p = getRuntime().getCallerFactory().createInternalPhonenumber(pn.getTelephoneNumber());
            c.setPhoneNumber(p);
        }
        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;
                for (int k = 0; k < uuids.size(); k++) {
                    uuid = (String) uuids.get(k);
                    ActiveXComponent outlook = new ActiveXComponent("Outlook.Application");
                    Dispatch mapiNS = null;
                    Dispatch contactsFolder = null;
                    Dispatch contactsSubFolder = null;
                    Dispatch items = null;
                    Dispatch contact = null;
                    try {
                        if (this.m_logger.isLoggable(Level.INFO))
                            this.m_logger.info("created Outlook.Application dispatch");
                        if (this.m_logger.isLoggable(Level.INFO))
                            this.m_logger.info("Microsoft Outlook version: " + Dispatch.get(outlook.getObject(), "Version"));
                        mapiNS = outlook.getProperty("Session").toDispatch();
                        if (this.m_logger.isLoggable(Level.INFO))
                            this.m_logger.info("Microsoft Outlook namespace: " + mapiNS);
                        Variant contactsVariant = new Variant(10);
                        contactsFolder = Dispatch.call(mapiNS, "GetDefaultFolder", contactsVariant).toDispatch();
                        if (this.m_logger.isLoggable(Level.INFO))
                            this.m_logger.info("Microsoft Outlook folder: " + contactsFolder);
                        contactsVariant.safeRelease();
                        // getting configured subfolders
                        List subfolders = new ArrayList();
                        subfolders.add("");
                        subfolders.addAll(getAllContactFolders());
                        String folder = null;
                        for (int i = 0, j = subfolders.size(); i < j; i++) {
                            folder = (String) subfolders.get(i);
                            items = this.getItemsOfFolder(contactsFolder, folder, false);
                            if (items == null)
                                continue;
                            contact = this.findContactByUUID(items, uuid);
                            if (contact != null) {
                                if (this.m_logger.isLoggable(Level.INFO)) {
                                    this.m_logger.info("Outlook contact found for UUID: " + uuid);
                                }
                                ICallerList cl = getCallerListFromSingleContact(contact);
                                if (cl.size() == 1) {
                                    ICaller rc = cl.get(0);
                                    rc.setUUID(new UUID().toString());
                                    if (rc instanceof IMultiPhoneCaller) {
                                        ((IMultiPhoneCaller) rc).getPhonenumbers().clear();
                                    }
                                    rc.setPhoneNumber(pn);
                                    IAttribute att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION, pn.getTelephoneNumber());
                                    rc.setAttribute(att);
                                    if (this.m_logger.isLoggable(Level.INFO)) {
                                        this.m_logger.info("Exact caller match: " + rc.toString());
                                    }
                                    return rc;
                                }
                                if (cl.size() == 2) {
                                    ICaller rc = null;
                                    for (int x = 0; x < cl.size(); x++) {
                                        rc = cl.get(x);
                                        if (rc instanceof IMultiPhoneCaller) {
                                            List phones = ((IMultiPhoneCaller) rc).getPhonenumbers();
                                            IPhonenumber p = null;
                                            for (int z = 0; z < phones.size(); z++) {
                                                p = (IPhonenumber) phones.get(z);
                                                if (p.getIntAreaCode().equalsIgnoreCase(pn.getIntAreaCode()) && p.getAreaCode().equalsIgnoreCase(pn.getAreaCode()) && pn.getCallNumber().startsWith(p.getCallNumber())) {
                                                    if (this.m_logger.isLoggable(Level.INFO)) {
                                                        this.m_logger.info("Caller match (IMultiPhoneCaller): " + rc.toString());
                                                    }
                                                    rc.setUUID(new UUID().toString());
                                                    if (rc instanceof IMultiPhoneCaller) {
                                                        ((IMultiPhoneCaller) rc).getPhonenumbers().clear();
                                                    }
                                                    rc.setPhoneNumber(p);
                                                    return rc;
                                                }
                                            }
                                        } else {
                                            if (rc.getPhoneNumber().getIntAreaCode().equalsIgnoreCase(pn.getIntAreaCode()) && rc.getPhoneNumber().getAreaCode().equalsIgnoreCase(pn.getAreaCode()) && pn.getCallNumber().startsWith(rc.getPhoneNumber().getCallNumber())) {
                                                if (this.m_logger.isLoggable(Level.INFO)) {
                                                    this.m_logger.info("Caller match (ICaller): " + rc.toString());
                                                }
                                                return rc;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } catch (ComFailException ex) {
                        this.m_logger.warning("1 item (e.g. distribution list) was ignored on loading.");
                        if (ex.toString().indexOf("Can't get object clsid from progid") > -1) {
                            this.m_logger.log(Level.SEVERE, ex.toString(), ex);
                            PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "olstarterror", ex));
                        } else
                            this.m_logger.warning(ex.getMessage() + ", " + ex.getSource());
                    } catch (Exception ex) {
                        throw new OutlookContactProxyException("Error in Application Outlook.", ex);
                    } finally {
                        // added 2006/02/05: clean outlook references
                        if (contact != null)
                            contact.safeRelease();
                        if (items != null)
                            items.safeRelease();
                        if (contactsFolder != null)
                            contactsFolder.safeRelease();
                        if (contactsSubFolder != null)
                            contactsSubFolder.safeRelease();
                        if (mapiNS != null)
                            mapiNS.safeRelease();
                        if (outlook != null)
                            outlook.safeRelease();
                    }
                }
            } else {
                Properties config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(NAMESPACE);
                if (config.getProperty("keepextension", "false").equalsIgnoreCase("true")) {
                    // iterate down
                    String callnumber = pn.getCallNumber();
                    if (callnumber.length() > 1) {
                        pn.setCallNumber(callnumber.substring(0, callnumber.length() - 1));
                        ICaller ca = this.findContact(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 : Message(de.janrufmonitor.exception.Message) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Dispatch(com.jacob.com.Dispatch) Properties(java.util.Properties) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) SQLException(java.sql.SQLException) ComFailException(com.jacob.com.ComFailException) Variant(com.jacob.com.Variant) ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) ActiveXComponent(com.jacob.activeX.ActiveXComponent) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) UUID(de.janrufmonitor.util.uuid.UUID) ComFailException(com.jacob.com.ComFailException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 15 with IMultiPhoneCaller

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

the class GoogleContactsProxy method createContacts.

public synchronized void createContacts(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);
    }
    if (cl.size() == 0)
        return;
    ContactsService cs = login();
    ICaller caller = null;
    ContactEntry entry = null;
    for (int i = 0, j = cl.size(); i < j; i++) {
        this.m_current++;
        caller = cl.get(i);
        IAttributeMap m = caller.getAttributes();
        try {
            entry = new ContactEntry();
            Name name = new Name();
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_LASTNAME))
                name.setFamilyName(new FamilyName((m.get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue().length() == 0 ? " " : m.get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue()), null));
            else
                name.setFamilyName(new FamilyName(" ", null));
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME))
                name.setGivenName(new GivenName((m.get(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME).getValue().length() == 0 ? " " : m.get(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME).getValue()), null));
            else
                name.setGivenName(new GivenName(" ", null));
            name.setFullName(new FullName(Formatter.getInstance(getRuntime()).parse("%a:ln%, %a:fn%", m), null));
            entry.setName(name);
            entry.addStructuredPostalAddress(createPostalAddress(m));
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_EMAIL)) {
                String emails = m.get(IJAMConst.ATTRIBUTE_NAME_EMAIL).getValue();
                Email email = new Email();
                email.setAddress(emails);
                entry.addEmailAddress(email);
            }
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
                String cat = m.get(IJAMConst.ATTRIBUTE_NAME_CATEGORY).getValue();
                if (this.m_reverseCategories.containsKey(cat)) {
                    GroupMembershipInfo gmi = new GroupMembershipInfo();
                    gmi.setHref((String) this.m_reverseCategories.get(cat));
                    entry.addGroupMembershipInfo(gmi);
                }
            }
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_GEO_ACC)) {
                ExtendedProperty acc = new ExtendedProperty();
                acc.setName(IJAMConst.ATTRIBUTE_NAME_GEO_ACC);
                acc.setValue(m.get(IJAMConst.ATTRIBUTE_NAME_GEO_ACC).getValue());
                entry.addExtendedProperty(acc);
            }
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_GEO_LNG)) {
                ExtendedProperty acc = new ExtendedProperty();
                acc.setName(IJAMConst.ATTRIBUTE_NAME_GEO_LNG);
                acc.setValue(m.get(IJAMConst.ATTRIBUTE_NAME_GEO_LNG).getValue());
                entry.addExtendedProperty(acc);
            }
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_GEO_LAT)) {
                ExtendedProperty acc = new ExtendedProperty();
                acc.setName(IJAMConst.ATTRIBUTE_NAME_GEO_LAT);
                acc.setValue(m.get(IJAMConst.ATTRIBUTE_NAME_GEO_LAT).getValue());
                entry.addExtendedProperty(acc);
            }
            PhoneNumber pn = null;
            if (caller instanceof IMultiPhoneCaller) {
                List phones = ((IMultiPhoneCaller) caller).getPhonenumbers();
                IPhonenumber p = null;
                for (int k = 0, l = phones.size(); k < l; k++) {
                    p = (IPhonenumber) phones.get(k);
                    pn = new PhoneNumber();
                    pn.setPrimary(k == 0);
                    IAttribute type = m.get(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + p.getTelephoneNumber());
                    if (type != null && type.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE)) {
                        pn.setRel(PhoneNumber.Rel.MOBILE);
                    } else if (type != null && type.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE)) {
                        pn.setRel(PhoneNumber.Rel.HOME_FAX);
                    } else {
                        pn.setRel(PhoneNumber.Rel.HOME);
                    }
                    pn.setPhoneNumber(Formatter.getInstance(getRuntime()).parse(IJAMConst.GLOBAL_VARIABLE_CALLERNUMBER, p));
                    entry.addPhoneNumber(pn);
                }
            } else {
                pn = new PhoneNumber();
                IAttribute type = m.get(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + caller.getPhoneNumber().getTelephoneNumber());
                if (type != null && type.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE)) {
                    pn.setRel(PhoneNumber.Rel.MOBILE);
                } else if (type != null && type.getValue().equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE)) {
                    pn.setRel(PhoneNumber.Rel.HOME_FAX);
                } else {
                    pn.setRel(PhoneNumber.Rel.HOME);
                }
                pn.setPhoneNumber(Formatter.getInstance(getRuntime()).parse(IJAMConst.GLOBAL_VARIABLE_CALLERNUMBER, caller.getPhoneNumber()));
                entry.addPhoneNumber(pn);
            }
            URL postUrl = new URL("https://www.google.com/m8/feeds/contacts/" + getLoginUser() + "/full");
            entry = (ContactEntry) cs.insert(postUrl, entry);
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH)) {
                String file = PathResolver.getInstance(getRuntime()).resolve(m.get(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH).getValue());
                if (new File(file).exists()) {
                    FileInputStream in = new FileInputStream(file);
                    Link photoLink = entry.getContactPhotoLink();
                    URL photoUrl = new URL(photoLink.getHref());
                    GDataRequest request = cs.createRequest(GDataRequest.RequestType.UPDATE, photoUrl, new ContentType("image/jpeg"));
                    Stream.copy(in, request.getRequestStream());
                    request.execute();
                }
            }
            if (entry != null && this.m_dbh != null) {
                try {
                    if (caller instanceof IMultiPhoneCaller) {
                        List phones = ((IMultiPhoneCaller) caller).getPhonenumbers();
                        IPhonenumber p = null;
                        for (int k = 0; k < phones.size(); k++) {
                            p = (IPhonenumber) phones.get(k);
                            this.m_dbh.insert(caller.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.getCallNumber());
                        }
                    } else {
                        IPhonenumber p = caller.getPhoneNumber();
                        this.m_dbh.insert(caller.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.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...");
            }
        } 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 : MalformedURLException(java.net.MalformedURLException) Email(com.google.gdata.data.extensions.Email) ContentType(com.google.gdata.util.ContentType) FamilyName(com.google.gdata.data.extensions.FamilyName) SQLException(java.sql.SQLException) GivenName(com.google.gdata.data.extensions.GivenName) GDataRequest(com.google.gdata.client.Service.GDataRequest) URL(java.net.URL) FamilyName(com.google.gdata.data.extensions.FamilyName) Name(com.google.gdata.data.extensions.Name) GivenName(com.google.gdata.data.extensions.GivenName) FullName(com.google.gdata.data.extensions.FullName) ContactsService(com.google.gdata.client.contacts.ContactsService) ContactEntry(com.google.gdata.data.contacts.ContactEntry) GroupMembershipInfo(com.google.gdata.data.contacts.GroupMembershipInfo) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) List(java.util.List) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) IOException(java.io.IOException) ExtendedProperty(com.google.gdata.data.extensions.ExtendedProperty) FileInputStream(java.io.FileInputStream) ICaller(de.janrufmonitor.framework.ICaller) ServiceException(com.google.gdata.util.ServiceException) FullName(com.google.gdata.data.extensions.FullName) IAttribute(de.janrufmonitor.framework.IAttribute) PhoneNumber(com.google.gdata.data.extensions.PhoneNumber) File(java.io.File) Link(com.google.gdata.data.Link) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)32 ICaller (de.janrufmonitor.framework.ICaller)25 ICallerList (de.janrufmonitor.framework.ICallerList)25 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)25 List (java.util.List)25 ArrayList (java.util.ArrayList)20 SQLException (java.sql.SQLException)15 IAttribute (de.janrufmonitor.framework.IAttribute)14 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)8 IOException (java.io.IOException)8 UUID (de.janrufmonitor.util.uuid.UUID)6 File (java.io.File)5 Properties (java.util.Properties)5 ContactsService (com.google.gdata.client.contacts.ContactsService)4 ContactEntry (com.google.gdata.data.contacts.ContactEntry)4 ServiceException (com.google.gdata.util.ServiceException)4 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 Iterator (java.util.Iterator)4 ComFailException (com.jacob.com.ComFailException)3