Search in sources :

Example 56 with IAttributeMap

use of de.janrufmonitor.framework.IAttributeMap 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 57 with IAttributeMap

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

the class FritzBoxCallCsv method toCall.

public ICall toCall() {
    Logger logger = Logger.getLogger(IJAMConst.DEFAULT_LOGGER);
    if (this.m_line == null || this.m_line.trim().length() == 0) {
        if (logger != null && logger.isLoggable(Level.INFO))
            logger.info("No call data found in CSV line: " + this.m_line);
        return null;
    }
    /**
     * Added 2011/01/05: added do to NumberFormatException in log, remove the header
     *
     * Format: Typ;Datum;Name;Rufnummer;Nebenstelle;Eigene Rufnummer;Dauer
     */
    if (this.m_line.trim().toLowerCase().startsWith("typ;")) {
        if (logger != null && logger.isLoggable(Level.INFO))
            logger.info("Ignore CSV header line: " + this.m_line);
        return null;
    }
    if (this.m_call == null) {
        try {
            IRuntime r = PIMRuntime.getInstance();
            String[] call = this.m_line.split(";");
            if (call.length >= 7) {
                if (logger != null && logger.isLoggable(Level.INFO))
                    logger.info("Tokens in CSV line: " + call.length);
                // create msn
                IMsn msn = r.getCallFactory().createMsn(getMsn(call[5]), "");
                msn.setAdditional(r.getMsnManager().getMsnLabel(msn));
                if (logger != null && logger.isLoggable(Level.INFO))
                    logger.info("MSN set to: " + msn.toString());
                // create caller data
                int state = Integer.parseInt(call[0]);
                if (logger != null && logger.isLoggable(Level.INFO))
                    logger.info("State set to: " + state);
                // added 2016/01/26: ignore incoming active (5) and outgoung active calls (6)
                if (state == 5 || state == 6) {
                    if (logger != null && logger.isLoggable(Level.INFO))
                        logger.info("Ignoring call state: " + state);
                    return null;
                }
                String callByCall = null;
                ICaller caller = null;
                IPhonenumber pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toClirPhonenumber(call[3].trim());
                // if no CLIR call, check internal
                if (pn == null && state != this.getOutgoingState())
                    pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toInternalPhonenumber(call[3].trim(), msn.getMSN());
                // if no internal call, check regular
                if (pn == null && state != this.getOutgoingState()) {
                    // if incoming call does not start with 0, the Provider number seems to have the wrong format
                    // assume it is an international format 4971657110
                    boolean onlyNumbers = call[3].matches("[+-]?[0-9]+");
                    if (!call[3].startsWith("0") && onlyNumbers) {
                        if (logger != null && logger.isLoggable(Level.INFO))
                            logger.info("Assuming international call: " + call[3]);
                        call[3] = "00" + call[3];
                    }
                    pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toPhonenumber(call[3].trim(), msn.getMSN());
                }
                if (pn == null && state == this.getOutgoingState()) {
                    // added 2006/08/10: trim call-by-call information
                    // only can occure on state 3/4 (out-going calls)
                    callByCall = getCallByCall(call[3]);
                    if (callByCall != null) {
                        call[3] = call[3].substring(callByCall.length());
                    }
                    pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toInternalPhonenumber(call[3].trim(), msn.getMSN());
                    if (pn == null) {
                        // requires addition of areacode
                        if (!call[3].startsWith("0")) {
                            if (logger != null && logger.isLoggable(Level.INFO))
                                logger.info("Assuming number " + call[3] + " has missing areacode.");
                            call[3] = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).getAreaCode() + call[3];
                            if (logger != null && logger.isLoggable(Level.INFO))
                                logger.info("Added areacode to number " + call[3]);
                        }
                        pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toPhonenumber(call[3].trim(), msn.getMSN());
                    }
                }
                if (logger != null && logger.isLoggable(Level.INFO))
                    logger.info("Phonenumber set to: " + pn);
                caller = Identifier.identify(r, pn);
                if (caller == null) {
                    caller = r.getCallerFactory().createCaller(r.getCallerFactory().createName("", call[2]), pn);
                    if (logger != null && logger.isLoggable(Level.INFO))
                        logger.info("Setting CSV name field as caller name: " + call[2]);
                }
                // added 2016/01/19: FB Name data if jAnrufmonitor did not find any in his callermanagers
                if (caller.getName().getLastname().length() == 0 && caller.getName().getFirstname().length() == 0 && call[2].trim().length() > 0) {
                    caller.getAttributes().add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, call[2]));
                    caller.getAttributes().add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, FritzBoxPhonebookManager.ID));
                    caller.getAttributes().remove(IJAMConst.ATTRIBUTE_NAME_CITY);
                }
                // create call data
                SimpleDateFormat sdf = new SimpleDateFormat(this.m_config.getProperty(CFG_DATEFORMAT, "dd.MM.yy HH:mm"));
                Date date = new Date(0);
                try {
                    date = sdf.parse(call[1]);
                } catch (ParseException e) {
                    if (logger != null && logger.isLoggable(Level.SEVERE))
                        logger.severe("Wrong date format detected: " + e.getMessage());
                }
                ICip cip = r.getCallFactory().createCip(getCip(call[4]), "");
                cip.setAdditional(r.getCipManager().getCipLabel(cip, ""));
                if (logger != null && logger.isLoggable(Level.INFO))
                    logger.info("Set CIP to: " + cip);
                // create attributes
                IAttributeMap am = r.getCallFactory().createAttributeMap();
                if (state == 1) {
                    am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_ACCEPTED));
                } else if (state == this.getOutgoingState()) {
                    am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_OUTGOING));
                } else if (this.hasRejectedState() && state == this.getRejectedState()) {
                    am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_REJECTED));
                } else {
                    am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_MISSED));
                }
                am.add(r.getCallFactory().createAttribute("fritzbox.line", call[4]));
                am.add(r.getCallFactory().createAttribute("fritzbox.duration", Integer.toString(getTime(call[6]))));
                am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALL_DURATION, Integer.toString(getTime(call[6]))));
                am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALL_ACTIVE_INDICATOR, IJAMConst.ATTRIBUTE_VALUE_NO));
                if (callByCall != null)
                    am.add(r.getCallFactory().createAttribute("fritzbox.callbycall", callByCall));
                if (isSpoofingnumber(call[2])) {
                    if (logger != null && logger.isLoggable(Level.INFO))
                        logger.info("Spoofing number detected: " + call[2]);
                    String sn = getSpoofingnumber(call[2]);
                    IPhonenumber pnx = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toPhonenumber(sn.trim());
                    ICaller cx = Identifier.identify(r, pnx);
                    if (cx != null) {
                        am.add(r.getCallFactory().createAttribute("fritzbox.spoofing", cx.getPhoneNumber().getIntAreaCode() + ";" + cx.getPhoneNumber().getAreaCode() + ";" + cx.getPhoneNumber().getCallNumber()));
                        am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_SPOOFED, "true"));
                    }
                }
                if (logger != null && logger.isLoggable(Level.INFO))
                    logger.info("Set attributes to: " + am);
                // // create UUID
                // StringBuffer uuid = new StringBuffer();
                // uuid.append(date.getTime());
                // uuid.append("-");
                // uuid.append(pn.getTelephoneNumber());
                // uuid.append("-");
                // uuid.append(msn.getMSN());
                // 
                // if (logger!=null && logger.isLoggable(Level.INFO))
                // logger.info("Set UUID to: "+uuid);
                // 
                // // limit uuid to 32 chars
                // if (uuid.length()>31) {
                // // reduce byte length to append -1 for redundant calls max -1-1 --> 3 calls
                // uuid = new StringBuffer(uuid.substring(0,31));
                // if (logger!=null && logger.isLoggable(Level.INFO))
                // logger.info("Reduce UUID to: "+uuid);
                // }
                this.m_call = r.getCallFactory().createCall(FritzBoxUUIDManager.getInstance().getUUID(date, pn, msn), caller, msn, cip, date);
                this.m_call.setAttributes(am);
            }
        } catch (NumberFormatException ex) {
            if (logger != null && logger.isLoggable(Level.SEVERE))
                logger.log(Level.SEVERE, ex.toString(), ex);
        } catch (Exception ex) {
            if (logger != null && logger.isLoggable(Level.WARNING))
                logger.log(Level.WARNING, ex.toString() + ":" + ex.getMessage() + " : problem with line parsing : " + this.m_line, ex);
            if (ex instanceof NullPointerException)
                if (logger != null && logger.isLoggable(Level.SEVERE))
                    logger.log(Level.SEVERE, ex.toString(), ex);
            return null;
        }
    }
    return this.m_call;
}
Also used : ICip(de.janrufmonitor.framework.ICip) Logger(java.util.logging.Logger) Date(java.util.Date) ParseException(java.text.ParseException) IRuntime(de.janrufmonitor.runtime.IRuntime) ICaller(de.janrufmonitor.framework.ICaller) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ParseException(java.text.ParseException) IMsn(de.janrufmonitor.framework.IMsn) SimpleDateFormat(java.text.SimpleDateFormat) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 58 with IAttributeMap

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

