Search in sources :

Example 76 with IPhonenumber

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

the class ConsoleSimulate method execute.

public void execute() {
    this.isExecuting = true;
    String number = "";
    String cip = "";
    String msn = "";
    if (this.getExecuteParams().length < 2 || this.getExecuteParams().length > 3) {
        System.out.println("ERROR: Invalid SIMULATE command.");
        System.out.println("USAGE for regular call simulation: SIMULATE <number> <msn> <cip>");
        System.out.println("USAGE for CLIR call simulation: SIMULATE <msn> <cip>");
        this.isExecuting = false;
        return;
    }
    if (this.getExecuteParams().length == 2) {
        msn = this.getExecuteParams()[0];
        cip = this.getExecuteParams()[1];
    }
    if (this.getExecuteParams().length == 3) {
        number = this.getExecuteParams()[0];
        msn = this.getExecuteParams()[1];
        cip = this.getExecuteParams()[2];
    }
    IEventBroker evtBroker = PIMRuntime.getInstance().getEventBroker();
    IPhonenumber phone = PhonenumberAnalyzer.getInstance(getRuntime()).toClirPhonenumber(number);
    if (phone != null)
        System.out.println("Call detected as CLIR: " + phone.isClired());
    if (phone == null) {
        phone = PhonenumberAnalyzer.getInstance(getRuntime()).toInternalPhonenumber(number, msn);
        if (phone != null)
            System.out.println("Call detected as internal: " + number.trim());
    }
    if (phone == null) {
        phone = PhonenumberAnalyzer.getInstance(getRuntime()).toPhonenumber(number, msn);
        if (phone != null)
            System.out.println("Call detected as external: " + number.trim());
    }
    IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
    ICaller aCaller = PIMRuntime.getInstance().getCallerFactory().createCaller(name, phone);
    ICip ocip = PIMRuntime.getInstance().getCallFactory().createCip(cip, "");
    IMsn omsn = PIMRuntime.getInstance().getCallFactory().createMsn(msn, "");
    ICall newCall = PIMRuntime.getInstance().getCallFactory().createCall(aCaller, omsn, ocip);
    evtBroker.register(this);
    IEvent ev = evtBroker.createEvent(IEventConst.EVENT_TYPE_INCOMINGCALL, newCall);
    evtBroker.send(this, ev);
    evtBroker.unregister(this);
    this.isExecuting = false;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICip(de.janrufmonitor.framework.ICip) ICall(de.janrufmonitor.framework.ICall) IEvent(de.janrufmonitor.framework.event.IEvent) IName(de.janrufmonitor.framework.IName) IMsn(de.janrufmonitor.framework.IMsn) IEventBroker(de.janrufmonitor.framework.event.IEventBroker) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 77 with IPhonenumber

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

the class CountryDirectory method importAreacodeCsvFiles.

private void importAreacodeCsvFiles() {
    String restart = System.getProperty(IJAMConst.SYSTEM_INSTALLER_RESTART);
    if (restart == null || restart.equalsIgnoreCase("true")) {
        this.m_logger.info("Detected jam.installer.restart flag as: " + System.getProperty(IJAMConst.SYSTEM_INSTALLER_RESTART));
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }
        restart = System.getProperty(IJAMConst.SYSTEM_INSTALLER_RESTART);
        if (restart != null && restart.equalsIgnoreCase("true")) {
            this.m_logger.info("Areacode update is not started, due to installation of new modules.");
            return;
        }
    }
    this.m_isMigrating = true;
    File areacodeFolder = new File(PathResolver.getInstance(this.getRuntime()).getDataDirectory() + File.separator + "areacodes");
    if (!areacodeFolder.exists())
        areacodeFolder.mkdirs();
    File[] areacodeCsvs = areacodeFolder.listFiles(new FilenameFilter() {

        public boolean accept(File f, String name) {
            return name.endsWith(".areacode.csv");
        }
    });
    if (areacodeCsvs.length > 0) {
        File areacodeCsv = null;
        ICallerList l = getRuntime().getCallerFactory().createCallerList();
        for (int i = 0; i < areacodeCsvs.length; i++) {
            areacodeCsv = areacodeCsvs[i];
            if (areacodeCsv.isFile() && areacodeCsv.exists()) {
                try {
                    // structure of file
                    // #intareacode;areacode;country;city
                    InputStream content = new FileInputStream(areacodeCsv);
                    if (content != null) {
                        BufferedReader reader = new BufferedReader(new InputStreamReader(content, "ISO-8859-1"));
                        String[] entry = new String[4];
                        StringTokenizer st = null;
                        for (String line; (line = reader.readLine()) != null; ) {
                            if (line.startsWith("#")) {
                                if (this.m_logger.isLoggable(Level.INFO))
                                    this.m_logger.info("Skipping line from import (start comment line #): " + line);
                                continue;
                            }
                            st = new StringTokenizer(line, ";");
                            if (st.countTokens() == 2) {
                                entry[0] = st.nextToken().trim();
                                entry[1] = st.nextToken().trim();
                                IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(entry[0], "", "country");
                                IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
                                if (entry[1].length() > 0)
                                    m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, entry[1]));
                                ICaller c = getRuntime().getCallerFactory().createCaller(getRuntime().getCallerFactory().createName("", ""), pn, m);
                                if (this.m_logger.isLoggable(Level.INFO))
                                    this.m_logger.info("Adding intareacode entry: " + c);
                                l.add(c);
                            } else if (st.countTokens() == 4) {
                                entry[0] = st.nextToken().trim();
                                entry[1] = st.nextToken().trim();
                                entry[2] = st.nextToken().trim();
                                entry[3] = st.nextToken().trim();
                                IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(entry[0], entry[1], (entry[1].length() == 0 ? "country" : "area"));
                                IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
                                if (entry[2].length() > 0)
                                    m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, entry[2]));
                                if (entry[3].length() > 0)
                                    m.add(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CITY, entry[3]));
                                ICaller c = getRuntime().getCallerFactory().createCaller(getRuntime().getCallerFactory().createName("", ""), pn, m);
                                if (this.m_logger.isLoggable(Level.INFO))
                                    this.m_logger.info("Adding areacode entry: " + c);
                                l.add(c);
                            } else {
                                if (this.m_logger.isLoggable(Level.INFO))
                                    this.m_logger.info("Skipping line from import (invalid token count): " + line);
                            }
                        }
                        reader.close();
                    }
                    if (l.size() > 0)
                        this.storeCountryAreacodes(l);
                    l.clear();
                    if (!areacodeCsv.delete())
                        areacodeCsv.deleteOnExit();
                } catch (IOException e) {
                    this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                }
            }
        }
    } else {
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("No .areacode.csv file found in path: " + areacodeFolder.getAbsolutePath());
    }
    this.m_isMigrating = false;
}
Also used : InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FilenameFilter(java.io.FilenameFilter) ICaller(de.janrufmonitor.framework.ICaller) StringTokenizer(java.util.StringTokenizer) ICallerList(de.janrufmonitor.framework.ICallerList) BufferedReader(java.io.BufferedReader) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) File(java.io.File) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 78 with IPhonenumber

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

