Search in sources :

Example 41 with IAttributeMap

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

the class GoogleContactsProxy method updateContact.

public synchronized void updateContact(ICaller caller) throws GoogleContactsException {
    try {
        fetchCategories();
    } catch (IOException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    } catch (ServiceException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    }
    if (caller == null)
        return;
    ContactsService cs = login();
    ContactEntry entry = null;
    IAttributeMap m = caller.getAttributes();
    try {
        if (caller.getAttributes().contains("entryUrl")) {
            String entryUrl = caller.getAttribute("entryUrl").getValue();
            if (entryUrl.length() > 0) {
                entry = (ContactEntry) cs.getEntry(new URL(entryUrl), ContactEntry.class);
                if (entry == null) {
                    this.m_logger.warning("Cannot update google contact: " + caller.toString());
                    return;
                }
            } else {
                this.m_logger.warning("Invalid entryUrl parameter. Cannot update google contact: " + caller.toString());
                return;
            }
        } else {
            // no update possible, contact must be new
            if (this.m_logger.isLoggable(Level.INFO))
                this.m_logger.info("No update possible dur to missing entryUrl. Creating google contact: " + caller.toString());
            ICallerList cl = getRuntime().getCallerFactory().createCallerList();
            cl.add(caller);
            this.createContacts(cl);
            return;
        }
        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.getStructuredPostalAddresses().clear();
        entry.addStructuredPostalAddress(createPostalAddress(m));
        if (m.contains(IJAMConst.ATTRIBUTE_NAME_EMAIL)) {
            List emaillist = entry.getEmailAddresses();
            String rel = Email.Rel.HOME;
            if (emaillist.size() > 0) {
                Email eold = entry.getEmailAddresses().remove(0);
                rel = eold.getRel();
            }
            Email email = new Email();
            email.setAddress(m.get(IJAMConst.ATTRIBUTE_NAME_EMAIL).getValue());
            email.setRel(rel);
            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;
        entry.getPhoneNumbers().clear();
        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 editUrl = new URL(entry.getEditLink().getHref());
        entry = (ContactEntry) cs.update(editUrl, 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"));
                if (photoLink.getEtag() != null) {
                    request.setEtag(photoLink.getEtag());
                }
                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;
                    this.m_dbh.delete(caller.getUUID());
                    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.delete(caller.getUUID());
                    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) {
        throw new GoogleContactsException(e.getMessage(), e);
    } catch (IOException e) {
        throw new GoogleContactsException(e.getMessage(), e);
    } catch (ServiceException e) {
        throw new GoogleContactsException(e.getMessage(), 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) List(java.util.List) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) IOException(java.io.IOException) ExtendedProperty(com.google.gdata.data.extensions.ExtendedProperty) FileInputStream(java.io.FileInputStream) ICallerList(de.janrufmonitor.framework.ICallerList) 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)

Example 42 with IAttributeMap

use of de.janrufmonitor.framework.IAttributeMap 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 43 with IAttributeMap

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

the class OutlookTransformer method createPrivateAddressAttributes.

private IAttributeMap createPrivateAddressAttributes(Dispatch contact) throws ComFailException {
    IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
    IAttribute attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_CITY, Dispatch.get(contact, "HomeAddressCity").toString().trim());
    if (attribute != null)
        m.add(attribute);
    attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, Dispatch.get(contact, "HomeAddressPostalCode").toString().trim());
    if (attribute != null)
        m.add(attribute);
    attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET, Dispatch.get(contact, "HomeAddressStreet").toString().trim());
    if (attribute != null)
        m.add(attribute);
    attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, Dispatch.get(contact, "HomeAddressCountry").toString().trim());
    if (attribute != null)
        m.add(attribute);
    return m;
}
Also used : IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

Example 44 with IAttributeMap

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

Example 45 with IAttributeMap

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

the class OutlookContactManager 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.PHONENUMBER)) {
            String intarea = ((PhonenumberFilter) filter).getPhonenumber().getIntAreaCode();
            String area = ((PhonenumberFilter) filter).getPhonenumber().getAreaCode();
            return getProxy().getContactsByAreaCode(intarea + area);
        }
        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 (OutlookContactProxyException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    return getRuntime().getCallerFactory().createCallerList();
}
Also used : ICallerList(de.janrufmonitor.framework.ICallerList) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

Aggregations

IAttributeMap (de.janrufmonitor.framework.IAttributeMap)64 IAttribute (de.janrufmonitor.framework.IAttribute)37 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)36 ICaller (de.janrufmonitor.framework.ICaller)31 List (java.util.List)24 ICallerList (de.janrufmonitor.framework.ICallerList)23 ArrayList (java.util.ArrayList)21 Iterator (java.util.Iterator)17 IOException (java.io.IOException)14 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)13 Date (java.util.Date)12 IMsn (de.janrufmonitor.framework.IMsn)11 File (java.io.File)10 ICip (de.janrufmonitor.framework.ICip)8 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)8 Message (de.janrufmonitor.exception.Message)6 ICall (de.janrufmonitor.framework.ICall)6 SimpleDateFormat (java.text.SimpleDateFormat)6 StringTokenizer (java.util.StringTokenizer)6 IFilter (de.janrufmonitor.repository.filter.IFilter)5