Search in sources :

Example 1 with IIdentifyCallerRepository

use of de.janrufmonitor.repository.types.IIdentifyCallerRepository in project janrufmonitor by tbrandt77.

the class GetCaller method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallerManager mgr = null;
    String manager = null;
    try {
        manager = req.getParameter(GetCaller.PARAMETER_CALLERMANAGER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (manager == null)
        mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
    if (manager != null && manager.length() > 0)
        mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
    if (mgr == null || !mgr.isActive() || !mgr.isSupported(IIdentifyCallerRepository.class)) {
        throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
    }
    String number = null;
    try {
        number = req.getParameter(GetCaller.PARAMETER_NUMBER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (number == null || number.length() == 0) {
        this.m_logger.severe("Parameter &number= was empty or not set.");
        throw new HandlerException("Parameter &number= was empty or not set.", 404);
    }
    IPhonenumber pn = null;
    StringTokenizer st = new StringTokenizer(number, ";");
    if (st.countTokens() == 3) {
        pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), st.nextToken().trim(), st.nextToken().trim());
    }
    if (st.countTokens() == 2) {
        pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), "", st.nextToken().trim());
    }
    if (st.countTokens() == 1) {
        pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim());
    }
    try {
        ICaller caller = ((IIdentifyCallerRepository) mgr).getCaller(pn);
        String xml = XMLSerializer.toXML(caller, false);
        resp.setParameter("Content-Type", "text/xml");
        resp.setParameter("Content-Length", Long.toString(xml.length()));
        OutputStream ps = resp.getContentStreamForWrite();
        ps.write(xml.getBytes());
        ps.flush();
        ps.close();
    } catch (CallerNotFoundException e) {
        throw new HandlerException(e.getMessage(), 404);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) StringTokenizer(java.util.StringTokenizer) OutputStream(java.io.OutputStream) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 2 with IIdentifyCallerRepository

use of de.janrufmonitor.repository.types.IIdentifyCallerRepository in project janrufmonitor by tbrandt77.

the class Image method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallerManager mgr = null;
    String manager = null;
    try {
        manager = req.getParameter(Image.PARAMETER_CALLERMANAGER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (manager == null)
        mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
    if (manager != null && manager.length() > 0)
        mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
    if (mgr == null || !mgr.isActive() || !mgr.isSupported(IIdentifyCallerRepository.class)) {
        throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
    }
    String number = null;
    try {
        number = req.getParameter(Image.PARAMETER_NUMBER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (number == null || number.length() == 0) {
        this.m_logger.severe("Parameter &number= was empty or not set.");
        throw new HandlerException("Parameter &number= was empty or not set.", 404);
    }
    IPhonenumber pn = null;
    StringTokenizer st = new StringTokenizer(number, ";");
    if (st.countTokens() == 3) {
        pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), st.nextToken().trim(), st.nextToken().trim());
    }
    if (st.countTokens() == 2) {
        pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), "", st.nextToken().trim());
    }
    if (st.countTokens() == 1) {
        pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim());
    }
    try {
        ICaller caller = ((IIdentifyCallerRepository) mgr).getCaller(pn);
        IAttribute imageAtt = caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH);
        if (ImageHandler.getInstance().hasImage(caller)) {
            InputStream in = ImageHandler.getInstance().getImageStream(caller);
            if (in != null) {
                resp.setParameter("Content-Type", this.getMimetype("jpg"));
                OutputStream ps = resp.getContentStreamForWrite();
                byte[] buffer = new byte[8092];
                int bytesRead;
                while ((bytesRead = in.read(buffer)) != -1) {
                    ps.write(buffer, 0, bytesRead);
                }
                in.close();
                ps.flush();
                ps.close();
            }
        } else if (imageAtt != null) {
            String pathToImage = PathResolver.getInstance(getRuntime()).resolve(imageAtt.getValue());
            File image = new File(pathToImage);
            if (image.exists()) {
                resp.setParameter("Content-Type", this.getMimetype(pathToImage));
                resp.setParameter("Content-Length", Long.toString(image.length()));
                OutputStream ps = resp.getContentStreamForWrite();
                FileInputStream in = new FileInputStream(image);
                byte[] buffer = new byte[8092];
                int bytesRead;
                while ((bytesRead = in.read(buffer)) != -1) {
                    ps.write(buffer, 0, bytesRead);
                }
                in.close();
                ps.flush();
                ps.close();
            } else {
                throw new CallerNotFoundException("Image " + pathToImage + " not found");
            }
        } else {
            throw new CallerNotFoundException("No image assigned for caller " + caller);
        }
    } catch (CallerNotFoundException e) {
        throw new HandlerException(e.getMessage(), 404);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) FileInputStream(java.io.FileInputStream) ICaller(de.janrufmonitor.framework.ICaller) StringTokenizer(java.util.StringTokenizer) IAttribute(de.janrufmonitor.framework.IAttribute) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) File(java.io.File) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 3 with IIdentifyCallerRepository

