Search in sources :

Example 1 with IWriteCallRepository

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

the class Refresh method isEnabled.

public boolean isEnabled() {
    Properties cfg = getRuntime().getConfigManagerFactory().getConfigManager().getProperties(NAMESPACE);
    boolean isEnabled = Boolean.parseBoolean(cfg.getProperty("enabled", "false"));
    if (!isEnabled)
        return false;
    if (this.m_app != null && this.m_app.getController() != null) {
        Object o = this.m_app.getController().getRepository();
        return (o instanceof IWriteCallRepository);
    }
    return false;
}
Also used : Properties(java.util.Properties) IWriteCallRepository(de.janrufmonitor.repository.types.IWriteCallRepository)

Example 2 with IWriteCallRepository

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

use of de.janrufmonitor.repository.types.IWriteCallRepository 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)

Example 4 with IWriteCallRepository

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

the class ArchiveJournal method startArchiving.

private void startArchiving() {
    if (m_archivingThread == null || !m_archivingThread.isAlive()) {
        m_archivingThread = new Thread(new Runnable() {

            public void run() {
                String currentRepository = getRuntime().getConfigManagerFactory().getConfigManager().getProperty("ui.jface.application.journal.Journal", "repository");
                if (currentRepository != null && currentRepository.length() > 0) {
                    ICallManager cmg = getRuntime().getCallManagerFactory().getCallManager(currentRepository);
                    if (!currentRepository.equalsIgnoreCase(ID) && cmg != null && cmg.isActive() && cmg.isSupported(IReadCallRepository.class) && cmg.isSupported(IWriteCallRepository.class)) {
                        long timeframe = Long.parseLong(m_configuration.getProperty(CFG_TIMEFRAME, "0"));
                        if (timeframe > 0) {
                            try {
                                Thread.sleep(10000);
                            } catch (InterruptedException e1) {
                            }
                            long time = System.currentTimeMillis() - (timeframe * 86400000L);
                            IFilter tf = new DateFilter(new Date(time), new Date(0));
                            ICallList cl = ((IReadCallRepository) cmg).getCalls(tf);
                            if (cl.size() > 0) {
                                try {
                                    getDatabaseHandler().setCallList(cl);
                                    ((IWriteCallRepository) cmg).removeCalls(cl);
                                    // added 2010/12/06: added due to high memory consumption
                                    getDatabaseHandler().commit();
                                    getDatabaseHandler().disconnect();
                                    getRuntime().getConfigManagerFactory().getConfigManager().setProperty(NAMESPACE, "lastrun", Long.toString(System.currentTimeMillis()));
                                    getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
                                    String root = PathResolver.getInstance(getRuntime()).resolve(m_configuration.getProperty(CFG_DB, PathResolver.getInstance(getRuntime()).getDataDirectory() + "/journal.archive"));
                                    if (root != null && root.length() > 64) {
                                        root = root.substring(0, root.indexOf(File.separator, 4) + 1) + "..." + root.substring(root.lastIndexOf(File.separator));
                                    }
                                    PropagationFactory.getInstance().fire(new Message(Message.INFO, "ui.jface.configuration.pages.ArchiveJournal", "success", new String[] { Integer.toString(cl.size()), root }, new Exception()));
                                } catch (SQLException e) {
                                    m_logger.log(Level.SEVERE, e.getMessage(), e);
                                    PropagationFactory.getInstance().fire(new Message(Message.ERROR, "ui.jface.configuration.pages.ArchiveJournal", "failed", e));
                                }
                            }
                        } else {
                            m_logger.warning("No archiving timeframe is set. Archiving is stopped.");
                            PropagationFactory.getInstance().fire(new Message(Message.ERROR, "ui.jface.configuration.pages.ArchiveJournal", "failed", new Exception("No archiving timeframe is set. Archiving is stopped.")));
                        }
                    } else {
                        m_logger.warning("Journal <" + currentRepository + "> invalid or not enabled. Archiving is stopped.");
                    }
                } else {
                    m_logger.warning("No journal configured to be archived.");
                    PropagationFactory.getInstance().fire(new Message(Message.ERROR, "ui.jface.configuration.pages.ArchiveJournal", "failed", new Exception("No journal configured to be archived.")));
                }
            }
        });
        m_archivingThread.setDaemon(true);
        m_archivingThread.setName("JAM-JournalArchiving#" + System.currentTimeMillis() + "-Thread-(non-deamon)");
        m_archivingThread.start();
    }
}
Also used : IReadCallRepository(de.janrufmonitor.repository.types.IReadCallRepository) Message(de.janrufmonitor.exception.Message) SQLException(java.sql.SQLException) IWriteCallRepository(de.janrufmonitor.repository.types.IWriteCallRepository) Date(java.util.Date) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) IFilter(de.janrufmonitor.repository.filter.IFilter) ICallList(de.janrufmonitor.framework.ICallList) DateFilter(de.janrufmonitor.repository.filter.DateFilter)

Example 5 with IWriteCallRepository

use of de.janrufmonitor.repository.types.IWriteCallRepository 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)

Aggregations

IWriteCallRepository (de.janrufmonitor.repository.types.IWriteCallRepository)12 ICallManager (de.janrufmonitor.repository.ICallManager)10 ICallList (de.janrufmonitor.framework.ICallList)9 IReadCallRepository (de.janrufmonitor.repository.types.IReadCallRepository)4 List (java.util.List)4 ICall (de.janrufmonitor.framework.ICall)3 IEventBroker (de.janrufmonitor.framework.event.IEventBroker)3 Message (de.janrufmonitor.exception.Message)2 ICaller (de.janrufmonitor.framework.ICaller)2 DateFilter (de.janrufmonitor.repository.filter.DateFilter)2 IFilter (de.janrufmonitor.repository.filter.IFilter)2 HandlerException (de.janrufmonitor.service.commons.http.handler.HandlerException)2 Date (java.util.Date)2 Properties (java.util.Properties)2 ICip (de.janrufmonitor.framework.ICip)1 FritzBoxCallCsv (de.janrufmonitor.fritzbox.FritzBoxCallCsv)1 FirmwareManager (de.janrufmonitor.fritzbox.firmware.FirmwareManager)1 DeleteCallListException (de.janrufmonitor.fritzbox.firmware.exception.DeleteCallListException)1 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)1 GetCallListException (de.janrufmonitor.fritzbox.firmware.exception.GetCallListException)1