Search in sources :

Example 1 with AttributeFilter

use of de.janrufmonitor.repository.filter.AttributeFilter in project janrufmonitor by tbrandt77.

the class GoogleContactsCallerManager method getCallers.

public ICallerList getCallers(IFilter filter) {
    try {
        if (filter != null && filter.getType().equals(FilterType.ATTRIBUTE)) {
            IAttributeMap m = ((AttributeFilter) filter).getAttributeMap();
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
                IAttribute a = m.get(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
                return getProxy().getContacts(a.getValue());
            }
        }
        if (filter != null && filter.getType().equals(FilterType.CHARACTER)) {
            ICallerList cl = getProxy().getContacts(null);
            this.applyFilters(cl, new IFilter[] { filter });
            return cl;
        }
        return getProxy().getContacts(null);
    } catch (GoogleContactsException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "loginerror", e));
    }
    return getRuntime().getCallerFactory().createCallerList();
}
Also used : ICallerList(de.janrufmonitor.framework.ICallerList) Message(de.janrufmonitor.exception.Message) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

Example 2 with AttributeFilter

use of de.janrufmonitor.repository.filter.AttributeFilter in project janrufmonitor by tbrandt77.

the class MacAddressBookManager method getCallers.

public ICallerList getCallers(IFilter filter) {
    try {
        if (filter != null && filter.getType().equals(FilterType.ATTRIBUTE)) {
            IAttributeMap m = ((AttributeFilter) filter).getAttributeMap();
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
                IAttribute a = m.get(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
                return getProxy().getContacts(a.getValue());
            }
        }
        if (filter != null && filter.getType().equals(FilterType.PHONENUMBER)) {
            String intarea = ((PhonenumberFilter) filter).getPhonenumber().getIntAreaCode();
            String area = ((PhonenumberFilter) filter).getPhonenumber().getAreaCode();
            return getProxy().getContactsByAreaCode(intarea, area);
        }
        if (filter != null && filter.getType().equals(FilterType.CHARACTER)) {
            IAttribute charAtt = getRuntime().getCallerFactory().createAttribute(((CharacterFilter) filter).getAttributeName(), ((CharacterFilter) filter).getCharacter());
            return getProxy().getContactsByCharAttribute(charAtt);
        }
        return getProxy().getContacts(null);
    } catch (MacAddressBookProxyException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
    }
    return getRuntime().getCallerFactory().createCallerList();
}
Also used : AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

Example 3 with AttributeFilter

use of de.janrufmonitor.repository.filter.AttributeFilter in project janrufmonitor by tbrandt77.

the class HsqldbCallDatabaseHandler method prepareStatement.

