use of de.janrufmonitor.framework.ICaller 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.ICaller in project janrufmonitor by tbrandt77.
the class GpxCallerExporter method doExport.
public boolean doExport() {
File db = new File(m_filename);
try {
StringBuffer xml = new StringBuffer();
xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>");
xml.append(IJAMConst.CRLF);
xml.append("<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" creator=\"jAnrufmonitor\" version=\"1.1\"");
xml.append(IJAMConst.CRLF);
xml.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
xml.append(IJAMConst.CRLF);
xml.append("xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">");
xml.append(IJAMConst.CRLF);
ICaller c = null;
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
String now = df.format(new Date());
for (int i = 0; i < this.m_callerList.size(); i++) {
c = this.m_callerList.get(i);
IAttributeMap attributes = c.getAttributes();
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_GEO_ACC) && attributes.contains(IJAMConst.ATTRIBUTE_NAME_GEO_LNG) && attributes.contains(IJAMConst.ATTRIBUTE_NAME_GEO_LAT)) {
xml.append("<wpt lat=\"");
xml.append(attributes.get(IJAMConst.ATTRIBUTE_NAME_GEO_LAT).getValue());
xml.append("\" lon=\"");
xml.append(attributes.get(IJAMConst.ATTRIBUTE_NAME_GEO_LNG).getValue());
xml.append("\">");
xml.append(IJAMConst.CRLF);
xml.append("<time>");
xml.append(now);
xml.append("</time>");
xml.append(IJAMConst.CRLF);
xml.append("<name>");
try {
xml.append(StringEscapeUtils.escapeXml(StringUtils.replaceString(Formatter.getInstance(PIMRuntime.getInstance()).parse(IJAMConst.GLOBAL_VARIABLE_CALLERNAME, c), IJAMConst.CRLF, " ").trim()));
} catch (Exception e) {
m_logger.log(Level.SEVERE, e.toString(), e);
}
xml.append("</name>");
xml.append(IJAMConst.CRLF);
xml.append("<sym>Dot</sym>");
xml.append(IJAMConst.CRLF);
xml.append("</wpt>");
xml.append(IJAMConst.CRLF);
}
}
xml.append("</gpx>");
FileOutputStream fo = new FileOutputStream(db);
ByteArrayInputStream bin = new ByteArrayInputStream(xml.toString().getBytes());
Stream.copy(bin, fo, true);
fo.close();
} catch (FileNotFoundException ex) {
this.m_logger.severe("File not found: " + m_filename);
return false;
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + m_filename);
return false;
}
return true;
}
use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.
the class OldDatFileCallerImporter method doImport.
public ICallerList doImport() {
m_callerList = PIMRuntime.getInstance().getCallerFactory().createCallerList();
Date startDate = new Date();
File db = new File(m_filename);
try {
FileReader dbReader = new FileReader(db);
BufferedReader bufReader = new BufferedReader(dbReader);
String line = null;
ICaller aCaller = null;
while (bufReader.ready()) {
line = bufReader.readLine();
aCaller = this.migrateCallerFromString(line);
if (aCaller != null) {
this.m_callerList.add(aCaller);
}
}
bufReader.close();
dbReader.close();
} 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.ICaller in project janrufmonitor by tbrandt77.
the class GeoCoding method modifyObject.
public void modifyObject(Object o) {
if (o instanceof ICall) {
o = ((ICall) o).getCaller();
}
if (o instanceof ICaller) {
ICaller caller = ((ICaller) o);
if (caller.getPhoneNumber().isClired())
return;
if (caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT) != null && caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG) != null) {
this.m_logger.info("Caller already set with geo data ...");
return;
}
Point p = GeoCoder.getInstance().getCoordinates(caller.getAttributes());
if (p != null) {
caller.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_ACC, Integer.toString(p.getAccurance())));
caller.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT, Double.toString(p.getLatitude())));
caller.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG, Double.toString(p.getLongitude())));
}
}
}
use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.
the class GeoCoding method receivedValidRule.
public void receivedValidRule(ICall call) {
if (call == null)
return;
if (call.getCaller().getPhoneNumber().isClired())
return;
ICaller caller = call.getCaller();
if (caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT) != null && caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG) != null) {
this.m_logger.info("Call already set with geo data ...");
return;
}
Point p = GeoCoder.getInstance().getCoordinates(caller.getAttributes());
if (p != null) {
caller.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_ACC, Integer.toString(p.getAccurance())));
caller.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT, Double.toString(p.getLatitude())));
caller.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG, Double.toString(p.getLongitude())));
List callManagerList = this.getRuntime().getCallManagerFactory().getAllCallManagers();
ICallManager icm = null;
IEventBroker eventBroker = this.getRuntime().getEventBroker();
for (int i = 0; i < callManagerList.size(); i++) {
icm = (ICallManager) callManagerList.get(i);
// check if the repository manager allows read/write access
if (icm.isActive() && icm.isSupported(IWriteCallRepository.class)) {
((IWriteCallRepository) icm).updateCall(call);
this.m_logger.info("Call update sent with geocoding: " + call);
eventBroker.send(this, eventBroker.createEvent(IEventConst.EVENT_TYPE_UPDATE_CALL, call));
}
}
} else {
this.m_logger.info("Geocoding not successfully for call: " + call);
}
}
Aggregations