Search in sources :

Example 1 with SearchTermSeriarlizer

use of de.janrufmonitor.repository.search.SearchTermSeriarlizer 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 SearchTermSeriarlizer

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

the class EditorController method buildControllerData.

private void buildControllerData() {
    ICallerManager cm = this._getRepository();
    if (cm != null && cm.isActive() && cm.isSupported(IReadCallerRepository.class)) {
        if (cm.isSupported(ISearchableCallerRepository.class)) {
            this.m_data = ((ISearchableCallerRepository) cm).getCallers(new IFilter[] { this.getFilter() }, new SearchTermSeriarlizer().getSearchTermsFromString(StringUtils.urlEncode(this.m_configuration.getProperty(CFG_SEARCHTERMS, ""))));
        } else {
            this.m_data = ((IReadCallerRepository) cm).getCallers(this.getFilter());
        }
        if (this.m_data == null)
            this.m_data = this.getRuntime().getCallerFactory().createCallerList();
        this.doSorting();
        List lastnames = new ArrayList(26);
        List cities = new ArrayList(26);
        List pcode = new ArrayList(9);
        List countries = new ArrayList(12);
        ICaller c = null;
        for (int i = 0; i < this.m_data.size(); i++) {
            c = this.m_data.get(i);
            if (c instanceof ICaller) {
                if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_LASTNAME) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue().trim().length() > 0) {
                    if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue().substring(0, 1).toUpperCase()))
                        lastnames.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue().substring(0, 1).toUpperCase());
                }
                if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_CITY) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_CITY).getValue().trim().length() > 0) {
                    if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_CITY).getValue().substring(0, 1).toUpperCase()))
                        cities.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_CITY).getValue().substring(0, 1).toUpperCase());
                }
                if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue().trim().length() > 0) {
                    if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue().substring(0, 1).toUpperCase()))
                        pcode.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue().substring(0, 1).toUpperCase());
                }
                if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_COUNTRY) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue().trim().length() > 0) {
                    if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue().substring(0, 1).toUpperCase()))
                        countries.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue().substring(0, 1).toUpperCase());
                }
            }
        }
        Collections.sort(lastnames);
        Collections.sort(cities);
        Collections.sort(pcode);
        Collections.sort(countries);
        for (int i = 0; i < lastnames.size(); i++) {
            this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "_" + (String) lastnames.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "=" + (String) lastnames.get(i) + ")");
            this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "_" + (String) lastnames.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "=" + (String) lastnames.get(i) + ")");
        }
        for (int i = 0; i < cities.size(); i++) {
            this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_CITY + "_" + (String) cities.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_CITY + "=" + (String) cities.get(i) + ")");
            this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_CITY + "_" + (String) cities.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_CITY + "=" + (String) cities.get(i) + ")");
        }
        for (int i = 0; i < pcode.size(); i++) {
            this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE + "_" + (String) pcode.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE + "=" + (String) pcode.get(i) + ")");
            this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE + "_" + (String) pcode.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "=" + (String) pcode.get(i) + ")");
        }
        for (int i = 0; i < countries.size(); i++) {
            this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "_" + (String) countries.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "=" + (String) countries.get(i) + ")");
            this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "_" + (String) countries.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "=" + (String) countries.get(i) + ")");
        }
        this.getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
    }
    if (this.m_data == null)
        this.m_data = this.getRuntime().getCallerFactory().createCallerList();
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) IFilter(de.janrufmonitor.repository.filter.IFilter) ArrayList(java.util.ArrayList) IReadCallerRepository(de.janrufmonitor.repository.types.IReadCallerRepository) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) ICallerManager(de.janrufmonitor.repository.ICallerManager) SearchTermSeriarlizer(de.janrufmonitor.repository.search.SearchTermSeriarlizer)

Example 3 with SearchTermSeriarlizer

use of de.janrufmonitor.repository.search.SearchTermSeriarlizer 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 SearchTermSeriarlizer

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

Aggregations

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