Search in sources :

Example 6 with ICallManager

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

the class JournalController method _getRepository.

private ICallManager _getRepository() {
    String managerID = this.m_configuration.getProperty(CFG_REPOSITORY, "");
    if (managerID.length() > 0) {
        ICallManager cm = this.getRuntime().getCallManagerFactory().getCallManager(managerID);
        if (cm != null)
            return cm;
    }
    this.m_logger.severe("CallManager with ID " + managerID + " does not exist.");
    return null;
}
Also used : ICallManager(de.janrufmonitor.repository.ICallManager)

Example 7 with ICallManager

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

the class JournalController method updateElement.

public synchronized void updateElement(Object call, boolean isUpdateAll) {
    if (call instanceof ICall) {
        ICallManager cm = this._getRepository();
        if (cm != null && cm.isActive() && cm.isSupported(IReadCallRepository.class) && cm.isSupported(IWriteCallRepository.class)) {
            ICaller caller = ((ICall) call).getCaller();
            if (!caller.getPhoneNumber().isClired() && isUpdateAll) {
                ICallList cl = ((IReadCallRepository) cm).getCalls(new CallerFilter(caller));
                ICall aCall = null;
                for (int i = cl.size() - 1; i >= 0; i--) {
                    aCall = cl.get(i);
                    aCall.setCaller(caller);
                }
                ((IWriteCallRepository) cm).updateCalls(cl);
            } else {
                // update a single CLIR call or isUpdateAll == false
                if (cm.isSupported(IWriteCallRepository.class))
                    ((IWriteCallRepository) cm).updateCall((ICall) call);
            }
        }
    }
}
Also used : ICallManager(de.janrufmonitor.repository.ICallManager) ICaller(de.janrufmonitor.framework.ICaller) IReadCallRepository(de.janrufmonitor.repository.types.IReadCallRepository) ICall(de.janrufmonitor.framework.ICall) ICallList(de.janrufmonitor.framework.ICallList) CallerFilter(de.janrufmonitor.repository.filter.CallerFilter) IWriteCallRepository(de.janrufmonitor.repository.types.IWriteCallRepository)

Example 8 with ICallManager

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

the class JournalController method deleteAllElements.

public synchronized void deleteAllElements() {
    ICallManager cm = this._getRepository();
    if (cm != null && this.m_data != null && cm.isActive() && cm.isSupported(IWriteCallRepository.class)) {
        ((IWriteCallRepository) cm).removeCalls(this.m_data);
        this.m_data = null;
    }
}
Also used : ICallManager(de.janrufmonitor.repository.ICallManager) IWriteCallRepository(de.janrufmonitor.repository.types.IWriteCallRepository)

Example 9 with ICallManager

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

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

the class RemoveCallList method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallManager mgr = null;
    String manager = null;
    boolean isCompression = false;
    try {
        manager = req.getParameter(RemoveCallList.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(IWriteCallRepository.class)) {
        throw new HandlerException("Requested Callmanager does not exist or is not active.", 404);
    }
    ICallList l;
    try {
        byte[] data = this.getPostData(req).getBytes();
        if (isCompression) {
            data = CompressBase64.decompressBase64Decode(data);
        }
        l = XMLSerializer.toCallList(new String(data));
        if (l != null) {
            this.m_logger.info("Removing call list with " + l.size() + " entries.");
            ((IWriteCallRepository) mgr).removeCalls(l);
            resp.getContentStreamForWrite().close();
        } else {
            this.m_logger.severe("Invalid call list transfered from client.");
            throw new HandlerException("Invalid call list transfered from client.", 500);
        }
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : ICallManager(de.janrufmonitor.repository.ICallManager) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICallList(de.janrufmonitor.framework.ICallList) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) IWriteCallRepository(de.janrufmonitor.repository.types.IWriteCallRepository)

Aggregations

ICallManager (de.janrufmonitor.repository.ICallManager)18 ICallList (de.janrufmonitor.framework.ICallList)12 IWriteCallRepository (de.janrufmonitor.repository.types.IWriteCallRepository)10 IReadCallRepository (de.janrufmonitor.repository.types.IReadCallRepository)8 List (java.util.List)6 IFilter (de.janrufmonitor.repository.filter.IFilter)5 HandlerException (de.janrufmonitor.service.commons.http.handler.HandlerException)5 ICall (de.janrufmonitor.framework.ICall)4 ICaller (de.janrufmonitor.framework.ICaller)3 IEventBroker (de.janrufmonitor.framework.event.IEventBroker)3 OutputStream (java.io.OutputStream)3 UUIDFilter (de.janrufmonitor.repository.filter.UUIDFilter)2 ISearchTerm (de.janrufmonitor.repository.search.ISearchTerm)2 SearchTermSeriarlizer (de.janrufmonitor.repository.search.SearchTermSeriarlizer)2 ILocalRepository (de.janrufmonitor.repository.types.ILocalRepository)2 IRemoteRepository (de.janrufmonitor.repository.types.IRemoteRepository)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 Message (de.janrufmonitor.exception.Message)1