Search in sources :

Example 26 with IPhonenumber

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

the class EabFileCallerImporter method doImport.

public ICallerList doImport() {
    this.m_current = 0;
    m_callerList = PIMRuntime.getInstance().getCallerFactory().createCallerList();
    Date startDate = new Date();
    File db = new File(m_filename);
    try {
        FileInputStream in = new FileInputStream(db);
        Properties addressbook = new Properties();
        addressbook.load(in);
        in.close();
        m_total = Integer.parseInt(addressbook.getProperty("total", "1"));
        boolean hasMore = true;
        int i = 1;
        String key = null;
        while (hasMore && addressbook.size() > 0) {
            key = addressbook.getProperty(i + ".phonecount");
            addressbook.remove(i + ".phonecount");
            // found old format
            if (key == null) {
                key = addressbook.getProperty(i + ".phone");
                addressbook.remove(i + ".phone");
                if (key != null && key.length() > 0) {
                    IPhonenumber pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(false);
                    pn.setCallNumber(key);
                    pn.setAreaCode(addressbook.getProperty(i + ".area"));
                    addressbook.remove(i + ".area");
                    key = addressbook.getProperty(i + ".intarea");
                    addressbook.remove(i + ".intarea");
                    if (key == null || key.length() == 0)
                        key = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_INTAREA);
                    pn.setIntAreaCode(key);
                    IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
                    IAttributeMap m = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
                    Enumeration en = addressbook.keys();
                    List keys = new ArrayList();
                    while (en.hasMoreElements()) {
                        key = (String) en.nextElement();
                        if (key.startsWith(i + ".")) {
                            keys.add(key);
                            m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(key.substring((i + ".").length()), addressbook.getProperty(key)));
                        }
                    }
                    if (keys.size() > 0) {
                        for (int j = 0; j < keys.size(); j++) {
                            addressbook.remove(keys.get(j));
                        }
                        keys.clear();
                        keys = null;
                    }
                    ICaller caller = PIMRuntime.getInstance().getCallerFactory().createCaller(name, pn);
                    caller.setAttributes(m);
                    this.m_callerList.add(caller);
                    i++;
                } else {
                    this.m_logger.info("Found no more valid keys. Left data: " + addressbook);
                    hasMore = false;
                }
            } else {
                // new format since 5.0.0
                int phonecount = Integer.parseInt(key);
                List phones = new ArrayList(1);
                ICaller caller = null;
                for (int a = 0; a < phonecount; a++) {
                    key = addressbook.getProperty(i + ".phone." + a);
                    addressbook.remove(i + ".phone." + a);
                    if (key != null && key.length() > 0) {
                        IPhonenumber pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(false);
                        pn.setCallNumber(key);
                        pn.setAreaCode(addressbook.getProperty(i + ".area." + a));
                        addressbook.remove(i + ".area." + a);
                        key = addressbook.getProperty(i + ".intarea." + a);
                        addressbook.remove(i + ".intarea." + a);
                        if (key == null || key.length() == 0)
                            key = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_INTAREA);
                        pn.setIntAreaCode(key);
                        phones.add(pn);
                    }
                }
                IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
                IAttributeMap m = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
                Enumeration en = addressbook.keys();
                List keys = new ArrayList();
                while (en.hasMoreElements()) {
                    key = (String) en.nextElement();
                    if (key.startsWith(i + ".")) {
                        keys.add(key);
                        m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(key.substring((i + ".").length()), addressbook.getProperty(key)));
                    }
                }
                if (keys.size() > 0) {
                    for (int j = 0; j < keys.size(); j++) {
                        addressbook.remove(keys.get(j));
                    }
                    keys.clear();
                    keys = null;
                }
                caller = PIMRuntime.getInstance().getCallerFactory().createCaller(name, phones);
                caller.setAttributes(m);
                this.m_callerList.add(caller);
                i++;
                this.m_current++;
            }
        }
    } catch (FileNotFoundException ex) {
        this.m_logger.warning("Cannot find caller backup file " + m_filename);
        return this.m_callerList;
    } catch (IOException ex) {
        this.m_logger.severe("IOException on file " + m_filename);
        return this.m_callerList;
    }
    Date endDate = new Date();
    this.m_logger.info("Successfully imported caller file " + m_filename);
    this.m_logger.info("Found " + new Integer(this.m_callerList.size()).toString() + " caller items in " + new Float((endDate.getTime() - startDate.getTime()) / 1000).toString() + " secs.");
    return this.m_callerList;
}
Also used : Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Properties(java.util.Properties) Date(java.util.Date) FileInputStream(java.io.FileInputStream) ICaller(de.janrufmonitor.framework.ICaller) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) List(java.util.List) ICallerList(de.janrufmonitor.framework.ICallerList) File(java.io.File) IName(de.janrufmonitor.framework.IName) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 27 with IPhonenumber

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