the class Rule method getPhonenumbers.

private IPhonenumber[] getPhonenumbers(String phones) {
    if (phones.equalsIgnoreCase(Rule.GENERIC_SIGN))
        return null;
    StringTokenizer st = new StringTokenizer(phones, "[");
    IPhonenumber[] pns = new IPhonenumber[st.countTokens()];
    int i = 0;
    while (st.hasMoreTokens()) {
        String pn = st.nextToken();
        pn = pn.substring(0, pn.length() - 1);
        if (pn.equalsIgnoreCase("clired")) {
            pns[i] = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true);
        } else {
            StringTokenizer pt = new StringTokenizer(pn, Rule.PHONE_SEPARATOR_SIGN);
            if (pt.countTokens() == 3) {
                pns[i] = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(pt.nextToken().trim(), pt.nextToken().trim(), pt.nextToken().trim());
            } else {
                this.m_logger.severe("Phonenumber in rule is not valid: " + pn);
            }
        }
        i++;
    }
    return pns;
}
Also used : StringTokenizer(java.util.StringTokenizer) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 79 with IPhonenumber

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

the class FritzBoxCallerExporter method toXml.

private void toXml(ICaller c, StringBuffer s) {
    s.append("<contact>");
    s.append(IJAMConst.CRLF);
    s.append("<category></category>");
    s.append(IJAMConst.CRLF);
    s.append("<person>");
    s.append(IJAMConst.CRLF);
    s.append("<realName>");
    try {
        if (c.getName().getFullname().trim().length() == 0) {
            s.append(StringUtils.replaceString(c.getName().getAdditional(), "&", "&amp;"));
        } else
            s.append(StringUtils.replaceString(c.getName().getFullname(), "&", "&amp;"));
    } catch (Exception e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    s.append("</realName>");
    s.append(IJAMConst.CRLF);
    s.append("<imageURL></imageURL>");
    s.append(IJAMConst.CRLF);
    s.append("</person>");
    s.append(IJAMConst.CRLF);
    s.append("<numbers>");
    s.append(IJAMConst.CRLF);
    if (c instanceof IMultiPhoneCaller) {
        List numbers = ((IMultiPhoneCaller) c).getPhonenumbers();
        IPhonenumber pn = null;
        String type = null;
        for (int i = 0; i < numbers.size(); i++) {
            pn = (IPhonenumber) numbers.get(i);
            if (!PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).isInternal(pn) && !pn.isClired()) {
                type = "home";
                if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber())) {
                    type = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber()).getValue();
                    if (type.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE))
                        type = "home";
                    if (type.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE))
                        type = "mobile";
                    if (type.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE))
                        type = "work_fax";
                }
                s.append("<number type=\"" + type + "\">");
                s.append((pn.getIntAreaCode().equalsIgnoreCase(m_intArea) ? "0" + pn.getTelephoneNumber() : "00" + pn.getIntAreaCode() + pn.getTelephoneNumber()));
                s.append("</number>");
                s.append(IJAMConst.CRLF);
            }
        }
    } else {
        s.append("<number type=\"home\">");
        s.append((c.getPhoneNumber().getIntAreaCode().equalsIgnoreCase(m_intArea) ? "0" + c.getPhoneNumber().getTelephoneNumber() : "00" + c.getPhoneNumber().getIntAreaCode() + c.getPhoneNumber().getTelephoneNumber()));
        s.append("</number>");
        s.append(IJAMConst.CRLF);
    }
    s.append("</numbers>");
    s.append(IJAMConst.CRLF);
    s.append("<services>");
    s.append(IJAMConst.CRLF);
    if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_EMAIL)) {
        s.append("<email classifier=\"private\">");
        s.append(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL).getValue());
        s.append("</email>");
        s.append(IJAMConst.CRLF);
    }
    s.append("</services>");
    s.append(IJAMConst.CRLF);
    s.append("</contact>");
    s.append(IJAMConst.CRLF);
}
Also used : IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 80 with IPhonenumber

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