the class FritzBoxCallRaw method toCall.

public ICall toCall() {
    if (this.m_line == null || this.m_line.length() == 0)
        return null;
    if (this.m_call == null) {
        IRuntime r = PIMRuntime.getInstance();
        String[] call = this.m_line.split(";");
        if (call.length >= 4 && call[1].equalsIgnoreCase("RING")) {
            // create MSN
            IMsn msn = r.getCallFactory().createMsn(getMsn(call[4]), "");
            msn.setAdditional(r.getMsnManager().getMsnLabel(msn));
            IPhonenumber pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toClirPhonenumber(call[3].trim());
            // if no CLIR call, check internal
            if (pn == null)
                pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toInternalPhonenumber(call[3].trim(), msn.getMSN());
            // if no internal call, check regular
            if (pn == null) {
                // if incoming call does not start with 0, the Provider number seems to have the wrong format
                // assume it is an international format 4971657110
                boolean onlyNumbers = call[3].matches("[+-]?[0-9]+");
                if (!call[3].startsWith("0") && onlyNumbers) {
                    call[3] = "00" + call[3];
                }
                pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toPhonenumber(call[3].trim(), msn.getMSN());
            }
            ICaller caller = r.getCallerFactory().createCaller(pn);
            // create call data
            // added 2009/05/01
            SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yy HH:mm:ss");
            Date date = new Date(0);
            try {
                date = sdf.parse(call[0]);
                date = this.toFritzboxDate(date);
            } catch (ParseException e) {
                Logger.getLogger(IJAMConst.DEFAULT_LOGGER).severe("Wrong standard date format detected.");
                sdf = new SimpleDateFormat(this.m_config.getProperty(CFG_DATEFORMAT, "dd.MM.yy HH:mm"));
                try {
                    date = sdf.parse(call[0]);
                    date = this.toFritzboxDate(date);
                } catch (ParseException ex) {
                    Logger.getLogger(IJAMConst.DEFAULT_LOGGER).severe("Wrong custom date format detected.");
                }
            }
            ICip cip = r.getCallFactory().createCip(getCip(call[5]), "");
            cip.setAdditional(r.getCipManager().getCipLabel(cip, ""));
            // create attributes
            IAttributeMap am = r.getCallFactory().createAttributeMap();
            am.add(r.getCallFactory().createAttribute("fritzbox.key", call[2]));
            am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_MISSED));
            this.m_call = r.getCallFactory().createCall(FritzBoxUUIDManager.getInstance().calculateUUID(FritzBoxUUIDManager.getInstance().getUUID(date, pn, msn)), caller, msn, cip, date);
            this.m_call.setAttributes(am);
        }
        if (call.length >= 4 && call[1].equalsIgnoreCase("CALL")) {
            // create msn
            String s_msn = null;
            if (call.length >= 7) {
                s_msn = getMsn(call[6]);
                if (s_msn == null || call[6].equalsIgnoreCase(s_msn))
                    s_msn = getMsn(call[4]);
            } else {
                s_msn = getMsn(call[4]);
            }
            IMsn msn = r.getCallFactory().createMsn((s_msn == null ? "" : s_msn), "");
            msn.setAdditional(r.getMsnManager().getMsnLabel(msn));
            // create caller data
            String callByCall = null;
            IPhonenumber pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toClirPhonenumber(call[5].trim());
            // if no CLIR call, check internal
            if (pn == null)
                pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toInternalPhonenumber(call[5].trim(), msn.getMSN());
            // if no internal call, check regular
            if (pn == null) {
                // added 2006/08/10: trim call-by-call information
                // only can occure on state CALL (out-going calls)
                callByCall = getCallByCall(call[5]);
                if (callByCall != null) {
                    call[5] = call[5].substring(callByCall.length());
                }
                // requires addition of areacode
                if (!call[5].startsWith("0")) {
                    Logger.getLogger(IJAMConst.DEFAULT_LOGGER).info("Assuming number " + call[5] + " has missing areacode.");
                    call[5] = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).getAreaCode() + call[5];
                    Logger.getLogger(IJAMConst.DEFAULT_LOGGER).info("Added areacode to number " + call[5]);
                }
                pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toPhonenumber(call[5].trim(), msn.getMSN());
            }
            ICaller caller = r.getCallerFactory().createCaller(pn);
            // create call data
            // added 2009/05/27
            SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yy HH:mm:ss");
            Date date = new Date(0);
            try {
                date = sdf.parse(call[0]);
                date = this.toFritzboxDate(date);
            } catch (ParseException e) {
                Logger.getLogger(IJAMConst.DEFAULT_LOGGER).severe("Wrong standard date format detected.");
                sdf = new SimpleDateFormat(this.m_config.getProperty(CFG_DATEFORMAT, "dd.MM.yy HH:mm"));
                try {
                    date = sdf.parse(call[0]);
                    date = this.toFritzboxDate(date);
                } catch (ParseException ex) {
                    Logger.getLogger(IJAMConst.DEFAULT_LOGGER).severe("Wrong custom date format detected.");
                }
            }
            ICip cip = r.getCallFactory().createCip(getCip(call[6]), "");
            cip.setAdditional(r.getCipManager().getCipLabel(cip, ""));
            // create attributes
            IAttributeMap am = r.getCallFactory().createAttributeMap();
            am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_OUTGOING));
            am.add(r.getCallFactory().createAttribute("fritzbox.key", call[2]));
            if (callByCall != null)
                am.add(r.getCallFactory().createAttribute("fritzbox.callbycall", callByCall));
            this.m_call = r.getCallFactory().createCall(FritzBoxUUIDManager.getInstance().calculateUUID(FritzBoxUUIDManager.getInstance().getUUID(date, pn, msn)), caller, msn, cip, date);
            this.m_call.setAttributes(am);
        }
    }
    return this.m_call;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICip(de.janrufmonitor.framework.ICip) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ParseException(java.text.ParseException) IMsn(de.janrufmonitor.framework.IMsn) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) IRuntime(de.janrufmonitor.runtime.IRuntime) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 59 with IAttributeMap

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

