Search in sources :

Example 21 with IFilter

use of de.janrufmonitor.repository.filter.IFilter in project janrufmonitor by tbrandt77.

the class History method getConfiguration.

public Properties getConfiguration() {
    Properties saved = super.getConfiguration();
    Properties journalConfig = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(Journal.NAMESPACE);
    if (journalConfig != null && journalConfig.size() > 0) {
        saved.setProperty(JournalConfigConst.CFG_REPOSITORY, journalConfig.getProperty(JournalConfigConst.CFG_REPOSITORY));
    }
    IFilter[] filters = null;
    if (this.m_caller instanceof IMultiPhoneCaller) {
        filters = new IFilter[((IMultiPhoneCaller) this.m_caller).getPhonenumbers().size()];
        for (int i = 0, j = ((IMultiPhoneCaller) this.m_caller).getPhonenumbers().size(); i < j; i++) {
            filters[i] = new PhonenumberFilter((IPhonenumber) ((IMultiPhoneCaller) this.m_caller).getPhonenumbers().get(i));
        }
    } else {
        filters = new IFilter[1];
        if (this.m_caller != null)
            filters[0] = new PhonenumberFilter(this.m_caller.getPhoneNumber());
    }
    saved.setProperty("filter", new JournalFilterManager().getFiltersToString(filters));
    return saved;
}
Also used : IFilter(de.janrufmonitor.repository.filter.IFilter) PhonenumberFilter(de.janrufmonitor.repository.filter.PhonenumberFilter) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) JournalFilterManager(de.janrufmonitor.ui.jface.application.journal.JournalFilterManager) Properties(java.util.Properties) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 22 with IFilter

use of de.janrufmonitor.repository.filter.IFilter 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 23 with IFilter

use of de.janrufmonitor.repository.filter.IFilter in project janrufmonitor by tbrandt77.

the class GetCallListCount method mergeFilters.

private IFilter[] mergeFilters(IFilter[] urlFilters, IFilter[] allowedMsnFilter) {
    if (urlFilters == null || urlFilters.length == 0)
        return allowedMsnFilter;
    if (allowedMsnFilter == null || allowedMsnFilter.length == 0)
        return urlFilters;
    List filters = new ArrayList();
    for (int i = 0; i < allowedMsnFilter.length; i++) {
        filters.add(allowedMsnFilter[i]);
    }
    for (int i = 0; i < urlFilters.length; i++) {
        if (urlFilters[i].getType() != FilterType.MSN)
            filters.add(urlFilters[i]);
    }
    m_logger.info("Merged list auf filters: " + filters.toString());
    IFilter[] f = new IFilter[filters.size()];
    for (int i = 0; i < filters.size(); i++) {
        f[i] = (IFilter) filters.get(i);
    }
    return f;
}
Also used : IFilter(de.janrufmonitor.repository.filter.IFilter) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 24 with IFilter

use of de.janrufmonitor.repository.filter.IFilter in project janrufmonitor by tbrandt77.

the class GetCallList method getAllowedMsnFilter.

private IFilter[] getAllowedMsnFilter(IHttpRequest req) throws HandlerException {
    try {
        boolean allowedForAllMsns = (SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostName()) == null && SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostAddress()) == null);
        if (!allowedForAllMsns) {
            String[] allowedMSNs = SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostName());
            if (allowedMSNs == null)
                allowedMSNs = SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostAddress());
            if (allowedMSNs != null) {
                IFilter[] allowedMsnFilter = new IFilter[allowedMSNs.length];
                IMsn msn = null;
                for (int i = 0; i < allowedMSNs.length; i++) {
                    msn = getRuntime().getMsnManager().createMsn(allowedMSNs[i]);
                    allowedMsnFilter[i] = new MsnFilter(msn);
                    m_logger.info("Adding allowed MSN filter for client: " + allowedMsnFilter[i].toString());
                }
                return allowedMsnFilter;
            }
        }
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
        throw new HandlerException(e.getMessage(), 500);
    }
    return new IFilter[0];
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) IFilter(de.janrufmonitor.repository.filter.IFilter) MsnFilter(de.janrufmonitor.repository.filter.MsnFilter) IMsn(de.janrufmonitor.framework.IMsn) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException)

Example 25 with IFilter

use of de.janrufmonitor.repository.filter.IFilter 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)33 List (java.util.List)15 ArrayList (java.util.ArrayList)12 Iterator (java.util.Iterator)10 ICallList (de.janrufmonitor.framework.ICallList)8 IAttribute (de.janrufmonitor.framework.IAttribute)7 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)7 ICallerList (de.janrufmonitor.framework.ICallerList)7 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)7 ICaller (de.janrufmonitor.framework.ICaller)6 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)6 IReadCallRepository (de.janrufmonitor.repository.types.IReadCallRepository)6 Properties (java.util.Properties)6 Message (de.janrufmonitor.exception.Message)5 ICallManager (de.janrufmonitor.repository.ICallManager)5 HandlerException (de.janrufmonitor.service.commons.http.handler.HandlerException)5 JournalFilterManager (de.janrufmonitor.ui.jface.application.journal.JournalFilterManager)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IMsn (de.janrufmonitor.framework.IMsn)4 ICallerManager (de.janrufmonitor.repository.ICallerManager)4