Search in sources :

Example 6 with ComFailException

use of com.jacob.com.ComFailException in project janrufmonitor by tbrandt77.

the class OutlookContactProxy method removeContact.

public synchronized void removeContact(ICaller c) throws OutlookContactProxyException {
    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();
        String folder = null;
        List subfolders = new ArrayList();
        subfolders.add("");
        subfolders.addAll(getAllContactFolders());
        for (int i = 0; i < subfolders.size(); i++) {
            folder = (String) subfolders.get(i);
            items = this.getItemsOfFolder(contactsFolder, folder, false);
            if (items == null)
                continue;
            Dispatch aContact = this.findContactByUUID(items, c.getUUID());
            if (aContact != null) {
                if (this.countContactsByUUID(items, c.getUUID()) > 1)
                    this.m_logger.warning("More than one UUID found: " + c.getUUID());
                Dispatch.call(aContact, "Delete");
                this.clearPicture(c);
                if (this.m_dbh != null) {
                    this.m_dbh.delete(c.getUUID());
                }
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("Deleted outlook contact in folder " + (folder.length() > 0 ? folder : "<root>") + ": " + c);
                }
            }
            if (aContact != null)
                aContact.safeRelease();
        }
    } catch (ComFailException ex) {
        throw new OutlookContactProxyException("Error in Application Outlook.", ex);
    } 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();
    }
}
Also used : Variant(com.jacob.com.Variant) ActiveXComponent(com.jacob.activeX.ActiveXComponent) ArrayList(java.util.ArrayList) Dispatch(com.jacob.com.Dispatch) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) ComFailException(com.jacob.com.ComFailException) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) SQLException(java.sql.SQLException) ComFailException(com.jacob.com.ComFailException)

Example 7 with ComFailException

use of com.jacob.com.ComFailException 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 8 with ComFailException

use of com.jacob.com.ComFailException in project janrufmonitor by tbrandt77.

the class OutlookContactProxy method openContact.

public synchronized void openContact(ICaller c) throws OutlookContactProxyException {
    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;
            Dispatch contact = this.findContactByUUID(items, c.getUUID());
            if (contact != null) {
                Dispatch.call(contact, "Display");
                return;
            }
        }
        PropagationFactory.getInstance().fire(new Message(Message.INFO, OutlookContactManager.NAMESPACE, "display", new Exception("Sync contact folder with MS Outlook...")));
    } 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();
    }
}
Also used : Variant(com.jacob.com.Variant) Message(de.janrufmonitor.exception.Message) ActiveXComponent(com.jacob.activeX.ActiveXComponent) ArrayList(java.util.ArrayList) Dispatch(com.jacob.com.Dispatch) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) ComFailException(com.jacob.com.ComFailException) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) SQLException(java.sql.SQLException) ComFailException(com.jacob.com.ComFailException)

Example 9 with ComFailException

use of com.jacob.com.ComFailException in project janrufmonitor by tbrandt77.

the class OutlookTransformer method getAllContactFolders.

public List getAllContactFolders() {
    List subfolders = new ArrayList();
    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);
        // searching subfolders
        this.m_logger.info("Includig outlook contact subfolders");
        items = Dispatch.get(contactsFolder, "Folders").toDispatch();
        Variant itemf = Dispatch.call(items, "GetFirst");
        Dispatch f = null;
        while ((itemf != null) && (!itemf.isNull())) {
            f = itemf.toDispatch();
            subfolders.add(Dispatch.get(f, "Name").toString());
            itemf = Dispatch.call(items, "GetNext");
        }
        if (f != null)
            f.safeRelease();
        if (itemf != null)
            itemf.safeRelease();
        this.m_logger.info("List of including outlook contact subfolders: " + subfolders);
        contactsVariant.safeRelease();
    } 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) {
        this.m_logger.warning(ex.getMessage() + ", " + ex.toString());
    } 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 subfolders;
}
Also used : Variant(com.jacob.com.Variant) Message(de.janrufmonitor.exception.Message) ActiveXComponent(com.jacob.activeX.ActiveXComponent) ArrayList(java.util.ArrayList) Dispatch(com.jacob.com.Dispatch) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) ComFailException(com.jacob.com.ComFailException) ComFailException(com.jacob.com.ComFailException)

Example 10 with ComFailException

use of com.jacob.com.ComFailException in project janrufmonitor by tbrandt77.

the class OutlookTransformer 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")) {
            callers.add(createPrivateCallerList(contact));
            callers.add(createBusinessCallerList(contact));
        } else {
            ICaller c = null;
            ICallerList cl = createPrivateCallerList(contact);
            if (cl.size() > 0) {
                if (cl.size() > 1) {
                    c = cl.get(0);
                    for (int i = 0; i < cl.size(); i++) {
                        ((IMultiPhoneCaller) c).getPhonenumbers().addAll(((IMultiPhoneCaller) cl.get(i)).getPhonenumbers());
                    }
                } else {
                    c = cl.get(0);
                }
            }
            cl = createBusinessCallerList(contact);
            if (cl.size() > 0) {
                if (cl.size() > 1) {
                    if (c != null) {
                        for (int i = 0; i < cl.size(); i++) {
                            ((IMultiPhoneCaller) c).getPhonenumbers().addAll(((IMultiPhoneCaller) cl.get(i)).getPhonenumbers());
                        }
                    } else {
                        c = cl.get(0);
                        for (int i = 0; i < cl.size(); i++) {
                            ((IMultiPhoneCaller) c).getPhonenumbers().addAll(((IMultiPhoneCaller) cl.get(i)).getPhonenumbers());
                        }
                    }
                } else {
                    if (c != null) {
                        for (int i = 0; i < cl.size(); i++) {
                            ((IMultiPhoneCaller) c).getPhonenumbers().addAll(((IMultiPhoneCaller) cl.get(i)).getPhonenumbers());
                        }
                    } else {
                        c = cl.get(0);
                    }
                }
            }
            if (c != null)
                callers.add(c);
        }
    } 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) ICallerList(de.janrufmonitor.framework.ICallerList) Message(de.janrufmonitor.exception.Message) Properties(java.util.Properties) ComFailException(com.jacob.com.ComFailException) ComFailException(com.jacob.com.ComFailException)

Aggregations

ComFailException (com.jacob.com.ComFailException)22 Dispatch (com.jacob.com.Dispatch)19 Variant (com.jacob.com.Variant)17 ActiveXComponent (com.jacob.activeX.ActiveXComponent)16 Message (de.janrufmonitor.exception.Message)15 ICallerList (de.janrufmonitor.framework.ICallerList)15 ZipArchiveException (de.janrufmonitor.repository.zip.ZipArchiveException)14 SQLException (java.sql.SQLException)14 ArrayList (java.util.ArrayList)14 List (java.util.List)14 IAttribute (de.janrufmonitor.framework.IAttribute)10 ICaller (de.janrufmonitor.framework.ICaller)3 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)3 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)3 Properties (java.util.Properties)3 File (java.io.File)2 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)1 DefaultOutlookMapping (de.janrufmonitor.repository.mapping.DefaultOutlookMapping)1 UUID (de.janrufmonitor.util.uuid.UUID)1 SimpleDateFormat (java.text.SimpleDateFormat)1