the class AbstractFilterCallManager method filterCalls.

protected ICallList filterCalls(IFilter filter, ICallList cl) {
    if (cl == null) {
        cl = this.getInitialCallList(filter);
    }
    long start = System.currentTimeMillis();
    this.m_logger.info("Start filtering with filter: " + filter);
    this.m_logger.info("CallList size before filtering: " + cl.size());
    ICall c = null;
    if (filter != null) {
        if (filter.getType().equals(FilterType.DATE) || filter.getType().equals(FilterType.YEAR) || filter.getType().equals(FilterType.MONTH_YEAR)) {
            long from = 0;
            long to = 0;
            if (filter instanceof DateFilter) {
                DateFilter df = (DateFilter) filter;
                to = (df.getDateFrom() == null ? 0 : df.getDateFrom().getTime());
                from = df.getDateTo().getTime();
            }
            if (filter instanceof YearFilter) {
                YearFilter df = (YearFilter) filter;
                from = (df.getDateFrom() == null ? 0 : df.getDateFrom().getTime());
                to = df.getDateTo().getTime();
            }
            if (filter instanceof MonthYearFilter) {
                MonthYearFilter df = (MonthYearFilter) filter;
                from = (df.getDateFrom() == null ? 0 : df.getDateFrom().getTime());
                to = df.getDateTo().getTime();
            }
            long cdate = 0;
            for (int i = cl.size() - 1; i >= 0; i--) {
                c = cl.get(i);
                cdate = c.getDate().getTime();
                if (to > 0) {
                    if (cdate < from || cdate > to)
                        cl.remove(c);
                } else {
                    if (cdate < from)
                        cl.remove(c);
                }
            }
        }
        if (filter.getType().equals(FilterType.CALLER)) {
            ICaller cfilter = (ICaller) filter.getFilterObject();
            IPhonenumber pn = cfilter.getPhoneNumber();
            for (int i = cl.size() - 1; i >= 0; i--) {
                c = cl.get(i);
                if (!c.getCaller().getPhoneNumber().equals(pn))
                    cl.remove(c);
            }
        }
        if (filter.getType().equals(FilterType.PHONENUMBER)) {
            IPhonenumber pn = (IPhonenumber) filter.getFilterObject();
            for (int i = cl.size() - 1; i >= 0; i--) {
                c = cl.get(i);
                if (!c.getCaller().getPhoneNumber().equals(pn))
                    cl.remove(c);
            }
        }
        if (filter.getType().equals(FilterType.CIP)) {
            ICip cip = (ICip) filter.getFilterObject();
            for (int i = cl.size() - 1; i >= 0; i--) {
                c = cl.get(i);
                if (!c.getCIP().equals(cip))
                    cl.remove(c);
            }
        }
        if (filter.getType().equals(FilterType.MSN)) {
            IMsn msn = (IMsn) filter.getFilterObject();
            for (int i = cl.size() - 1; i >= 0; i--) {
                c = cl.get(i);
                if (!c.getMSN().equals(msn))
                    cl.remove(c);
            }
        }
        if (filter.getType().equals(FilterType.UUID)) {
            String[] uuids = (String[]) filter.getFilterObject();
            for (int i = cl.size() - 1; i >= 0; i--) {
                c = cl.get(i);
                boolean hasUUID = false;
                for (int j = 0; j < uuids.length; j++) {
                    if (c.getUUID().equalsIgnoreCase(uuids[j]))
                        hasUUID = true;
                }
                if (!hasUUID)
                    cl.remove(c);
            }
        }
        if (filter.getType().equals(FilterType.ATTRIBUTE)) {
            IAttributeMap m = ((AttributeFilter) filter).getAttributeMap();
            if (m != null && m.size() > 0) {
                Iterator iter = m.iterator();
                IAttribute a = null;
                while (iter.hasNext()) {
                    a = (IAttribute) iter.next();
                    IAttribute ua = null;
                    for (int i = cl.size() - 1; i >= 0; i--) {
                        c = cl.get(i);
                        ua = c.getAttribute(a.getName());
                        if (ua == null || !ua.getValue().equalsIgnoreCase(a.getValue())) {
                            cl.remove(c);
                        }
                    }
                }
            }
        }
        if (filter.getType().equals(FilterType.ITEMCOUNT)) {
            int itemcount = ((ItemCountFilter) filter).getLimit();
            if (itemcount > 0) {
                ICallList tmpCl = this.getRuntime().getCallFactory().createCallList(itemcount);
                // added: 2006/04/20: just a work-a-round
                cl.sort(0, false);
                for (int i = 0, j = Math.min(cl.size(), itemcount); i < j; i++) {
                    tmpCl.add(cl.get(i));
                }
                cl.clear();
                cl.add(tmpCl);
            }
        }
    }
    this.m_logger.info("CallList size after filtering: " + cl.size());
    this.m_logger.info("Finished filtering with filter <" + filter + "> in " + Long.toString(System.currentTimeMillis() - start) + " msec.");
    return cl;
}
Also used : ICall(de.janrufmonitor.framework.ICall) ICip(de.janrufmonitor.framework.ICip) ICaller(de.janrufmonitor.framework.ICaller) ItemCountFilter(de.janrufmonitor.repository.filter.ItemCountFilter) ICallList(de.janrufmonitor.framework.ICallList) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) MonthYearFilter(de.janrufmonitor.repository.filter.MonthYearFilter) YearFilter(de.janrufmonitor.repository.filter.YearFilter) DateFilter(de.janrufmonitor.repository.filter.DateFilter) IMsn(de.janrufmonitor.framework.IMsn) MonthYearFilter(de.janrufmonitor.repository.filter.MonthYearFilter) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 60 with IAttributeMap

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

