use of de.janrufmonitor.framework.ICall in project janrufmonitor by tbrandt77.
the class LineStatsAction method getStatisticItems.
public List getStatisticItems() {
final List items = new ArrayList();
ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
try {
IRunnableWithProgress r = new IRunnableWithProgress() {
public void run(IProgressMonitor progressMonitor) {
isCalculating = true;
progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "calculating", "label", getLanguage()), IProgressMonitor.UNKNOWN);
progressMonitor.worked(1);
final Properties stat = new Properties();
if (m_cl != null) {
ICall c = null;
for (int i = 0; i < m_cl.size(); i++) {
c = m_cl.get(i);
if (isLineCall(c)) {
String key = getLineCall(c);
String value = stat.getProperty(key, "");
if (value.length() == 0) {
stat.setProperty(key.trim(), "1");
stat.setProperty(key + ".line", key);
} else {
int val = new Integer(value).intValue();
val++;
stat.setProperty(key.trim(), new Integer(val).toString());
m_maxcount = Math.max(m_maxcount, val);
}
m_maxlistcount++;
}
}
}
progressMonitor.worked(1);
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "createstatistic", "label", getLanguage()));
Iterator iter = stat.keySet().iterator();
String key = null;
String count = null;
while (iter.hasNext()) {
key = (String) iter.next();
if (!(key.endsWith(".line"))) {
count = stat.getProperty(key, "");
items.add(new String[] { stat.getProperty(key + ".line"), count });
}
}
stat.clear();
Collections.sort(items, new StatisticComparator());
progressMonitor.done();
isCalculating = false;
}
};
pmd.setBlockOnOpen(false);
pmd.run(true, false, r);
// ModalContext.run(r, true, pmd.getProgressMonitor(),
// DisplayManager.getDefaultDisplay());
} catch (InterruptedException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
isCalculating = false;
} catch (InvocationTargetException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
isCalculating = false;
}
while (isCalculating) try {
Thread.sleep(1250);
} catch (InterruptedException e) {
}
return items;
}
use of de.janrufmonitor.framework.ICall in project janrufmonitor by tbrandt77.
the class GoogleMapsLocalize method run.
public void run() {
Viewer v = this.m_app.getApplication().getViewer();
if (v != null) {
IStructuredSelection selection = (IStructuredSelection) v.getSelection();
if (!selection.isEmpty()) {
Object o = selection.getFirstElement();
if (o instanceof ICall) {
o = ((ICall) o).getCaller();
}
if (o instanceof ICaller) {
// check if maps.google.com service is enabled
IService googlemap = getRuntime().getServiceFactory().getService(Maps.ID);
if (googlemap != null && googlemap.isEnabled()) {
Properties configuration = getRuntime().getConfigManagerFactory().getConfigManager().getProperties(Maps.NAMESPACE);
String url = configuration.getProperty("url");
if (url == null || url.trim().length() == 0) {
MessageDialog.openError(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "nourl", "label", this.getLanguage()), this.getI18nManager().getString(this.getNamespace(), "nourl", "description", this.getLanguage()));
return;
}
IAttribute postalCode = ((ICaller) o).getAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY);
if (postalCode == null || postalCode.getValue().trim().length() == 0) {
MessageDialog.openError(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "less", "label", this.getLanguage()), this.getI18nManager().getString(this.getNamespace(), "less", "description", this.getLanguage()));
return;
}
IAttribute city = ((ICaller) o).getAttribute(IJAMConst.ATTRIBUTE_NAME_CITY);
if (city == null || city.getValue().trim().length() == 0) {
MessageDialog.openError(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "less", "label", this.getLanguage()), this.getI18nManager().getString(this.getNamespace(), "less", "description", this.getLanguage()));
return;
}
StringBuffer googlemapUrl = new StringBuffer();
googlemapUrl.append(url);
googlemapUrl.append(buildRequestParameters((ICaller) o));
this.m_logger.info("Requesting maps.google.com URL: " + googlemapUrl.toString());
Program.launch(googlemapUrl.toString());
}
}
}
}
}
use of de.janrufmonitor.framework.ICall in project janrufmonitor by tbrandt77.
the class Map method renderAsImage.
public Image renderAsImage() {
if (this.m_o != null) {
if (this.m_o instanceof ICall) {
this.m_o = ((ICall) this.m_o).getCaller();
}
if (this.m_o instanceof ICaller) {
IAttribute lng = ((ICaller) this.m_o).getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG);
IAttribute lat = ((ICaller) this.m_o).getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT);
if (lng != null && lat != null) {
String maptype = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty("service.GoogleMaps", "type");
String zoom = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty("service.GoogleMaps", "zoom");
try {
File dir = new File(PathResolver.getInstance(PIMRuntime.getInstance()).getPhotoDirectory() + File.separator + "maps" + File.separator);
if (!dir.exists())
dir.mkdirs();
File img = new File(dir, lat.getValue() + lng.getValue() + maptype + zoom);
if (!img.exists()) {
URL url = new URL("http://maps.googleapis.com/maps/api/staticmap?center=" + lat.getValue() + "," + lng.getValue() + "&zoom=" + zoom + "&size=400x90&maptype=" + maptype + "&sensor=false&markers=color:blue%7Clabel:A%7C" + lat.getValue() + "," + lng.getValue());
URLConnection c = url.openConnection();
c.setDoInput(true);
c.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE; Windows NT)");
c.connect();
Object o = url.openStream();
if (o instanceof InputStream) {
BufferedInputStream bin = new BufferedInputStream((InputStream) o);
FileOutputStream fos = new FileOutputStream(img);
Stream.copy(bin, fos, true);
return new Image(DisplayManager.getDefaultDisplay(), img.getAbsolutePath());
}
return null;
}
return new Image(DisplayManager.getDefaultDisplay(), img.getAbsolutePath());
} catch (MalformedURLException e) {
} catch (IOException e) {
}
}
}
}
return null;
}
use of de.janrufmonitor.framework.ICall in project janrufmonitor by tbrandt77.
the class JournalBuilder method parse.
private static String parse(String text, ICallList calls) throws IOException {
ICall c = null;
for (int i = 0, j = calls.size(); i < j; i++) {
c = calls.get(i);
text = parseSingleCall(text, c);
}
return removeSingleCall(text);
}
use of de.janrufmonitor.framework.ICall in project janrufmonitor by tbrandt77.
the class Rejected method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
try {
String phone = req.getParameter(Rejected.PARAMETER_NUMBER);
String msn = req.getParameter(Rejected.PARAMETER_MSN);
if (phone == null || phone.length() == 0)
phone = IJAMConst.CLIRED_CALL;
ICall call = ClientCallMap.getInstance().getCall(phone + "/" + msn);
this.m_logger.info("Key for ClientCallMap: " + phone + "/" + msn);
if (call != null) {
long end = new Date().getTime();
long start = this.getStartTime(call);
call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_ENDRING, Long.toString(end)));
call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_RINGDURATION, Long.toString((end - start) / 1000)));
call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_REJECTED));
if (ClientCallMap.getInstance().removeCall(phone + "/" + msn))
this.m_logger.info("Successfully found call: " + phone + "/" + msn);
Thread sender = new Thread(new HandlerThread(call, this));
sender.start();
resp.getContentStreamForWrite().close();
}
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
Aggregations