use of de.janrufmonitor.framework.ICallerList 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;
}
use of de.janrufmonitor.framework.ICallerList 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;
}
use of de.janrufmonitor.framework.ICallerList 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;
}
use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class OutlookTransformer method getCallerListFromAllContacts.
public ICallerList getCallerListFromAllContacts() {
PropagationFactory.getInstance().fire(new Message(Message.INFO, OutlookContactManager.NAMESPACE, "sync", new Exception("Sync contact folder with MS Outlook...")));
ICallerList callers = getRuntime().getCallerFactory().createCallerList();
long outlookItemsCount = 0;
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(getConfiguredContactFolders());
String folder = null;
for (int i = 0, j = subfolders.size(); i < j; i++) {
folder = (String) subfolders.get(i);
if (folder.trim().length() == 0) {
items = Dispatch.get(contactsFolder, "Items").toDispatch();
} else {
// found subfolder
try {
contactsSubFolder = Dispatch.call(contactsFolder, "Folders", new Variant(folder)).toDispatch();
items = Dispatch.get(contactsSubFolder, "Items").toDispatch();
} catch (ComFailException ex) {
continue;
}
}
// items = Dispatch.get(contactsFolder, "Items").toDispatch();
Variant item = Dispatch.call(items, "GetFirst");
ICallerList cl = null;
while ((item != null) && (!item.isNull())) {
try {
outlookItemsCount++;
Dispatch contact = item.toDispatch();
cl = getCallerListFromSingleContact(contact);
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 (contact != null)
contact.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());
}
if (item != null)
item.safeRelease();
item = Dispatch.call(items, "GetNext");
}
}
} 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();
}
this.m_logger.info(outlookItemsCount + " Outlook contacts found and " + callers.size() + " numbers available.");
return callers;
}
use of de.janrufmonitor.framework.ICallerList in project janrufmonitor by tbrandt77.
the class OutlookContactManager method startup.
public void startup() {
super.startup();
if (m_logger.isLoggable(Level.INFO))
m_logger.info("<" + getID() + "> configuration: " + this.m_configuration);
if (this.isActive()) {
this.m_isUUIDCheck = true;
Thread t = new Thread() {
public void run() {
int mode = Integer.parseInt(m_configuration.getProperty(CFG_MODE, "0"));
// 2010-02-05: introduced for identification only use case
if (m_logger.isLoggable(Level.INFO))
m_logger.info("<" + getID() + "> is set to mode: " + mode);
if (mode == 1) {
while (m_isUUIDCheck) {
try {
ICallerList c = getProxy().getContacts(null);
if (m_logger.isLoggable(Level.INFO) && c.size() > 0)
m_logger.info("Found " + c.size() + " outlook contacts to be synced.");
} catch (OutlookContactProxyException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
}
try {
Thread.sleep(getIndexingInterval());
} catch (InterruptedException e) {
}
}
} else {
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Re-indexing interval for outlook contacts set to " + getIndexingInterval() + " ms.");
long t = Long.parseLong(m_configuration.getProperty(CFG_TS, "0"));
try {
Thread.sleep(getIndexingInterval());
} catch (InterruptedException e) {
}
while (m_isUUIDCheck) {
try {
ICallerList c = getProxy().getModifiedContacts(t);
if (m_logger.isLoggable(Level.INFO) && c.size() > 0)
m_logger.info("Found " + c.size() + " modified outlook contacts to be synced.");
} catch (OutlookContactProxyException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
}
try {
Thread.sleep(getIndexingInterval());
} catch (InterruptedException e) {
}
t = System.currentTimeMillis();
getRuntime().getConfigManagerFactory().getConfigManager().setProperty(getNamespace(), CFG_TS, Long.toString(t));
getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
m_configuration.setProperty(CFG_TS, Long.toString(t));
}
}
}
};
t.setName("JAM-OutlookSync-Thread-(deamon)");
t.setDaemon(true);
t.start();
if (m_logger.isLoggable(Level.INFO))
m_logger.info("JAM-OutlookSync-Thread-(deamon) started.");
}
}
Aggregations