use of de.janrufmonitor.framework.IName in project janrufmonitor by tbrandt77.
the class IncomingCall method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
IPhonenumber pn = null;
try {
String phone = req.getParameter(IncomingCall.PARAMETER_NUMBER);
if (phone == null || phone.length() == 0)
pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true);
else
pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(phone);
IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(name, pn);
ICip cip = PIMRuntime.getInstance().getCallFactory().createCip(req.getParameter(IncomingCall.PARAMETER_CIP), "");
IMsn msn = PIMRuntime.getInstance().getCallFactory().createMsn(req.getParameter(IncomingCall.PARAMETER_MSN), "");
Date date = new Date(Long.parseLong(req.getParameter(IncomingCall.PARAMETER_DATE)));
ICall call = PIMRuntime.getInstance().getCallFactory().createCall(c, msn, cip, date);
call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STARTRING, Long.toString(new Date().getTime())));
ClientCallMap.getInstance().setCall((pn.isClired() ? IJAMConst.CLIRED_CALL : pn.getTelephoneNumber()) + "/" + msn.getMSN(), call);
Thread sender = new Thread(new HandlerThread(call, this));
sender.start();
resp.getContentStreamForWrite().close();
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.framework.IName in project janrufmonitor by tbrandt77.
the class EabFileCallerImporter method doImport.
public ICallerList doImport() {
this.m_current = 0;
m_callerList = PIMRuntime.getInstance().getCallerFactory().createCallerList();
Date startDate = new Date();
File db = new File(m_filename);
try {
FileInputStream in = new FileInputStream(db);
Properties addressbook = new Properties();
addressbook.load(in);
in.close();
m_total = Integer.parseInt(addressbook.getProperty("total", "1"));
boolean hasMore = true;
int i = 1;
String key = null;
while (hasMore && addressbook.size() > 0) {
key = addressbook.getProperty(i + ".phonecount");
addressbook.remove(i + ".phonecount");
// found old format
if (key == null) {
key = addressbook.getProperty(i + ".phone");
addressbook.remove(i + ".phone");
if (key != null && key.length() > 0) {
IPhonenumber pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(false);
pn.setCallNumber(key);
pn.setAreaCode(addressbook.getProperty(i + ".area"));
addressbook.remove(i + ".area");
key = addressbook.getProperty(i + ".intarea");
addressbook.remove(i + ".intarea");
if (key == null || key.length() == 0)
key = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_INTAREA);
pn.setIntAreaCode(key);
IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
IAttributeMap m = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
Enumeration en = addressbook.keys();
List keys = new ArrayList();
while (en.hasMoreElements()) {
key = (String) en.nextElement();
if (key.startsWith(i + ".")) {
keys.add(key);
m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(key.substring((i + ".").length()), addressbook.getProperty(key)));
}
}
if (keys.size() > 0) {
for (int j = 0; j < keys.size(); j++) {
addressbook.remove(keys.get(j));
}
keys.clear();
keys = null;
}
ICaller caller = PIMRuntime.getInstance().getCallerFactory().createCaller(name, pn);
caller.setAttributes(m);
this.m_callerList.add(caller);
i++;
} else {
this.m_logger.info("Found no more valid keys. Left data: " + addressbook);
hasMore = false;
}
} else {
// new format since 5.0.0
int phonecount = Integer.parseInt(key);
List phones = new ArrayList(1);
ICaller caller = null;
for (int a = 0; a < phonecount; a++) {
key = addressbook.getProperty(i + ".phone." + a);
addressbook.remove(i + ".phone." + a);
if (key != null && key.length() > 0) {
IPhonenumber pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(false);
pn.setCallNumber(key);
pn.setAreaCode(addressbook.getProperty(i + ".area." + a));
addressbook.remove(i + ".area." + a);
key = addressbook.getProperty(i + ".intarea." + a);
addressbook.remove(i + ".intarea." + a);
if (key == null || key.length() == 0)
key = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_INTAREA);
pn.setIntAreaCode(key);
phones.add(pn);
}
}
IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
IAttributeMap m = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
Enumeration en = addressbook.keys();
List keys = new ArrayList();
while (en.hasMoreElements()) {
key = (String) en.nextElement();
if (key.startsWith(i + ".")) {
keys.add(key);
m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(key.substring((i + ".").length()), addressbook.getProperty(key)));
}
}
if (keys.size() > 0) {
for (int j = 0; j < keys.size(); j++) {
addressbook.remove(keys.get(j));
}
keys.clear();
keys = null;
}
caller = PIMRuntime.getInstance().getCallerFactory().createCaller(name, phones);
caller.setAttributes(m);
this.m_callerList.add(caller);
i++;
this.m_current++;
}
}
} catch (FileNotFoundException ex) {
this.m_logger.warning("Cannot find caller backup file " + m_filename);
return this.m_callerList;
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + m_filename);
return this.m_callerList;
}
Date endDate = new Date();
this.m_logger.info("Successfully imported caller file " + m_filename);
this.m_logger.info("Found " + new Integer(this.m_callerList.size()).toString() + " caller items in " + new Float((endDate.getTime() - startDate.getTime()) / 1000).toString() + " secs.");
return this.m_callerList;
}
use of de.janrufmonitor.framework.IName in project janrufmonitor by tbrandt77.
the class OldDatFileCallImporter method parseName.
private IName parseName(String caller) {
String name = "";
if (caller.indexOf("( -") > -1) {
name = caller.substring(0, caller.indexOf("( -"));
}
if (caller.indexOf("(0") > -1) {
name = caller.substring(0, caller.indexOf("(0"));
}
StringTokenizer st = new StringTokenizer(name, " ");
if (st.countTokens() == 1) {
return PIMRuntime.getInstance().getCallerFactory().createName("", "", st.nextToken());
}
if (st.countTokens() == 2) {
return PIMRuntime.getInstance().getCallerFactory().createName(st.nextToken(), st.nextToken());
}
if (st.countTokens() == 3) {
return PIMRuntime.getInstance().getCallerFactory().createName(st.nextToken(), st.nextToken(), st.nextToken());
}
if (st.countTokens() > 3) {
IName n = PIMRuntime.getInstance().getCallerFactory().createName("", "");
n.setFirstname(st.nextToken());
n.setLastname(st.nextToken());
n.setAdditional(st.nextToken());
while (st.hasMoreTokens()) {
n.setAdditional(n.getAdditional() + " " + st.nextToken());
}
return n;
}
return PIMRuntime.getInstance().getCallerFactory().createName("", "");
}
use of de.janrufmonitor.framework.IName 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());
}
}
use of de.janrufmonitor.framework.IName in project janrufmonitor by tbrandt77.
the class CallSimulator method sendEvent.
protected void sendEvent(String number, String msn, String cip) {
if (number != null && number.length() > 0)
number = PhonenumberAnalyzer.getInstance(this.getRuntime()).toCallable(number);
if (!number.startsWith("0") && isRaw) {
number = "0" + number;
}
IEventBroker evtBroker = this.getRuntime().getEventBroker();
evtBroker.register(this);
evtBroker.register(this, evtBroker.createEvent(IEventConst.EVENT_TYPE_IDENTIFIED_CALL));
IPhonenumber phone = PhonenumberAnalyzer.getInstance(this.getRuntime()).toClirPhonenumber(number);
if (phone == null)
phone = PhonenumberAnalyzer.getInstance(this.getRuntime()).toInternalPhonenumber(number, msn);
if (phone == null)
phone = PhonenumberAnalyzer.getInstance(this.getRuntime()).toPhonenumber(number, msn);
IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
ICaller aCaller = PIMRuntime.getInstance().getCallerFactory().createCaller(name, phone);
ICip ocip = PIMRuntime.getInstance().getCallFactory().createCip(cip, "");
IMsn omsn = PIMRuntime.getInstance().getCallFactory().createMsn(msn, "");
ICall currentCall = PIMRuntime.getInstance().getCallFactory().createCall(aCaller, omsn, ocip);
currentCall.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_MISSED));
IEvent ev = evtBroker.createEvent(IEventConst.EVENT_TYPE_INCOMINGCALL, currentCall);
evtBroker.send(this, ev);
evtBroker.unregister(this);
}
Aggregations