use of de.janrufmonitor.repository.types.IIdentifyCallerRepository in project janrufmonitor by tbrandt77.

the class Identifier method identify.

/**
 * Identifies a caller with all active caller managers specified in the configuration.
 *
 * @param r the current runtime
 * @param pn a valid number, should not be a clired number or null
 * @param activeCallerManagers a list of active caller managers
 * @return an identified ICaller object or null, if not identified by any caller manager
 */
public static ICaller identify(IRuntime r, IPhonenumber pn, List activeCallerManagers) {
    if (activeCallerManagers == null || activeCallerManagers.size() == 0)
        return null;
    long start = System.currentTimeMillis();
    Identifier.logger.info("<---- Begin caller identification ---->");
    Identifier.logger.info("Order of identification: " + activeCallerManagers.toString());
    ICaller identifiedCaller = null;
    int i = 0;
    Object obj = null;
    ICallerManager cm = null;
    while (identifiedCaller == null && i < activeCallerManagers.size()) {
        obj = activeCallerManagers.get(i);
        i++;
        if (obj != null && obj instanceof ICallerManager) {
            cm = (ICallerManager) obj;
            try {
                if (cm.isActive() && cm.isSupported(IIdentifyCallerRepository.class)) {
                    identifiedCaller = ((IIdentifyCallerRepository) cm).getCaller(pn);
                    Identifier.logger.info("Caller identified by [" + cm.getManagerID() + "]: " + identifiedCaller);
                }
            } catch (CallerNotFoundException e) {
                Identifier.logger.info("Caller was not identified by [" + cm.getManagerID() + "]: " + e.getMessage());
            }
        } else {
            Identifier.logger.severe("Invalid caller manager object: " + obj);
        }
    }
    Identifier.logger.info("<---- Finished caller identification (" + (System.currentTimeMillis() - start) + " msec.) ---->");
    return identifiedCaller;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Example 4 with IIdentifyCallerRepository

use of de.janrufmonitor.repository.types.IIdentifyCallerRepository in project janrufmonitor by tbrandt77.

the class OutlookImportAction method run.

public void run() {
    String filter = this.m_app.getApplication().getConfiguration().getProperty("filter", "");
    EditorFilterManager efm = new EditorFilterManager();
    final IAttribute category = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, "");
    if (filter.length() > 0) {
        String cat = null;
        IFilter[] filters = efm.getFiltersFromString(filter);
        for (int z = 0; z < filters.length; z++) {
            if (filters[z].getType().equals(FilterType.ATTRIBUTE)) {
                AttributeFilter cf = ((AttributeFilter) filters[z]);
                IAttributeMap m = cf.getAttributeMap();
                if (m != null && m.size() > 0) {
                    Iterator it = m.iterator();
                    IAttribute a = null;
                    while (it.hasNext()) {
                        a = (IAttribute) it.next();
                        if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
                            cat = a.getValue();
                        }
                    }
                }
            }
        }
        if (cat != null) {
            int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
            MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
            String text = this.getI18nManager().getString("ui.jface.application.editor.action.ImportAction", "assigncategoryconfirm", "label", this.getLanguage());
            text = StringUtils.replaceString(text, "{%1}", cat);
            messageBox.setMessage(text);
            if (messageBox.open() == SWT.YES) {
                category.setValue(cat);
            }
        }
    }
    // determine subfolders
    OutlookTransformer ot = new OutlookTransformer();
    List folders = ot.getAllContactFolders();
    if (folders.size() > 0) {
        int itemCount = 0;
        String folder = null;
        for (int i = 0, j = folders.size(); i < j; i++) {
            folder = (String) folders.get(i);
            itemCount = ot.getContactCount(folder);
            if (itemCount > 0) {
                getRuntime().getConfigManagerFactory().getConfigManager().setProperty(OutlookContactManager.NAMESPACE, "subfolder_" + folder, "true");
            }
        }
        getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
    }
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
    try {
        IRunnableWithProgress r = new IRunnableWithProgress() {

            public void run(IProgressMonitor progressMonitor) {
                progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "importprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                progressMonitor.worked(1);
                OutlookTransformer otf = new OutlookTransformer();
                ICallerList callers = otf.getCallerListFromAllContacts();
                progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "reduce", "label", getLanguage()));
                otf.removeCallerManagerID(callers);
                // determine duplicates
                String currentCallerManagerID = m_app.getApplication().getConfiguration().getProperty(CFG_REPOSITORY);
                if (currentCallerManagerID != null && currentCallerManagerID.trim().length() > 0) {
                    ICallerManager currentCallerManager = getRuntime().getCallerManagerFactory().getCallerManager(currentCallerManagerID);
                    if (currentCallerManager != null && currentCallerManager.isSupported(IWriteCallerRepository.class) && currentCallerManager.isSupported(IIdentifyCallerRepository.class)) {
                        ICallerList addCallers = getRuntime().getCallerFactory().createCallerList();
                        // ICallerList removeCallers = getRuntime().getCallerFactory().createCallerList();
                        ICaller currentCaller = null;
                        String text = null;
                        for (int i = 0, j = callers.size(); i < j; i++) {
                            // ICaller testCaller = null;
                            currentCaller = callers.get(i);
                            text = getI18nManager().getString(getNamespace(), "check", "label", getLanguage());
                            text = StringUtils.replaceString(text, "{%1}", Formatter.getInstance(getRuntime()).parse("%a:ln%, %a:fn%", currentCaller));
                            progressMonitor.setTaskName(text);
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException e1) {
                            }
                            try {
                                // testCaller = ((IIdentifyCallerRepository)currentCallerManager).getCaller(currentCaller.getPhoneNumber());
                                ((IIdentifyCallerRepository) currentCallerManager).getCaller(currentCaller.getPhoneNumber());
                            } catch (CallerNotFoundException e) {
                                if (category != null && category.getValue().length() > 0)
                                    currentCaller.setAttribute(category);
                                addCallers.add(currentCaller);
                            }
                        // if (testCaller!=null) {
                        // removeCallers.add(testCaller);
                        // }
                        }
                        progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "add", "label", getLanguage()));
                        try {
                            Thread.sleep(1250);
                        } catch (InterruptedException e1) {
                        }
                        // if (removeCallers.size()>0)
                        // m_app.getController().deleteElements(removeCallers);
                        m_app.getController().addElements(addCallers);
                    }
                } else {
                    progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "add", "label", getLanguage()));
                    m_app.getController().addElements(callers);
                }
                progressMonitor.done();
            }
        };
        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);
    } catch (InvocationTargetException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    m_app.updateViews(true);
    return;
}
Also used : EditorFilterManager(de.janrufmonitor.ui.jface.application.editor.EditorFilterManager) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) OutlookTransformer(de.janrufmonitor.repository.OutlookTransformer) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) MessageBox(org.eclipse.swt.widgets.MessageBox) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ICallerList(de.janrufmonitor.framework.ICallerList) IFilter(de.janrufmonitor.repository.filter.IFilter) IAttribute(de.janrufmonitor.framework.IAttribute) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) Iterator(java.util.Iterator) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List)

