Search in sources :

Example 1 with UUID

use of de.janrufmonitor.util.uuid.UUID in project janrufmonitor by tbrandt77.

the class GoogleContactsProxy method identify.

public synchronized ICaller identify(IPhonenumber pn) throws GoogleContactsException {
    ICaller c = Identifier.identifyDefault(getRuntime(), pn);
    if (c != null) {
        pn = c.getPhoneNumber();
        try {
            List uuids = this.m_dbh.select(pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
            if (this.m_logger.isLoggable(Level.INFO)) {
                this.m_logger.info("List of found UUIDs: " + uuids);
            }
            if (uuids.size() > 0) {
                String uuid = null;
                ICaller contact = null;
                for (int k = 0; k < uuids.size(); k++) {
                    uuid = (String) uuids.get(k);
                    try {
                        contact = this.identifyByUUID(uuid);
                        if (contact != null) {
                            if (this.m_logger.isLoggable(Level.INFO)) {
                                this.m_logger.info("Google contact found for UUID: " + uuid);
                            }
                            contact.setUUID(new UUID().toString());
                            if (contact instanceof IMultiPhoneCaller) {
                                ((IMultiPhoneCaller) contact).getPhonenumbers().clear();
                            }
                            contact.setPhoneNumber(pn);
                            contact.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION, pn.getTelephoneNumber()));
                            return contact;
                        }
                    } catch (GoogleContactsException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                    }
                }
            } else {
                Properties config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(GoogleContactsCallerManager.NAMESPACE);
                if (config.getProperty(CFG_GOOGLE_KEEPEXT, "false").equalsIgnoreCase("true")) {
                    // iterate down
                    String callnumber = pn.getCallNumber();
                    if (callnumber.length() > 1) {
                        pn.setCallNumber(callnumber.substring(0, callnumber.length() - 1));
                        ICaller ca = this.identify(pn);
                        if (ca != null) {
                            pn.setCallNumber(callnumber);
                            if (ca instanceof IMultiPhoneCaller) {
                                ((IMultiPhoneCaller) ca).getPhonenumbers().clear();
                            }
                            ca.setPhoneNumber(pn);
                            // set extension
                            if (ca.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION)) {
                                String centralnumber = ca.getAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION).getValue();
                                if (pn.getTelephoneNumber().length() > centralnumber.length()) {
                                    IAttribute att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EXTENSION, pn.getTelephoneNumber().substring(centralnumber.length()));
                                    ca.setAttribute(att);
                                }
                            }
                            if (this.m_logger.isLoggable(Level.INFO)) {
                                this.m_logger.info("Caller match by central number: " + ca.toString());
                            }
                            return ca;
                        }
                    }
                }
            }
        } catch (SQLException e) {
            this.m_logger.log(Level.SEVERE, e.toString(), e);
        }
    }
    this.m_logger.info("Caller not identified: " + pn.getTelephoneNumber());
    return null;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) SQLException(java.sql.SQLException) IAttribute(de.janrufmonitor.framework.IAttribute) List(java.util.List) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) UUID(de.janrufmonitor.util.uuid.UUID) Properties(java.util.Properties)

Example 2 with UUID

use of de.janrufmonitor.util.uuid.UUID in project janrufmonitor by tbrandt77.

the class LdapContactsProxy method identify.

