Search in sources :

Example 41 with ICallerList

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

the class OutlookImportAction method run.

public void run() {
    String filter = this.m_app.getApplication().getConfiguration().getProperty("filter", "");
    EditorFilterManager efm = new EditorFilterManager();
    final IAttribute category = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, "");
    if (filter.length() > 0) {
        String cat = null;
        IFilter[] filters = efm.getFiltersFromString(filter);
        for (int z = 0; z < filters.length; z++) {
            if (filters[z].getType().equals(FilterType.ATTRIBUTE)) {
                AttributeFilter cf = ((AttributeFilter) filters[z]);
                IAttributeMap m = cf.getAttributeMap();
                if (m != null && m.size() > 0) {
                    Iterator it = m.iterator();
                    IAttribute a = null;
                    while (it.hasNext()) {
                        a = (IAttribute) it.next();
                        if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
                            cat = a.getValue();
                        }
                    }
                }
            }
        }
        if (cat != null) {
            int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
            MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
            String text = this.getI18nManager().getString("ui.jface.application.editor.action.ImportAction", "assigncategoryconfirm", "label", this.getLanguage());
            text = StringUtils.replaceString(text, "{%1}", cat);
            messageBox.setMessage(text);
            if (messageBox.open() == SWT.YES) {
                category.setValue(cat);
            }
        }
    }
    // determine subfolders
    OutlookTransformer ot = new OutlookTransformer();
    List folders = ot.getAllContactFolders();
    if (folders.size() > 0) {
        int itemCount = 0;
        String folder = null;
        for (int i = 0, j = folders.size(); i < j; i++) {
            folder = (String) folders.get(i);
            itemCount = ot.getContactCount(folder);
            if (itemCount > 0) {
                getRuntime().getConfigManagerFactory().getConfigManager().setProperty(OutlookContactManager.NAMESPACE, "subfolder_" + folder, "true");
            }
        }
        getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
    }
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
    try {
        IRunnableWithProgress r = new IRunnableWithProgress() {

            public void run(IProgressMonitor progressMonitor) {
                progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "importprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                progressMonitor.worked(1);
                OutlookTransformer otf = new OutlookTransformer();
                ICallerList callers = otf.getCallerListFromAllContacts();
                progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "reduce", "label", getLanguage()));
                otf.removeCallerManagerID(callers);
                // determine duplicates
                String currentCallerManagerID = m_app.getApplication().getConfiguration().getProperty(CFG_REPOSITORY);
                if (currentCallerManagerID != null && currentCallerManagerID.trim().length() > 0) {
                    ICallerManager currentCallerManager = getRuntime().getCallerManagerFactory().getCallerManager(currentCallerManagerID);
                    if (currentCallerManager != null && currentCallerManager.isSupported(IWriteCallerRepository.class) && currentCallerManager.isSupported(IIdentifyCallerRepository.class)) {
                        ICallerList addCallers = getRuntime().getCallerFactory().createCallerList();
                        // ICallerList removeCallers = getRuntime().getCallerFactory().createCallerList();
                        ICaller currentCaller = null;
                        String text = null;
                        for (int i = 0, j = callers.size(); i < j; i++) {
                            // ICaller testCaller = null;
                            currentCaller = callers.get(i);
                            text = getI18nManager().getString(getNamespace(), "check", "label", getLanguage());
                            text = StringUtils.replaceString(text, "{%1}", Formatter.getInstance(getRuntime()).parse("%a:ln%, %a:fn%", currentCaller));
                            progressMonitor.setTaskName(text);
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException e1) {
                            }
                            try {
                                // testCaller = ((IIdentifyCallerRepository)currentCallerManager).getCaller(currentCaller.getPhoneNumber());
                                ((IIdentifyCallerRepository) currentCallerManager).getCaller(currentCaller.getPhoneNumber());
                            } catch (CallerNotFoundException e) {
                                if (category != null && category.getValue().length() > 0)
                                    currentCaller.setAttribute(category);
                                addCallers.add(currentCaller);
                            }
                        // if (testCaller!=null) {
                        // removeCallers.add(testCaller);
                        // }
                        }
                        progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "add", "label", getLanguage()));
                        try {
                            Thread.sleep(1250);
                        } catch (InterruptedException e1) {
                        }
                        // if (removeCallers.size()>0)
                        // m_app.getController().deleteElements(removeCallers);
                        m_app.getController().addElements(addCallers);
                    }
                } else {
                    progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "add", "label", getLanguage()));
                    m_app.getController().addElements(callers);
                }
                progressMonitor.done();
            }
        };
        pmd.setBlockOnOpen(false);
        pmd.run(true, false, r);
    // ModalContext.run(r, true, pmd.getProgressMonitor(), DisplayManager.getDefaultDisplay());
    } catch (InterruptedException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (InvocationTargetException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    m_app.updateViews(true);
    return;
}
Also used : EditorFilterManager(de.janrufmonitor.ui.jface.application.editor.EditorFilterManager) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) OutlookTransformer(de.janrufmonitor.repository.OutlookTransformer) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) MessageBox(org.eclipse.swt.widgets.MessageBox) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ICallerList(de.janrufmonitor.framework.ICallerList) IFilter(de.janrufmonitor.repository.filter.IFilter) IAttribute(de.janrufmonitor.framework.IAttribute) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) Iterator(java.util.Iterator) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List)

Example 42 with ICallerList

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

the class GoogleContactsCallerManager method removeCaller.

public void removeCaller(ICaller caller) {
    ICallerList cl = getRuntime().getCallerFactory().createCallerList(1);
    cl.add(caller);
    this.removeCaller(cl);
}
Also used : ICallerList(de.janrufmonitor.framework.ICallerList)

Example 43 with ICallerList

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

Example 44 with ICallerList

use of de.janrufmonitor.framework.ICallerList 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 45 with ICallerList

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

Aggregations

ICallerList (de.janrufmonitor.framework.ICallerList)81 ICaller (de.janrufmonitor.framework.ICaller)40 List (java.util.List)36 ArrayList (java.util.ArrayList)32 IAttribute (de.janrufmonitor.framework.IAttribute)24 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)24 SQLException (java.sql.SQLException)24 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)18 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)17 IOException (java.io.IOException)15 Message (de.janrufmonitor.exception.Message)14 Iterator (java.util.Iterator)11 Map (java.util.Map)11 File (java.io.File)10 HashMap (java.util.HashMap)10 Viewer (org.eclipse.jface.viewers.Viewer)10 ICallerManager (de.janrufmonitor.repository.ICallerManager)9 ComFailException (com.jacob.com.ComFailException)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)7