Search in sources :

Example 11 with IFilter

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

the class AbstractConfigurableCallerManager method applyFilters.

protected void applyFilters(ICallerList cl, IFilter[] filters) {
    if (cl == null)
        return;
    if (filters == null)
        return;
    IFilter f = null;
    for (int i = 0; i < filters.length; i++) {
        f = filters[i];
        if (f.getType() == FilterType.CHARACTER) {
            CharacterFilter cf = ((CharacterFilter) f);
            ICaller c = null;
            for (int j = cl.size() - 1; j >= 0; j--) {
                c = cl.get(j);
                if (!c.getAttributes().contains(cf.getAttributeName())) {
                    cl.remove(c);
                } else if (c.getAttributes().contains(cf.getAttributeName())) {
                    if (!c.getAttribute(cf.getAttributeName()).getValue().startsWith(cf.getCharacter())) {
                        cl.remove(c);
                    }
                }
            }
        }
        if (f.getType() == FilterType.PHONENUMBER) {
            PhonenumberFilter cf = ((PhonenumberFilter) f);
            ICaller c = null;
            for (int j = cl.size() - 1; j >= 0; j--) {
                c = cl.get(j);
                if (!c.getPhoneNumber().getIntAreaCode().equalsIgnoreCase(cf.getPhonenumber().getIntAreaCode())) {
                    cl.remove(c);
                } else if (!c.getPhoneNumber().getAreaCode().equalsIgnoreCase(cf.getPhonenumber().getAreaCode())) {
                    cl.remove(c);
                }
            }
        }
        if (f.getType() == FilterType.ATTRIBUTE) {
            AttributeFilter cf = ((AttributeFilter) f);
            ICaller c = null;
            for (int j = cl.size() - 1; j >= 0; j--) {
                c = cl.get(j);
                IAttributeMap atts = cf.getAttributeMap();
                Iterator iter = atts.iterator();
                IAttribute a = null;
                while (iter.hasNext()) {
                    a = (IAttribute) iter.next();
                    if (!c.getAttributes().contains(a)) {
                        cl.remove(c);
                    } else if (c.getAttributes().contains(a) && !c.getAttribute(a.getName()).getValue().equalsIgnoreCase(a.getValue())) {
                        cl.remove(c);
                    }
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) CharacterFilter(de.janrufmonitor.repository.filter.CharacterFilter) IFilter(de.janrufmonitor.repository.filter.IFilter) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) PhonenumberFilter(de.janrufmonitor.repository.filter.PhonenumberFilter) IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

Example 12 with IFilter

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

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

the class OutlookImportAction method run.

public void run() {
    String filter = this.m_app.getApplication().getConfiguration().getProperty("filter", "");
    EditorFilterManager efm = new EditorFilterManager();
    final IAttribute category = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, "");
    if (filter.length() > 0) {
        String cat = null;
        IFilter[] filters = efm.getFiltersFromString(filter);
        for (int z = 0; z < filters.length; z++) {
            if (filters[z].getType().equals(FilterType.ATTRIBUTE)) {
                AttributeFilter cf = ((AttributeFilter) filters[z]);
                IAttributeMap m = cf.getAttributeMap();
                if (m != null && m.size() > 0) {
                    Iterator it = m.iterator();
                    IAttribute a = null;
                    while (it.hasNext()) {
                        a = (IAttribute) it.next();
                        if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
                            cat = a.getValue();
                        }
                    }
                }
            }
        }
        if (cat != null) {
            int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
            MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
            String text = this.getI18nManager().getString("ui.jface.application.editor.action.ImportAction", "assigncategoryconfirm", "label", this.getLanguage());
            text = StringUtils.replaceString(text, "{%1}", cat);
            messageBox.setMessage(text);
            if (messageBox.open() == SWT.YES) {
                category.setValue(cat);
            }
        }
    }
    // determine subfolders
    OutlookTransformer ot = new OutlookTransformer();
    List folders = ot.getAllContactFolders();
    if (folders.size() > 0) {
        int itemCount = 0;
        String folder = null;
        for (int i = 0, j = folders.size(); i < j; i++) {
            folder = (String) folders.get(i);
            itemCount = ot.getContactCount(folder);
            if (itemCount > 0) {
                getRuntime().getConfigManagerFactory().getConfigManager().setProperty(OutlookContactManager.NAMESPACE, "subfolder_" + folder, "true");
            }
        }
        getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
    }
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
    try {
        IRunnableWithProgress r = new IRunnableWithProgress() {

            public void run(IProgressMonitor progressMonitor) {
                progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "importprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                progressMonitor.worked(1);
                OutlookTransformer otf = new OutlookTransformer();
                ICallerList callers = otf.getCallerListFromAllContacts();
                progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "reduce", "label", getLanguage()));
                otf.removeCallerManagerID(callers);
                // determine duplicates
                String currentCallerManagerID = m_app.getApplication().getConfiguration().getProperty(CFG_REPOSITORY);
                if (currentCallerManagerID != null && currentCallerManagerID.trim().length() > 0) {
                    ICallerManager currentCallerManager = getRuntime().getCallerManagerFactory().getCallerManager(currentCallerManagerID);
                    if (currentCallerManager != null && currentCallerManager.isSupported(IWriteCallerRepository.class) && currentCallerManager.isSupported(IIdentifyCallerRepository.class)) {
                        ICallerList addCallers = getRuntime().getCallerFactory().createCallerList();
                        // ICallerList removeCallers = getRuntime().getCallerFactory().createCallerList();
                        ICaller currentCaller = null;
                        String text = null;
                        for (int i = 0, j = callers.size(); i < j; i++) {
                            // ICaller testCaller = null;
                            currentCaller = callers.get(i);
                            text = getI18nManager().getString(getNamespace(), "check", "label", getLanguage());
                            text = StringUtils.replaceString(text, "{%1}", Formatter.getInstance(getRuntime()).parse("%a:ln%, %a:fn%", currentCaller));
                            progressMonitor.setTaskName(text);
                            try {
                                Thread.sleep(100);
                            } catch (InterruptedException e1) {
                            }
                            try {
                                // testCaller = ((IIdentifyCallerRepository)currentCallerManager).getCaller(currentCaller.getPhoneNumber());
                                ((IIdentifyCallerRepository) currentCallerManager).getCaller(currentCaller.getPhoneNumber());
                            } catch (CallerNotFoundException e) {
                                if (category != null && category.getValue().length() > 0)
                                    currentCaller.setAttribute(category);
                                addCallers.add(currentCaller);
                            }
                        // if (testCaller!=null) {
                        // removeCallers.add(testCaller);
                        // }
                        }
                        progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "add", "label", getLanguage()));
                        try {
                            Thread.sleep(1250);
                        } catch (InterruptedException e1) {
                        }
                        // if (removeCallers.size()>0)
                        // m_app.getController().deleteElements(removeCallers);
                        m_app.getController().addElements(addCallers);
                    }
                } else {
                    progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "add", "label", getLanguage()));
                    m_app.getController().addElements(callers);
                }
                progressMonitor.done();
            }
        };
        pmd.setBlockOnOpen(false);
        pmd.run(true, false, r);
    // ModalContext.run(r, true, pmd.getProgressMonitor(), DisplayManager.getDefaultDisplay());
    } catch (InterruptedException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
    } catch (InvocationTargetException e) {
        m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    m_app.updateViews(true);
    return;
}
Also used : EditorFilterManager(de.janrufmonitor.ui.jface.application.editor.EditorFilterManager) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) OutlookTransformer(de.janrufmonitor.repository.OutlookTransformer) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) MessageBox(org.eclipse.swt.widgets.MessageBox) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ICallerList(de.janrufmonitor.framework.ICallerList) IFilter(de.janrufmonitor.repository.filter.IFilter) IAttribute(de.janrufmonitor.framework.IAttribute) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) Iterator(java.util.Iterator) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List)

