Search in sources :

Example 11 with UUID

use of de.janrufmonitor.util.uuid.UUID 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 12 with UUID

use of de.janrufmonitor.util.uuid.UUID 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 13 with UUID

use of de.janrufmonitor.util.uuid.UUID 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)

Aggregations

UUID (de.janrufmonitor.util.uuid.UUID)13 ICaller (de.janrufmonitor.framework.ICaller)10 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)9 SQLException (java.sql.SQLException)9 List (java.util.List)9 IAttribute (de.janrufmonitor.framework.IAttribute)8 ArrayList (java.util.ArrayList)8 ICallerList (de.janrufmonitor.framework.ICallerList)6 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)6 SerializerException (de.janrufmonitor.util.io.SerializerException)4 PreparedStatement (java.sql.PreparedStatement)4 Properties (java.util.Properties)4 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)2 ActiveXComponent (com.jacob.activeX.ActiveXComponent)1 ComFailException (com.jacob.com.ComFailException)1 Dispatch (com.jacob.com.Dispatch)1 Variant (com.jacob.com.Variant)1 Message (de.janrufmonitor.exception.Message)1 ICall (de.janrufmonitor.framework.ICall)1 ICallList (de.janrufmonitor.framework.ICallList)1