private String prepareStatement(IFilter[] filters, int count, int offset, boolean isCounter, ISearchTerm[] searchTerms) {
    StringBuffer sql = new StringBuffer();
    // build SQL statement
    sql.append("SELECT");
    if (filters.length == 1 && filters[0] == null)
        filters = null;
    // 2008/11/28: optimized attribute filter call
    if (filters != null && filters.length > 0 && hasOnlyAttributeFilter(filters)) {
        if (isCounter) {
            sql.append(" COUNT(calls.uuid) ");
        } else {
            sql.append(" content ");
        }
        sql.append("FROM attributes LEFT JOIN calls ON calls.uuid=attributes.ref AND ");
        IFilter f = null;
        for (int i = 0; i < filters.length; i++) {
            f = filters[i];
            if (f.getType() == FilterType.ATTRIBUTE) {
                IAttributeMap m = ((AttributeFilter) f).getAttributeMap();
                if (m != null && m.size() > 0) {
                    sql.append("(");
                    sql.append("(");
                    Iterator iter = m.iterator();
                    IAttribute a = null;
                    while (iter.hasNext()) {
                        a = (IAttribute) iter.next();
                        sql.append("attributes.name='");
                        sql.append(a.getName());
                        sql.append("'");
                        sql.append(" AND ");
                        sql.append("attributes.value='");
                        sql.append(a.getValue());
                        sql.append("'");
                        if (iter.hasNext())
                            sql.append(" OR ");
                    }
                    sql.append("))");
                }
            }
        }
        if (searchTerms != null && searchTerms.length > 0) {
            sql.append(" AND");
            sql.append(createSearchTerm(searchTerms));
        }
    } else if (filters != null && filters.length > 0) {
        int limit = -1;
        for (int i = 0; i < filters.length; i++) {
            if (filters[i] != null && filters[i].getType() == FilterType.ITEMCOUNT) {
                limit = ((ItemCountFilter) filters[i]).getLimit();
                if (!isCounter) {
                    // 2008/05/19: to be done since offset was introduced !!
                    count = limit;
                    offset = 0;
                }
            }
        }
        if (isCounter) {
            sql.append(" COUNT(calls.uuid) ");
        } else {
            sql.append(" content ");
        }
        sql.append("FROM calls");
        if (hasAttributeFilter(filters))
            sql.append(", attributes");
        if (filters.length == 1 && filters[0] != null && filters[0].getType() == FilterType.ITEMCOUNT)
            sql.append("");
        else
            sql.append(" WHERE ");
        IFilter f = null;
        boolean isCallerFilter = false;
        boolean isMsnFilter = false;
        for (int i = 0; i < filters.length; i++) {
            if (filters[i] != null && filters[i].getType() == FilterType.ITEMCOUNT) {
                // limit=((ItemCountFilter)filters[i]).getLimit();
                continue;
            }
            f = filters[i];
            if (f == null)
                continue;
            if (isCallerFilter && (f.getType() == FilterType.CALLER || f.getType() == FilterType.PHONENUMBER)) {
                if (i > 0)
                    sql.append(" OR ");
            } else if (isMsnFilter && f.getType() == FilterType.MSN) {
                if (i > 0)
                    sql.append(" OR ");
            } else {
                if (i > 0 && filters[i - 1].getType() != FilterType.ITEMCOUNT)
                    sql.append(" AND ");
            }
            if (f.getType() == FilterType.DATE) {
                DateFilter df = (DateFilter) f;
                sql.append("(calls.cdate>");
                sql.append((df.getDateTo() == null ? new Date().getTime() : df.getDateTo().getTime()));
                sql.append(" AND calls.cdate<");
                sql.append((df.getDateFrom() == null ? new Date().getTime() : df.getDateFrom().getTime()));
                sql.append(")");
            }
            if (f.getType() == FilterType.YEAR) {
                YearFilter df = (YearFilter) f;
                sql.append("(calls.cdate>");
                sql.append((df.getDateFrom() == null ? new Date().getTime() : df.getDateFrom().getTime()));
                sql.append(" AND calls.cdate<");
                sql.append((df.getDateTo() == null ? new Date().getTime() : df.getDateTo().getTime()));
                sql.append(")");
            }
            if (f.getType() == FilterType.MONTH_YEAR) {
                MonthYearFilter df = (MonthYearFilter) f;
                sql.append("(calls.cdate>");
                sql.append((df.getDateFrom() == null ? new Date().getTime() : df.getDateFrom().getTime()));
                sql.append(" AND calls.cdate<");
                sql.append((df.getDateTo() == null ? new Date().getTime() : df.getDateTo().getTime()));
                sql.append(")");
            }
            if (f.getType() == FilterType.CALLER) {
                if (!isCallerFilter)
                    sql.append("(");
                isCallerFilter = true;
                ICaller c = (ICaller) f.getFilterObject();
                IPhonenumber pn = c.getPhoneNumber();
                sql.append("(calls.country='");
                sql.append(pn.getIntAreaCode());
                sql.append("' AND calls.areacode='");
                sql.append(pn.getAreaCode());
                sql.append("' AND calls.number='");
                sql.append(pn.getCallNumber());
                sql.append("')");
                if (isCallerFilter && ((i + 1) >= filters.length || (filters[i + 1] != null && (filters[i + 1].getType() != FilterType.CALLER))))
                    sql.append(")");
            }
            if (f.getType() == FilterType.PHONENUMBER) {
                if (!isCallerFilter)
                    sql.append("(");
                isCallerFilter = true;
                IPhonenumber pn = (IPhonenumber) f.getFilterObject();
                sql.append("(calls.country='");
                sql.append(pn.getIntAreaCode());
                sql.append("' AND calls.areacode='");
                sql.append(pn.getAreaCode());
                sql.append("' AND calls.number='");
                sql.append(pn.getCallNumber());
                sql.append("')");
                if (isCallerFilter && ((i + 1) >= filters.length || (filters[i + 1] != null && (filters[i + 1].getType() != FilterType.PHONENUMBER))))
                    sql.append(")");
            }
            if (f.getType() == FilterType.CIP) {
                ICip cip = (ICip) f.getFilterObject();
                sql.append("calls.cip='");
                sql.append(cip.getCIP());
                sql.append("'");
            }
            if (f.getType() == FilterType.MSN) {
                IMsn[] msn = (IMsn[]) f.getFilterObject();
                if (msn != null && msn.length > 0) {
                    if (!isMsnFilter)
                        sql.append("(");
                    isMsnFilter = true;
                    sql.append("(");
                    for (int j = 0; j < msn.length; j++) {
                        if (j > 0)
                            sql.append(" OR ");
                        sql.append("calls.msn='");
                        sql.append(msn[j].getMSN());
                        sql.append("'");
                    }
                    sql.append(")");
                    if (isMsnFilter && ((i + 1) >= filters.length || (filters[i + 1] != null && (filters[i + 1].getType() != FilterType.MSN))))
                        sql.append(")");
                }
            }
            if (f.getType() == FilterType.UUID) {
                String[] uuids = (String[]) f.getFilterObject();
                if (uuids != null && uuids.length > 0) {
                    sql.append("(");
                    for (int j = 0; j < uuids.length; j++) {
                        if (j > 0)
                            sql.append(" OR ");
                        sql.append("calls.uuid='");
                        sql.append(uuids[i]);
                        sql.append("'");
                    }
                    sql.append(")");
                }
            }
            if (f.getType() == FilterType.ATTRIBUTE) {
                IAttributeMap m = ((AttributeFilter) f).getAttributeMap();
                if (m != null && m.size() > 0) {
                    sql.append("(");
                    sql.append("calls.uuid=attributes.ref AND (");
                    Iterator iter = m.iterator();
                    IAttribute a = null;
                    while (iter.hasNext()) {
                        a = (IAttribute) iter.next();
                        sql.append("attributes.name='");
                        sql.append(a.getName());
                        sql.append("'");
                        sql.append(" AND ");
                        sql.append("attributes.value='");
                        sql.append(a.getValue());
                        sql.append("'");
                        if (iter.hasNext())
                            sql.append(" OR ");
                    }
                    sql.append("))");
                }
            }
        }
        if (searchTerms != null && searchTerms.length > 0) {
            if (filters.length == 1 && filters[0] != null && filters[0].getType() == FilterType.ITEMCOUNT)
                sql.append(" WHERE");
            else
                sql.append(" AND");
            sql.append(createSearchTerm(searchTerms));
        }
        if (limit > 0 && !isCounter) {
            sql.append(" ORDER BY cdate DESC");
        }
    } else {
        if (isCounter) {
            sql.append(" COUNT(calls.uuid) ");
        } else {
            sql.append(" content ");
        }
        sql.append("FROM calls");
        if (count > 0 && offset >= 0) {
            sql.append(" AS rtable");
        }
        if (searchTerms != null && searchTerms.length > 0) {
            sql.append(" WHERE");
            sql.append(createSearchTerm(searchTerms));
        }
    }
    if (count > 0 && offset >= 0) {
        sql.append(" LIMIT ");
        sql.append(count);
        sql.append(" OFFSET ");
        sql.append(offset);
    }
    sql.append(";");
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info(sql.toString());
    return sql.toString();
}
Also used : ICip(de.janrufmonitor.framework.ICip) Date(java.util.Date) ICaller(de.janrufmonitor.framework.ICaller) IFilter(de.janrufmonitor.repository.filter.IFilter) ItemCountFilter(de.janrufmonitor.repository.filter.ItemCountFilter) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) MonthYearFilter(de.janrufmonitor.repository.filter.MonthYearFilter) YearFilter(de.janrufmonitor.repository.filter.YearFilter) DateFilter(de.janrufmonitor.repository.filter.DateFilter) IMsn(de.janrufmonitor.framework.IMsn) MonthYearFilter(de.janrufmonitor.repository.filter.MonthYearFilter) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 4 with AttributeFilter

