Search in sources :

Example 1 with ComFailException

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

the class OutlookMappingManager method setPictureAttribute.

@SuppressWarnings("deprecation")
private void setPictureAttribute(ICaller outlookCaller, Dispatch contact) {
    try {
        if (Dispatch.get(contact, "HasPicture").getBoolean()) {
            String imagepath = MSO_IMAGE_CACHE_PATH + outlookCaller.getUUID() + ".jpg";
            if (!new File(imagepath).exists()) {
                Dispatch items = Dispatch.get(contact, "Attachments").toDispatch();
                int count = Dispatch.get(items, "Count").toInt();
                if (count > 1)
                    this.m_logger.info("Found " + count + " attachments for outlook contact " + outlookCaller.toString());
                for (int i = 1; i <= count; i++) {
                    Dispatch item = Dispatch.call(items, "Item", new Integer(i)).toDispatch();
                    int type = Dispatch.get(item, "Type").toInt();
                    // type 1 olAttachmentType = olByValue
                    if (type == 1) {
                        try {
                            String outlookFilename = Dispatch.get(item, "FileName").toString();
                            if (outlookFilename != null && (outlookFilename.startsWith("ContactPicture") || outlookFilename.startsWith("ContactPhoto"))) {
                                Dispatch.call(item, "SaveAsFile", new String(imagepath));
                            }
                        } catch (ComFailException ex) {
                            this.m_logger.warning("Could not get FileName attribute: " + ex.getMessage() + ", " + ex.getSource());
                        }
                    }
                    if (item != null)
                        item.safeRelease();
                }
                if (items != null)
                    items.safeRelease();
            }
            IAttribute img = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance().encode(imagepath));
            outlookCaller.setAttribute(img);
        }
    } catch (ComFailException ex) {
        this.m_logger.warning(ex.getMessage() + ", " + ex.getSource());
    }
}
Also used : IAttribute(de.janrufmonitor.framework.IAttribute) Dispatch(com.jacob.com.Dispatch) File(java.io.File) ComFailException(com.jacob.com.ComFailException)

Example 2 with ComFailException

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

the class OutlookMappingManager method mapToOutlookCaller.

