Search in sources :

Example 61 with ICallerList

use of de.janrufmonitor.framework.ICallerList 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 62 with ICallerList

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

Example 63 with ICallerList

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

the class MacAddressBookProxy method getContacts.

@SuppressWarnings("unchecked")
public synchronized ICallerList getContacts(String f) throws MacAddressBookProxyException {
    this.m_total = 0;
    this.m_current = 0;
    final ICallerList callers = getRuntime().getCallerFactory().createCallerList();
    List<Object> ac = null;
    // category is set
    if (f != null && f.length() > 0) {
        if (this.m_logger.isLoggable(Level.INFO))
            this.m_logger.info("Filtering with category " + f);
        String groupUID = (String) this.m_rcategories.get(f);
        if (groupUID != null && groupUID.length() > 0) {
            List uids = new ArrayList();
            uids.add(groupUID);
            List groups = getRecordsByUIDs(uids);
            if (groups.size() > 0) {
                List group = (List) groups.get(0);
                if (group.size() > 3) {
                    uids = (List) group.get(4);
                    ac = (List) getRecordsByUIDs(uids);
                    if (this.m_logger.isLoggable(Level.INFO))
                        this.m_logger.info("Filtered mac contact list " + ac);
                }
            }
        }
    }
    // get all contacts
    if (f == null)
        ac = this.getRawMacContacts();
    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) ArrayList(java.util.ArrayList) 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 64 with ICallerList

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

the class MacAddressBookProxy method findContact.

@SuppressWarnings("unchecked")
public synchronized ICaller findContact(IPhonenumber pn) throws MacAddressBookProxyException {
    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) {
        if (PhonenumberAnalyzer.getInstance(getRuntime()).isInternal(pn)) {
            IPhonenumber p = getRuntime().getCallerFactory().createInternalPhonenumber(pn.getTelephoneNumber());
            c.setPhoneNumber(p);
        }
        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;
                for (int k = 0; k < uuids.size(); k++) {
                    uuid = (String) uuids.get(k);
                    List uids = new ArrayList();
                    uids.add(uuid);
                    List contacts = getRecordsByUIDs(uids);
                    if (contacts.size() > 0) {
                        Object contact = contacts.get(0);
                        ICallerList cl = getRuntime().getCallerFactory().createCallerList(2);
                        if (contact instanceof Map<?, ?>) {
                            ICaller businessCaller, privateCaller = null;
                            privateCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new PrivateMacAddressBookMapping());
                            businessCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new BusinessMacAddressBookMapping());
                            if (privateCaller == null && businessCaller != null) {
                                cl.add(businessCaller);
                            }
                            if (privateCaller != null && businessCaller == null) {
                                cl.add(privateCaller);
                            }
                            if (privateCaller != null && businessCaller != null) {
                                if (((IMultiPhoneCaller) businessCaller).getPhonenumbers().size() == 1) {
                                    // only one entry available
                                    IPhonenumber pn1 = (IPhonenumber) ((IMultiPhoneCaller) businessCaller).getPhonenumbers().get(0);
                                    IAttribute numbertype = businessCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn1.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 pn1 = (IPhonenumber) ((IMultiPhoneCaller) privateCaller).getPhonenumbers().get(0);
                                    IAttribute numbertype = privateCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn1.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) {
                                    cl.add(privateCaller);
                                }
                                if (businessCaller != null) {
                                    cl.add(businessCaller);
                                }
                            }
                        }
                        if (cl.size() == 1) {
                            ICaller rc = cl.get(0);
                            rc.setUUID(new UUID().toString());
                            if (rc instanceof IMultiPhoneCaller) {
                                ((IMultiPhoneCaller) rc).getPhonenumbers().clear();
                            }
                            rc.setPhoneNumber(pn);
                            IAttribute att = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CENTRAL_NUMBER_OF_EXTENSION, pn.getTelephoneNumber());
                            rc.setAttribute(att);
                            if (this.m_logger.isLoggable(Level.INFO)) {
                                this.m_logger.info("Exact caller match: " + rc.toString());
                            }
                            return rc;
                        }
                        if (cl.size() == 2) {
                            ICaller rc = null;
                            for (int x = 0; x < cl.size(); x++) {
                                rc = cl.get(x);
                                if (rc instanceof IMultiPhoneCaller) {
                                    List phones = ((IMultiPhoneCaller) rc).getPhonenumbers();
                                    IPhonenumber p = null;
                                    for (int z = 0; z < phones.size(); z++) {
                                        p = (IPhonenumber) phones.get(z);
                                        if (p.getIntAreaCode().equalsIgnoreCase(pn.getIntAreaCode()) && p.getAreaCode().equalsIgnoreCase(pn.getAreaCode()) && pn.getCallNumber().startsWith(p.getCallNumber())) {
                                            if (this.m_logger.isLoggable(Level.INFO)) {
                                                this.m_logger.info("Caller match (IMultiPhoneCaller): " + rc.toString());
                                            }
                                            rc.setUUID(new UUID().toString());
                                            if (rc instanceof IMultiPhoneCaller) {
                                                ((IMultiPhoneCaller) rc).getPhonenumbers().clear();
                                            }
                                            rc.setPhoneNumber(p);
                                            return rc;
                                        }
                                    }
                                } else {
                                    if (rc.getPhoneNumber().getIntAreaCode().equalsIgnoreCase(pn.getIntAreaCode()) && rc.getPhoneNumber().getAreaCode().equalsIgnoreCase(pn.getAreaCode()) && pn.getCallNumber().startsWith(rc.getPhoneNumber().getCallNumber())) {
                                        if (this.m_logger.isLoggable(Level.INFO)) {
                                            this.m_logger.info("Caller match (ICaller): " + rc.toString());
                                        }
                                        return rc;
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                Properties config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(NAMESPACE);
                if (config.getProperty("keepextension", "false").equalsIgnoreCase("true")) {
                    // iterate down
                    String callnumber = pn.getCallNumber();
                    if (callnumber.length() > 1) {
                        pn.setCallNumber(callnumber.substring(0, callnumber.length() - 1));
                        ICaller ca = this.findContact(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 : PrivateMacAddressBookMapping(de.janrufmonitor.repository.mapping.PrivateMacAddressBookMapping) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Properties(java.util.Properties) ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) 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) UUID(de.janrufmonitor.util.uuid.UUID) HashMap(java.util.HashMap) Map(java.util.Map) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 65 with ICallerList

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

Aggregations

ICallerList (de.janrufmonitor.framework.ICallerList)81 ICaller (de.janrufmonitor.framework.ICaller)40 List (java.util.List)36 ArrayList (java.util.ArrayList)32 IAttribute (de.janrufmonitor.framework.IAttribute)24 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)24 SQLException (java.sql.SQLException)24 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)18 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)17 IOException (java.io.IOException)15 Message (de.janrufmonitor.exception.Message)14 Iterator (java.util.Iterator)11 Map (java.util.Map)11 File (java.io.File)10 HashMap (java.util.HashMap)10 Viewer (org.eclipse.jface.viewers.Viewer)10 ICallerManager (de.janrufmonitor.repository.ICallerManager)9 ComFailException (com.jacob.com.ComFailException)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)7