the class ClickDialAction 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) {
                o = ((ICaller) o).getPhoneNumber();
            }
            if (o instanceof ITreeItemCallerData) {
                o = ((ITreeItemCallerData) o).getPhone();
            }
            if (o instanceof IPhonenumber) {
                if (((IPhonenumber) o).isClired())
                    return;
                String dial = ((IPhonenumber) o).getTelephoneNumber();
                if (!((IPhonenumber) o).getIntAreaCode().equalsIgnoreCase(this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_INTAREA))) {
                    dial = "00" + ((IPhonenumber) o).getIntAreaCode() + dial;
                }
                if (!dial.startsWith("0"))
                    dial = "0" + dial;
                Properties config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(FritzBoxMonitor.NAMESPACE);
                String prefixes = getRuntime().getConfigManagerFactory().getConfigManager().getProperty(FritzBoxMonitor.NAMESPACE, "dialprefixes");
                if ((prefixes != null && prefixes.length() > 0) || config.getProperty(CFG_CLICKDIAL, "50").equalsIgnoreCase("0")) {
                    DialerDialog id = new DialerDialog(new Shell(DisplayManager.getDefaultDisplay()), dial);
                    id.open();
                } else {
                    // added 2010/03/06: check for dial prefix for outgoing calls
                    if (this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_DIAL_PREFIX).length() > 0) {
                        if (this.m_logger.isLoggable(Level.INFO))
                            this.m_logger.info("Using dial prefix: " + this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_DIAL_PREFIX));
                        dial = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_DIAL_PREFIX).trim() + dial;
                    }
                    String text = getI18nManager().getString(getNamespace(), "dial", "description", getLanguage());
                    text = StringUtils.replaceString(text, "{%1}", dial);
                    if (MessageDialog.openConfirm(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "success", "label", this.getLanguage()), text)) {
                        FirmwareManager fwm = FirmwareManager.getInstance();
                        try {
                            if (!fwm.isLoggedIn())
                                fwm.login();
                            fwm.doCall(dial + "#", config.getProperty(CFG_CLICKDIAL, "50"));
                            try {
                                final String n = dial;
                                ModalContext.run(new IRunnableWithProgress() {

                                    public void run(IProgressMonitor progressMonitor) {
                                        progressMonitor.done();
                                        String text = getI18nManager().getString(getNamespace(), "success", "description", getLanguage());
                                        text = StringUtils.replaceString(text, "{%1}", n);
                                        MessageDialog.openInformation(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespace(), "success", "label", getLanguage()), text);
                                    }
                                }, false, m_app.getApplication().getStatusLineManager().getProgressMonitor(), m_app.getApplication().getShell().getDisplay());
                            } catch (InterruptedException e) {
                                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                            } catch (InvocationTargetException e) {
                                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                            }
                        } catch (IOException e) {
                            this.m_logger.warning(e.toString());
                            PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "faileddial", e));
                        } catch (FritzBoxLoginException e) {
                            this.m_logger.warning(e.toString());
                        } catch (DoCallException e) {
                            this.m_logger.warning(e.toString());
                            PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "faileddial", e));
                        }
                        this.m_app.updateViews(false);
                    }
                }
            }
        }
    }
}
Also used : DoCallException(de.janrufmonitor.fritzbox.firmware.exception.DoCallException) FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) ICall(de.janrufmonitor.framework.ICall) Message(de.janrufmonitor.exception.Message) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) Properties(java.util.Properties) DialerDialog(de.janrufmonitor.ui.jface.application.dialer.DialerDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICaller(de.janrufmonitor.framework.ICaller) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) ITreeItemCallerData(de.janrufmonitor.ui.jface.application.ITreeItemCallerData) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IPhonenumber (de.janrufmonitor.framework.IPhonenumber)99 ICaller (de.janrufmonitor.framework.ICaller)62 List (java.util.List)49 ArrayList (java.util.ArrayList)44 IAttribute (de.janrufmonitor.framework.IAttribute)38 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)37 ICallerList (de.janrufmonitor.framework.ICallerList)36 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)26 ICall (de.janrufmonitor.framework.ICall)19 SQLException (java.sql.SQLException)19 IMsn (de.janrufmonitor.framework.IMsn)17 Date (java.util.Date)17 IOException (java.io.IOException)16 ICip (de.janrufmonitor.framework.ICip)13 IName (de.janrufmonitor.framework.IName)13 File (java.io.File)13 Iterator (java.util.Iterator)13 ITreeItemCallerData (de.janrufmonitor.ui.jface.application.ITreeItemCallerData)9 UUID (de.janrufmonitor.util.uuid.UUID)9 FileInputStream (java.io.FileInputStream)9