Search in sources :

Example 1 with IReadCallerRepository

use of de.janrufmonitor.repository.types.IReadCallerRepository 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 2 with IReadCallerRepository

use of de.janrufmonitor.repository.types.IReadCallerRepository 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 3 with IReadCallerRepository

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

the class CallerReaderFactory method getAllCallers.

public List getAllCallers() {
    if (m_list == null) {
        List managers = this.getActiveCallerManagers();
        ICallerList list = PIMRuntime.getInstance().getCallerFactory().createCallerList();
        ICallerList manList = null;
        ICallerManager man = null;
        for (int i = 0; i < managers.size(); i++) {
            man = (ICallerManager) managers.get(i);
            if (man != null && man.isActive() && man.isSupported(IReadCallerRepository.class)) {
                this.m_currentCM = man;
                manList = ((IReadCallerRepository) man).getCallers((IFilter) null);
                list.add(unMultiPhoneCaller(manList, managers));
            }
        }
        list.sort(CallerListComparator.ORDER_CALLERNAME, false);
        m_list = new ArrayList();
        m_list.add(PIMRuntime.getInstance().getCallerFactory().createCaller(PIMRuntime.getInstance().getCallerFactory().createName("", ""), PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true)));
        // added 2009/04/18: added internal numbers
        m_list.add(PIMRuntime.getInstance().getCallerFactory().createCaller(PIMRuntime.getInstance().getCallerFactory().createName("", ""), PIMRuntime.getInstance().getCallerFactory().createPhonenumber(IJAMConst.INTERNAL_CALL, "", IJAMConst.INTERNAL_CALL_NUMBER_SYMBOL)));
        for (int i = list.size() - 1; i >= 0; i--) {
            m_list.add(list.get(i));
        }
    }
    this.m_currentCM = null;
    return m_list;
}
Also used : ICallerList(de.janrufmonitor.framework.ICallerList) IFilter(de.janrufmonitor.repository.filter.IFilter) ArrayList(java.util.ArrayList) IReadCallerRepository(de.janrufmonitor.repository.types.IReadCallerRepository) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) ArrayList(java.util.ArrayList) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Aggregations

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