use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class AbstractWebCallerManager method getCaller.
public ICaller getCaller(IPhonenumber p) throws CallerNotFoundException {
if (p == null)
throw new CallerNotFoundException("Phone number is not set (null). No caller found.");
if (p.isClired())
throw new CallerNotFoundException("Phone number is CLIR. Identification impossible.");
if (PhonenumberAnalyzer.getInstance(this.getRuntime()).isInternal(p))
throw new CallerNotFoundException("Phone number is internal number.");
IPhonenumber number = this.getRuntime().getCallerFactory().createPhonenumber(p.getTelephoneNumber());
if (isUsedCache() && this.m_unidentified != null && this.m_unidentified.containsKey(number.getTelephoneNumber())) {
Integer io = (Integer) this.m_unidentified.get(number.getTelephoneNumber());
if (io.intValue() == 10) {
this.m_unidentified.remove(number.getTelephoneNumber());
} else {
this.m_unidentified.put(number.getTelephoneNumber(), new Integer(io.intValue() + 1));
}
throw new CallerNotFoundException("Phone number " + number.getTelephoneNumber() + " not identified. (cached)");
}
ICaller caller = null;
if (isUsedCache() && this.m_cache != null && this.m_cache.containsKey(number)) {
caller = (ICaller) this.m_cache.get(number);
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Taking caller from cache: " + caller);
if (caller != null)
return caller;
} else {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Number is not cached, start identifiing ...");
IPhonenumber pn = null;
try {
ICallerManager defaultManager = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
if (defaultManager != null && defaultManager.isActive() && defaultManager.isSupported(IIdentifyCallerRepository.class)) {
ICaller defaultIdentified = ((IIdentifyCallerRepository) defaultManager).getCaller(number);
pn = defaultIdentified.getPhoneNumber();
}
} catch (CallerNotFoundException e) {
// ignore this exception
}
// check correct country code
if (!this.getSupportedIntAreaCode().equalsIgnoreCase("00")) {
if (pn != null && !pn.getIntAreaCode().equalsIgnoreCase(this.getSupportedIntAreaCode()))
throw new CallerNotFoundException("Phone number has country code " + pn.getIntAreaCode() + ". Caller manager " + this.getID() + " is supporting only " + this.getSupportedIntAreaCode());
// added 2013/07/22: number format compatibility 0911234567 must be equal +49 (911) 234567
if (pn != null)
number.setTelephoneNumber(pn.getTelephoneNumber());
}
// added 2009/05/28
// add detection of web services which provides number in middle of URL
String url = this.getURL();
if (url.indexOf(IJAMConst.GLOBAL_VARIABLE_WEBCM_NUMBER) > 0) {
url = StringUtils.replaceString(url, IJAMConst.GLOBAL_VARIABLE_WEBCM_NUMBER, (number.getTelephoneNumber().startsWith("0") ? "" : "0") + number.getTelephoneNumber());
} else {
// added 2010/11/18: added URL attribute parsing
String urlx = url;
url = Formatter.getInstance(this.getRuntime()).parse(url, pn);
if (urlx.equalsIgnoreCase(url))
url += (number.getTelephoneNumber().startsWith("0") ? "" : "0") + number.getTelephoneNumber();
}
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("URL to call: " + url);
AbstractURLRequester r = this.createURLRequester(url, this.getSkipBytes(), number.getTelephoneNumber());
try {
long ts = System.currentTimeMillis();
Executor ex = new Executor(r);
Thread t = new Thread(ex);
t.start();
while (t.isAlive() && (System.currentTimeMillis() - ts < r.getTimeout())) {
Thread.sleep(100);
}
if (ex != null && ex.isFailed()) {
if (this.m_unidentified != null && !this.m_unidentified.containsKey(number.getTelephoneNumber()))
this.m_unidentified.put(number.getTelephoneNumber(), new Integer(1));
throw new CallerNotFoundException("Phone number " + number.getTelephoneNumber() + " not identified.", (ex.getException() != null ? ex.getException() : new Exception()));
}
if (t.isAlive())
throw new Exception("Identification thread is blocking.");
// r.go();
} catch (Exception e) {
if (this.m_unidentified != null && !this.m_unidentified.containsKey(number.getTelephoneNumber()))
this.m_unidentified.put(number.getTelephoneNumber(), new Integer(1));
throw new CallerNotFoundException("Phone number " + number.getTelephoneNumber() + " not identified: " + e.getMessage(), e);
}
IAttributeMap m = r.getAttributes();
if (pn == null)
pn = r.getPhonenumber();
if (!getKeepSourceNumber() && pn != null && r.getPhonenumber() != null && !r.getPhonenumber().getTelephoneNumber().endsWith(pn.getTelephoneNumber())) {
pn = r.getPhonenumber();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Incoming call number " + number.getTelephoneNumber() + " was not identified but extension " + pn.getTelephoneNumber());
}
caller = this.getRuntime().getCallerFactory().createCaller(pn);
caller.setAttributes(m);
IAttribute cm = this.getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, this.getID());
caller.setAttribute(cm);
// add caller to cache
if (this.m_cache != null)
this.m_cache.put(number, caller);
return caller;
}
throw new CallerNotFoundException("No caller found for number " + number);
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class CallerReaderFactory method unMultiPhoneCaller.
private ICallerList unMultiPhoneCaller(ICallerList cl, List managers) {
ICallerList l = PIMRuntime.getInstance().getCallerFactory().createCallerList(cl.size());
ICaller c = null;
ICaller nc = null;
for (int i = 0, j = cl.size(); i < j; i++) {
c = cl.get(i);
if (c instanceof IMultiPhoneCaller) {
List phones = ((IMultiPhoneCaller) c).getPhonenumbers();
IPhonenumber pn = null;
for (int k = 0; k < phones.size(); k++) {
pn = (IPhonenumber) phones.get(k);
// removed due to performance issues: c = this.getCaller(pn, managers);
nc = PIMRuntime.getInstance().getCallerFactory().createCaller(null, pn, c.getAttributes());
if (nc != null) {
l.add(nc);
}
}
} else
l.add(c);
}
return l;
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class InitAreaCodePage method identify.
private void identify() {
IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(m_newIntArea, m_newArea.substring(1), "0000000000");
ICaller c = Identifier.identifyDefault(getRuntime(), pn);
if (c != null) {
IAttribute city = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CITY);
if (city != null && city.getValue().trim().length() > 0) {
m_city.setText(city.getValue());
} else {
city = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY);
if (city != null && city.getValue().trim().length() > 0) {
m_city.setText(city.getValue());
} else
m_city.setText(this.m_i18n.getString(this.getNamespace(), "unknownareacode", "label", this.m_language));
}
}
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class AbstractFilterSerializer method getFilterToString.
/**
* Transforms a IFilter object into a string representation
* @param f a valid IFilter object, should not be null
* @return a string representation of the filter.
*/
public String getFilterToString(IFilter f) {
StringBuffer sb = new StringBuffer();
if (f != null) {
FilterType ft = f.getType();
if (ft.equals(FilterType.DATE)) {
sb.append(ft.toString());
sb.append(",");
if (((DateFilter) f).getTimeframe() == -1) {
Date d = ((DateFilter) f).getDateFrom();
if (d == null)
sb.append(-1);
else
sb.append(d.getTime());
sb.append(",");
sb.append(((DateFilter) f).getDateTo().getTime());
} else {
sb.append("0");
sb.append(",");
sb.append("0");
sb.append(",");
sb.append(((DateFilter) f).getTimeframe());
}
}
if (ft.equals(FilterType.YEAR)) {
sb.append(ft.toString());
sb.append(",");
sb.append(((YearFilter) f).getYear());
}
if (ft.equals(FilterType.MONTH_YEAR)) {
sb.append(ft.toString());
sb.append(",");
sb.append(((MonthYearFilter) f).getYear());
sb.append(",");
sb.append(((MonthYearFilter) f).getMonth());
}
if (ft.equals(FilterType.CIP)) {
sb.append(ft.toString());
sb.append(",");
sb.append(((CipFilter) f).getCip().getCIP());
}
if (ft.equals(FilterType.MSN)) {
sb.append(ft.toString());
sb.append(",");
IMsn[] msns = ((MsnFilter) f).getMsn();
if (msns.length == 1)
sb.append(((MsnFilter) f).getMsn()[0].getMSN());
else {
for (int i = 0, j = msns.length; i < j; i++) {
sb.append(((MsnFilter) f).getMsn()[i].getMSN());
if (i < j - 1)
sb.append(",");
}
}
}
if (ft.equals(FilterType.CALLER)) {
sb.append(ft.toString());
sb.append(",");
IPhonenumber pn = ((CallerFilter) f).getCaller().getPhoneNumber();
if (pn.isClired()) {
sb.append("clired");
} else {
sb.append(pn.getIntAreaCode());
sb.append(",");
sb.append(pn.getAreaCode());
sb.append(",");
sb.append(pn.getCallNumber());
}
}
if (ft.equals(FilterType.PHONENUMBER)) {
sb.append(ft.toString());
sb.append(",");
IPhonenumber pn = ((PhonenumberFilter) f).getPhonenumber();
sb.append(pn.getIntAreaCode());
sb.append(",");
sb.append((pn.getAreaCode().trim().length() > 0 ? pn.getAreaCode() : "+"));
sb.append(",");
sb.append((pn.getCallNumber().trim().length() > 0 ? pn.getCallNumber() : "+"));
}
if (ft.equals(FilterType.ITEMCOUNT)) {
sb.append(ft.toString());
sb.append(",");
sb.append(((ItemCountFilter) f).getLimit());
}
if (ft.equals(FilterType.ATTRIBUTE)) {
sb.append(ft.toString());
sb.append(",");
IAttributeMap m = ((AttributeFilter) f).getAttributeMap();
if (m != null && m.size() > 0) {
Iterator i = m.iterator();
IAttribute a = null;
while (i.hasNext()) {
a = (IAttribute) i.next();
sb.append(a.getName());
sb.append("=");
sb.append(a.getValue());
if (i.hasNext())
sb.append(",");
}
}
}
if (ft.equals(FilterType.CHARACTER)) {
sb.append(ft.toString());
sb.append(",");
sb.append(((CharacterFilter) f).getAttributeName());
sb.append("=");
sb.append(((CharacterFilter) f).getCharacter());
}
if (ft.equals(FilterType.UUID)) {
sb.append(ft.toString());
sb.append(",");
String[] uuids = ((UUIDFilter) f).getUUID();
for (int i = uuids.length, j = 0; j < i; j++) {
sb.append(uuids[j]);
if (j < (i - 1))
sb.append(";");
}
}
// TODO: more filters to be added here
}
return sb.toString();
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class ThunderbirdTransformer method buildWorkContact.
private ICaller buildWorkContact(Map m) {
IAttributeMap attributes = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
if (m.containsKey(FIRSTNAME))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, removeEscapedChars(((mork.Alias) m.get(FIRSTNAME)).getValue())));
if (m.containsKey(LASTNAME))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, removeEscapedChars(((mork.Alias) m.get(LASTNAME)).getValue())));
if (m.containsKey(COMPANY))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL, removeEscapedChars(((mork.Alias) m.get(COMPANY)).getValue())));
if (m.containsKey(WORK_STREET))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET, removeEscapedChars(((mork.Alias) m.get(WORK_STREET)).getValue())));
if (m.containsKey(WORK_ZIP))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, ((mork.Alias) m.get(WORK_ZIP)).getValue()));
if (m.containsKey(WORK_CITY))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CITY, removeEscapedChars(((mork.Alias) m.get(WORK_CITY)).getValue())));
if (m.containsKey(WORK_COUNTRY))
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, removeEscapedChars(((mork.Alias) m.get(WORK_COUNTRY)).getValue())));
List phones = new ArrayList();
IPhonenumber pn = null;
if (m.containsKey(WORK_PHONE)) {
pn = this.parsePhonenumber(((mork.Alias) m.get(WORK_PHONE)).getValue());
if (pn != null) {
phones.add(pn);
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE));
m.remove(WORK_PHONE);
}
}
if (m.containsKey(FAX_PHONE)) {
pn = this.parsePhonenumber(((mork.Alias) m.get(FAX_PHONE)).getValue());
if (pn != null) {
phones.add(pn);
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE));
m.remove(FAX_PHONE);
}
}
if (m.containsKey(MOBILE_PHONE)) {
pn = this.parsePhonenumber(((mork.Alias) m.get(MOBILE_PHONE)).getValue());
if (pn != null) {
phones.add(pn);
attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE));
m.remove(MOBILE_PHONE);
}
}
if (phones.size() == 0)
return null;
ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(null, phones, attributes);
c.setUUID(c.getName().getLastname() + "_" + c.getName().getFirstname() + "_" + c.getPhoneNumber().getTelephoneNumber());
IAttribute cm = PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, ThunderbirdCallerManager.ID);
c.setAttribute(cm);
return c;
}
Aggregations