Search in sources :

Example 26 with IMultiPhoneCaller

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

the class MacAddressBookProxy method updateProxyDatabase.

private void updateProxyDatabase(ICallerList callers) {
    ICaller c = null;
    for (int i = 0, j = callers.size(); i < j; i++) {
        c = callers.get(i);
        if (c instanceof IMultiPhoneCaller) {
            try {
                // clean up cache
                if (this.m_dbh != null) {
                    this.m_dbh.delete(c.getUUID());
                // this.m_dbh.deleteAttributes(c.getUUID());
                }
            } catch (SQLException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
    }
    for (int i = 0, j = callers.size(); i < j; i++) {
        c = callers.get(i);
        if (c instanceof IMultiPhoneCaller) {
            List pns = ((IMultiPhoneCaller) c).getPhonenumbers();
            IPhonenumber pn = null;
            for (int k = 0, l = pns.size(); k < l; k++) {
                pn = (IPhonenumber) pns.get(k);
                if (this.m_dbh != null) {
                    try {
                        this.m_dbh.insert(c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
                    } catch (SQLException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                    }
                }
            }
        } else {
            if (this.m_dbh != null) {
                try {
                    this.m_dbh.delete(c.getUUID());
                    this.m_dbh.deleteAttributes(c.getUUID());
                    this.m_dbh.insert(c.getUUID(), c.getPhoneNumber().getIntAreaCode(), c.getPhoneNumber().getAreaCode(), c.getPhoneNumber().getCallNumber());
                } catch (SQLException e) {
                    this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                }
            }
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) SQLException(java.sql.SQLException) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 27 with IMultiPhoneCaller

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

the class VcfFileCallerExporter method doExport.

public boolean doExport() {
    File db = new File(m_filename);
    try {
        StringBuffer vcf = new StringBuffer();
        Formatter f = Formatter.getInstance(PIMRuntime.getInstance());
        String number_pattern = "+%intareacode% (%areacode%) %callnumber%";
        ICaller c = null;
        for (int i = 0, j = this.m_callerList.size(); i < j; i++) {
            c = this.m_callerList.get(i);
            vcf.append("BEGIN:VCARD");
            vcf.append(CRLF);
            vcf.append("VERSION:3.0");
            vcf.append(CRLF);
            vcf.append("N;CHARSET=ISO-8859-1:");
            vcf.append(c.getName().getLastname());
            vcf.append(";");
            vcf.append(c.getName().getFirstname());
            vcf.append(";;");
            vcf.append(CRLF);
            vcf.append("FN;CHARSET=ISO-8859-1:");
            vcf.append(c.getName().getFirstname());
            vcf.append(" ");
            vcf.append(c.getName().getLastname());
            vcf.append(CRLF);
            if (c.getName().getAdditional().trim().length() > 0)
                vcf.append("ORG;CHARSET=ISO-8859-1:");
            vcf.append(c.getName().getAdditional());
            vcf.append(CRLF);
            vcf.append("SORT-STRING:");
            vcf.append(c.getName().getLastname());
            vcf.append(CRLF);
            vcf.append("CLASS:PRIVATE");
            vcf.append(CRLF);
            if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_EMAIL)) {
                vcf.append("EMAIL;TYPE=home:");
                vcf.append(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL).getValue());
                vcf.append(CRLF);
            }
            vcf.append("ADR;TYPE=home;CHARSET=ISO-8859-1:;;");
            vcf.append(this.getAttribute(c, IJAMConst.ATTRIBUTE_NAME_STREET));
            vcf.append(" ");
            vcf.append(this.getAttribute(c, IJAMConst.ATTRIBUTE_NAME_STREET_NO));
            vcf.append(";");
            vcf.append(this.getAttribute(c, IJAMConst.ATTRIBUTE_NAME_CITY));
            vcf.append(";;");
            vcf.append(this.getAttribute(c, IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE));
            vcf.append(";");
            vcf.append(this.getAttribute(c, IJAMConst.ATTRIBUTE_NAME_COUNTRY));
            vcf.append(CRLF);
            if (c instanceof IMultiPhoneCaller) {
                List pns = ((IMultiPhoneCaller) c).getPhonenumbers();
                IPhonenumber p = null;
                for (int k = 0, l = pns.size(); k < l; k++) {
                    p = (IPhonenumber) pns.get(k);
                    if (p.isClired())
                        continue;
                    String numbertype = this.getPhoneType(p, c);
                    if (PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).isInternal(p)) {
                        if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE)) {
                            vcf.append("TEL;TYPE=home:");
                            vcf.append(p.getCallNumber());
                            vcf.append(CRLF);
                        }
                        if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE)) {
                            vcf.append("TEL;TYPE=fax,home:");
                            vcf.append(p.getCallNumber());
                            vcf.append(CRLF);
                        }
                        if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE)) {
                            vcf.append("TEL;TYPE=cell:");
                            vcf.append(p.getCallNumber());
                            vcf.append(CRLF);
                        }
                    } else {
                        if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE)) {
                            vcf.append("TEL;TYPE=home:");
                            vcf.append(f.parse(number_pattern, p));
                            vcf.append(CRLF);
                        }
                        if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE)) {
                            vcf.append("TEL;TYPE=fax,home:");
                            vcf.append(f.parse(number_pattern, p));
                            vcf.append(CRLF);
                        }
                        if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE)) {
                            vcf.append("TEL;TYPE=cell:");
                            vcf.append(f.parse(number_pattern, p));
                            vcf.append(CRLF);
                        }
                    }
                }
            } else {
                String numbertype = this.getPhoneType(c.getPhoneNumber(), c);
                if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE)) {
                    vcf.append("TEL;TYPE=home:");
                    vcf.append(f.parse(number_pattern, c.getPhoneNumber()));
                    vcf.append(CRLF);
                }
                if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE)) {
                    vcf.append("TEL;TYPE=fax,home:");
                    vcf.append(f.parse(number_pattern, c.getPhoneNumber()));
                    vcf.append(CRLF);
                }
                if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE)) {
                    vcf.append("TEL;TYPE=cell:");
                    vcf.append(f.parse(number_pattern, c.getPhoneNumber()));
                    vcf.append(CRLF);
                }
            }
            if (ImageHandler.getInstance().hasImage(c)) {
                vcf.append("PHOTO;ENCODING=b;TYPE=JPEG:");
                InputStream fim = ImageHandler.getInstance().getImageStream(c);
                if (c != null) {
                    ByteArrayOutputStream encodedOut = new ByteArrayOutputStream();
                    // finalize lines with '\n ' instead of '\n'
                    Base64Encoder b64 = new Base64Encoder(encodedOut, " ".getBytes());
                    Stream.copy(fim, b64);
                    b64.flush();
                    b64.close();
                    String imagedata = new String(encodedOut.toByteArray());
                    int size = imagedata.length();
                    vcf.append(imagedata.substring(0, 43));
                    int z = 43;
                    while (z < imagedata.length()) {
                        vcf.append(imagedata.substring(z, Math.min((z + 69), size)));
                        z += 69;
                    }
                    vcf.append(CRLF);
                }
            } else if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH)) {
                // add embedded photo as base 64 encoded object
                String file = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH).getValue();
                File img = new File(PathResolver.getInstance().resolve(file));
                if (img.exists()) {
                    vcf.append("PHOTO;ENCODING=b;TYPE=JPEG:");
                    FileInputStream fim = new FileInputStream(img);
                    ByteArrayOutputStream encodedOut = new ByteArrayOutputStream();
                    // finalize lines with '\n ' instead of '\n'
                    Base64Encoder b64 = new Base64Encoder(encodedOut, " ".getBytes());
                    Stream.copy(fim, b64);
                    b64.flush();
                    b64.close();
                    String imagedata = new String(encodedOut.toByteArray());
                    int size = imagedata.length();
                    vcf.append(imagedata.substring(0, 43));
                    int z = 43;
                    while (z < imagedata.length()) {
                        vcf.append(imagedata.substring(z, Math.min((z + 69), size)));
                        z += 69;
                    }
                    vcf.append(CRLF);
                }
            }
            if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_GEO_LAT) && c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_GEO_LNG)) {
                // add geo tagging
                vcf.append("GEO:");
                vcf.append(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT).getValue());
                vcf.append(";");
                vcf.append(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG).getValue());
                vcf.append(CRLF);
            }
            vcf.append("PRODID:-//jAnrufmonitor//www.janrufmonitor.de//Version 5.0");
            vcf.append(CRLF);
            vcf.append("UID:JAM-UID-");
            vcf.append(c.getUUID());
            vcf.append(CRLF);
            vcf.append("REV:");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
            vcf.append(sdf.format(new Date()));
            vcf.append(CRLF);
            vcf.append("END:VCARD");
            vcf.append(CRLF);
            vcf.append(CRLF);
        }
        FileOutputStream fos = new FileOutputStream(db);
        ByteArrayInputStream bin = new ByteArrayInputStream(vcf.toString().getBytes());
        Stream.copy(bin, fos, true);
    } catch (FileNotFoundException ex) {
        this.m_logger.severe("File not found: " + m_filename);
        return false;
    } catch (IOException ex) {
        this.m_logger.severe("IOException on file " + m_filename);
        return false;
    }
    return true;
}
Also used : Formatter(de.janrufmonitor.util.formatter.Formatter) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Base64Encoder(de.janrufmonitor.util.io.Base64Encoder) FileInputStream(java.io.FileInputStream) Date(java.util.Date) ICaller(de.janrufmonitor.framework.ICaller) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 28 with IMultiPhoneCaller

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

