Search in sources :

Example 31 with ICallerList

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

the class VcfFileCallerImporter method doImport.

public ICallerList doImport() {
    ICallerList cl = PIMRuntime.getInstance().getCallerFactory().createCallerList();
    ;
    m_vcf = new VcfParser30(m_filename);
    try {
        cl = m_vcf.parse();
    } catch (VcfParserException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    return cl;
}
Also used : ICallerList(de.janrufmonitor.framework.ICallerList)

Example 32 with ICallerList

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

the class CsvCallerImporter method doImport.

public ICallerList doImport() {
    this.m_current = 0;
    this.m_total = 0;
    ICallerList cl = PIMRuntime.getInstance().getCallerFactory().createCallerList();
    this.m_logger.info("Start reading CSV file " + this.m_filename);
    File csv = new File(this.m_filename);
    if (csv == null || !csv.exists() || !csv.isFile())
        return cl;
    List contacts = new ArrayList();
    List attributes = new ArrayList();
    try {
        InputStreamReader inr = new InputStreamReader(new FileInputStream(csv));
        BufferedReader bufReader = new BufferedReader(inr);
        String line = null;
        String[] tokens = null;
        while (bufReader.ready()) {
            line = bufReader.readLine();
            // ignore comments
            if (line.trim().startsWith("#"))
                continue;
            tokens = line.split(";");
            if (attributes.size() == 0) {
                attributes.addAll(Arrays.asList(tokens));
                continue;
            }
            contacts.add(tokens);
        }
        bufReader.close();
        inr.close();
        this.m_total = contacts.size();
        for (int i = 0; i < this.m_total; i++) {
            this.m_current++;
            tokens = (String[]) contacts.get(i);
            if (tokens.length == attributes.size()) {
                List phones = new ArrayList();
                IAttributeMap m = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
                String attributename = null;
                for (int j = 0; j < tokens.length; j++) {
                    attributename = (String) attributes.get(j);
                    if (attributename.trim().toLowerCase().startsWith("pn:")) {
                        IPhonenumber pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toIdentifiedPhonenumber(tokens[j]);
                        if (pn != null) {
                            phones.add(pn);
                            if (attributename.endsWith(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE))
                                m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE));
                            if (attributename.endsWith(IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE))
                                m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE));
                            if (attributename.endsWith(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE))
                                m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE));
                        }
                    } else {
                        if (tokens[j].trim().length() > 0) {
                            m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(attributename, tokens[j]));
                            if (attributename.equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_IMAGEURL)) {
                                String img = getImageFromURL(tokens[j]);
                                if (img != null) {
                                    m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, img));
                                }
                            }
                        }
                    }
                }
                if (phones.size() == 0) {
                    this.m_logger.warning("No phone numbers found. Can't parse CSV contact: " + Arrays.asList(tokens));
                    continue;
                }
                if (!m.contains(IJAMConst.ATTRIBUTE_NAME_LASTNAME)) {
                    this.m_logger.warning("No LASTANME (ln) attribute found. Can't parse CSV contact: " + Arrays.asList(tokens));
                    continue;
                }
                cl.add(PIMRuntime.getInstance().getCallerFactory().createCaller(null, phones, m));
            } else {
                this.m_logger.warning("Invalid token length. Can't parse CSV contact data: " + Arrays.asList(tokens));
            }
        }
    } catch (FileNotFoundException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (IOException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    return cl;
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ICallerList(de.janrufmonitor.framework.ICallerList) BufferedReader(java.io.BufferedReader) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) File(java.io.File) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 33 with ICallerList

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

the class QuickRejectAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null && v instanceof Viewer) {
        final IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            Iterator i = selection.iterator();
            ICallerList list = this.getRuntime().getCallerFactory().createCallerList(selection.size());
            Object o = null;
            while (i.hasNext()) {
                o = i.next();
                if (o instanceof ICaller) {
                    if (this.isRejectable(((ICaller) o))) {
                        ((ICaller) o).setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_REJECT, IJAMConst.ATTRIBUTE_VALUE_NO));
                    } else
                        ((ICaller) o).setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_REJECT, IJAMConst.ATTRIBUTE_VALUE_YES));
                    list.add((ICaller) o);
                }
            }
            if (list.size() > 0) {
                this.m_app.getController().deleteElements(list);
                this.m_app.getController().addElements(list);
            }
            m_app.updateViews(true);
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) Iterator(java.util.Iterator) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 34 with ICallerList

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

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

the class OutlookContactProxy method getModifiedContacts.

public synchronized ICallerList getModifiedContacts(long timestamp) throws OutlookContactProxyException {
    ICallerList callers = getRuntime().getCallerFactory().createCallerList();
    ActiveXComponent outlook = new ActiveXComponent("Outlook.Application");
    Dispatch mapiNS = null;
    Dispatch contactsFolder = null;
    Dispatch contactsSubFolder = null;
    Dispatch items = 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;
            if (this.countContactsByLastModificationTime(items, timestamp) > 0) {
                Date d = new Date(timestamp);
                SimpleDateFormat sfd = new SimpleDateFormat("MM/dd/yyyy h:mm a");
                Dispatch aContact = Dispatch.call(items, "Find", new Variant("[LastModificationTime] >= '" + sfd.format(d) + "'")).toDispatch();
                if (aContact != null && aContact.m_pDispatch > 0) {
                    do {
                        // check UUID in User1 attribute
                        this.checkContactUUID(aContact);
                        ICallerList cl = getCallerListFromSingleContact(aContact);
                        if (cl.size() > 0) {
                            if (folder.trim().length() > 0) {
                                IAttribute category = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, folder);
                                for (int l = 0, m = cl.size(); l < m; l++) {
                                    cl.get(l).setAttribute(category);
                                }
                            }
                            callers.add(cl);
                        }
                        if (aContact != null)
                            aContact.safeRelease();
                        aContact = Dispatch.call(items, "FindNext").toDispatch();
                    } while (aContact != null && aContact.m_pDispatch > 0);
                }
            }
        }
    } 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 (items != null)
            items.safeRelease();
        if (contactsFolder != null)
            contactsFolder.safeRelease();
        if (contactsSubFolder != null)
            contactsSubFolder.safeRelease();
        if (mapiNS != null)
            mapiNS.safeRelease();
        if (outlook != null)
            outlook.safeRelease();
    }
    return callers;
}
Also used : Message(de.janrufmonitor.exception.Message) ArrayList(java.util.ArrayList) Dispatch(com.jacob.com.Dispatch) Date(java.util.Date) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) SQLException(java.sql.SQLException) ComFailException(com.jacob.com.ComFailException) Variant(com.jacob.com.Variant) 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) SimpleDateFormat(java.text.SimpleDateFormat) ComFailException(com.jacob.com.ComFailException)

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