the class MultiPhoneCaller method clone.

public Object clone() throws CloneNotSupportedException {
    Name cloneName = new Name(this.getName().getFirstname(), this.getName().getLastname(), this.getName().getAdditional());
    List clonePhones = new ArrayList(m_phones.size());
    Phonenumber pn = null;
    for (int i = 0, j = m_phones.size(); i < j; i++) {
        pn = new Phonenumber(((IPhonenumber) m_phones.get(i)).getTelephoneNumber());
        pn.setAreaCode(((IPhonenumber) m_phones.get(i)).getAreaCode());
        pn.setCallNumber(((IPhonenumber) m_phones.get(i)).getCallNumber());
        pn.setIntAreaCode(((IPhonenumber) m_phones.get(i)).getIntAreaCode());
        pn.setClired(((IPhonenumber) m_phones.get(i)).isClired());
        clonePhones.add(pn);
    }
    AttributeMap cloneAttribs = new AttributeMap(this.getAttributes().size());
    Iterator i = this.getAttributes().iterator();
    IAttribute att = null;
    while (i.hasNext()) {
        att = (IAttribute) i.next();
        Attribute cloneAttrib = new Attribute(att.getName(), att.getValue());
        cloneAttribs.add(cloneAttrib);
    }
    if (clonePhones.size() == 0)
        clonePhones.add(this.getPhoneNumber());
    MultiPhoneCaller cloneCaller = new MultiPhoneCaller(this.getUUID(), cloneName, clonePhones, cloneAttribs);
    if (clonePhones.size() > 0)
        cloneCaller.setPhoneNumber((IPhonenumber) clonePhones.get(0));
    return cloneCaller;
}
Also used : IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) List(java.util.List) ArrayList(java.util.ArrayList) IPhonenumber(de.janrufmonitor.framework.IPhonenumber) IName(de.janrufmonitor.framework.IName) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 28 with IPhonenumber

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

the class RuleEngine method validate.

