Search in sources :

Example 1 with BusinessMacAddressBookMapping

use of de.janrufmonitor.repository.mapping.BusinessMacAddressBookMapping in project janrufmonitor by tbrandt77.

the class MacAddressBookProxy method getContactsByAreaCode.

@SuppressWarnings("unchecked")
public synchronized ICallerList getContactsByAreaCode(String countrycode, String areacode) throws MacAddressBookProxyException {
    this.m_total = 0;
    this.m_current = 0;
    final ICallerList callers = getRuntime().getCallerFactory().createCallerList();
    if (this.m_dbh != null) {
        try {
            List uuids = this.m_dbh.select(countrycode, areacode);
            if (uuids.size() > 0) {
                List contacts = getRecordsByUIDs(uuids);
                if (contacts.size() > 0) {
                    this.m_total = contacts.size();
                    ICaller businessCaller, privateCaller = null;
                    for (Object contact : contacts) {
                        if (contact instanceof Map<?, ?>) {
                            this.m_current++;
                            privateCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new PrivateMacAddressBookMapping());
                            businessCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new BusinessMacAddressBookMapping());
                            if (privateCaller == null && businessCaller != null && this.containsCountryAndAreaCode(businessCaller, countrycode, areacode)) {
                                callers.add(businessCaller);
                            }
                            if (privateCaller != null && businessCaller == null && this.containsCountryAndAreaCode(privateCaller, countrycode, areacode)) {
                                callers.add(privateCaller);
                            }
                            if (privateCaller != null && businessCaller != null) {
                                if (((IMultiPhoneCaller) businessCaller).getPhonenumbers().size() == 1) {
                                    // only one entry available
                                    IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) businessCaller).getPhonenumbers().get(0);
                                    IAttribute numbertype = businessCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
                                    if (numbertype != null && numbertype.getValue().equalsIgnoreCase(IMacAddressBookConst.MOBILE)) {
                                        this.m_logger.info("Bussiness caller will be dropped. Only mobile number available, but still in private contact: " + businessCaller);
                                        businessCaller = null;
                                    }
                                }
                                if (((IMultiPhoneCaller) privateCaller).getPhonenumbers().size() == 1 && businessCaller != null) {
                                    // only one entry available
                                    IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) privateCaller).getPhonenumbers().get(0);
                                    IAttribute numbertype = privateCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
                                    if (numbertype != null && numbertype.getValue().equalsIgnoreCase(IMacAddressBookConst.MOBILE)) {
                                        this.m_logger.info("Private caller will be dropped. Only mobile number available, but still in business contact: " + privateCaller);
                                        privateCaller = null;
                                    }
                                }
                                if (privateCaller != null && this.containsCountryAndAreaCode(privateCaller, countrycode, areacode)) {
                                    callers.add(privateCaller);
                                }
                                if (businessCaller != null && this.containsCountryAndAreaCode(businessCaller, countrycode, areacode)) {
                                    callers.add(businessCaller);
                                }
                            }
                        }
                    }
                }
            }
        } catch (SQLException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        }
    }
    if (callers.size() > 0) {
        Thread updateDbhThread = new Thread() {

            public void run() {
                updateProxyDatabase(callers);
            }
        };
        updateDbhThread.setName("JAM-MacAddressBookSync-Thread-(deamon)");
        updateDbhThread.start();
    }
    return callers;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) PrivateMacAddressBookMapping(de.janrufmonitor.repository.mapping.PrivateMacAddressBookMapping) SQLException(java.sql.SQLException) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) BusinessMacAddressBookMapping(de.janrufmonitor.repository.mapping.BusinessMacAddressBookMapping) HashMap(java.util.HashMap) Map(java.util.Map) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 2 with BusinessMacAddressBookMapping

use of de.janrufmonitor.repository.mapping.BusinessMacAddressBookMapping in project janrufmonitor by tbrandt77.

the class MacAddressBookProxy method preload.

public void preload() throws MacAddressBookProxyException {
    final ICallerList callers = getRuntime().getCallerFactory().createCallerList();
    List<Object> ac = this.getRawMacContacts();
    if (ac == null)
        return;
    ICaller businessCaller, privateCaller = null;
    for (Object contact : ac) {
        if (contact instanceof Map<?, ?>) {
            privateCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new PrivateMacAddressBookMapping());
            businessCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new BusinessMacAddressBookMapping());
            if (businessCaller != null) {
                callers.add(businessCaller);
            }
            if (privateCaller != null) {
                callers.add(privateCaller);
            }
        }
    }
    if (callers.size() > 0) {
        Thread updateDbhThread = new Thread() {

            public void run() {
                updateProxyDatabase(callers);
            }
        };
        updateDbhThread.setName("JAM-MacAddressBookSync-Thread-(deamon)");
        updateDbhThread.start();
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) PrivateMacAddressBookMapping(de.janrufmonitor.repository.mapping.PrivateMacAddressBookMapping) BusinessMacAddressBookMapping(de.janrufmonitor.repository.mapping.BusinessMacAddressBookMapping) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with BusinessMacAddressBookMapping

