Search in sources :

Example 1 with ICallManager

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

the class LastCalled method renderAsText.

public String renderAsText() {
    if (this.m_o != null) {
        if (this.m_o instanceof ICaller) {
            this.m_o = new TreeItemCallerData(((ICaller) this.m_o).getAttributes(), ((ICaller) this.m_o).getPhoneNumber());
        }
        if (this.m_o instanceof ITreeItemCallerData) {
            IPhonenumber pn = ((ITreeItemCallerData) m_o).getPhone();
            List cms = PIMRuntime.getInstance().getCallManagerFactory().getTypedCallManagers(IReadCallRepository.class);
            if (cms.size() > 0) {
                ICallManager cm = null;
                for (int i = 0, j = cms.size(); i < j; i++) {
                    cm = (ICallManager) cms.get(i);
                    if (cm.isActive() && cm.isSupported(IReadCallRepository.class)) {
                        IFilter[] filters = new IFilter[] { new PhonenumberFilter(pn), new ItemCountFilter(1) };
                        ICallList cl = ((IReadCallRepository) cm).getCalls(filters, 1, 0);
                        cl.sort(0, false);
                        if (cl.size() > 0) {
                            ICall c = cl.get(0);
                            return getFormatter().parse(IJAMConst.GLOBAL_VARIABLE_CALLTIME, c.getDate());
                        }
                    }
                }
            }
        }
    }
    return "";
}
Also used : IReadCallRepository(de.janrufmonitor.repository.types.IReadCallRepository) ICall(de.janrufmonitor.framework.ICall) ICallManager(de.janrufmonitor.repository.ICallManager) ICaller(de.janrufmonitor.framework.ICaller) IFilter(de.janrufmonitor.repository.filter.IFilter) ItemCountFilter(de.janrufmonitor.repository.filter.ItemCountFilter) ICallList(de.janrufmonitor.framework.ICallList) PhonenumberFilter(de.janrufmonitor.repository.filter.PhonenumberFilter) ICallList(de.janrufmonitor.framework.ICallList) List(java.util.List) ITreeItemCallerData(de.janrufmonitor.ui.jface.application.ITreeItemCallerData) ITreeItemCallerData(de.janrufmonitor.ui.jface.application.ITreeItemCallerData) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 2 with ICallManager

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

the class GetCall method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    ICallManager mgr = null;
    String manager = null;
    try {
        manager = req.getParameter(GetCall.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 uuid = null;
    try {
        uuid = req.getParameter(GetCall.PARAMETER_UUID);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
    if (uuid == null || uuid.length() == 0) {
        this.m_logger.severe("Parameter &uuid= was empty or not set.");
        throw new HandlerException("Parameter &uuid= was empty or not set.", 404);
    }
    try {
        ICallList callList = ((IReadCallRepository) mgr).getCalls(new UUIDFilter(new String[] { uuid }));
        if (callList.size() > 0) {
            String xml = XMLSerializer.toXML(callList.get(0), false);
            resp.setParameter("Content-Type", "text/xml");
            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 : ICallManager(de.janrufmonitor.repository.ICallManager) IReadCallRepository(de.janrufmonitor.repository.types.IReadCallRepository) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) ICallList(de.janrufmonitor.framework.ICallList) UUIDFilter(de.janrufmonitor.repository.filter.UUIDFilter) OutputStream(java.io.OutputStream) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException)

Example 3 with ICallManager

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

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

the class SetCallList 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 Callermanager 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("Setting call list with " + l.size() + " entries.");
            ((IWriteCallRepository) mgr).setCalls(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)

Example 5 with ICallManager

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

the class GeoCoding method receivedValidRule.

public void receivedValidRule(ICall call) {
    if (call == null)
        return;
    if (call.getCaller().getPhoneNumber().isClired())
        return;
    ICaller caller = call.getCaller();
    if (caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT) != null && caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG) != null) {
        this.m_logger.info("Call already set with geo data ...");
        return;
    }
    Point p = GeoCoder.getInstance().getCoordinates(caller.getAttributes());
    if (p != null) {
        caller.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_ACC, Integer.toString(p.getAccurance())));
        caller.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT, Double.toString(p.getLatitude())));
        caller.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG, Double.toString(p.getLongitude())));
        List callManagerList = this.getRuntime().getCallManagerFactory().getAllCallManagers();
        ICallManager icm = null;
        IEventBroker eventBroker = this.getRuntime().getEventBroker();
        for (int i = 0; i < callManagerList.size(); i++) {
            icm = (ICallManager) callManagerList.get(i);
            // check if the repository manager allows read/write access
            if (icm.isActive() && icm.isSupported(IWriteCallRepository.class)) {
                ((IWriteCallRepository) icm).updateCall(call);
                this.m_logger.info("Call update sent with geocoding: " + call);
                eventBroker.send(this, eventBroker.createEvent(IEventConst.EVENT_TYPE_UPDATE_CALL, call));
            }
        }
    } else {
        this.m_logger.info("Geocoding not successfully for call: " + call);
    }
}
Also used : ICallManager(de.janrufmonitor.repository.ICallManager) ICaller(de.janrufmonitor.framework.ICaller) List(java.util.List) Point(de.janrufmonitor.util.math.Point) IEventBroker(de.janrufmonitor.framework.event.IEventBroker) Point(de.janrufmonitor.util.math.Point) 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