Search in sources :

Example 6 with ICallerManager

use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.

the class LastOpenEditorAction method getLastopenedRepositories.

private List getLastopenedRepositories() {
    List cms = new ArrayList();
    Properties config = getRuntime().getConfigManagerFactory().getConfigManager().getProperties(NAMESPACE);
    String lastOpen = config.getProperty(EditorConfigConst.CFG_LASTOPEN, "");
    if (lastOpen.length() > 0) {
        String[] locm = lastOpen.split(";");
        if (locm != null && locm.length > 0) {
            String l = null;
            for (int i = 0; i < locm.length; i++) {
                l = locm[i];
                if (l.split("%").length == 1) {
                    ICallerManager mgr = getRuntime().getCallerManagerFactory().getCallerManager(l.split("%")[0]);
                    if (mgr != null && mgr.isActive() && mgr.isSupported(IRemoteRepository.class)) {
                        cms.add(new RemoteAction((IRemoteRepository) mgr));
                    }
                    continue;
                }
                if (l.split("%").length == 2) {
                    ICallerManager mgr = getRuntime().getCallerManagerFactory().getCallerManager(l.split("%")[0]);
                    if (mgr != null && mgr.isActive() && mgr.isSupported(ILocalRepository.class)) {
                        if (new File(l.split("%")[1]).exists())
                            cms.add(new LocalAction((ILocalRepository) mgr, l.split("%")[1]));
                    }
                }
            }
        }
    }
    return cms;
}
Also used : IRemoteRepository(de.janrufmonitor.repository.types.IRemoteRepository) ArrayList(java.util.ArrayList) ILocalRepository(de.janrufmonitor.repository.types.ILocalRepository) ArrayList(java.util.ArrayList) List(java.util.List) Properties(java.util.Properties) File(java.io.File) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Example 7 with ICallerManager

use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.

the class UpdateCallerList method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallerManager mgr = null;
    String manager = null;
    try {
        manager = req.getParameter(UpdateCallerList.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(IWriteCallerRepository.class)) {
        throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
    }
    ICallerList l;
    try {
        l = XMLSerializer.toCallerList(this.getPostData(req));
        if (l != null) {
            this.m_logger.info("Updating caller list with " + l.size() + " entries.");
            for (int i = 0, j = l.size(); i < j; i++) ((IWriteCallerRepository) mgr).updateCaller(l.get(i));
            resp.getContentStreamForWrite().close();
        } else {
            this.m_logger.severe("Invalid caller list transfered from client.");
            throw new HandlerException("Invalid caller list transfered from client.", 500);
        }
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICallerList(de.janrufmonitor.framework.ICallerList) ICallerManager(de.janrufmonitor.repository.ICallerManager) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException)

Example 8 with ICallerManager

use of de.janrufmonitor.repository.ICallerManager 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 9 with ICallerManager

use of de.janrufmonitor.repository.ICallerManager 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 10 with ICallerManager

use of de.janrufmonitor.repository.ICallerManager 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)

Aggregations

ICallerManager (de.janrufmonitor.repository.ICallerManager)31 List (java.util.List)15 ArrayList (java.util.ArrayList)14 ICallerList (de.janrufmonitor.framework.ICallerList)13 ICaller (de.janrufmonitor.framework.ICaller)12 IIdentifyCallerRepository (de.janrufmonitor.repository.types.IIdentifyCallerRepository)11 CallerNotFoundException (de.janrufmonitor.repository.CallerNotFoundException)9 IWriteCallerRepository (de.janrufmonitor.repository.types.IWriteCallerRepository)7 IAttribute (de.janrufmonitor.framework.IAttribute)6 HandlerException (de.janrufmonitor.service.commons.http.handler.HandlerException)6 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)5 IFilter (de.janrufmonitor.repository.filter.IFilter)4 RepositoryManagerComparator (de.janrufmonitor.repository.RepositoryManagerComparator)3 ILocalRepository (de.janrufmonitor.repository.types.ILocalRepository)3 IReadCallerRepository (de.janrufmonitor.repository.types.IReadCallerRepository)3 File (java.io.File)3 OutputStream (java.io.OutputStream)3 StringTokenizer (java.util.StringTokenizer)3 Shell (org.eclipse.swt.widgets.Shell)3 IConfigurable (de.janrufmonitor.framework.configuration.IConfigurable)2