Example 14 with IFilter

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

the class AbstractStatisticAction method getDescription.

public String getDescription() {
    IFilterManager fm = new JournalFilterManager();
    IFilter[] f = fm.getFiltersFromString(this.m_app.getApplication().getConfiguration().getProperty(CFG_FILTER, ""));
    String activeFilter = getFilterLabel(fm, f);
    String description = getI18nManager().getString(getNamespace(), "dialogtitle", "description", getLanguage());
    description = StringUtils.replaceString(description, "{%1}", activeFilter);
    return description;
}
Also used : IFilterManager(de.janrufmonitor.ui.jface.application.IFilterManager) IFilter(de.janrufmonitor.repository.filter.IFilter) JournalFilterManager(de.janrufmonitor.ui.jface.application.journal.JournalFilterManager)

Example 15 with IFilter

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

the class AbstractStatisticAction method getMessage.

public String getMessage() {
    IFilterManager fm = new JournalFilterManager();
    IFilter[] f = fm.getFiltersFromString(this.m_app.getApplication().getConfiguration().getProperty(CFG_FILTER, ""));
    String activeFilter = getFilterLabel(fm, f);
    String description = getI18nManager().getString(getNamespace(), "current", "label", getLanguage());
    description = StringUtils.replaceString(description, "{%1}", activeFilter);
    return description;
}
Also used : IFilterManager(de.janrufmonitor.ui.jface.application.IFilterManager) IFilter(de.janrufmonitor.repository.filter.IFilter) JournalFilterManager(de.janrufmonitor.ui.jface.application.journal.JournalFilterManager)

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