public void mapToOutlookCaller(Dispatch oCaller, ICaller jamCaller, IOutlookMapping om) {
    if (this.m_logger.isLoggable(Level.INFO)) {
        this.m_logger.info("Appliing mapping: " + om.toString());
    }
    // clear all supported fields in outlook
    List outlookContacFieldMappings = om.getSupportedContactFields();
    String field = null;
    for (int i = 0, j = outlookContacFieldMappings.size(); i < j; i++) {
        field = (String) outlookContacFieldMappings.get(i);
        Dispatch.put(oCaller, field, "");
    }
    // clear all supported numbers in outlook
    List outlookNumberMappings = om.getSupportedNumbers();
    String numbertype = null;
    for (int i = 0, j = outlookNumberMappings.size(); i < j; i++) {
        numbertype = (String) outlookNumberMappings.get(i);
        Dispatch.put(oCaller, numbertype, "");
    }
    // set address data
    Dispatch.put(oCaller, OutlookContactConst.User1, jamCaller.getUUID());
    Dispatch.put(oCaller, OutlookContactConst.User2, jamCaller.getPhoneNumber().getIntAreaCode() + jamCaller.getPhoneNumber().getAreaCode());
    String jamField = null;
    IAttribute a = null;
    for (int i = 0, j = outlookContacFieldMappings.size(); i < j; i++) {
        field = (String) outlookContacFieldMappings.get(i);
        jamField = om.mapToJamField(field);
        if (jamField != null) {
            a = jamCaller.getAttribute(jamField);
            if (a != null) {
                // TODO: 2008/08/13 - Hack for street no
                if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_STREET)) {
                    if (jamCaller.getAttributes().contains((IJAMConst.ATTRIBUTE_NAME_STREET_NO))) {
                        Dispatch.put(oCaller, field, a.getValue() + " " + jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_STREET_NO).getValue());
                    } else {
                        Dispatch.put(oCaller, field, a.getValue());
                    }
                } else if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_GEO_ACC) || a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_GEO_LNG) || a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_GEO_LAT)) {
                    StringBuffer geodata = new StringBuffer();
                    geodata.append(jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_ACC).getValue());
                    geodata.append(",");
                    geodata.append(jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG).getValue());
                    geodata.append(",");
                    geodata.append(jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT).getValue());
                    Dispatch.put(oCaller, field, geodata.toString());
                } else {
                    Dispatch.put(oCaller, field, a.getValue());
                }
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("Setting attribute: " + a.toString());
                }
            }
        }
    }
    // set phone numbers
    if (jamCaller instanceof IMultiPhoneCaller) {
        List pns = ((IMultiPhoneCaller) jamCaller).getPhonenumbers();
        IPhonenumber pn = null;
        IAttributeMap m = jamCaller.getAttributes();
        for (int k = 0; k < pns.size(); k++) {
            pn = (IPhonenumber) pns.get(k);
            this.setContactPhone(oCaller, pn, m, om);
        }
    } else {
        this.setContactPhone(oCaller, jamCaller.getPhoneNumber(), jamCaller.getAttributes(), om);
    }
    Dispatch.call(oCaller, "RemovePicture");
    if (this.getAttribute(jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH)).length() > 0) {
        try {
            Dispatch.call(oCaller, "AddPicture", PathResolver.getInstance().resolve(this.getAttribute(jamCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH))));
        } catch (ComFailException e) {
            this.m_logger.log(Level.WARNING, e.getMessage(), e);
        }
    }
    Dispatch.call(oCaller, "Save");
}
Also used : IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) List(java.util.List) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) ComFailException(com.jacob.com.ComFailException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 3 with ComFailException

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

Example 4 with ComFailException

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

the class OutlookContactProxy 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")) {
            ICaller privateCaller = createPrivateCaller(contact);
            ICaller businessCaller = createBusinessCaller(contact);
            if (privateCaller == null && businessCaller != null) {
                callers.add(businessCaller);
            }
            if (privateCaller != null && businessCaller == null) {
                callers.add(privateCaller);
            }
            if (privateCaller != null && businessCaller != null) {
                if (((IMultiPhoneCaller) businessCaller).getPhonenumbers().size() == 1) {
                    // only one entry available
                    IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) businessCaller).getPhonenumbers().get(0);
                    IAttribute numbertype = businessCaller.getAttribute(IOutlookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
                    if (numbertype != null && numbertype.getValue().equalsIgnoreCase(OutlookContactConst.MobileTelephoneNumber)) {
                        this.m_logger.info("Bussiness caller will be dropped. Only mobile number available, but still in private contact: " + businessCaller);
                        businessCaller = null;
                    }
                }
                if (((IMultiPhoneCaller) privateCaller).getPhonenumbers().size() == 1 && businessCaller != null) {
                    // only one entry available
                    IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) privateCaller).getPhonenumbers().get(0);
                    IAttribute numbertype = privateCaller.getAttribute(IOutlookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
                    if (numbertype != null && numbertype.getValue().equalsIgnoreCase(OutlookContactConst.MobileTelephoneNumber)) {
                        this.m_logger.info("Private caller will be dropped. Only mobile number available, but still in business contact: " + privateCaller);
                        privateCaller = null;
                    }
                }
                if (privateCaller != null) {
                    callers.add(privateCaller);
                }
                if (businessCaller != null) {
                    callers.add(businessCaller);
                }
            }
        } else {
            ICaller c = OutlookMappingManager.getInstance().mapToJamCaller(contact, new DefaultOutlookMapping());
            if (c != null)
                callers.add(c);
        }
        updateProxyDatabase(callers);
    } 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) DefaultOutlookMapping(de.janrufmonitor.repository.mapping.DefaultOutlookMapping) ICallerList(de.janrufmonitor.framework.ICallerList) Message(de.janrufmonitor.exception.Message) IAttribute(de.janrufmonitor.framework.IAttribute) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) Properties(java.util.Properties) ComFailException(com.jacob.com.ComFailException) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) SQLException(java.sql.SQLException) ComFailException(com.jacob.com.ComFailException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 5 with ComFailException

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

the class OutlookContactProxy method updateContact.

public synchronized boolean updateContact(ICaller c) throws OutlookContactProxyException {
    boolean processed = false;
    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 = this.getAttribute(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY));
        items = this.getItemsOfFolder(contactsFolder, folder, true);
        if (items == null)
            throw new OutlookContactProxyException("Error in Application Outlook. Folder <" + folder + "> could not be created");
        Dispatch oldContact = this.findContactByUUID(items, c.getUUID());
        if (oldContact != null) {
            processed = true;
            boolean business = (c.getAttribute("outlook.business") != null && c.getAttribute("outlook.business").getValue().equalsIgnoreCase("true") ? true : false);
            this.setContactData(oldContact, c, business);
            this.clearPicture(c);
            if (this.m_logger.isLoggable(Level.INFO)) {
                this.m_logger.info("Updating outlook contact in folder " + (folder.length() > 0 ? folder : "<root>") + ": " + c);
            }
        } else {
            // contact does not exist in this folder maybe somewhere other...
            List subfolders = new ArrayList();
            subfolders.add("");
            subfolders.addAll(getAllContactFolders());
            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;
                oldContact = this.findContactByUUID(items, c.getUUID());
                if (oldContact != null) {
                    processed = true;
                    boolean business = (c.getAttribute("outlook.business") != null && c.getAttribute("outlook.business").getValue().equalsIgnoreCase("true") ? true : false);
                    this.setContactData(oldContact, c, business);
                    this.moveContactToFolder(oldContact, contactsFolder, this.getAttribute(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY)));
                    if (this.m_logger.isLoggable(Level.INFO)) {
                        this.m_logger.info("Updated outlook contact in folder " + (folder.length() > 0 ? folder : "<root>") + " and moved to folder " + this.getAttribute(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) + ": " + c);
                    }
                    break;
                }
            }
            if (!processed) {
                // try to find upon creation and modification date
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("An outlook contact in folder " + (folder.length() > 0 ? folder : "<root>") + " could not be found: " + c);
                }
                String[] name = c.getUUID().split("_");
                if (name != null && name.length > 1) {
                    folder = null;
                    processed = false;
                    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;
                        oldContact = this.findContactByName(items, name[1], name[0]);
                        if (oldContact != null) {
                            processed = true;
                            boolean business = (c.getAttribute("outlook.business") != null && c.getAttribute("outlook.business").getValue().equalsIgnoreCase("true") ? true : false);
                            this.setContactData(oldContact, c, business);
                            this.moveContactToFolder(oldContact, contactsFolder, this.getAttribute(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY)));
                            if (this.m_logger.isLoggable(Level.INFO)) {
                                this.m_logger.info("Updated outlook contact in folder " + (folder.length() > 0 ? folder : "<root>") + " and moved to folder " + this.getAttribute(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) + " after UUID search: " + c);
                            }
                            break;
                        }
                    }
                    if (!processed) {
                        this.m_logger.warning("Contact " + c.toString() + " not found in Outlook contact list by creation and modified date. Contact is not updated.");
                    }
                } else
                    this.m_logger.warning("Contact " + c.toString() + " not found in Outlook contact list. Contact is not updated.");
            }
        }
        if (oldContact != null)
            oldContact.safeRelease();
    } catch (ComFailException ex) {
        throw new OutlookContactProxyException("Error in Application Outlook.", ex);
    } catch (Exception ex) {
        throw new OutlookContactProxyException("Error in Application Outlook.", ex);
    } finally {
        if (this.m_dbh != null) {
            try {
                this.m_dbh.delete(c.getUUID());
            } catch (SQLException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
        // 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 processed;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Dispatch(com.jacob.com.Dispatch) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) SQLException(java.sql.SQLException) ComFailException(com.jacob.com.ComFailException) Variant(com.jacob.com.Variant) ActiveXComponent(com.jacob.activeX.ActiveXComponent) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) 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