Search in sources :

Example 41 with ICall

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;
}
Also used : ICall(de.janrufmonitor.framework.ICall) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) Properties(java.util.Properties) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 42 with ICall

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());
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) ICall(de.janrufmonitor.framework.ICall) IAttribute(de.janrufmonitor.framework.IAttribute) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Properties(java.util.Properties) IService(de.janrufmonitor.service.IService)

Example 43 with ICall

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) ICall(de.janrufmonitor.framework.ICall) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL) URLConnection(java.net.URLConnection) ICaller(de.janrufmonitor.framework.ICaller) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) IAttribute(de.janrufmonitor.framework.IAttribute) File(java.io.File)

Example 44 with ICall

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);
}
Also used : ICall(de.janrufmonitor.framework.ICall)

Example 45 with ICall

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);
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICall(de.janrufmonitor.framework.ICall) Date(java.util.Date) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException)

Aggregations

ICall (de.janrufmonitor.framework.ICall)89 ICaller (de.janrufmonitor.framework.ICaller)41 List (java.util.List)23 Viewer (org.eclipse.jface.viewers.Viewer)20 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)19 ArrayList (java.util.ArrayList)19 IAttribute (de.janrufmonitor.framework.IAttribute)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)18 ICallList (de.janrufmonitor.framework.ICallList)17 IOException (java.io.IOException)14 Properties (java.util.Properties)14 Date (java.util.Date)13 Iterator (java.util.Iterator)13 Shell (org.eclipse.swt.widgets.Shell)13 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)11 ICip (de.janrufmonitor.framework.ICip)10 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)10