public synchronized boolean validate(IRule rule) {
    this.m_logger.entering(RuleEngine.class.getName(), "validate");
    if (!rule.isValid()) {
        this.m_logger.severe("Rule is invalid.");
        return false;
    }
    List rules = this.getRulesForService(rule.getServiceID());
    if (rules.size() < 1) {
        this.m_logger.info("no rules found for service: " + rule.getServiceID());
        return false;
    }
    List filtered = this.getActiveRules(rules);
    if (filtered.size() < 1) {
        this.m_logger.info("no active rules found for service: " + rule.getServiceID());
        return false;
    }
    filtered = this.getRulesForMSN(filtered, rule.getMsn());
    if (filtered.size() < 1) {
        this.m_logger.info("no active rules found for service " + rule.getServiceID() + " and MSN " + rule.getMsn());
        return false;
    }
    filtered = this.getRulesForCIP(filtered, rule.getCip());
    if (filtered.size() < 1) {
        this.m_logger.info("no active rules found for service " + rule.getServiceID() + ", MSN " + rule.getMsn() + " and CIP " + rule.getCip());
        return false;
    }
    filtered = this.getRulesForTimeslot(filtered);
    if (filtered.size() < 1) {
        this.m_logger.info("no active rules found for service " + rule.getServiceID() + ", MSN " + rule.getMsn() + ", CIP " + rule.getCip() + " and Date " + new Date().toString());
        return false;
    }
    IPhonenumber pn = null;
    if (rule.getPhonenumbers() != null && rule.getPhonenumbers().length > 0) {
        pn = rule.getPhonenumbers()[0];
    }
    filtered = this.getRulesForPhone(filtered, pn);
    if (filtered.size() < 1) {
        this.m_logger.info("no active rules found for service " + rule.getServiceID() + ", MSN " + rule.getMsn() + ", CIP " + rule.getCip() + " and number " + pn);
        return false;
    }
    filtered = this.getRulesForExcludePhone(filtered, pn);
    if (filtered.size() < 1) {
        this.m_logger.info("caller " + pn.toString() + " is exluded in rule for service " + rule.getServiceID() + ", MSN " + rule.getMsn() + ", CIP " + rule.getCip() + " and number " + pn);
        return false;
    }
    if (filtered.size() > 0) {
        this.m_logger.info("found " + filtered.size() + " rule(s) for service " + rule.getServiceID() + " which match with check rule.");
        return true;
    }
    this.m_logger.info("no rules found for service " + rule.getServiceID() + ", which match with check rule.");
    this.m_logger.exiting(RuleEngine.class.getName(), "validate");
    return false;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Date(java.util.Date) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 29 with IPhonenumber

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

the class RuleEngine method getRulesForExcludePhone.

private List getRulesForExcludePhone(List filteredList, IPhonenumber pn) {
    if (filteredList == null) {
        this.m_logger.warning("Filtered list is null for Phonenumber " + pn + ". Taking all rules.");
        filteredList = this.getRules();
    }
    List pnsList = new ArrayList();
    IPhonenumber[] phones = null;
    for (int i = 0, n = filteredList.size(); i < n; i++) {
        phones = ((IRule) filteredList.get(i)).getExcludePhonenumbers();
        if (phones != null) {
            for (int j = 0; j < phones.length; j++) {
                if (phones[j] != null && pn != null) {
                    // added 2009/04/18 added support for internal telefon system calls, accept internal calls
                    if (phones[j].getIntAreaCode().equalsIgnoreCase(IJAMConst.INTERNAL_CALL) && phones[j].getCallNumber().equalsIgnoreCase(IJAMConst.INTERNAL_CALL_NUMBER_SYMBOL) && pn.getIntAreaCode().equalsIgnoreCase(IJAMConst.INTERNAL_CALL)) {
                        return new ArrayList();
                    }
                    if (phones[j].isClired() && pn.isClired()) {
                        return new ArrayList();
                    }
                    if (phones[j].getIntAreaCode().equalsIgnoreCase(pn.getIntAreaCode()) && phones[j].getAreaCode().equalsIgnoreCase(pn.getAreaCode()) && pn.getCallNumber().startsWith(phones[j].getCallNumber())) {
                        return new ArrayList();
                    }
                    pnsList.add(filteredList.get(i));
                }
            }
        } else {
            // all phones are allowed --> phones == null
            pnsList.add(filteredList.get(i));
        }
    }
    return pnsList;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 30 with IPhonenumber

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

the class RuleEngine method getRulesForPhone.

private List getRulesForPhone(List filteredList, IPhonenumber pn) {
    if (filteredList == null) {
        this.m_logger.warning("Filtered list is null for Phonenumber " + pn + ". Taking all rules.");
        filteredList = this.getRules();
    }
    List pnsList = new ArrayList();
    IPhonenumber[] phones = null;
    for (int i = 0, n = filteredList.size(); i < n; i++) {
        phones = ((IRule) filteredList.get(i)).getPhonenumbers();
        if (phones != null) {
            for (int j = 0; j < phones.length; j++) {
                if (phones[j] != null && pn != null) {
                    // added 2009/04/18 added support for internal telefon system calls, accept internal calls
                    if (phones[j].getIntAreaCode().equalsIgnoreCase(IJAMConst.INTERNAL_CALL) && phones[j].getCallNumber().equalsIgnoreCase(IJAMConst.INTERNAL_CALL_NUMBER_SYMBOL) && pn.getIntAreaCode().equalsIgnoreCase(IJAMConst.INTERNAL_CALL)) {
                        pnsList.add(filteredList.get(i));
                    }
                    if (phones[j].isClired() && pn.isClired()) {
                        pnsList.add(filteredList.get(i));
                    }
                    if (phones[j].getIntAreaCode().equalsIgnoreCase(pn.getIntAreaCode()) && phones[j].getAreaCode().equalsIgnoreCase(pn.getAreaCode()) && pn.getCallNumber().startsWith(phones[j].getCallNumber())) {
                        pnsList.add(filteredList.get(i));
                    } else // added 2008/04/04:
                    if (pn.getTelephoneNumber().equalsIgnoreCase(phones[j].getTelephoneNumber())) {
                        pnsList.add(filteredList.get(i));
                    }
                }
            }
        } else {
            // all phones are allowed --> phones == null
            pnsList.add(filteredList.get(i));
        }
    }
    return pnsList;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IPhonenumber (de.janrufmonitor.framework.IPhonenumber)99 ICaller (de.janrufmonitor.framework.ICaller)62 List (java.util.List)49 ArrayList (java.util.ArrayList)44 IAttribute (de.janrufmonitor.framework.IAttribute)38 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)37 ICallerList (de.janrufmonitor.framework.ICallerList)36 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)26 ICall (de.janrufmonitor.framework.ICall)19 SQLException (java.sql.SQLException)19 IMsn (de.janrufmonitor.framework.IMsn)17 Date (java.util.Date)17 IOException (java.io.IOException)16 ICip (de.janrufmonitor.framework.ICip)13 IName (de.janrufmonitor.framework.IName)13 File (java.io.File)13 Iterator (java.util.Iterator)13 ITreeItemCallerData (de.janrufmonitor.ui.jface.application.ITreeItemCallerData)9 UUID (de.janrufmonitor.util.uuid.UUID)9 FileInputStream (java.io.FileInputStream)9