Search in sources :

Example 6 with CallerNotFoundException

use of de.janrufmonitor.repository.CallerNotFoundException in project janrufmonitor by tbrandt77.

the class OldDatFileCallImporter method parsePhone.

private IPhonenumber parsePhone(String caller) {
    if (caller.indexOf("(0") > -1) {
        IPhonenumber phone = null;
        String pn = caller.substring(caller.indexOf("(0") + 2, caller.lastIndexOf(")"));
        if (pn.length() > 0) {
            phone = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(pn);
            ICallerManager cm = PIMRuntime.getInstance().getCallerManagerFactory().getDefaultCallerManager();
            if (cm != null && cm.isActive() && cm.isSupported(IIdentifyCallerRepository.class)) {
                try {
                    ICaller parsedCaller = ((IIdentifyCallerRepository) cm).getCaller(phone);
                    return parsedCaller.getPhoneNumber();
                } catch (CallerNotFoundException e) {
                    this.m_logger.warning(e.getMessage());
                }
            }
        }
    }
    return PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true);
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) ICallerManager(de.janrufmonitor.repository.ICallerManager) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 7 with CallerNotFoundException

use of de.janrufmonitor.repository.CallerNotFoundException in project janrufmonitor by tbrandt77.

the class OldDatFileCallerImporter method migrateCallerFromString.

private ICaller migrateCallerFromString(String scaller) {
    if (scaller != null && scaller.trim().length() == 0)
        return null;
    StringTokenizer st = new StringTokenizer(scaller, ";");
    String number = st.nextToken().trim();
    String caller = st.nextToken().trim();
    String reject = "0";
    if (st.hasMoreTokens())
        reject = st.nextToken().trim();
    IPhonenumber pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(number.substring(1));
    try {
        ICaller migCaller = null;
        ICallerManager def = PIMRuntime.getInstance().getCallerManagerFactory().getDefaultCallerManager();
        if (def != null && def.isActive() && def.isSupported(IIdentifyCallerRepository.class)) {
            migCaller = ((IIdentifyCallerRepository) def).getCaller(pn);
        } else
            throw new CallerNotFoundException();
        StringTokenizer ctoken = new StringTokenizer(caller, " ");
        IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
        if (ctoken.hasMoreTokens()) {
            name.setFirstname(ctoken.nextToken());
        }
        if (ctoken.hasMoreTokens()) {
            name.setLastname(ctoken.nextToken());
        }
        if (ctoken.hasMoreTokens()) {
            name.setAdditional(ctoken.nextToken());
        }
        while (ctoken.hasMoreTokens()) {
            name.setAdditional(name.getAdditional() + " " + ctoken.nextToken());
        }
        migCaller.setName(name);
        if (reject.equalsIgnoreCase("1")) {
            IAttribute att = PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_REJECT, IJAMConst.ATTRIBUTE_VALUE_YES);
            migCaller.setAttribute(att);
        }
        if (reject.equalsIgnoreCase("0")) {
            IAttribute att = PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_REJECT, IJAMConst.ATTRIBUTE_VALUE_NO);
            migCaller.setAttribute(att);
        }
        LogManager.getLogManager().getLogger(IJAMConst.DEFAULT_LOGGER).info(migCaller.toString());
        return migCaller;
    } catch (CallerNotFoundException e) {
        LogManager.getLogManager().getLogger(IJAMConst.DEFAULT_LOGGER).warning(e.getMessage());
    }
    return null;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) StringTokenizer(java.util.StringTokenizer) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) IAttribute(de.janrufmonitor.framework.IAttribute) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) IName(de.janrufmonitor.framework.IName) ICallerManager(de.janrufmonitor.repository.ICallerManager) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 8 with CallerNotFoundException

use of de.janrufmonitor.repository.CallerNotFoundException 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 9 with CallerNotFoundException

use of de.janrufmonitor.repository.CallerNotFoundException 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 10 with CallerNotFoundException

use of de.janrufmonitor.repository.CallerNotFoundException in project janrufmonitor by tbrandt77.

the class AbstractPhonesPage method getCaller.

private ICaller getCaller(IPhonenumber pn, List managers) {
    if (pn.isClired()) {
        return this.getRuntime().getCallerFactory().createCaller(this.getRuntime().getCallerFactory().createName("", ""), this.getRuntime().getCallerFactory().createPhonenumber(true));
    }
    if (pn.getIntAreaCode().equalsIgnoreCase(IJAMConst.INTERNAL_CALL) && pn.getCallNumber().equalsIgnoreCase(IJAMConst.INTERNAL_CALL_NUMBER_SYMBOL)) {
        return (this.getRuntime().getCallerFactory().createCaller(this.getRuntime().getCallerFactory().createName("", ""), this.getRuntime().getCallerFactory().createPhonenumber(IJAMConst.INTERNAL_CALL, "", IJAMConst.INTERNAL_CALL_NUMBER_SYMBOL)));
    }
    if (managers == null)
        managers = this.getActiveCallerManagers();
    ICallerManager man = null;
    List remoteManagers = new ArrayList();
    for (int i = 0; i < managers.size(); i++) {
        man = (ICallerManager) managers.get(i);
        // first only check local repository managers for performance
        if (!(man instanceof ILocalRepository)) {
            remoteManagers.add(man);
        } else {
            try {
                if (man != null && man.isActive() && man.isSupported(IIdentifyCallerRepository.class))
                    return ((IIdentifyCallerRepository) man).getCaller(pn);
            } catch (CallerNotFoundException e) {
                this.m_logger.warning(e.getMessage());
            }
        }
    }
    // check for all non-local repositorymanagers
    for (int i = 0; i < remoteManagers.size(); i++) {
        man = (ICallerManager) remoteManagers.get(i);
        try {
            if (man != null && man.isActive() && man.isSupported(IIdentifyCallerRepository.class))
                return ((IIdentifyCallerRepository) man).getCaller(pn);
        } catch (CallerNotFoundException e) {
            this.m_logger.warning(e.getMessage());
        }
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) CallerNotFoundException(de.janrufmonitor.repository.CallerNotFoundException) ILocalRepository(de.janrufmonitor.repository.types.ILocalRepository) IIdentifyCallerRepository(de.janrufmonitor.repository.types.IIdentifyCallerRepository) ArrayList(java.util.ArrayList) List(java.util.List) ICallerManager(de.janrufmonitor.repository.ICallerManager)

Aggregations

CallerNotFoundException (de.janrufmonitor.repository.CallerNotFoundException)10 ICaller (de.janrufmonitor.framework.ICaller)9 ICallerManager (de.janrufmonitor.repository.ICallerManager)9 IIdentifyCallerRepository (de.janrufmonitor.repository.types.IIdentifyCallerRepository)9 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)6 IAttribute (de.janrufmonitor.framework.IAttribute)4 List (java.util.List)4 ArrayList (java.util.ArrayList)3 StringTokenizer (java.util.StringTokenizer)3 ICallerList (de.janrufmonitor.framework.ICallerList)2 HandlerException (de.janrufmonitor.service.commons.http.handler.HandlerException)2 SerializerException (de.janrufmonitor.util.io.SerializerException)2 File (java.io.File)2 OutputStream (java.io.OutputStream)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Message (de.janrufmonitor.exception.Message)1 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)1 ICall (de.janrufmonitor.framework.ICall)1