Search in sources :

Example 96 with IAttribute

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

the class AbstractCallerDatabaseHandler method getCaller.

public ICaller getCaller(IPhonenumber pn) throws SQLException {
    if (!isConnected())
        try {
            this.connect();
        } catch (ClassNotFoundException e) {
            throw new SQLException(e.getMessage());
        }
    PreparedStatement ps = this.getStatement("SELECT_CALLER_PHONE");
    String p = pn.getTelephoneNumber();
    ResultSet rs = null;
    // check for internal telephone system numbers
    if (this.isInternalNumber(pn)) {
        ps.setString(1, p);
        rs = ps.executeQuery();
        while (rs.next()) {
            this.m_logger.info("Found exact match of call number: " + p);
            try {
                return Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
    int maxLength = this.maxInternalNumberLength();
    // p must be an internal number but has no entry in this caller manager
    if (p.length() < maxLength)
        return null;
    // check for international call
    if (p.startsWith(this.getPrefix())) {
        this.m_logger.info("Found international call number: " + p);
        ICaller internationaCaller = null;
        ICallerManager cmg = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
        if (cmg != null && cmg.isActive() && cmg.isSupported(IIdentifyCallerRepository.class)) {
            try {
                internationaCaller = ((IIdentifyCallerRepository) cmg).getCaller(pn);
            } catch (CallerNotFoundException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
        if (internationaCaller != null)
            pn = internationaCaller.getPhoneNumber();
        ps.setString(1, pn.getTelephoneNumber());
        rs = ps.executeQuery();
        while (rs.next()) {
            try {
                ICaller c = Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
                if (pn.getTelephoneNumber().equalsIgnoreCase(c.getPhoneNumber().getTelephoneNumber()) && pn.getIntAreaCode().equalsIgnoreCase(c.getPhoneNumber().getIntAreaCode())) {
                    // found international number
                    return c;
                }
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
    // check for extension
    if (pn.getIntAreaCode() == null || pn.getIntAreaCode().length() == 0) {
        pn.setIntAreaCode(this.getDefaultIntAreaCode());
    }
    for (int i = 0; i < p.length() - maxLength; i++) {
        ps.setString(1, p.substring(0, p.length() - i) + "%");
        rs = ps.executeQuery();
        while (rs.next()) {
            try {
                ICaller c = Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
                if (p.startsWith(c.getPhoneNumber().getTelephoneNumber()) && pn.getIntAreaCode().equalsIgnoreCase(c.getPhoneNumber().getIntAreaCode())) {
                    // found extension phone
                    String extension = p.substring(c.getPhoneNumber().getTelephoneNumber().length(), p.length());
                    this.m_logger.info("Found call extension -" + extension + " for call number: " + p);
                    c.setUUID(new UUID().toString());
                    c.getPhoneNumber().setTelephoneNumber(p);
                    c.getPhoneNumber().setCallNumber(c.getPhoneNumber().getCallNumber() + extension);
                    // add attributes
                    IAttribute att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EXTENSION, extension);
                    c.setAttribute(att);
                    att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION, p.substring(0, p.length() - extension.length()));
                    c.setAttribute(att);
                    return c;
                }
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
    return null;
}
Also used : SQLException(java.sql.SQLException) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) PreparedStatement(java.sql.PreparedStatement) SerializerException(de.janrufmonitor.util.io.SerializerException) ICallerManager(de.janrufmonitor.repository.ICallerManager) ICaller(de.janrufmonitor.framework.ICaller) ResultSet(java.sql.ResultSet) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) IAttribute(de.janrufmonitor.framework.IAttribute) UUID(de.janrufmonitor.util.uuid.UUID)

Example 97 with IAttribute

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

the class AbstractDatabaseHandler method updateAttributes.

protected void updateAttributes(PreparedStatement ps, String uuid, IAttributeMap m) throws SQLException {
    Iterator i = m.iterator();
    IAttribute att = null;
    while (i.hasNext()) {
        att = (IAttribute) i.next();
        ps.clearParameters();
        ps.setString(1, att.getValue());
        ps.setString(2, uuid);
        ps.setString(3, att.getName());
        ps.addBatch();
    }
}
Also used : Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute)

Example 98 with IAttribute

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

the class AbstractMultiPhoneCallerDatabaseHandler method process.

private ICaller process(ICaller c, IPhonenumber pn, String p) {
    if (c instanceof IMultiPhoneCaller) {
        this.m_logger.info("Found multi phone caller.");
        IPhonenumber cp = null;
        for (int x = 0, j = ((IMultiPhoneCaller) c).getPhonenumbers().size(); x < j; x++) {
            cp = (IPhonenumber) ((IMultiPhoneCaller) c).getPhonenumbers().get(x);
            if (p.startsWith(cp.getTelephoneNumber()) && pn.getIntAreaCode().equalsIgnoreCase(cp.getIntAreaCode())) {
                // found extension phone
                String extension = p.substring(cp.getTelephoneNumber().length(), p.length());
                this.m_logger.info("Found call extension -" + extension + " for call number: " + p);
                c.setUUID(new UUID().toString());
                ((IMultiPhoneCaller) c).getPhonenumbers().clear();
                cp.setCallNumber(cp.getCallNumber() + extension);
                c.setPhoneNumber(cp);
                // add attributes
                IAttribute att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EXTENSION, extension);
                c.setAttribute(att);
                att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION, p.substring(0, p.length() - extension.length()));
                c.setAttribute(att);
                return c;
            }
        }
    } else if (c instanceof ICaller) {
        if (p.startsWith(c.getPhoneNumber().getTelephoneNumber()) && pn.getIntAreaCode().equalsIgnoreCase(c.getPhoneNumber().getIntAreaCode())) {
            // found extension phone
            String extension = p.substring(c.getPhoneNumber().getTelephoneNumber().length(), p.length());
            this.m_logger.info("Found call extension -" + extension + " for call number: " + p);
            c.setUUID(new UUID().toString());
            c.getPhoneNumber().setTelephoneNumber(p);
            c.getPhoneNumber().setCallNumber(c.getPhoneNumber().getCallNumber() + extension);
            // add attributes
            IAttribute att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EXTENSION, extension);
            c.setAttribute(att);
            att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION, p.substring(0, p.length() - extension.length()));
            c.setAttribute(att);
            return c;
        }
    }
    return null;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) IAttribute(de.janrufmonitor.framework.IAttribute) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) UUID(de.janrufmonitor.util.uuid.UUID) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 99 with IAttribute

use of de.janrufmonitor.framework.IAttribute 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 100 with IAttribute

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

IAttribute (de.janrufmonitor.framework.IAttribute)111 ICaller (de.janrufmonitor.framework.ICaller)44 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)40 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)39 List (java.util.List)34 ICallerList (de.janrufmonitor.framework.ICallerList)31 ArrayList (java.util.ArrayList)29 Iterator (java.util.Iterator)25 ICall (de.janrufmonitor.framework.ICall)19 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)15 SQLException (java.sql.SQLException)15 File (java.io.File)14 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)12 IOException (java.io.IOException)12 Message (de.janrufmonitor.exception.Message)11 ComFailException (com.jacob.com.ComFailException)10 Date (java.util.Date)10 IMsn (de.janrufmonitor.framework.IMsn)9 Dispatch (com.jacob.com.Dispatch)8 UUID (de.janrufmonitor.util.uuid.UUID)8