use of de.janrufmonitor.framework.IPhonenumber 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.IPhonenumber 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.IPhonenumber in project janrufmonitor by tbrandt77.
the class FilterWizard method performFinish.
public boolean performFinish() {
if (this.m_pages[0].isPageComplete() && this.m_pages[1].isPageComplete() && this.m_pages[2].isPageComplete() && this.m_pages[3].isPageComplete() && this.m_pages[4].isPageComplete() && this.m_pages[5].isPageComplete() && this.m_pages[6].isPageComplete()) {
List filterList = new ArrayList();
IPhonenumber[] phones = ((FilterPhonesPage) this.m_pages[3]).getResult();
if (phones != null) {
filterList.addAll(this.getCallerFilters(phones));
}
Date[] dates = ((FilterDatePage) this.m_pages[2]).getResult();
if (dates != null && dates.length > 0) {
filterList.add(this.getDateFilter(dates));
}
IMsn msn = ((FilterMsnPage) this.m_pages[0]).getResult();
if (msn != null) {
if (!msn.getMSN().equalsIgnoreCase("*"))
filterList.add(new MsnFilter(new IMsn[] { msn }));
}
int limit = ((FilterItemCountPage) this.m_pages[4]).getResult();
if (limit > 0) {
filterList.add(new ItemCountFilter(limit));
}
IAttributeMap m = ((FilterCallTypePage) this.m_pages[5]).getResult();
if (m != null && m.size() > 0) {
filterList.add(new AttributeFilter(m));
}
ICip cip = ((FilterCipPage) this.m_pages[1]).getResult();
if (cip != null)
if (!cip.getCIP().equalsIgnoreCase("*"))
filterList.add(new CipFilter(cip));
this.m_filters = new IFilter[filterList.size()];
for (int i = 0; i < filterList.size(); i++) {
this.m_filters[i] = (IFilter) filterList.get(i);
}
String name = ((FilterNamePage) this.m_pages[6]).getResult();
IFilterManager fm = new JournalFilterManager();
if (name != null && name.trim().length() > 0) {
this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Journal.NAMESPACE, "filtername_" + fm.getFiltersToString(getResult()), name);
this.getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
} else {
this.getRuntime().getConfigManagerFactory().getConfigManager().removeProperty(Journal.NAMESPACE, "filtername_" + fm.getFiltersToString(getResult()));
this.getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
}
return true;
}
this.m_filters = null;
return false;
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class Serializer method toString.
private static String toString(IMultiPhoneCaller caller, boolean includeImage) throws SerializerException {
StringBuffer serialized = new StringBuffer(128);
try {
List pns = caller.getPhonenumbers();
if (pns.size() > 0) {
// add type
serialized.append("mpc");
serialized.append(m_token);
// add phonelist size
serialized.append(pns.size());
serialized.append(m_token);
for (int i = 0, j = pns.size(); i < j; i++) {
// add int area code
serialized.append(encode((((IPhonenumber) pns.get(i)).getIntAreaCode().length() == 0 ? BLANK : ((IPhonenumber) pns.get(i)).getIntAreaCode())));
serialized.append(m_token);
// add area code
serialized.append(encode((((IPhonenumber) pns.get(i)).getAreaCode().length() == 0 ? BLANK : ((IPhonenumber) pns.get(i)).getAreaCode())));
serialized.append(m_token);
// add call number
serialized.append(encode((((IPhonenumber) pns.get(i)).getCallNumber().length() == 0 ? BLANK : ((IPhonenumber) pns.get(i)).getCallNumber())));
serialized.append(m_token);
}
} else {
// add int area code
serialized.append(encode((caller.getPhoneNumber().getIntAreaCode().length() == 0 ? BLANK : caller.getPhoneNumber().getIntAreaCode())));
serialized.append(m_token);
// add area code
serialized.append(encode((caller.getPhoneNumber().getAreaCode().length() == 0 ? BLANK : caller.getPhoneNumber().getAreaCode())));
serialized.append(m_token);
// add call number
serialized.append(encode((caller.getPhoneNumber().getCallNumber().length() == 0 ? BLANK : caller.getPhoneNumber().getCallNumber())));
serialized.append(m_token);
}
// add firstname
serialized.append(encode((caller.getName().getFirstname().length() == 0 ? BLANK : caller.getName().getFirstname())));
serialized.append(m_token);
// add lastname
serialized.append(encode((caller.getName().getLastname().length() == 0 ? BLANK : caller.getName().getLastname())));
serialized.append(m_token);
// add additional
serialized.append(encode((caller.getName().getAdditional().length() == 0 ? BLANK : caller.getName().getAdditional())));
serialized.append(m_token);
// add caller UUID
serialized.append(encode((caller.getUUID().length() == 0 ? BLANK : caller.getUUID())));
serialized.append(m_token);
// add attributes
IAttributeMap al = caller.getAttributes();
if (al.size() == 0)
serialized.append(BLANK);
if (includeImage && ImageHandler.getInstance().hasImage(caller)) {
InputStream in = ImageHandler.getInstance().getImageStream(caller);
if (in != null) {
ByteArrayOutputStream encodedOut = new ByteArrayOutputStream();
Base64Encoder b64 = new Base64Encoder(encodedOut);
Stream.copy(in, b64);
b64.flush();
b64.close();
final String imgdata = StringUtils.replaceString(new String(encodedOut.toByteArray()), m_imglftoken, IMGLFTOKEN_ESCAPE_SYMBOL);
encodedOut.close();
IAttribute img = new IAttribute() {
public void setName(String name) {
}
public void setValue(String value) {
}
public String getName() {
return IJAMConst.ATTRIBUTE_NAME_IMAGEBINARY;
}
public String getValue() {
return imgdata;
}
};
caller.getAttributes().add(img);
caller.getAttributes().remove(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH);
// caller.getAttributes().remove(IJAMConst.ATTRIBUTE_NAME_IMAGEREF);
caller.getAttributes().remove(IJAMConst.ATTRIBUTE_NAME_IMAGEURL);
}
}
Iterator i = al.iterator();
IAttribute att = null;
while (i.hasNext()) {
att = (IAttribute) i.next();
serialized.append(encode(att.getName()));
serialized.append(EQUAL);
serialized.append(encodeAttributeValue(att.getValue()));
serialized.append(m_atoken);
}
} catch (Throwable t) {
throw new SerializerException(t.getMessage());
}
return serialized.toString();
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class Serializer method toCaller.
/**
* Deserializes a byte array stream into an caller object.
*
* @param caller caller as a byte array representation.
* @param runtime runtime to used
* @return caller object
* @throws SerializerException
*/
public static ICaller toCaller(byte[] caller, IRuntime runtime) throws SerializerException {
if (runtime == null)
throw new SerializerException("Runtime object is not set but required.");
String callerString = new String(caller);
// tokenize the input
StringTokenizer st = new StringTokenizer(callerString, m_token);
if (st.countTokens() < 8) {
throw new SerializerException("Caller format is invalid: " + callerString);
}
try {
// Check for new mpc format
String test = st.nextToken().trim();
List phones = null;
if (test.equalsIgnoreCase("mpc")) {
int phone_count = Integer.parseInt(st.nextToken().trim());
phones = new ArrayList(phone_count);
for (int i = 0; i < phone_count; i++) {
// build number
IPhonenumber pn = runtime.getCallerFactory().createPhonenumber(// token 1
decode(st.nextToken().trim()), decode(st.nextToken().trim()), decode(st.nextToken().trim()));
if (pn.getCallNumber().length() == 0) {
pn.setClired(true);
}
phones.add(pn);
}
} else {
phones = new ArrayList(1);
// build number
IPhonenumber pn = runtime.getCallerFactory().createPhonenumber(// token 1
test, // token 2
decode(st.nextToken().trim()), // token 3
decode(st.nextToken().trim()));
if (pn.getCallNumber().length() == 0) {
pn.setClired(true);
}
phones.add(pn);
}
// build name
IName name = runtime.getCallerFactory().createName(// token 4
decode(st.nextToken().trim()), // token 5
decode(st.nextToken().trim()), // token 6
decode(st.nextToken().trim()));
// token 7
String UUID = decode(st.nextToken().trim());
// build attributes
String attString = decode(st.nextToken().trim());
IAttributeMap attList = runtime.getCallerFactory().createAttributeMap();
if (attString.length() > 0) {
StringTokenizer ast = new StringTokenizer(attString, m_atoken);
String attrib = null;
while (ast.hasMoreTokens()) {
attrib = ast.nextToken().trim();
if (attrib.indexOf(EQUAL) > -1) {
IAttribute att = runtime.getCallerFactory().createAttribute(decode(attrib.substring(0, attrib.indexOf(EQUAL))), decodeAttributeValue(attrib.substring(attrib.indexOf(EQUAL) + EQUAL.length())));
attList.add(att);
}
}
// check for imagebinary
if (attList.contains(IJAMConst.ATTRIBUTE_NAME_IMAGEBINARY)) {
IAttribute imgbinary = attList.get(IJAMConst.ATTRIBUTE_NAME_IMAGEBINARY);
if (imgbinary != null) {
imgbinary.setValue(StringUtils.replaceString(imgbinary.getValue(), IMGLFTOKEN_ESCAPE_SYMBOL, m_imglftoken));
}
}
}
// create an IMultiPhoneCaller object
if (test.equalsIgnoreCase("mpc") || phones.size() > 1) {
return runtime.getCallerFactory().createCaller(UUID, name, phones, attList);
}
// create an ICaller object
return runtime.getCallerFactory().createCaller(UUID, name, (IPhonenumber) phones.get(0), attList);
} catch (Exception e) {
throw new SerializerException(e.toString());
}
}
Aggregations