Search in sources :

Example 1 with ISearchTerm

use of de.janrufmonitor.repository.search.ISearchTerm in project janrufmonitor by tbrandt77.

the class GetCallList method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallManager mgr = null;
    String manager = null;
    boolean isCompression = false;
    try {
        manager = req.getParameter(GetCallList.PARAMETER_CALLMANAGER);
        isCompression = (req.getParameter(GetCallList.PARAMETER_COMPRESSION) != null ? req.getParameter(GetCallList.PARAMETER_COMPRESSION).equalsIgnoreCase("true") : false);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (manager == null)
        mgr = this.getRuntime().getCallManagerFactory().getDefaultCallManager();
    if (manager != null && manager.length() > 0)
        mgr = this.getRuntime().getCallManagerFactory().getCallManager(manager);
    if (mgr == null || !mgr.isActive() || !mgr.isSupported(IReadCallRepository.class)) {
        throw new HandlerException("Requested Callmanager does not exist or is not active.", 404);
    }
    ICallList l = this.getRuntime().getCallFactory().createCallList();
    String filter = null;
    try {
        filter = req.getParameter(GetCallList.PARAMETER_FILTER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    String s = null;
    ISearchTerm[] searchterms = null;
    try {
        s = req.getParameter(GetCallList.PARAMETER_SEARCHTERMS);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (s != null && s.length() > 0) {
        searchterms = new SearchTermSeriarlizer().getSearchTermsFromString(s);
    }
    if (filter == null || filter.length() == 0) {
        this.m_logger.info("Filter parameter &filter= was not set.");
        if (mgr.isSupported(ISearchableCallRepository.class)) {
            l = ((ISearchableCallRepository) mgr).getCalls(getAllowedMsnFilter(req), -1, -1, searchterms);
        } else
            l = ((IReadCallRepository) mgr).getCalls(getAllowedMsnFilter(req));
    } else {
        IFilter[] f = new URLFilterManager().getFiltersFromString(filter);
        f = mergeFilters(f, getAllowedMsnFilter(req));
        if (mgr.isSupported(ISearchableCallRepository.class)) {
            l = ((ISearchableCallRepository) mgr).getCalls(f, -1, -1, searchterms);
        } else
            l = ((IReadCallRepository) mgr).getCalls(f);
    }
    try {
        String xml = XMLSerializer.toXML(l, false);
        if (isCompression && xml.length() > 1024) {
            this.m_logger.info("Compressing requested data.");
            this.m_logger.info("Uncompressed data size [bytes] : " + xml.length());
            xml = CompressBase64.compressBase64Encode(xml);
            this.m_logger.info("Compressed data size [bytes] : " + xml.length());
            resp.setParameter("Content-Type", "application/janrufmonitor-compressed");
            resp.setParameter(GetCallList.PARAMETER_COMPRESSION, "true");
        } else {
            resp.setParameter("Content-Type", "text/xml");
            resp.setParameter(GetCallList.PARAMETER_COMPRESSION, "false");
        }
        resp.setParameter("Content-Length", Long.toString(xml.length()));
        OutputStream ps = resp.getContentStreamForWrite();
        ps.write(xml.getBytes());
        ps.flush();
        ps.close();
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : IReadCallRepository(de.janrufmonitor.repository.types.IReadCallRepository) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) OutputStream(java.io.OutputStream) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICallManager(de.janrufmonitor.repository.ICallManager) ISearchTerm(de.janrufmonitor.repository.search.ISearchTerm) ICallList(de.janrufmonitor.framework.ICallList) IFilter(de.janrufmonitor.repository.filter.IFilter) SearchTermSeriarlizer(de.janrufmonitor.repository.search.SearchTermSeriarlizer)

Example 2 with ISearchTerm

use of de.janrufmonitor.repository.search.ISearchTerm in project janrufmonitor by tbrandt77.

the class JournalController method getSearchTerms.

private ISearchTerm[] getSearchTerms() {
    String st = this.m_configuration.getProperty(CFG_SEARCHTERMS, "");
    if (st != null && st.trim().length() > 0) {
        List terms = new ArrayList();
        StringTokenizer and_t = new StringTokenizer(st, Operator.AND.toString());
        final String[] ands = new String[and_t.countTokens()];
        int i = 0;
        while (and_t.hasMoreTokens()) {
            ands[i] = and_t.nextToken().trim();
            i++;
        }
        for (i = 0; i < ands.length; i++) {
            final String term = ands[i];
            final StringTokenizer or_t = new StringTokenizer(ands[i], Operator.OR.toString());
            if (or_t.countTokens() == 1) {
                terms.add(new ISearchTerm() {

                    public String getSearchTerm() {
                        return term.trim();
                    }

                    public Operator getOperator() {
                        return Operator.AND;
                    }

                    public String toString() {
                        return term + "->" + Operator.AND.toString();
                    }
                });
                or_t.nextToken();
            }
            while (or_t.hasMoreTokens()) {
                final String termo = or_t.nextToken().trim();
                terms.add(new ISearchTerm() {

                    public String toString() {
                        return termo + "->" + Operator.OR.toString();
                    }

                    public String getSearchTerm() {
                        return termo;
                    }

                    public Operator getOperator() {
                        return Operator.OR;
                    }
                });
            }
        }
        ISearchTerm[] s = new ISearchTerm[terms.size()];
        for (int j = terms.size(), k = 0; k < j; k++) {
            s[k] = (ISearchTerm) terms.get(k);
        }
        return s;
    }
    return null;
}
Also used : Operator(de.janrufmonitor.repository.search.Operator) StringTokenizer(java.util.StringTokenizer) ISearchTerm(de.janrufmonitor.repository.search.ISearchTerm) ArrayList(java.util.ArrayList) ICallList(de.janrufmonitor.framework.ICallList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with ISearchTerm

use of de.janrufmonitor.repository.search.ISearchTerm in project janrufmonitor by tbrandt77.

the class GetCallListCount method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallManager mgr = null;
    String manager = null;
    try {
        manager = req.getParameter(GetCallListCount.PARAMETER_CALLMANAGER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (manager == null)
        mgr = this.getRuntime().getCallManagerFactory().getDefaultCallManager();
    if (manager != null && manager.length() > 0)
        mgr = this.getRuntime().getCallManagerFactory().getCallManager(manager);
    if (mgr == null || !mgr.isActive() || !mgr.isSupported(IReadCallRepository.class)) {
        throw new HandlerException("Requested Callmanager does not exist or is not active.", 404);
    }
    String filter = null;
    try {
        filter = req.getParameter(GetCallListCount.PARAMETER_FILTER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    String s = null;
    ISearchTerm[] searchterms = null;
    try {
        s = req.getParameter(GetCallList.PARAMETER_SEARCHTERMS);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (s != null && s.length() > 0) {
        this.m_logger.info("SearchTerms: " + s);
        searchterms = new SearchTermSeriarlizer().getSearchTermsFromString(s);
    }
    int count = 0;
    if (filter == null || filter.length() == 0) {
        this.m_logger.info("Filter parameter &filter= was not set.");
        if (mgr.isSupported(ISearchableCallRepository.class)) {
            count = ((ISearchableCallRepository) mgr).getCallCount(getAllowedMsnFilter(req), searchterms);
        } else
            count = ((IReadCallRepository) mgr).getCallCount(getAllowedMsnFilter(req));
    } else {
        IFilter[] f = new URLFilterManager().getFiltersFromString(filter);
        f = mergeFilters(f, getAllowedMsnFilter(req));
        if (mgr.isSupported(ISearchableCallRepository.class)) {
            count = ((ISearchableCallRepository) mgr).getCallCount(f, searchterms);
        } else
            count = ((IReadCallRepository) mgr).getCallCount(f);
    }
    try {
        String xml = Integer.toString(count);
        resp.setParameter("Content-Type", "text/plain");
        resp.setParameter("Content-Length", Long.toString(xml.length()));
        OutputStream ps = resp.getContentStreamForWrite();
        ps.write(xml.getBytes());
        ps.flush();
        ps.close();
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : IReadCallRepository(de.janrufmonitor.repository.types.IReadCallRepository) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) OutputStream(java.io.OutputStream) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICallManager(de.janrufmonitor.repository.ICallManager) ISearchTerm(de.janrufmonitor.repository.search.ISearchTerm) IFilter(de.janrufmonitor.repository.filter.IFilter) SearchTermSeriarlizer(de.janrufmonitor.repository.search.SearchTermSeriarlizer)

Example 4 with ISearchTerm

use of de.janrufmonitor.repository.search.ISearchTerm in project janrufmonitor by tbrandt77.

the class GetCallerList method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallerManager mgr = null;
    String manager = null;
    boolean isCompression = false;
    try {
        manager = req.getParameter(GetCallerList.PARAMETER_CALLERMANAGER);
        isCompression = (req.getParameter(GetCallList.PARAMETER_COMPRESSION) != null ? req.getParameter(GetCallList.PARAMETER_COMPRESSION).equalsIgnoreCase("true") : false);
    } 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(IReadCallerRepository.class)) {
        throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
    }
    ICallerList l = this.getRuntime().getCallerFactory().createCallerList();
    String filter = null;
    try {
        filter = req.getParameter(GetCallerList.PARAMETER_FILTER);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    String s = null;
    ISearchTerm[] searchterms = null;
    try {
        s = req.getParameter(GetCallList.PARAMETER_SEARCHTERMS);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (s != null && s.length() > 0) {
        searchterms = new SearchTermSeriarlizer().getSearchTermsFromString(s);
    }
    if (filter == null || filter.length() == 0) {
        if (mgr.isSupported(ISearchableCallerRepository.class)) {
            l = ((ISearchableCallerRepository) mgr).getCallers(new IFilter[] {}, searchterms);
        } else
            l = ((IReadCallerRepository) mgr).getCallers((IFilter) null);
        this.m_logger.info("Filter parameter &filter= was not set.");
    } else {
        IFilter[] f = new URLFilterManager().getFiltersFromString(filter);
        if (mgr.isSupported(ISearchableCallerRepository.class)) {
            l = ((ISearchableCallerRepository) mgr).getCallers(f, searchterms);
        } else
            l = ((IReadCallerRepository) mgr).getCallers(f);
    }
    try {
        String xml = XMLSerializer.toXML(l, false);
        if (isCompression && xml.length() > 1024) {
            this.m_logger.info("Compressing requested data.");
            this.m_logger.info("Uncompressed data size [bytes] : " + xml.length());
            xml = CompressBase64.compressBase64Encode(xml);
            this.m_logger.info("Compressed data size [bytes] : " + xml.length());
            resp.setParameter("Content-Type", "application/janrufmonitor-compressed");
            resp.setParameter(GetCallList.PARAMETER_COMPRESSION, "true");
        } else {
            resp.setParameter("Content-Type", "text/xml");
            resp.setParameter(GetCallList.PARAMETER_COMPRESSION, "false");
        }
        resp.setParameter("Content-Length", Long.toString(xml.length()));
        OutputStream ps = resp.getContentStreamForWrite();
        ps.write(xml.getBytes());
        ps.flush();
        ps.close();
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) OutputStream(java.io.OutputStream) IReadCallerRepository(de.janrufmonitor.repository.types.IReadCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ISearchTerm(de.janrufmonitor.repository.search.ISearchTerm) ICallerList(de.janrufmonitor.framework.ICallerList) IFilter(de.janrufmonitor.repository.filter.IFilter) SearchTermSeriarlizer(de.janrufmonitor.repository.search.SearchTermSeriarlizer)

Example 5 with ISearchTerm

use of de.janrufmonitor.repository.search.ISearchTerm in project janrufmonitor by tbrandt77.

the class HsqldbCallDatabaseHandler method createSearchTerm.

private String createSearchTerm(ISearchTerm[] searchTerms) {
    if (searchTerms == null)
        return "";
    if (searchTerms.length == 0)
        return "";
    StringBuffer sql = new StringBuffer();
    sql.append(" (");
    ISearchTerm st = null;
    for (int i = 0, j = searchTerms.length; i < j; i++) {
        st = searchTerms[i];
        sql.append("LOWER(content) like LOWER('%");
        // remove % signs in search term
        sql.append(StringUtils.replaceString(st.getSearchTerm(), "%", ""));
        sql.append("%')");
        if (i < (j - 1)) {
            sql.append(" ");
            sql.append(st.getOperator().toString());
            sql.append(" ");
        }
    }
    sql.append(")");
    return sql.toString();
}
Also used : ISearchTerm(de.janrufmonitor.repository.search.ISearchTerm)

Aggregations

ISearchTerm (de.janrufmonitor.repository.search.ISearchTerm)6 IFilter (de.janrufmonitor.repository.filter.IFilter)3 SearchTermSeriarlizer (de.janrufmonitor.repository.search.SearchTermSeriarlizer)3 HandlerException (de.janrufmonitor.service.commons.http.handler.HandlerException)3 OutputStream (java.io.OutputStream)3 ICallList (de.janrufmonitor.framework.ICallList)2 ICallManager (de.janrufmonitor.repository.ICallManager)2 IReadCallRepository (de.janrufmonitor.repository.types.IReadCallRepository)2 ICallerList (de.janrufmonitor.framework.ICallerList)1 ICallerManager (de.janrufmonitor.repository.ICallerManager)1 Operator (de.janrufmonitor.repository.search.Operator)1 IReadCallerRepository (de.janrufmonitor.repository.types.IReadCallerRepository)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1