use of de.janrufmonitor.repository.filter.ItemCountFilter in project janrufmonitor by tbrandt77.
the class LastCalled method renderAsText.
public String renderAsText() {
if (this.m_o != null) {
if (this.m_o instanceof ICaller) {
this.m_o = new TreeItemCallerData(((ICaller) this.m_o).getAttributes(), ((ICaller) this.m_o).getPhoneNumber());
}
if (this.m_o instanceof ITreeItemCallerData) {
IPhonenumber pn = ((ITreeItemCallerData) m_o).getPhone();
List cms = PIMRuntime.getInstance().getCallManagerFactory().getTypedCallManagers(IReadCallRepository.class);
if (cms.size() > 0) {
ICallManager cm = null;
for (int i = 0, j = cms.size(); i < j; i++) {
cm = (ICallManager) cms.get(i);
if (cm.isActive() && cm.isSupported(IReadCallRepository.class)) {
IFilter[] filters = new IFilter[] { new PhonenumberFilter(pn), new ItemCountFilter(1) };
ICallList cl = ((IReadCallRepository) cm).getCalls(filters, 1, 0);
cl.sort(0, false);
if (cl.size() > 0) {
ICall c = cl.get(0);
return getFormatter().parse(IJAMConst.GLOBAL_VARIABLE_CALLTIME, c.getDate());
}
}
}
}
}
}
return "";
}
use of de.janrufmonitor.repository.filter.ItemCountFilter 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();
}
use of de.janrufmonitor.repository.filter.ItemCountFilter in project janrufmonitor by tbrandt77.
the class FilterWizard method performFinish.
public boolean performFinish() {
if (this.m_pages[0].isPageComplete() && this.m_pages[1].isPageComplete() && this.m_pages[2].isPageComplete() && this.m_pages[3].isPageComplete() && this.m_pages[4].isPageComplete() && this.m_pages[5].isPageComplete() && this.m_pages[6].isPageComplete()) {
List filterList = new ArrayList();
IPhonenumber[] phones = ((FilterPhonesPage) this.m_pages[3]).getResult();
if (phones != null) {
filterList.addAll(this.getCallerFilters(phones));
}
Date[] dates = ((FilterDatePage) this.m_pages[2]).getResult();
if (dates != null && dates.length > 0) {
filterList.add(this.getDateFilter(dates));
}
IMsn msn = ((FilterMsnPage) this.m_pages[0]).getResult();
if (msn != null) {
if (!msn.getMSN().equalsIgnoreCase("*"))
filterList.add(new MsnFilter(new IMsn[] { msn }));
}
int limit = ((FilterItemCountPage) this.m_pages[4]).getResult();
if (limit > 0) {
filterList.add(new ItemCountFilter(limit));
}
IAttributeMap m = ((FilterCallTypePage) this.m_pages[5]).getResult();
if (m != null && m.size() > 0) {
filterList.add(new AttributeFilter(m));
}
ICip cip = ((FilterCipPage) this.m_pages[1]).getResult();
if (cip != null)
if (!cip.getCIP().equalsIgnoreCase("*"))
filterList.add(new CipFilter(cip));
this.m_filters = new IFilter[filterList.size()];
for (int i = 0; i < filterList.size(); i++) {
this.m_filters[i] = (IFilter) filterList.get(i);
}
String name = ((FilterNamePage) this.m_pages[6]).getResult();
IFilterManager fm = new JournalFilterManager();
if (name != null && name.trim().length() > 0) {
this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Journal.NAMESPACE, "filtername_" + fm.getFiltersToString(getResult()), name);
this.getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
} else {
this.getRuntime().getConfigManagerFactory().getConfigManager().removeProperty(Journal.NAMESPACE, "filtername_" + fm.getFiltersToString(getResult()));
this.getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
}
return true;
}
this.m_filters = null;
return false;
}
use of de.janrufmonitor.repository.filter.ItemCountFilter in project janrufmonitor by tbrandt77.
the class AbstractFilterManager method getFiltersToLabelText.
public String getFiltersToLabelText(IFilter[] f, int shorten) {
if (f != null && f.length > 0) {
boolean processedCaller = false;
StringBuffer sb = new StringBuffer();
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_limit", "label", this.getLanguage()));
for (int i = 0; i < f.length; i++) {
IFilter f1 = f[i];
if (f1.getType().equals(FilterType.CIP)) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_cip", "label", this.getLanguage()));
sb.append(this.getRuntime().getCipManager().getCipLabel(((CipFilter) f1).getCip(), this.getLanguage()));
if ((i + 1) < f.length)
sb.append(", ");
}
if (f1.getType().equals(FilterType.MSN)) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_msn", "label", this.getLanguage()));
IMsn[] m = ((MsnFilter) f1).getMsn();
for (int k = 0, l = m.length; k < l; k++) {
sb.append(m[k].getMSN());
m[k].setAdditional(this.getRuntime().getMsnManager().getMsnLabel(m[k]));
if (m[k].getAdditional().length() > 0) {
sb.append(" (" + m[k].getAdditional() + ")");
}
if ((k + 1) < l)
sb.append(", ");
}
if ((i + 1) < f.length)
sb.append(", ");
}
if (f1.getType().equals(FilterType.DATE)) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_date", "label", this.getLanguage()));
if (((DateFilter) f1).getTimeframe() == -1) {
Date d1 = ((DateFilter) f1).getDateFrom();
Date d2 = ((DateFilter) f1).getDateTo();
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
sb.append("[");
sb.append(sdf.format(d2));
sb.append(" - ");
if (d1 != null)
sb.append(sdf.format(d1));
else {
sb.append(this.getI18nManager().getString(this.getNamespace(), "today", "label", this.getLanguage()));
}
sb.append("]");
if ((i + 1) < f.length)
sb.append(", ");
} else {
sb.append("[");
sb.append(this.getI18nManager().getString(this.getNamespace(), Long.toString(((DateFilter) f1).getTimeframe()), "label", this.getLanguage()));
sb.append("]");
if ((i + 1) < f.length)
sb.append(", ");
}
}
if (f1.getType().equals(FilterType.YEAR)) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_date", "label", this.getLanguage()));
sb.append("[");
sb.append(((YearFilter) f1).getYear());
sb.append("]");
if ((i + 1) < f.length)
sb.append(", ");
}
if (f1.getType().equals(FilterType.MONTH_YEAR)) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_date", "label", this.getLanguage()));
sb.append("[");
sb.append(((MonthYearFilter) f1).getYear());
sb.append(".");
sb.append((((MonthYearFilter) f1).getMonth() > 9 ? ((MonthYearFilter) f1).getMonth() : "0" + ((MonthYearFilter) f1).getMonth()));
sb.append("]");
if ((i + 1) < f.length)
sb.append(", ");
}
if (f1.getType().equals(FilterType.CALLER) && !processedCaller) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_caller", "label", this.getLanguage()));
if ((i + 1) < f.length && !processedCaller)
sb.append(", ");
processedCaller = true;
}
if (f1.getType().equals(FilterType.PHONENUMBER)) {
PhonenumberFilter cf = ((PhonenumberFilter) f1);
IPhonenumber pnc = getRuntime().getCallerFactory().createPhonenumber(cf.getPhonenumber().getIntAreaCode(), cf.getPhonenumber().getAreaCode(), "0000000000");
ICaller c = Identifier.identifyDefault(getRuntime(), pnc);
if (c != null) {
IAttribute city = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CITY);
if (city != null && city.getValue().trim().length() > 0) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_area", "label", this.getLanguage()).substring(2));
sb.append(city.getValue().trim());
sb.append(" (0");
sb.append(cf.getPhonenumber().getAreaCode());
sb.append(")");
if ((i + 1) < f.length)
sb.append(", ");
continue;
}
}
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_intarea", "label", this.getLanguage()));
sb.append("00" + cf.getPhonenumber().getIntAreaCode());
if (cf.getPhonenumber().getAreaCode().trim().length() > 0) {
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_area", "label", this.getLanguage()));
sb.append("0" + cf.getPhonenumber().getAreaCode().trim());
}
if ((i + 1) < f.length)
sb.append(", ");
}
if (f1.getType().equals(FilterType.ITEMCOUNT)) {
ItemCountFilter cf = ((ItemCountFilter) f1);
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_itemcount", "label", this.getLanguage()));
sb.append(cf.getLimit());
if ((i + 1) < f.length)
sb.append(", ");
}
if (f1.getType().equals(FilterType.ATTRIBUTE)) {
AttributeFilter cf = ((AttributeFilter) f1);
IAttributeMap m = cf.getAttributeMap();
if (m != null && m.size() > 0) {
Iterator it = m.iterator();
IAttribute a = null;
while (it.hasNext()) {
a = (IAttribute) it.next();
if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS)) {
sb.append(this.getI18nManager().getString(this.getNamespace(), a.getValue(), "label", this.getLanguage()));
} else if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
sb.append(this.getI18nManager().getString(this.getNamespace(), a.getName(), "label", this.getLanguage()));
sb.append(a.getValue());
} else {
sb.append(this.getI18nManager().getString(this.getNamespace(), a.getName(), "label", this.getLanguage()));
}
if (it.hasNext())
sb.append(", ");
}
}
if ((i + 1) < f.length)
sb.append(", ");
}
if (f1.getType().equals(FilterType.CHARACTER)) {
CharacterFilter cf = ((CharacterFilter) f1);
sb.append(this.getI18nManager().getString(this.getNamespace(), "view_" + cf.getAttributeName(), "label", this.getLanguage()));
sb.append("[");
sb.append(cf.getCharacter().toUpperCase());
sb.append("...]");
if ((i + 1) < f.length)
sb.append(", ");
}
}
String s = sb.toString();
if (s.trim().endsWith(","))
s = s.trim().substring(0, s.trim().length() - 1);
if (shorten > -1 && shorten < s.length()) {
return s.substring(0, Math.min(shorten, s.length())) + "...";
}
if (s.trim().length() > 0)
return s;
}
return this.getI18nManager().getString(this.getNamespace(), "view_all", "label", this.getLanguage());
}
use of de.janrufmonitor.repository.filter.ItemCountFilter in project janrufmonitor by tbrandt77.
the class AbstractFilterCallManager method filterCalls.
protected ICallList filterCalls(IFilter filter, ICallList cl) {
if (cl == null) {
cl = this.getInitialCallList(filter);
}
long start = System.currentTimeMillis();
this.m_logger.info("Start filtering with filter: " + filter);
this.m_logger.info("CallList size before filtering: " + cl.size());
ICall c = null;
if (filter != null) {
if (filter.getType().equals(FilterType.DATE) || filter.getType().equals(FilterType.YEAR) || filter.getType().equals(FilterType.MONTH_YEAR)) {
long from = 0;
long to = 0;
if (filter instanceof DateFilter) {
DateFilter df = (DateFilter) filter;
to = (df.getDateFrom() == null ? 0 : df.getDateFrom().getTime());
from = df.getDateTo().getTime();
}
if (filter instanceof YearFilter) {
YearFilter df = (YearFilter) filter;
from = (df.getDateFrom() == null ? 0 : df.getDateFrom().getTime());
to = df.getDateTo().getTime();
}
if (filter instanceof MonthYearFilter) {
MonthYearFilter df = (MonthYearFilter) filter;
from = (df.getDateFrom() == null ? 0 : df.getDateFrom().getTime());
to = df.getDateTo().getTime();
}
long cdate = 0;
for (int i = cl.size() - 1; i >= 0; i--) {
c = cl.get(i);
cdate = c.getDate().getTime();
if (to > 0) {
if (cdate < from || cdate > to)
cl.remove(c);
} else {
if (cdate < from)
cl.remove(c);
}
}
}
if (filter.getType().equals(FilterType.CALLER)) {
ICaller cfilter = (ICaller) filter.getFilterObject();
IPhonenumber pn = cfilter.getPhoneNumber();
for (int i = cl.size() - 1; i >= 0; i--) {
c = cl.get(i);
if (!c.getCaller().getPhoneNumber().equals(pn))
cl.remove(c);
}
}
if (filter.getType().equals(FilterType.PHONENUMBER)) {
IPhonenumber pn = (IPhonenumber) filter.getFilterObject();
for (int i = cl.size() - 1; i >= 0; i--) {
c = cl.get(i);
if (!c.getCaller().getPhoneNumber().equals(pn))
cl.remove(c);
}
}
if (filter.getType().equals(FilterType.CIP)) {
ICip cip = (ICip) filter.getFilterObject();
for (int i = cl.size() - 1; i >= 0; i--) {
c = cl.get(i);
if (!c.getCIP().equals(cip))
cl.remove(c);
}
}
if (filter.getType().equals(FilterType.MSN)) {
IMsn msn = (IMsn) filter.getFilterObject();
for (int i = cl.size() - 1; i >= 0; i--) {
c = cl.get(i);
if (!c.getMSN().equals(msn))
cl.remove(c);
}
}
if (filter.getType().equals(FilterType.UUID)) {
String[] uuids = (String[]) filter.getFilterObject();
for (int i = cl.size() - 1; i >= 0; i--) {
c = cl.get(i);
boolean hasUUID = false;
for (int j = 0; j < uuids.length; j++) {
if (c.getUUID().equalsIgnoreCase(uuids[j]))
hasUUID = true;
}
if (!hasUUID)
cl.remove(c);
}
}
if (filter.getType().equals(FilterType.ATTRIBUTE)) {
IAttributeMap m = ((AttributeFilter) filter).getAttributeMap();
if (m != null && m.size() > 0) {
Iterator iter = m.iterator();
IAttribute a = null;
while (iter.hasNext()) {
a = (IAttribute) iter.next();
IAttribute ua = null;
for (int i = cl.size() - 1; i >= 0; i--) {
c = cl.get(i);
ua = c.getAttribute(a.getName());
if (ua == null || !ua.getValue().equalsIgnoreCase(a.getValue())) {
cl.remove(c);
}
}
}
}
}
if (filter.getType().equals(FilterType.ITEMCOUNT)) {
int itemcount = ((ItemCountFilter) filter).getLimit();
if (itemcount > 0) {
ICallList tmpCl = this.getRuntime().getCallFactory().createCallList(itemcount);
// added: 2006/04/20: just a work-a-round
cl.sort(0, false);
for (int i = 0, j = Math.min(cl.size(), itemcount); i < j; i++) {
tmpCl.add(cl.get(i));
}
cl.clear();
cl.add(tmpCl);
}
}
}
this.m_logger.info("CallList size after filtering: " + cl.size());
this.m_logger.info("Finished filtering with filter <" + filter + "> in " + Long.toString(System.currentTimeMillis() - start) + " msec.");
return cl;
}
Aggregations