public synchronized ICaller identify(IPhonenumber pn) throws LdapContactsException {
    ICaller c = Identifier.identifyDefault(getRuntime(), pn);
    if (c == null && PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(pn)) {
        IPhonenumber p = getRuntime().getCallerFactory().createInternalPhonenumber(pn.getTelephoneNumber());
        c = getRuntime().getCallerFactory().createCaller(p);
    }
    if (c != null) {
        pn = c.getPhoneNumber();
        try {
            List uuids = this.m_dbh.select(pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber());
            if (this.m_logger.isLoggable(Level.INFO)) {
                this.m_logger.info("List of found UUIDs: " + uuids);
            }
            if (uuids.size() > 0) {
                String uuid = null;
                ICaller contact = null;
                for (int k = 0; k < uuids.size(); k++) {
                    uuid = (String) uuids.get(k);
                    try {
                        contact = this.identifyByUUID(uuid);
                        if (contact != null) {
                            if (this.m_logger.isLoggable(Level.INFO)) {
                                this.m_logger.info("LDAP contact found for UUID: " + uuid);
                            }
                            contact.setUUID(new UUID().toString());
                            if (contact instanceof IMultiPhoneCaller) {
                                ((IMultiPhoneCaller) contact).getPhonenumbers().clear();
                            }
                            contact.setPhoneNumber(pn);
                            contact.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION, pn.getTelephoneNumber()));
                            return contact;
                        }
                    } catch (LdapContactsException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                    }
                }
            } else {
                Properties config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(LdapRepository.NAMESPACE);
                if (config.getProperty(CFG_LDAP_KEEPEXT, "false").equalsIgnoreCase("true")) {
                    // iterate down
                    String callnumber = pn.getCallNumber();
                    if (callnumber.length() > 1) {
                        pn.setCallNumber(callnumber.substring(0, callnumber.length() - 1));
                        ICaller ca = this.identify(pn);
                        if (ca != null) {
                            pn.setCallNumber(callnumber);
                            if (ca instanceof IMultiPhoneCaller) {
                                ((IMultiPhoneCaller) ca).getPhonenumbers().clear();
                            }
                            ca.setPhoneNumber(pn);
                            // set extension
                            if (ca.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION)) {
                                String centralnumber = ca.getAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION).getValue();
                                if (pn.getTelephoneNumber().length() > centralnumber.length()) {
                                    IAttribute att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EXTENSION, pn.getTelephoneNumber().substring(centralnumber.length()));
                                    ca.setAttribute(att);
                                }
                            }
                            if (this.m_logger.isLoggable(Level.INFO)) {
                                this.m_logger.info("Caller match by central number: " + ca.toString());
                            }
                            return ca;
                        }
                    }
                }
            }
        } catch (SQLException e) {
            this.m_logger.log(Level.SEVERE, e.toString(), e);
        }
    }
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info("Caller not identified: " + pn.getTelephoneNumber());
    return null;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) SQLException(java.sql.SQLException) IAttribute(de.janrufmonitor.framework.IAttribute) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) UUID(de.janrufmonitor.util.uuid.UUID) Properties(java.util.Properties) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 3 with UUID

use of de.janrufmonitor.util.uuid.UUID in project janrufmonitor by tbrandt77.

the class MacAddressBookMappingManager method mapToJamCaller.

