Search in sources :

Example 86 with IPhonenumber

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

the class AbstractCallDatabaseHandler method setCallList.

/**
 * Sets all calls in the submitted list to the database.
 *
 * @param cl
 * @throws SQLException
 */
public void setCallList(ICallList cl) throws SQLException {
    if (!isConnected())
        try {
            this.connect();
        } catch (ClassNotFoundException e) {
            throw new SQLException(e.getMessage());
        }
    this.internalDeleteCallList(cl);
    List uuid_check = new ArrayList(cl.size());
    PreparedStatement ps = this.getStatement("INSERT_CALL");
    PreparedStatement psa = this.getStatement("INSERT_ATTRIBUTE");
    ps.clearBatch();
    psa.clearBatch();
    ICall c = null;
    IPhonenumber pn = null;
    String uuid = null;
    for (int i = 0, j = cl.size(); i < j; i++) {
        c = cl.get(i);
        if (this.m_logger.isLoggable(Level.INFO) && c != null)
            this.m_logger.info("Adding to database: " + c.toString());
        // check if redundant uuid could occure
        uuid = c.getUUID();
        if (uuid_check.contains(uuid)) {
            this.m_logger.warning("Found duplicated UUID: " + c.toString());
            c.setUUID(new UUID().toString());
            uuid = c.getUUID();
        }
        uuid_check.add(uuid);
        pn = c.getCaller().getPhoneNumber();
        try {
            this.createCall(ps, uuid, c.getCaller().getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), c.getMSN().getMSN(), c.getCIP().getCIP(), c.getDate().getTime(), Serializer.toByteArray(c));
            this.createAttributes(psa, uuid, c.getAttributes());
            this.createAttributes(psa, c.getCaller().getUUID(), c.getCaller().getAttributes());
        } catch (SerializerException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        }
        if (i % this.commit_count == 0) {
            try {
                ps.executeBatch();
                psa.executeBatch();
                ps.clearBatch();
                psa.clearBatch();
                this.m_logger.info("-------------------> executed Batch");
            } catch (SQLException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage() + c.toString(), e);
            // throw new SQLException("Batch execution failed: ");
            }
        }
    }
    // execute the rest batch content
    ps.executeBatch();
    psa.executeBatch();
    uuid_check.clear();
    uuid_check = null;
}
Also used : ICall(de.janrufmonitor.framework.ICall) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ICallList(de.janrufmonitor.framework.ICallList) ArrayList(java.util.ArrayList) List(java.util.List) PreparedStatement(java.sql.PreparedStatement) UUID(de.janrufmonitor.util.uuid.UUID) SerializerException(de.janrufmonitor.util.io.SerializerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 87 with IPhonenumber

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

the class AbstractMultiPhoneCallerDatabaseHandler method getCaller.

@SuppressWarnings("resource")
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();
    ICaller c = null;
    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 {
                c = Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
                if (c instanceof IMultiPhoneCaller) {
                    IPhonenumber cp = null;
                    for (int i = 0, j = ((IMultiPhoneCaller) c).getPhonenumbers().size(); i < j; i++) {
                        cp = (IPhonenumber) ((IMultiPhoneCaller) c).getPhonenumbers().get(i);
                        if (cp.getTelephoneNumber().startsWith(p)) {
                            this.m_logger.info("Found correct phonenumber match: " + p + " = " + cp.getTelephoneNumber());
                            ((IMultiPhoneCaller) c).getPhonenumbers().clear();
                            c.setPhoneNumber(cp);
                            return c;
                        }
                    }
                }
            } 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 {
                c = Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
                if (c instanceof IMultiPhoneCaller) {
                    IPhonenumber cp = null;
                    for (int i = 0, j = ((IMultiPhoneCaller) c).getPhonenumbers().size(); i < j; i++) {
                        cp = (IPhonenumber) ((IMultiPhoneCaller) c).getPhonenumbers().get(i);
                        if (pn.getTelephoneNumber().equalsIgnoreCase(cp.getTelephoneNumber()) && pn.getIntAreaCode().equalsIgnoreCase(cp.getIntAreaCode())) {
                            this.m_logger.info("Found correct phonenumber match: " + p + " = " + cp.getTelephoneNumber());
                            ((IMultiPhoneCaller) c).getPhonenumbers().clear();
                            c.setPhoneNumber(cp);
                            // found international number
                            return c;
                        }
                    }
                } else if (c instanceof ICaller) {
                    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());
    }
    PreparedStatement ps2 = this.getStatement("SELECT_PHONE_REF_COUNT");
    if (ps2 == null)
        return null;
    boolean multiprocess = false;
    for (int i = 0; i < p.length() - maxLength; i++) {
        ps2.setString(1, p.substring(0, p.length() - i) + "%");
        rs = ps2.executeQuery();
        while (rs.next()) {
            multiprocess = rs.getInt(1) > 1;
        }
        if (!multiprocess) {
            ps.setString(1, p.substring(0, p.length() - i) + "%");
            rs = ps.executeQuery();
            while (rs.next()) {
                try {
                    c = Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
                    ICaller nc = this.process(c, pn, p);
                    if (nc != null)
                        return nc;
                } catch (SerializerException e) {
                    this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                }
            }
        } else {
            // added 2008/04/18: processing of multiple callers is possible
            PreparedStatement ps3 = this.getStatement("SELECT_PHONE_REF");
            ps3.setString(1, p.substring(0, p.length() - i) + "%");
            rs = ps3.executeQuery();
            List uuids = new ArrayList(2);
            while (rs.next()) {
                uuids.add(rs.getString(1));
            }
            // process all UUIDs
            String uuid = null;
            ps3 = this.getStatement("SELECT_CALLER_PHONE2");
            for (int j = 0; j < uuids.size(); j++) {
                uuid = (String) uuids.get(j);
                ps3.setString(1, uuid);
                rs = ps3.executeQuery();
                while (rs.next()) {
                    try {
                        c = Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime());
                        ICaller nc = this.process(c, pn, p);
                        if (nc != null)
                            return nc;
                    } catch (SerializerException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                    }
                }
            }
        }
    }
    return null;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) 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) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 88 with IPhonenumber

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

the class AbstractMultiPhoneCallerDatabaseHandler method existsPhones.

private List existsPhones(List phones) throws SQLException {
    if (phones == null || phones.size() == 0)
        return new ArrayList(1);
    if (!isConnected())
        try {
            this.connect();
        } catch (ClassNotFoundException e) {
            throw new SQLException(e.getMessage());
        }
    List existancePhones = new ArrayList(phones.size());
    IPhonenumber pn = null;
    for (int i = 0, j = phones.size(); i < j; i++) {
        pn = (IPhonenumber) phones.get(i);
        PreparedStatement ps = this.getStatement("SELECT_PHONE_COUNT");
        ps.setString(1, pn.getIntAreaCode());
        ps.setString(2, pn.getAreaCode());
        ps.setString(3, pn.getCallNumber());
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            if (rs.getInt(1) > 0) {
                existancePhones.add(pn);
            }
        }
    }
    return existancePhones;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) PreparedStatement(java.sql.PreparedStatement) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 89 with IPhonenumber

use of de.janrufmonitor.framework.IPhonenumber 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 90 with IPhonenumber

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

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