use of de.janrufmonitor.repository.mapping.BusinessMacAddressBookMapping in project janrufmonitor by tbrandt77.

the class MacAddressBookProxy method getContactsByCharAttribute.

@SuppressWarnings("unchecked")
public synchronized ICallerList getContactsByCharAttribute(IAttribute charAttribute) throws MacAddressBookProxyException {
    this.m_total = 0;
    this.m_current = 0;
    final ICallerList callers = getRuntime().getCallerFactory().createCallerList();
    if (this.m_dbh != null) {
        try {
            List uuids = this.m_dbh.select(charAttribute);
            if (uuids.size() > 0) {
                List contacts = getRecordsByUIDs(uuids);
                if (contacts.size() > 0) {
                    this.m_total = contacts.size();
                    ICaller businessCaller, privateCaller = null;
                    for (Object contact : contacts) {
                        if (contact instanceof Map<?, ?>) {
                            this.m_current++;
                            privateCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new PrivateMacAddressBookMapping());
                            businessCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new BusinessMacAddressBookMapping());
                            if (privateCaller != null && businessCaller != null) {
                                // check if firstname, lastname or additional is filled or not
                                if (privateCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME) == null && privateCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME) == null && privateCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL) == null) {
                                    ((IMultiPhoneCaller) businessCaller).getPhonenumbers().addAll(((IMultiPhoneCaller) privateCaller).getPhonenumbers());
                                    privateCaller = null;
                                }
                                if (businessCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME) == null && businessCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME) == null && businessCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL) == null) {
                                    ((IMultiPhoneCaller) privateCaller).getPhonenumbers().addAll(((IMultiPhoneCaller) businessCaller).getPhonenumbers());
                                    businessCaller = null;
                                }
                            }
                            if (businessCaller != null) {
                                callers.add(businessCaller);
                            }
                            if (privateCaller != null) {
                                callers.add(privateCaller);
                            }
                        }
                    }
                }
            }
        } catch (SQLException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        }
    }
    if (callers.size() > 0) {
        Thread updateDbhThread = new Thread() {

            public void run() {
                updateProxyDatabase(callers);
            }
        };
        updateDbhThread.setName("JAM-MacAddressBookSync-Thread-(deamon)");
        updateDbhThread.start();
    }
    return callers;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) PrivateMacAddressBookMapping(de.janrufmonitor.repository.mapping.PrivateMacAddressBookMapping) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) BusinessMacAddressBookMapping(de.janrufmonitor.repository.mapping.BusinessMacAddressBookMapping) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with BusinessMacAddressBookMapping

use of de.janrufmonitor.repository.mapping.BusinessMacAddressBookMapping in project janrufmonitor by tbrandt77.

the class MacAddressBookProxy method findContacts.

@SuppressWarnings("unchecked")
public synchronized ICallerList findContacts(String searchTerm) throws MacAddressBookProxyException {
    this.m_total = 0;
    this.m_current = 0;
    final ICallerList callers = getRuntime().getCallerFactory().createCallerList();
    List<Map<String, ?>> ac = this.findContactsByFullTextSearch(searchTerm);
    if (ac == null)
        return callers;
    this.m_total = ac.size();
    ICaller businessCaller, privateCaller = null;
    for (Object contact : ac) {
        if (contact instanceof Map<?, ?>) {
            this.m_current++;
            privateCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new PrivateMacAddressBookMapping());
            businessCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new BusinessMacAddressBookMapping());
            if (privateCaller != null && businessCaller != null) {
                // check if firstname, lastname or additional is filled or not
                if (privateCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME) == null && privateCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME) == null && privateCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL) == null) {
                    ((IMultiPhoneCaller) businessCaller).getPhonenumbers().addAll(((IMultiPhoneCaller) privateCaller).getPhonenumbers());
                    privateCaller = null;
                }
                if (businessCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME) == null && businessCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME) == null && businessCaller.getAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL) == null) {
                    ((IMultiPhoneCaller) privateCaller).getPhonenumbers().addAll(((IMultiPhoneCaller) businessCaller).getPhonenumbers());
                    businessCaller = null;
                }
            }
            if (businessCaller != null) {
                callers.add(businessCaller);
            }
            if (privateCaller != null) {
                callers.add(privateCaller);
            }
        }
    }
    if (callers.size() > 0) {
        Thread updateDbhThread = new Thread() {

            public void run() {
                updateProxyDatabase(callers);
            }
        };
        updateDbhThread.setName("JAM-MacAddressBookSync-Thread-(deamon)");
        updateDbhThread.start();
    }
    return callers;
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) PrivateMacAddressBookMapping(de.janrufmonitor.repository.mapping.PrivateMacAddressBookMapping) BusinessMacAddressBookMapping(de.janrufmonitor.repository.mapping.BusinessMacAddressBookMapping) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with BusinessMacAddressBookMapping

