Search in sources :

Example 66 with ICaller

use of de.janrufmonitor.framework.ICaller 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 67 with ICaller

use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.

the class Sound method receivedValidRule.

public void receivedValidRule(ICall aCall) {
    String filename = "";
    // check wether user has an own file
    ICaller aCaller = aCall.getCaller();
    IAttribute filenameAttribute = aCaller.getAttribute(ATTRIBUTE_USER_SOUNDFILE);
    if (filenameAttribute != null) {
        filename = filenameAttribute.getValue();
        if (filename.length() > 0) {
            filename = PathResolver.getInstance(PIMRuntime.getInstance()).resolve(filename);
            this.m_logger.info("Playing user assigned sound file: " + filename);
        }
    }
    // use file from MSN assignment
    if (filename.length() == 0) {
        String msn = aCall.getMSN().getMSN();
        filename = this.m_configuration.getProperty(msn + "_" + ATTRIBUTE_USER_SOUNDFILE, "");
        if (filename.length() > 0) {
            filename = PathResolver.getInstance(PIMRuntime.getInstance()).resolve(filename);
            this.m_logger.info("Playing MSN assigned sound file: " + filename);
        }
    }
    if (filename.length() == 0) {
        filename = this.m_configuration.getProperty("default_" + ATTRIBUTE_USER_SOUNDFILE, "");
        if (filename.length() > 0) {
            filename = PathResolver.getInstance(PIMRuntime.getInstance()).resolve(filename);
            this.m_logger.info("Playing default sound file: " + filename);
        }
    }
    if (filename.length() == 0) {
        this.m_logger.warning("No sound file assigned.");
    } else {
        SoundThread st = new SoundThread(filename);
        st.setName("JAM-SoundFile-Thread-(non-deamon)");
        st.start();
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) IAttribute(de.janrufmonitor.framework.IAttribute)

Example 68 with ICaller

use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.

the class MailNotification method sendTestMail.

public void sendTestMail() {
    ICaller caller = getRuntime().getCallerFactory().createCaller(getRuntime().getCallerFactory().createName("Max", "Mustermann"), getRuntime().getCallerFactory().createPhonenumber("49", "30", "1234567890"));
    IMsn msn = getRuntime().getMsnManager().createMsn("12345");
    ICip cip = getRuntime().getCipManager().createCip("999");
    ICall call = getRuntime().getCallFactory().createCall(caller, msn, cip);
    if (this.m_configuration == null) {
        PropagationFactory.getInstance().fire(new de.janrufmonitor.exception.Message(de.janrufmonitor.exception.Message.ERROR, NAMESPACE, "notstarted", new String[] {}, new Exception()), "Tray");
        return;
    }
    if (this.m_task == null) {
        this.m_task = new MailTask();
        this.m_logger.info("Created new MailTask instance");
    }
    PropagationFactory.getInstance().fire(new de.janrufmonitor.exception.Message(de.janrufmonitor.exception.Message.INFO, NAMESPACE, "testmail", new String[] {}, new Exception()), "Tray");
    this.m_task.setConfiguration(this.m_configuration);
    this.m_task.addMail(call);
    this.m_task.run();
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICip(de.janrufmonitor.framework.ICip) ICall(de.janrufmonitor.framework.ICall) IMsn(de.janrufmonitor.framework.IMsn) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException)

Example 69 with ICaller

use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.

the class DeleteAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null) {
        IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            Object o = selection.getFirstElement();
            if (o instanceof ICall) {
                o = ((ICall) o).getCaller();
            }
            if (o instanceof ICaller) {
                if (hasCallerSound((ICaller) o) && MessageDialog.openConfirm(new Shell(Display.getCurrent()), this.getI18nManager().getString(this.getNamespace(), "delete", "label", this.getLanguage()), this.getI18nManager().getString(this.getNamespace(), "delete", "description", this.getLanguage()))) {
                    IAttribute att = ((ICaller) o).getAttribute(SoundConst.ATTRIBUTE_USER_SOUNDFILE);
                    att.setValue("");
                    ((ICaller) o).setAttribute(att);
                    this.m_app.getController().updateElement(o);
                    this.m_app.updateViews(false);
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) ICall(de.janrufmonitor.framework.ICall) IAttribute(de.janrufmonitor.framework.IAttribute) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 70 with ICaller

use of de.janrufmonitor.framework.ICaller 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

ICaller (de.janrufmonitor.framework.ICaller)144 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)62 ICallerList (de.janrufmonitor.framework.ICallerList)49 List (java.util.List)46 IAttribute (de.janrufmonitor.framework.IAttribute)42 ICall (de.janrufmonitor.framework.ICall)41 ArrayList (java.util.ArrayList)40 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)32 SQLException (java.sql.SQLException)26 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)25 IOException (java.io.IOException)25 Viewer (org.eclipse.jface.viewers.Viewer)24 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 File (java.io.File)20 Date (java.util.Date)17 Iterator (java.util.Iterator)17 Shell (org.eclipse.swt.widgets.Shell)17 IMsn (de.janrufmonitor.framework.IMsn)16 Properties (java.util.Properties)15 ICip (de.janrufmonitor.framework.ICip)14