the class AbstractWebCallerManager method getCaller.

public ICaller getCaller(IPhonenumber p) throws CallerNotFoundException {
    if (p == null)
        throw new CallerNotFoundException("Phone number is not set (null). No caller found.");
    if (p.isClired())
        throw new CallerNotFoundException("Phone number is CLIR. Identification impossible.");
    if (PhonenumberAnalyzer.getInstance(this.getRuntime()).isInternal(p))
        throw new CallerNotFoundException("Phone number is internal number.");
    IPhonenumber number = this.getRuntime().getCallerFactory().createPhonenumber(p.getTelephoneNumber());
    if (isUsedCache() && this.m_unidentified != null && this.m_unidentified.containsKey(number.getTelephoneNumber())) {
        Integer io = (Integer) this.m_unidentified.get(number.getTelephoneNumber());
        if (io.intValue() == 10) {
            this.m_unidentified.remove(number.getTelephoneNumber());
        } else {
            this.m_unidentified.put(number.getTelephoneNumber(), new Integer(io.intValue() + 1));
        }
        throw new CallerNotFoundException("Phone number " + number.getTelephoneNumber() + " not identified. (cached)");
    }
    ICaller caller = null;
    if (isUsedCache() && this.m_cache != null && this.m_cache.containsKey(number)) {
        caller = (ICaller) this.m_cache.get(number);
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("Taking caller from cache: " + caller);
        if (caller != null)
            return caller;
    } else {
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("Number is not cached, start identifiing ...");
        IPhonenumber pn = null;
        try {
            ICallerManager defaultManager = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
            if (defaultManager != null && defaultManager.isActive() && defaultManager.isSupported(IIdentifyCallerRepository.class)) {
                ICaller defaultIdentified = ((IIdentifyCallerRepository) defaultManager).getCaller(number);
                pn = defaultIdentified.getPhoneNumber();
            }
        } catch (CallerNotFoundException e) {
        // ignore this exception
        }
        // check correct country code
        if (!this.getSupportedIntAreaCode().equalsIgnoreCase("00")) {
            if (pn != null && !pn.getIntAreaCode().equalsIgnoreCase(this.getSupportedIntAreaCode()))
                throw new CallerNotFoundException("Phone number has country code " + pn.getIntAreaCode() + ". Caller manager " + this.getID() + " is supporting only " + this.getSupportedIntAreaCode());
            // added 2013/07/22: number format compatibility 0911234567 must be equal +49 (911) 234567
            if (pn != null)
                number.setTelephoneNumber(pn.getTelephoneNumber());
        }
        // added 2009/05/28
        // add detection of web services which provides number in middle of URL
        String url = this.getURL();
        if (url.indexOf(IJAMConst.GLOBAL_VARIABLE_WEBCM_NUMBER) > 0) {
            url = StringUtils.replaceString(url, IJAMConst.GLOBAL_VARIABLE_WEBCM_NUMBER, (number.getTelephoneNumber().startsWith("0") ? "" : "0") + number.getTelephoneNumber());
        } else {
            // added 2010/11/18: added URL attribute parsing
            String urlx = url;
            url = Formatter.getInstance(this.getRuntime()).parse(url, pn);
            if (urlx.equalsIgnoreCase(url))
                url += (number.getTelephoneNumber().startsWith("0") ? "" : "0") + number.getTelephoneNumber();
        }
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("URL to call: " + url);
        AbstractURLRequester r = this.createURLRequester(url, this.getSkipBytes(), number.getTelephoneNumber());
        try {
            long ts = System.currentTimeMillis();
            Executor ex = new Executor(r);
            Thread t = new Thread(ex);
            t.start();
            while (t.isAlive() && (System.currentTimeMillis() - ts < r.getTimeout())) {
                Thread.sleep(100);
            }
            if (ex != null && ex.isFailed()) {
                if (this.m_unidentified != null && !this.m_unidentified.containsKey(number.getTelephoneNumber()))
                    this.m_unidentified.put(number.getTelephoneNumber(), new Integer(1));
                throw new CallerNotFoundException("Phone number " + number.getTelephoneNumber() + " not identified.", (ex.getException() != null ? ex.getException() : new Exception()));
            }
            if (t.isAlive())
                throw new Exception("Identification thread is blocking.");
        // r.go();
        } catch (Exception e) {
            if (this.m_unidentified != null && !this.m_unidentified.containsKey(number.getTelephoneNumber()))
                this.m_unidentified.put(number.getTelephoneNumber(), new Integer(1));
            throw new CallerNotFoundException("Phone number " + number.getTelephoneNumber() + " not identified: " + e.getMessage(), e);
        }
        IAttributeMap m = r.getAttributes();
        if (pn == null)
            pn = r.getPhonenumber();
        if (!getKeepSourceNumber() && pn != null && r.getPhonenumber() != null && !r.getPhonenumber().getTelephoneNumber().endsWith(pn.getTelephoneNumber())) {
            pn = r.getPhonenumber();
            if (this.m_logger.isLoggable(Level.INFO))
                this.m_logger.info("Incoming call number " + number.getTelephoneNumber() + " was not identified but extension " + pn.getTelephoneNumber());
        }
        caller = this.getRuntime().getCallerFactory().createCaller(pn);
        caller.setAttributes(m);
        IAttribute cm = this.getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, this.getID());
        caller.setAttribute(cm);
        // add caller to cache
        if (this.m_cache != null)
            this.m_cache.put(number, caller);
        return caller;
    }
    throw new CallerNotFoundException("No caller found for number " + number);
}
Also used : AbstractURLRequester(de.janrufmonitor.repository.web.AbstractURLRequester) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) ICaller(de.janrufmonitor.framework.ICaller) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IAttributeMap (de.janrufmonitor.framework.IAttributeMap)64 IAttribute (de.janrufmonitor.framework.IAttribute)37 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)36 ICaller (de.janrufmonitor.framework.ICaller)31 List (java.util.List)24 ICallerList (de.janrufmonitor.framework.ICallerList)23 ArrayList (java.util.ArrayList)21 Iterator (java.util.Iterator)17 IOException (java.io.IOException)14 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)13 Date (java.util.Date)12 IMsn (de.janrufmonitor.framework.IMsn)11 File (java.io.File)10 ICip (de.janrufmonitor.framework.ICip)8 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)8 Message (de.janrufmonitor.exception.Message)6 ICall (de.janrufmonitor.framework.ICall)6 SimpleDateFormat (java.text.SimpleDateFormat)6 StringTokenizer (java.util.StringTokenizer)6 IFilter (de.janrufmonitor.repository.filter.IFilter)5