Search in sources :

Example 61 with IAttribute

use of de.janrufmonitor.framework.IAttribute 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 62 with IAttribute

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

the class GoogleContactsProxy method parseNumberType.

private IAttribute parseNumberType(IPhonenumber pn, PhoneNumber p) {
    IAttribute nt = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE);
    String rel = p.getRel();
    if (rel != null && rel.endsWith("mobile")) {
        nt.setValue(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE);
    }
    if (rel != null && rel.endsWith("fax")) {
        nt.setValue(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE);
    }
    return nt;
}
Also used : IAttribute(de.janrufmonitor.framework.IAttribute)

Example 63 with IAttribute

use of de.janrufmonitor.framework.IAttribute 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 64 with IAttribute

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

the class GoogleMapsLocalize 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 = ((ICall) o).getCaller();
            }
            if (o instanceof ICaller) {
                // check if maps.google.com service is enabled
                IService googlemap = getRuntime().getServiceFactory().getService(Maps.ID);
                if (googlemap != null && googlemap.isEnabled()) {
                    Properties configuration = getRuntime().getConfigManagerFactory().getConfigManager().getProperties(Maps.NAMESPACE);
                    String url = configuration.getProperty("url");
                    if (url == null || url.trim().length() == 0) {
                        MessageDialog.openError(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "nourl", "label", this.getLanguage()), this.getI18nManager().getString(this.getNamespace(), "nourl", "description", this.getLanguage()));
                        return;
                    }
                    IAttribute postalCode = ((ICaller) o).getAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY);
                    if (postalCode == null || postalCode.getValue().trim().length() == 0) {
                        MessageDialog.openError(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "less", "label", this.getLanguage()), this.getI18nManager().getString(this.getNamespace(), "less", "description", this.getLanguage()));
                        return;
                    }
                    IAttribute city = ((ICaller) o).getAttribute(IJAMConst.ATTRIBUTE_NAME_CITY);
                    if (city == null || city.getValue().trim().length() == 0) {
                        MessageDialog.openError(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "less", "label", this.getLanguage()), this.getI18nManager().getString(this.getNamespace(), "less", "description", this.getLanguage()));
                        return;
                    }
                    StringBuffer googlemapUrl = new StringBuffer();
                    googlemapUrl.append(url);
                    googlemapUrl.append(buildRequestParameters((ICaller) o));
                    this.m_logger.info("Requesting maps.google.com URL: " + googlemapUrl.toString());
                    Program.launch(googlemapUrl.toString());
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) ICall(de.janrufmonitor.framework.ICall) IAttribute(de.janrufmonitor.framework.IAttribute) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Properties(java.util.Properties) IService(de.janrufmonitor.service.IService)

Example 65 with IAttribute

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

the class Map method renderAsImage.

public Image renderAsImage() {
    if (this.m_o != null) {
        if (this.m_o instanceof ICall) {
            this.m_o = ((ICall) this.m_o).getCaller();
        }
        if (this.m_o instanceof ICaller) {
            IAttribute lng = ((ICaller) this.m_o).getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG);
            IAttribute lat = ((ICaller) this.m_o).getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT);
            if (lng != null && lat != null) {
                String maptype = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty("service.GoogleMaps", "type");
                String zoom = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty("service.GoogleMaps", "zoom");
                try {
                    File dir = new File(PathResolver.getInstance(PIMRuntime.getInstance()).getPhotoDirectory() + File.separator + "maps" + File.separator);
                    if (!dir.exists())
                        dir.mkdirs();
                    File img = new File(dir, lat.getValue() + lng.getValue() + maptype + zoom);
                    if (!img.exists()) {
                        URL url = new URL("http://maps.googleapis.com/maps/api/staticmap?center=" + lat.getValue() + "," + lng.getValue() + "&zoom=" + zoom + "&size=400x90&maptype=" + maptype + "&sensor=false&markers=color:blue%7Clabel:A%7C" + lat.getValue() + "," + lng.getValue());
                        URLConnection c = url.openConnection();
                        c.setDoInput(true);
                        c.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE; Windows NT)");
                        c.connect();
                        Object o = url.openStream();
                        if (o instanceof InputStream) {
                            BufferedInputStream bin = new BufferedInputStream((InputStream) o);
                            FileOutputStream fos = new FileOutputStream(img);
                            Stream.copy(bin, fos, true);
                            return new Image(DisplayManager.getDefaultDisplay(), img.getAbsolutePath());
                        }
                        return null;
                    }
                    return new Image(DisplayManager.getDefaultDisplay(), img.getAbsolutePath());
                } catch (MalformedURLException e) {
                } catch (IOException e) {
                }
            }
        }
    }
    return null;
}
Also used : MalformedURLException(java.net.MalformedURLException) ICall(de.janrufmonitor.framework.ICall) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL) URLConnection(java.net.URLConnection) ICaller(de.janrufmonitor.framework.ICaller) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) IAttribute(de.janrufmonitor.framework.IAttribute) File(java.io.File)

Aggregations

IAttribute (de.janrufmonitor.framework.IAttribute)111 ICaller (de.janrufmonitor.framework.ICaller)44 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)40 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)39 List (java.util.List)34 ICallerList (de.janrufmonitor.framework.ICallerList)31 ArrayList (java.util.ArrayList)29 Iterator (java.util.Iterator)25 ICall (de.janrufmonitor.framework.ICall)19 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)15 SQLException (java.sql.SQLException)15 File (java.io.File)14 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)12 IOException (java.io.IOException)12 Message (de.janrufmonitor.exception.Message)11 ComFailException (com.jacob.com.ComFailException)10 Date (java.util.Date)10 IMsn (de.janrufmonitor.framework.IMsn)9 Dispatch (com.jacob.com.Dispatch)8 UUID (de.janrufmonitor.util.uuid.UUID)8