@SuppressWarnings("unchecked")
public synchronized ICaller mapToJamCaller(Map<?, ?> oCaller, IMacAddressBookMapping om) {
    if (!oCaller.containsKey(IMacAddressBookConst.PHONE)) {
        if (this.m_logger.isLoggable(Level.INFO)) {
            this.m_logger.info("Mac Address Book entry has no phone numbers: " + oCaller);
        }
        return null;
    }
    if (((List) oCaller.get(IMacAddressBookConst.PHONE)).size() == 0) {
        if (this.m_logger.isLoggable(Level.INFO)) {
            this.m_logger.info("Mac Address Book entry phone numbers are empty: " + oCaller);
        }
        return null;
    }
    if (this.m_logger.isLoggable(Level.INFO)) {
        this.m_logger.info("Appliing mapping: " + om.toString());
    }
    IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
    // processing the numbers
    List macNumberMappings = om.getSupportedNumbers();
    // added 2015/05/03: added generic etiketts
    if (macNumberMappings.contains("*")) {
        macNumberMappings.addAll(this.getGenericMappings(((List) oCaller.get(IMacAddressBookConst.PHONE))));
    }
    List phones = new ArrayList(macNumberMappings.size());
    String numbertype = null;
    String number = null;
    IPhonenumber phone = null;
    for (int i = 0, j = macNumberMappings.size(); i < j; i++) {
        numbertype = (String) macNumberMappings.get(i);
        while ((number = getRawNumber(((List) oCaller.get(IMacAddressBookConst.PHONE)), numbertype)) != null) {
            if (number != null && !PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(number) && !PhonenumberAnalyzer.getInstance(getRuntime()).isClired(number)) {
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("MacAddressbook raw number: " + number);
                }
                phone = PhonenumberAnalyzer.getInstance(getRuntime()).toIdentifiedPhonenumber(number);
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("MacAddressbook identified number: " + phone);
                }
                if (phone != null && phone.getTelephoneNumber().trim().length() > 0 && !phone.isClired()) {
                    m.add(getNumberTypeAttribute(numbertype, phone, om));
                    m.add(om.createMacAddressBookNumberTypeAttribute(phone, numbertype));
                    phones.add(phone);
                    if (this.m_logger.isLoggable(Level.INFO)) {
                        this.m_logger.info("Added phone " + phone.toString());
                    }
                }
            } else if (number != null && PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(number)) {
                // found internal number
                phone = getRuntime().getCallerFactory().createInternalPhonenumber(number);
                if (phone != null && phone.getTelephoneNumber().trim().length() > 0 && !phone.isClired()) {
                    m.add(getNumberTypeAttribute(numbertype, phone, om));
                    m.add(om.createMacAddressBookNumberTypeAttribute(phone, numbertype));
                    phones.add(phone);
                    if (this.m_logger.isLoggable(Level.INFO)) {
                        this.m_logger.info("Added internal phone " + phone.toString());
                    }
                }
            }
        }
    }
    if (phones.size() > 0) {
        if (phones.size() > 1)
            Collections.sort(phones, new PhonenumberTypeComparator(m, om));
        // process address data
        List macContacFieldMappings = om.getSupportedContactFields();
        String field = null;
        String jamField = null;
        IAttribute a = null;
        if (oCaller.containsKey(IMacAddressBookAddressMapping.ADDRESS)) {
            for (int i = 0, j = macContacFieldMappings.size(); i < j; i++) {
                field = (String) macContacFieldMappings.get(i);
                jamField = om.mapToJamField(field);
                if (jamField != null) {
                    a = createAttribute(jamField, this.getRawAddress((List) oCaller.get(IMacAddressBookAddressMapping.ADDRESS), om.getSupportedAddressType(), field));
                    if (a != null) {
                        m.add(a);
                        if (this.m_logger.isLoggable(Level.INFO)) {
                            this.m_logger.info("Added attribute " + a.toString());
                        }
                    }
                }
            }
        }
        if (oCaller.containsKey(IMacAddressBookAddressMapping.EMAIL)) {
            jamField = om.mapToJamField(IMacAddressBookAddressMapping.EMAIL);
            a = createAttribute(jamField, this.getRawEmail((List) oCaller.get(IMacAddressBookAddressMapping.EMAIL), om.getSupportedEmailType()));
            if (a != null) {
                m.add(a);
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("Added attribute " + a.toString());
                }
            }
        }
        for (int i = 0, j = macContacFieldMappings.size(); i < j; i++) {
            field = (String) macContacFieldMappings.get(i);
            jamField = om.mapToJamField(field);
            if (jamField != null) {
                a = createAttribute(jamField, (String) oCaller.get(field));
                if (a != null) {
                    m.add(a);
                    if (this.m_logger.isLoggable(Level.INFO)) {
                        this.m_logger.info("Added attribute " + a.toString());
                    }
                }
            }
        }
        // date format 2010-07-22 15:34:45 +0200
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
        if (oCaller.containsKey(IMacAddressBookConst.CREATION)) {
            try {
                a = createAttribute(IJAMConst.ATTRIBUTE_NAME_CREATION, Long.toString(sdf.parse((String) oCaller.get(IMacAddressBookConst.CREATION)).getTime()));
            } catch (ParseException e) {
                this.m_logger.warning("Could not parse creation date: " + oCaller.get(IMacAddressBookConst.CREATION));
            }
            if (a != null)
                m.add(a);
        }
        if (oCaller.containsKey(IMacAddressBookConst.MODIFICATION)) {
            try {
                a = createAttribute(IJAMConst.ATTRIBUTE_NAME_MODIFIED, Long.toString(sdf.parse((String) oCaller.get(IMacAddressBookConst.MODIFICATION)).getTime()));
            } catch (ParseException e) {
                this.m_logger.warning("Could not parse modification date: " + oCaller.get(IMacAddressBookConst.MODIFICATION));
            }
            if (a != null)
                m.add(a);
        }
        if (oCaller.containsKey(IMacAddressBookConst.PARENT_GROUPS)) {
            List categories = (List) oCaller.get(IMacAddressBookConst.PARENT_GROUPS);
            if (categories.size() > 0) {
                for (int i = 0; i < categories.size(); i++) {
                    a = createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, MacAddressBookProxy.getInstance().getCategory((String) categories.get(i)));
                    if (a != null) {
                        m.add(a);
                        break;
                    }
                }
            }
        }
        // TODO: 2008/08/13 - Hack - split up street and street no
        IAttribute street = m.get(IJAMConst.ATTRIBUTE_NAME_STREET);
        if (street != null && street.getValue().trim().length() > 0) {
            String[] streetSplit = street.getValue().trim().split(" ");
            if (streetSplit.length > 1) {
                street.setValue("");
                for (int i = 0; i < streetSplit.length - 1; i++) {
                    street.setValue(street.getValue() + " " + streetSplit[i]);
                }
                street.setValue(street.getValue().trim());
                m.add(street);
                IAttribute streetno = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET_NO, streetSplit[streetSplit.length - 1]);
                m.add(streetno);
            }
        }
        String uuid = (String) oCaller.get(IMacAddressBookConst.UID);
        if (uuid == null || uuid.trim().length() == 0)
            uuid = new UUID().toString();
        try {
            MacAddressBookProxy.getInstance().getDataHandler().deleteAttributes(uuid);
        } catch (SQLException e) {
            this.m_logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
        }
        ICaller macCaller = getRuntime().getCallerFactory().createCaller(uuid, null, phones, m);
        this.setPictureAttribute(macCaller, oCaller);
        this.setGeoData(macCaller);
        IAttribute cm = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, ID);
        macCaller.setAttribute(cm);
        if (this.m_logger.isLoggable(Level.INFO)) {
            this.m_logger.info("Created Mac address book contact: " + macCaller.toString());
        }
        try {
            if (macCaller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_LASTNAME))
                MacAddressBookProxy.getInstance().getDataHandler().insertAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_LASTNAME, macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue());
            if (macCaller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_CITY))
                MacAddressBookProxy.getInstance().getDataHandler().insertAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_CITY, macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_CITY).getValue());
            if (macCaller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_COUNTRY))
                MacAddressBookProxy.getInstance().getDataHandler().insertAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_COUNTRY, macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue());
            if (macCaller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE))
                MacAddressBookProxy.getInstance().getDataHandler().insertAttribute(macCaller.getUUID(), IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, macCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue());
        } catch (SQLException e) {
            this.m_logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
        }
        return macCaller;
    }
    return null;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ICaller(de.janrufmonitor.framework.ICaller) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(java.text.ParseException) UUID(de.janrufmonitor.util.uuid.UUID) SimpleDateFormat(java.text.SimpleDateFormat) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 4 with UUID