the class FritzBoxCallerExporter method toXml.

private void toXml(ICaller c, StringBuffer s) {
    s.append("<contact>");
    s.append(IJAMConst.CRLF);
    s.append("<category></category>");
    s.append(IJAMConst.CRLF);
    s.append("<person>");
    s.append(IJAMConst.CRLF);
    s.append("<realName>");
    try {
        if (c.getName().getFullname().trim().length() == 0) {
            s.append(StringUtils.replaceString(c.getName().getAdditional(), "&", "&amp;"));
        } else
            s.append(StringUtils.replaceString(c.getName().getFullname(), "&", "&amp;"));
    } catch (Exception e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    s.append("</realName>");
    s.append(IJAMConst.CRLF);
    s.append("<imageURL></imageURL>");
    s.append(IJAMConst.CRLF);
    s.append("</person>");
    s.append(IJAMConst.CRLF);
    s.append("<numbers>");
    s.append(IJAMConst.CRLF);
    if (c instanceof IMultiPhoneCaller) {
        List numbers = ((IMultiPhoneCaller) c).getPhonenumbers();
        IPhonenumber pn = null;
        String type = null;
        for (int i = 0; i < numbers.size(); i++) {
            pn = (IPhonenumber) numbers.get(i);
            if (!PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).isInternal(pn) && !pn.isClired()) {
                type = "home";
                if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber())) {
                    type = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber()).getValue();
                    if (type.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE))
                        type = "home";
                    if (type.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE))
                        type = "mobile";
                    if (type.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE))
                        type = "work_fax";
                }
                s.append("<number type=\"" + type + "\">");
                s.append((pn.getIntAreaCode().equalsIgnoreCase(m_intArea) ? "0" + pn.getTelephoneNumber() : "00" + pn.getIntAreaCode() + pn.getTelephoneNumber()));
                s.append("</number>");
                s.append(IJAMConst.CRLF);
            }
        }
    } else {
        s.append("<number type=\"home\">");
        s.append((c.getPhoneNumber().getIntAreaCode().equalsIgnoreCase(m_intArea) ? "0" + c.getPhoneNumber().getTelephoneNumber() : "00" + c.getPhoneNumber().getIntAreaCode() + c.getPhoneNumber().getTelephoneNumber()));
        s.append("</number>");
        s.append(IJAMConst.CRLF);
    }
    s.append("</numbers>");
    s.append(IJAMConst.CRLF);
    s.append("<services>");
    s.append(IJAMConst.CRLF);
    if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_EMAIL)) {
        s.append("<email classifier=\"private\">");
        s.append(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL).getValue());
        s.append("</email>");
        s.append(IJAMConst.CRLF);
    }
    s.append("</services>");
    s.append(IJAMConst.CRLF);
    s.append("</contact>");
    s.append(IJAMConst.CRLF);
}
Also used : IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 29 with IMultiPhoneCaller

use of de.janrufmonitor.framework.IMultiPhoneCaller 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 30 with IMultiPhoneCaller

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

IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)32 ICaller (de.janrufmonitor.framework.ICaller)25 ICallerList (de.janrufmonitor.framework.ICallerList)25 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)25 List (java.util.List)25 ArrayList (java.util.ArrayList)20 SQLException (java.sql.SQLException)15 IAttribute (de.janrufmonitor.framework.IAttribute)14 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)8 IOException (java.io.IOException)8 UUID (de.janrufmonitor.util.uuid.UUID)6 File (java.io.File)5 Properties (java.util.Properties)5 ContactsService (com.google.gdata.client.contacts.ContactsService)4 ContactEntry (com.google.gdata.data.contacts.ContactEntry)4 ServiceException (com.google.gdata.util.ServiceException)4 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 Iterator (java.util.Iterator)4 ComFailException (com.jacob.com.ComFailException)3