use of de.janrufmonitor.repository.filter.AttributeFilter in project janrufmonitor by tbrandt77.

the class HsqldbCallerDatabaseHandler method buildCallerList.

protected ICallerList buildCallerList(IFilter[] filters) throws SQLException {
    ICallerList cl = this.getRuntime().getCallerFactory().createCallerList();
    if (!isConnected())
        return cl;
    StringBuffer sql = new StringBuffer();
    Statement stmt = m_con.createStatement();
    // build SQL statement
    sql.append("SELECT content FROM callers");
    if (hasAttributeFilter(filters))
        sql.append(", attributes");
    if (filters != null && filters.length > 0 && filters[0] != null) {
        IFilter f = null;
        sql.append(" WHERE ");
        for (int i = 0; i < filters.length; i++) {
            f = filters[i];
            if (i > 0)
                sql.append(" AND ");
            if (f.getType() == FilterType.PHONENUMBER) {
                IPhonenumber pn = (IPhonenumber) f.getFilterObject();
                sql.append("country='" + pn.getIntAreaCode() + "' AND areacode='" + pn.getAreaCode() + "'");
            }
            if (f.getType() == FilterType.ATTRIBUTE) {
                IAttributeMap m = ((AttributeFilter) f).getAttributeMap();
                if (m != null && m.size() > 0) {
                    sql.append("(");
                    sql.append("callers.uuid=attributes.ref AND (");
                    Iterator iter = m.iterator();
                    IAttribute a = null;
                    while (iter.hasNext()) {
                        a = (IAttribute) iter.next();
                        sql.append("attributes.name='");
                        sql.append(a.getName());
                        sql.append("'");
                        sql.append(" AND ");
                        sql.append("attributes.value='");
                        sql.append(a.getValue());
                        sql.append("'");
                        if (iter.hasNext())
                            sql.append(" OR ");
                    }
                    sql.append("))");
                }
            }
            if (f.getType() == FilterType.CHARACTER) {
                sql.append("(");
                sql.append("callers.uuid=attributes.ref AND (");
                sql.append("attributes.name='");
                sql.append(((CharacterFilter) f).getAttributeName());
                sql.append("'");
                sql.append(" AND ");
                sql.append("(attributes.value like '");
                sql.append(((CharacterFilter) f).getCharacter().toUpperCase());
                sql.append("%'");
                sql.append(" OR attributes.value like '");
                sql.append(((CharacterFilter) f).getCharacter().toLowerCase());
                sql.append("%'");
                sql.append(")))");
            }
        }
    }
    sql.append(";");
    ResultSet rs = stmt.executeQuery(sql.toString());
    while (rs.next()) {
        try {
            cl.add(Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime()));
        } catch (SerializerException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        }
    }
    return cl;
}
Also used : CharacterFilter(de.janrufmonitor.repository.filter.CharacterFilter) Statement(java.sql.Statement) SerializerException(de.janrufmonitor.util.io.SerializerException) ICallerList(de.janrufmonitor.framework.ICallerList) IFilter(de.janrufmonitor.repository.filter.IFilter) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) ResultSet(java.sql.ResultSet) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 5 with AttributeFilter