use of de.janrufmonitor.util.uuid.UUID in project janrufmonitor by tbrandt77.

the class AbstractCallerDatabaseHandler method insertOrUpdateCallerList.

/**
 * Insert the callers in the list or update the callers if it already exists.
 *
 * @param cl
 * @throws SQLException
 */
public void insertOrUpdateCallerList(ICallerList cl) throws SQLException {
    if (!isConnected())
        try {
            this.connect();
        } catch (ClassNotFoundException e) {
            throw new SQLException(e.getMessage());
        }
    PreparedStatement insert_caller = this.getStatement("INSERT_CALLER");
    PreparedStatement insert_attributes = this.getStatement("INSERT_ATTRIBUTE");
    PreparedStatement update_caller = this.getStatement("UPDATE_CALLER");
    PreparedStatement update_caller_phone = this.getStatement("UPDATE_CALLER_PHONE");
    PreparedStatement update_attributes = this.getStatement("UPDATE_ATTRIBUTE");
    insert_caller.clearBatch();
    insert_attributes.clearBatch();
    update_caller.clearBatch();
    update_caller_phone.clearBatch();
    update_attributes.clearBatch();
    List uuid_check = new ArrayList(cl.size());
    ICaller 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.getPhoneNumber();
        if (this.existsCaller(c)) {
            // do an update
            try {
                this.updateCaller(update_caller, c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), pn.getTelephoneNumber(), Serializer.toByteArray(c));
                this.updateAttributes(update_attributes, c.getUUID(), c.getAttributes());
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        } else if (this.existsCaller(pn)) {
            try {
                this.updateCallerPhone(update_caller_phone, c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), pn.getTelephoneNumber(), Serializer.toByteArray(c));
                this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        } else {
            // do an insert
            try {
                this.createCaller(insert_caller, c.getUUID(), pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), pn.getTelephoneNumber(), Serializer.toByteArray(c));
                this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
        if (i % this.commit_count == 0) {
            try {
                insert_caller.executeBatch();
                insert_caller.clearBatch();
                insert_attributes.executeBatch();
                insert_attributes.clearBatch();
                update_caller.executeBatch();
                update_caller.clearBatch();
                update_caller_phone.executeBatch();
                update_caller_phone.clearBatch();
                update_attributes.executeBatch();
                update_attributes.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
    insert_caller.executeBatch();
    insert_attributes.executeBatch();
    update_caller.executeBatch();
    update_caller_phone.executeBatch();
    update_attributes.executeBatch();
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) UUID(de.janrufmonitor.util.uuid.UUID) SerializerException(de.janrufmonitor.util.io.SerializerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 5 with UUID

use of de.janrufmonitor.util.uuid.UUID in project janrufmonitor by tbrandt77.

the class AbstractMultiPhoneCallerDatabaseHandler method insertOrUpdateCallerList.

/**
 * Insert the callers in the list or update the callers if it already
 * exists.
 *
 * @param cl
 * @throws SQLException
 */
public void insertOrUpdateCallerList(ICallerList cl) throws SQLException {
    if (!isConnected())
        try {
            this.connect();
        } catch (ClassNotFoundException e) {
            throw new SQLException(e.getMessage());
        }
    // check prepared statements
    PreparedStatement insert_caller = this.getStatement("INSERT_CALLER");
    PreparedStatement insert_attributes = this.getStatement("INSERT_ATTRIBUTE");
    PreparedStatement insert_phones = this.getStatement("INSERT_PHONE");
    PreparedStatement update_caller = this.getStatement("UPDATE_CALLER");
    PreparedStatement delete_phones = this.getStatement("DELETE_PHONE");
    PreparedStatement delete_phones2 = this.getStatement("DELETE_PHONE2");
    PreparedStatement delete_attributes = this.getStatement("DELETE_ATTRIBUTE");
    // clean up prpared statements
    insert_caller.clearBatch();
    insert_attributes.clearBatch();
    insert_phones.clearBatch();
    update_caller.clearBatch();
    delete_attributes.clearBatch();
    delete_phones.clearBatch();
    delete_phones2.clearBatch();
    // list for redundant UUIDs checks
    List uuid_check = new ArrayList(cl.size());
    ICaller c = null;
    String uuid = null;
    List phones = new ArrayList(1);
    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);
        // check which type of Interface the caller object implements
        if (!(c instanceof IMultiPhoneCaller)) {
            if (this.m_logger.isLoggable(Level.INFO) && c != null)
                this.m_logger.info("Caller is not type IMultiPhoneCaller. Transforming is triggered... : " + c.toString());
            c = this.getRuntime().getCallerFactory().toMultiPhoneCaller(c);
            // 2008/11/30: added to fix duplicated address book entries after category assignement
            c.setUUID(uuid);
        }
        phones.clear();
        phones.addAll(((IMultiPhoneCaller) c).getPhonenumbers());
        // check if single caller (uuid) is already in DB
        if (existsCaller(c)) {
            internalUpdate(c);
            if (this.m_logger.isLoggable(Level.INFO) && c != null)
                this.m_logger.info("Caller already exists in database. Update is triggered: " + c.toString());
            try {
                // update caller table
                this.updateCaller(update_caller, c.getUUID(), Serializer.toByteArray(c));
                // update attributes table
                this.deleteAttributes(delete_attributes, c.getUUID());
                this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
                // update phones table
                this.deletePhone(delete_phones, c.getUUID());
                IPhonenumber p = null;
                for (int a = 0, b = phones.size(); a < b; a++) {
                    p = (IPhonenumber) phones.get(a);
                    this.createPhone(insert_phones, c.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.getCallNumber(), p.getTelephoneNumber());
                }
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        } else if (this.existsPhones(phones).size() > 0) {
            internalInsert(c);
            // check if phone numnbers are already in DB and overwrite them
            List existingPhones = this.existsPhones(phones);
            IPhonenumber pn = null;
            for (int a = 0, b = existingPhones.size(); a < b; a++) {
                pn = (IPhonenumber) existingPhones.get(a);
                if (this.m_logger.isLoggable(Level.INFO) && c != null)
                    this.m_logger.info("Phone already exists in database. Update is triggered: " + pn.toString());
                this.deletePhone(delete_phones2, pn.getIntAreaCode(), pn.getAreaCode(), pn.getCallNumber(), pn.getTelephoneNumber());
            }
            try {
                this.createCaller(insert_caller, c.getUUID(), Serializer.toByteArray(c));
                this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
                IPhonenumber p = null;
                for (int a = 0, b = phones.size(); a < b; a++) {
                    p = (IPhonenumber) phones.get(a);
                    this.createPhone(insert_phones, c.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.getCallNumber(), p.getTelephoneNumber());
                }
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        } else {
            internalInsert(c);
            // insert new caller
            try {
                this.createCaller(insert_caller, c.getUUID(), Serializer.toByteArray(c));
                this.createAttributes(insert_attributes, c.getUUID(), c.getAttributes());
                IPhonenumber p = null;
                for (int a = 0, b = phones.size(); a < b; a++) {
                    p = (IPhonenumber) phones.get(a);
                    this.createPhone(insert_phones, c.getUUID(), p.getIntAreaCode(), p.getAreaCode(), p.getCallNumber(), p.getTelephoneNumber());
                }
            } catch (SerializerException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
        if (i % this.commit_count == 0) {
            try {
                delete_attributes.executeBatch();
                delete_attributes.clearBatch();
                this.m_logger.info("Batch DELETE_ATTRIBUTES executed...");
                delete_phones.executeBatch();
                delete_phones.clearBatch();
                this.m_logger.info("Batch DELETE_PHONES executed...");
                delete_phones2.executeBatch();
                delete_phones2.clearBatch();
                this.m_logger.info("Batch DELETE_PHONES2 executed...");
                insert_caller.executeBatch();
                insert_caller.clearBatch();
                this.m_logger.info("Batch INSERT_CALLER executed...");
                insert_attributes.executeBatch();
                insert_attributes.clearBatch();
                this.m_logger.info("Batch INSERT_ATTRIBUTES executed...");
                insert_phones.executeBatch();
                insert_phones.clearBatch();
                this.m_logger.info("Batch INSERT_PHONES executed...");
                update_caller.executeBatch();
                update_caller.clearBatch();
                this.m_logger.info("Batch UPDATE_CALLER executed...");
            } 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
    delete_attributes.executeBatch();
    delete_attributes.clearBatch();
    this.m_logger.info("Batch DELETE_ATTRIBUTES executed...");
    delete_phones.executeBatch();
    delete_phones.clearBatch();
    this.m_logger.info("Batch DELETE_PHONES executed...");
    delete_phones2.executeBatch();
    delete_phones2.clearBatch();
    this.m_logger.info("Batch DELETE_PHONES2 executed...");
    insert_caller.executeBatch();
    insert_caller.clearBatch();
    this.m_logger.info("Batch INSERT_CALLER executed...");
    insert_attributes.executeBatch();
    insert_attributes.clearBatch();
    this.m_logger.info("Batch INSERT_ATTRIBUTES executed...");
    insert_phones.executeBatch();
    insert_phones.clearBatch();
    this.m_logger.info("Batch INSERT_PHONES executed...");
    update_caller.executeBatch();
    update_caller.clearBatch();
    this.m_logger.info("Batch UPDATE_CALLER executed...");
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) UUID(de.janrufmonitor.util.uuid.UUID) SerializerException(de.janrufmonitor.util.io.SerializerException) 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