Search in sources :

Example 1 with UUIDFilter

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

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

the class Journaling method receivedOtherEventCall.

public void receivedOtherEventCall(IEvent event) {
    if (event.getType() == IEventConst.EVENT_TYPE_CALLACCEPTED || event.getType() == IEventConst.EVENT_TYPE_CALLCLEARED || event.getType() == IEventConst.EVENT_TYPE_MANUALCALLACCEPTED || event.getType() == IEventConst.EVENT_TYPE_CALLREJECTED || event.getType() == IEventConst.EVENT_TYPE_CALLMARKEDSPAM || event.getType() == IEventConst.EVENT_TYPE_IDENTIFIED_OUTGOING_CALL_ACCEPTED) {
        // checks wether this service is available for the incoming MSN or not.
        ICall updateCall = (ICall) event.getData();
        if (updateCall == null) {
            this.m_logger.warning("Call reference is null.");
            return;
        }
        if (this.getRuntime().getRuleEngine().validate(this.ID, updateCall.getMSN(), updateCall.getCIP(), updateCall.getCaller().getPhoneNumber())) {
            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)) {
                    // try to keep old attribute information of call and caller
                    if (icm.isSupported(IReadCallRepository.class)) {
                        this.m_logger.info("Call manager <" + icm.getManagerID() + "> is supporting read mode.");
                        ICallList cl = ((IReadCallRepository) icm).getCalls(new UUIDFilter(new String[] { updateCall.getUUID() }));
                        if (cl.size() == 1) {
                            this.m_logger.info("Found exact 1 old call in call manager <" + icm.getManagerID() + "> with UUID " + updateCall.getUUID());
                            ICall oldCall = cl.get(0);
                            if (oldCall != null) {
                                this.m_logger.info("Setting old call info : " + oldCall + " to new call : " + updateCall);
                                oldCall.getCaller().getAttributes().addAll(updateCall.getCaller().getAttributes());
                                oldCall.getAttributes().addAll(updateCall.getAttributes());
                                updateCall = oldCall;
                                this.m_logger.info("Updated new call : " + updateCall);
                            }
                        }
                    }
                    ((IWriteCallRepository) icm).updateCall(updateCall);
                    this.m_logger.info("Call update sent to repository manager <" + icm.getManagerID() + ">: " + updateCall);
                    eventBroker.send(this, eventBroker.createEvent(IEventConst.EVENT_TYPE_UPDATE_CALL, updateCall));
                }
            }
        }
    }
}
Also used : ICallManager(de.janrufmonitor.repository.ICallManager) IReadCallRepository(de.janrufmonitor.repository.types.IReadCallRepository) ICall(de.janrufmonitor.framework.ICall) ICallList(de.janrufmonitor.framework.ICallList) UUIDFilter(de.janrufmonitor.repository.filter.UUIDFilter) ICallList(de.janrufmonitor.framework.ICallList) List(java.util.List) IEventBroker(de.janrufmonitor.framework.event.IEventBroker) IWriteCallRepository(de.janrufmonitor.repository.types.IWriteCallRepository)

Aggregations

ICallList (de.janrufmonitor.framework.ICallList)2 ICallManager (de.janrufmonitor.repository.ICallManager)2 UUIDFilter (de.janrufmonitor.repository.filter.UUIDFilter)2 IReadCallRepository (de.janrufmonitor.repository.types.IReadCallRepository)2 ICall (de.janrufmonitor.framework.ICall)1 IEventBroker (de.janrufmonitor.framework.event.IEventBroker)1 IWriteCallRepository (de.janrufmonitor.repository.types.IWriteCallRepository)1 HandlerException (de.janrufmonitor.service.commons.http.handler.HandlerException)1 OutputStream (java.io.OutputStream)1 List (java.util.List)1