Search in sources :

Example 11 with ICallerManager

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

the class AbstractPhonesPage method getActiveCallerManagers.

private List getActiveCallerManagers() {
    List managers = this.getRuntime().getCallerManagerFactory().getAllCallerManagers();
    ICallerManager man = null;
    for (int i = managers.size() - 1; i >= 0; i--) {
        man = (ICallerManager) managers.get(i);
        // removed: 2009/04/30: if (!man.isActive() || !(man.isSupported(IReadCallerRepository.class) && man.isSupported(IWriteCallerRepository.class))){
        if (!man.isActive() || !man.isSupported(IReadCallerRepository.class)) {
            managers.remove(i);
        }
    }
    return managers;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Example 12 with ICallerManager

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

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

the class Caller method performOk.

public boolean performOk() {
    if (this.managers != null && this.managers.size() > 0) {
        IConfigurable conf = null;
        ICallerManager o;
        for (int i = 0; i < managers.size(); i++) {
            o = this.getRuntime().getCallerManagerFactory().getCallerManager((String) managers.get(i));
            if (o != null && o instanceof IConfigurable) {
                conf = (IConfigurable) o;
                this.getPreferenceStore().setValue(conf.getNamespace() + SEPARATOR + "priority", i + 10);
            }
        }
    }
    boolean ok = super.performOk();
    if (ok) {
        // notify all changed namespaces
        if (this.managers != null && this.managers.size() > 0) {
            IConfigurable conf = null;
            ICallerManager o = null;
            for (int i = 0; i < managers.size(); i++) {
                o = this.getRuntime().getCallerManagerFactory().getCallerManager((String) managers.get(i));
                if (o != null && o instanceof IConfigurable) {
                    conf = (IConfigurable) o;
                    this.getRuntime().getConfigurableNotifier().notifyByNamespace(conf.getNamespace());
                }
            }
        }
    }
    return ok;
}
Also used : IConfigurable(de.janrufmonitor.framework.configuration.IConfigurable) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Example 14 with ICallerManager

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

the class Identifier method getAllActiveCallerManagers.

private static List getAllActiveCallerManagers(IRuntime r) {
    List allManagers = r.getCallerManagerFactory().getAllCallerManagers();
    List activeManager = new ArrayList();
    Object o = null;
    ICallerManager cm = null;
    for (int i = 0; i < allManagers.size(); i++) {
        o = allManagers.get(i);
        if (o != null && o instanceof ICallerManager) {
            cm = (ICallerManager) o;
            if (cm.isActive()) {
                activeManager.add(cm);
            }
        }
    }
    Collections.sort(activeManager, new RepositoryManagerComparator());
    Identifier.logger.info("List with all caller managers: " + allManagers.toString());
    Identifier.logger.info("List with all active caller managers: " + activeManager.toString());
    return activeManager;
}
Also used : ArrayList(java.util.ArrayList) RepositoryManagerComparator(de.janrufmonitor.repository.RepositoryManagerComparator) ArrayList(java.util.ArrayList) List(java.util.List) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Example 15 with ICallerManager

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

the class Identifier method identifyDefault.

/**
 * Identifies a caller with the default caller manager specified in the configuration.
 *
 * @param r the current runtime
 * @param pn a valid number, should not be a clired number or null
 * @return an identified ICaller object or null, if not identified by the default caller manager
 */
public static ICaller identifyDefault(IRuntime r, IPhonenumber pn) {
    List activeCallerManagers = new ArrayList(1);
    ICallerManager def = r.getCallerManagerFactory().getDefaultCallerManager();
    if (def != null && def.isActive() && def.isSupported(IIdentifyCallerRepository.class))
        activeCallerManagers.add(def);
    else {
        Identifier.logger.info("Problem with default caller manager: Either reference is null, managers is deactived or it does not support identification.");
    }
    return identify(r, pn, activeCallerManagers);
}
Also used : ArrayList(java.util.ArrayList) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) ArrayList(java.util.ArrayList) List(java.util.List) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Aggregations

ICallerManager (de.janrufmonitor.repository.ICallerManager)31 List (java.util.List)15 ArrayList (java.util.ArrayList)14 ICallerList (de.janrufmonitor.framework.ICallerList)13 ICaller (de.janrufmonitor.framework.ICaller)12 IIdentifyCallerRepository (de.janrufmonitor.repository.types.IIdentifyCallerRepository)11 CallerNotFoundException (de.janrufmonitor.repository.CallerNotFoundException)9 IWriteCallerRepository (de.janrufmonitor.repository.types.IWriteCallerRepository)7 IAttribute (de.janrufmonitor.framework.IAttribute)6 HandlerException (de.janrufmonitor.service.commons.http.handler.HandlerException)6 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)5 IFilter (de.janrufmonitor.repository.filter.IFilter)4 RepositoryManagerComparator (de.janrufmonitor.repository.RepositoryManagerComparator)3 ILocalRepository (de.janrufmonitor.repository.types.ILocalRepository)3 IReadCallerRepository (de.janrufmonitor.repository.types.IReadCallerRepository)3 File (java.io.File)3 OutputStream (java.io.OutputStream)3 StringTokenizer (java.util.StringTokenizer)3 Shell (org.eclipse.swt.widgets.Shell)3 IConfigurable (de.janrufmonitor.framework.configuration.IConfigurable)2