use of de.janrufmonitor.repository.mapping.BusinessMacAddressBookMapping in project janrufmonitor by tbrandt77.

the class MacAddressBookProxy method addressBookChanged.

@SuppressWarnings("unchecked")
public void addressBookChanged(AddressBookNotification notification) {
    this.m_logger.info("Mac Address Book update for UID " + notification.getUpdatedRecords());
    Set updates = notification.getUpdatedRecords();
    Iterator i = updates.iterator();
    while (i.hasNext()) {
        String uid = (String) i.next();
        List uids = new ArrayList();
        uids.add(uid);
        List contacts = getRecordsByUIDs(uids);
        if (contacts.size() > 0) {
            final ICallerList callers = getRuntime().getCallerFactory().createCallerList();
            for (Object contact : contacts) {
                if (contact instanceof Map<?, ?>) {
                    ICaller privateCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new PrivateMacAddressBookMapping());
                    ICaller businessCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new BusinessMacAddressBookMapping());
                    if (privateCaller == null && businessCaller != null) {
                        callers.add(businessCaller);
                    }
                    if (privateCaller != null && businessCaller == null) {
                        callers.add(privateCaller);
                    }
                    if (privateCaller != null && businessCaller != null) {
                        if (((IMultiPhoneCaller) businessCaller).getPhonenumbers().size() == 1) {
                            // only one entry available
                            IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) businessCaller).getPhonenumbers().get(0);
                            IAttribute numbertype = businessCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
                            if (numbertype != null && numbertype.getValue().equalsIgnoreCase(IMacAddressBookConst.MOBILE)) {
                                this.m_logger.info("Bussiness caller will be dropped. Only mobile number available, but still in private contact: " + businessCaller);
                                businessCaller = null;
                            }
                        }
                        if (((IMultiPhoneCaller) privateCaller).getPhonenumbers().size() == 1 && businessCaller != null) {
                            // only one entry available
                            IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) privateCaller).getPhonenumbers().get(0);
                            IAttribute numbertype = privateCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
                            if (numbertype != null && numbertype.getValue().equalsIgnoreCase(IMacAddressBookConst.MOBILE)) {
                                this.m_logger.info("Private caller will be dropped. Only mobile number available, but still in business contact: " + privateCaller);
                                privateCaller = null;
                            }
                        }
                        if (privateCaller != null) {
                            callers.add(privateCaller);
                        }
                        if (businessCaller != null) {
                            callers.add(businessCaller);
                        }
                    }
                }
            }
            if (callers.size() > 0) {
                Thread updateDbhThread = new Thread() {

                    public void run() {
                        updateProxyDatabase(callers);
                    }
                };
                updateDbhThread.setName("JAM-MacAddressBookSync-Thread-(deamon)");
                updateDbhThread.start();
            }
        }
    }
}
Also used : Set(java.util.Set) PrivateMacAddressBookMapping(de.janrufmonitor.repository.mapping.PrivateMacAddressBookMapping) ArrayList(java.util.ArrayList) ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) BusinessMacAddressBookMapping(de.janrufmonitor.repository.mapping.BusinessMacAddressBookMapping) HashMap(java.util.HashMap) Map(java.util.Map) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

ICaller (de.janrufmonitor.framework.ICaller)7 ICallerList (de.janrufmonitor.framework.ICallerList)7 BusinessMacAddressBookMapping (de.janrufmonitor.repository.mapping.BusinessMacAddressBookMapping)7 PrivateMacAddressBookMapping (de.janrufmonitor.repository.mapping.PrivateMacAddressBookMapping)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 IAttribute (de.janrufmonitor.framework.IAttribute)3 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)3 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)3 SQLException (java.sql.SQLException)3 UUID (de.janrufmonitor.util.uuid.UUID)1 Iterator (java.util.Iterator)1 Properties (java.util.Properties)1 Set (java.util.Set)1