use of com.jacob.com.Variant in project janrufmonitor by tbrandt77.
the class OutlookContactProxy method countContactsByUUID.
private int countContactsByUUID(Dispatch items, String uuid) {
int count = 0;
Dispatch aContact = Dispatch.call(items, "Find", new Variant("[User1]='" + uuid + "'")).toDispatch();
if (aContact != null && aContact.m_pDispatch > 0) {
do {
count++;
aContact = Dispatch.call(items, "FindNext").toDispatch();
} while (aContact != null && aContact.m_pDispatch > 0);
}
return count;
}
use of com.jacob.com.Variant 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;
}
use of com.jacob.com.Variant 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;
}
use of com.jacob.com.Variant 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();
}
}
use of com.jacob.com.Variant 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;
}
Aggregations