Example 5 with IIdentifyCallerRepository

use of de.janrufmonitor.repository.types.IIdentifyCallerRepository in project janrufmonitor by tbrandt77.

the class OldDatFileCallImporter method parsePhone.

private IPhonenumber parsePhone(String caller) {
    if (caller.indexOf("(0") > -1) {
        IPhonenumber phone = null;
        String pn = caller.substring(caller.indexOf("(0") + 2, caller.lastIndexOf(")"));
        if (pn.length() > 0) {
            phone = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(pn);
            ICallerManager cm = PIMRuntime.getInstance().getCallerManagerFactory().getDefaultCallerManager();
            if (cm != null && cm.isActive() && cm.isSupported(IIdentifyCallerRepository.class)) {
                try {
                    ICaller parsedCaller = ((IIdentifyCallerRepository) cm).getCaller(phone);
                    return parsedCaller.getPhoneNumber();
                } catch (CallerNotFoundException e) {
                    this.m_logger.warning(e.getMessage());
                }
            }
        }
    }
    return PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true);
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IIdentifyCallerRepository (de.janrufmonitor.repository.types.IIdentifyCallerRepository)10 ICaller (de.janrufmonitor.framework.ICaller)9 CallerNotFoundException (de.janrufmonitor.repository.CallerNotFoundException)9 ICallerManager (de.janrufmonitor.repository.ICallerManager)9 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)6 IAttribute (de.janrufmonitor.framework.IAttribute)5 List (java.util.List)3 StringTokenizer (java.util.StringTokenizer)3 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)2 ICallerList (de.janrufmonitor.framework.ICallerList)2 HandlerException (de.janrufmonitor.service.commons.http.handler.HandlerException)2 SerializerException (de.janrufmonitor.util.io.SerializerException)2 OutputStream (java.io.OutputStream)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)1 IName (de.janrufmonitor.framework.IName)1 OutlookTransformer (de.janrufmonitor.repository.OutlookTransformer)1