use of de.janrufmonitor.repository.filter.AttributeFilter in project janrufmonitor by tbrandt77.

the class HsqldbMultiPhoneCallerDatabaseHandler method buildCallerList.

protected ICallerList buildCallerList(IFilter[] filters, ISearchTerm[] searchTerms) throws SQLException {
    ICallerList cl = this.getRuntime().getCallerFactory().createCallerList();
    if (!isConnected())
        return cl;
    StringBuffer sql = new StringBuffer();
    Statement stmt = m_con.createStatement();
    // build SQL statement
    sql.append("SELECT content FROM callers");
    if (hasAttributeFilter(filters))
        sql.append(", attributes");
    if (filters != null && filters.length > 0 && filters[0] != null) {
        IFilter f = null;
        sql.append(" WHERE ");
        for (int i = 0; i < filters.length; i++) {
            f = filters[i];
            if (i > 0)
                sql.append(" AND ");
            if (f.getType() == FilterType.PHONENUMBER) {
                IPhonenumber pn = (IPhonenumber) f.getFilterObject();
                // sql.append("country='"+pn.getIntAreaCode()+"' AND areacode='"+pn.getAreaCode()+"'");
                ResultSet rs = stmt.executeQuery("SELECT ref FROM phones WHERE country='" + pn.getIntAreaCode() + "' AND areacode='" + pn.getAreaCode() + "';");
                if (rs.next()) {
                    sql.append("uuid='");
                    sql.append(rs.getString(1));
                    sql.append("'");
                    while (rs.next()) {
                        sql.append(" OR uuid='");
                        sql.append(rs.getString(1));
                        sql.append("'");
                    }
                }
            }
            if (f.getType() == FilterType.ATTRIBUTE) {
                IAttributeMap m = ((AttributeFilter) f).getAttributeMap();
                if (m != null && m.size() > 0) {
                    sql.append("(");
                    sql.append("callers.uuid=attributes.ref AND (");
                    Iterator iter = m.iterator();
                    IAttribute a = null;
                    while (iter.hasNext()) {
                        a = (IAttribute) iter.next();
                        sql.append("attributes.name='");
                        sql.append(a.getName());
                        sql.append("'");
                        sql.append(" AND ");
                        sql.append("attributes.value='");
                        sql.append(a.getValue());
                        sql.append("'");
                        if (iter.hasNext())
                            sql.append(" OR ");
                    }
                    sql.append("))");
                }
            }
            if (f.getType() == FilterType.CHARACTER) {
                sql.append("(");
                sql.append("callers.uuid=attributes.ref AND (");
                sql.append("attributes.name='");
                sql.append(((CharacterFilter) f).getAttributeName());
                sql.append("'");
                sql.append(" AND ");
                sql.append("(attributes.value like '");
                sql.append(((CharacterFilter) f).getCharacter().toUpperCase());
                sql.append("%'");
                sql.append(" OR attributes.value like '");
                sql.append(((CharacterFilter) f).getCharacter().toLowerCase());
                sql.append("%'");
                sql.append(")))");
            }
        }
        if (searchTerms != null && searchTerms.length > 0) {
            sql.append(" AND");
            sql.append(createSearchTerm(searchTerms));
        }
    } else {
        if (searchTerms != null && searchTerms.length > 0) {
            sql.append(" WHERE");
            sql.append(createSearchTerm(searchTerms));
        }
    }
    sql.append(";");
    if (this.m_logger.isLoggable(Level.INFO))
        this.m_logger.info(sql.toString());
    ResultSet rs = stmt.executeQuery(sql.toString());
    while (rs.next()) {
        try {
            cl.add(Serializer.toCaller(rs.getString("content").getBytes(), this.getRuntime()));
        } catch (SerializerException e) {
            this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        }
    }
    return cl;
}
Also used : CharacterFilter(de.janrufmonitor.repository.filter.CharacterFilter) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) SerializerException(de.janrufmonitor.util.io.SerializerException) ICallerList(de.janrufmonitor.framework.ICallerList) IFilter(de.janrufmonitor.repository.filter.IFilter) ResultSet(java.sql.ResultSet) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) Iterator(java.util.Iterator) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IAttributeMap (de.janrufmonitor.framework.IAttributeMap)13 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)13 IAttribute (de.janrufmonitor.framework.IAttribute)12 Iterator (java.util.Iterator)8 ICallerList (de.janrufmonitor.framework.ICallerList)7 IFilter (de.janrufmonitor.repository.filter.IFilter)7 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)6 ICaller (de.janrufmonitor.framework.ICaller)5 IMsn (de.janrufmonitor.framework.IMsn)4 CharacterFilter (de.janrufmonitor.repository.filter.CharacterFilter)4 ItemCountFilter (de.janrufmonitor.repository.filter.ItemCountFilter)4 Message (de.janrufmonitor.exception.Message)3 ICip (de.janrufmonitor.framework.ICip)3 DateFilter (de.janrufmonitor.repository.filter.DateFilter)3 MonthYearFilter (de.janrufmonitor.repository.filter.MonthYearFilter)3 Date (java.util.Date)3 List (java.util.List)3 CipFilter (de.janrufmonitor.repository.filter.CipFilter)2 MsnFilter (de.janrufmonitor.repository.filter.MsnFilter)2 PhonenumberFilter (de.janrufmonitor.repository.filter.PhonenumberFilter)2