use of de.janrufmonitor.repository.filter.DateFilter 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.DateFilter in project janrufmonitor by tbrandt77.
the class ArchiveJournal method startArchiving.
private void startArchiving() {
if (m_archivingThread == null || !m_archivingThread.isAlive()) {
m_archivingThread = new Thread(new Runnable() {
public void run() {
String currentRepository = getRuntime().getConfigManagerFactory().getConfigManager().getProperty("ui.jface.application.journal.Journal", "repository");
if (currentRepository != null && currentRepository.length() > 0) {
ICallManager cmg = getRuntime().getCallManagerFactory().getCallManager(currentRepository);
if (!currentRepository.equalsIgnoreCase(ID) && cmg != null && cmg.isActive() && cmg.isSupported(IReadCallRepository.class) && cmg.isSupported(IWriteCallRepository.class)) {
long timeframe = Long.parseLong(m_configuration.getProperty(CFG_TIMEFRAME, "0"));
if (timeframe > 0) {
try {
Thread.sleep(10000);
} catch (InterruptedException e1) {
}
long time = System.currentTimeMillis() - (timeframe * 86400000L);
IFilter tf = new DateFilter(new Date(time), new Date(0));
ICallList cl = ((IReadCallRepository) cmg).getCalls(tf);
if (cl.size() > 0) {
try {
getDatabaseHandler().setCallList(cl);
((IWriteCallRepository) cmg).removeCalls(cl);
// added 2010/12/06: added due to high memory consumption
getDatabaseHandler().commit();
getDatabaseHandler().disconnect();
getRuntime().getConfigManagerFactory().getConfigManager().setProperty(NAMESPACE, "lastrun", Long.toString(System.currentTimeMillis()));
getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
String root = PathResolver.getInstance(getRuntime()).resolve(m_configuration.getProperty(CFG_DB, PathResolver.getInstance(getRuntime()).getDataDirectory() + "/journal.archive"));
if (root != null && root.length() > 64) {
root = root.substring(0, root.indexOf(File.separator, 4) + 1) + "..." + root.substring(root.lastIndexOf(File.separator));
}
PropagationFactory.getInstance().fire(new Message(Message.INFO, "ui.jface.configuration.pages.ArchiveJournal", "success", new String[] { Integer.toString(cl.size()), root }, new Exception()));
} catch (SQLException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
PropagationFactory.getInstance().fire(new Message(Message.ERROR, "ui.jface.configuration.pages.ArchiveJournal", "failed", e));
}
}
} else {
m_logger.warning("No archiving timeframe is set. Archiving is stopped.");
PropagationFactory.getInstance().fire(new Message(Message.ERROR, "ui.jface.configuration.pages.ArchiveJournal", "failed", new Exception("No archiving timeframe is set. Archiving is stopped.")));
}
} else {
m_logger.warning("Journal <" + currentRepository + "> invalid or not enabled. Archiving is stopped.");
}
} else {
m_logger.warning("No journal configured to be archived.");
PropagationFactory.getInstance().fire(new Message(Message.ERROR, "ui.jface.configuration.pages.ArchiveJournal", "failed", new Exception("No journal configured to be archived.")));
}
}
});
m_archivingThread.setDaemon(true);
m_archivingThread.setName("JAM-JournalArchiving#" + System.currentTimeMillis() + "-Thread-(non-deamon)");
m_archivingThread.start();
}
}
use of de.janrufmonitor.repository.filter.DateFilter 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.DateFilter in project janrufmonitor by tbrandt77.
the class SynchronizerService method synchronize.
public void synchronize(IProgressMonitor progressMonitor) {
if (m_activeSync)
return;
this.m_activeSync = true;
long start = System.currentTimeMillis();
if (m_logger.isLoggable(Level.INFO))
m_logger.info("--> Start Synchronizing (" + (progressMonitor == null ? "w/o progress monitor" : "with progress monitor") + ")");
if (this.m_tamMap == null)
this.m_tamMap = new HashMap();
this.m_tamMap.clear();
if (progressMonitor != null) {
progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "refreshprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
progressMonitor.worked(1);
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "loginprogress", "label", getLanguage()));
}
try {
Thread.sleep((progressMonitor != null ? 500 : 100));
} catch (InterruptedException e1) {
m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
FirmwareManager fwm = FirmwareManager.getInstance();
// fwm.startup();
try {
if (!fwm.isLoggedIn())
fwm.login();
if (progressMonitor != null)
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "getprogress", "label", getLanguage()));
try {
Thread.sleep((progressMonitor != null ? 1500 : 100));
} catch (InterruptedException e1) {
m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
long synctime = Long.parseLong(SynchronizerService.this.m_configuration.getProperty(CFG_SYNCTIME, "-1"));
long oldestCallTime = -1;
// added: 2013/02/04: check sync all
boolean syncall = SynchronizerService.this.m_configuration.getProperty(CFG_SYNCALL, "false").equalsIgnoreCase("true");
if (syncall) {
synctime = -1;
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Sync all option enabled.");
}
// sub getSynctimeOffset from time
if (synctime > 0) {
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Sync timestamp before decrementing offset: " + synctime);
synctime -= this.getSyncTimeOffset();
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Sync timestamp after decrementing offset: " + synctime);
}
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Syncing call list from FRITZ!Box with timestamp: " + synctime);
List result = fwm.getCallList(synctime);
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Call list size from FRITZ!Box: " + result.size());
if (result.size() > 0) {
ICallList m_callList = PIMRuntime.getInstance().getCallFactory().createCallList(result.size());
List m_prefilteredList = new ArrayList(result.size());
FritzBoxCallCsv call = null;
Properties conf = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperties(FritzBoxMonitor.NAMESPACE);
ICall c = null;
FritzBoxUUIDManager.getInstance().init();
boolean skipOutgoing = !Boolean.parseBoolean(conf.getProperty(CFG_OUTGOING, "false"));
for (int i = 0, j = result.size(); i < j; i++) {
call = new FritzBoxCallCsv((String) result.get(i), conf);
// added 2016/01/11: check if outgoing call applicable
if (call != null) {
if (call.isOutgoingCall() && skipOutgoing) {
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Call import skipped by call state (outgoing) from FRITZ!Box.");
continue;
}
Date calltime = call.getPrecalculatedDate();
if (calltime != null && calltime.getTime() < synctime && synctime > 0) {
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Call import skipped by timestamp (last sync time: " + new Date(synctime).toString() + ", call time: " + calltime.toString() + ") from FRITZ!Box.");
continue;
}
if (calltime != null && synctime < 0) {
if (oldestCallTime == -1)
oldestCallTime = calltime.getTime();
if (oldestCallTime > calltime.getTime())
oldestCallTime = calltime.getTime();
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Set oldest call time to: " + new Date(oldestCallTime).toString());
}
m_prefilteredList.add(call);
}
}
if (m_prefilteredList.size() > 0) {
if (progressMonitor != null)
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "identifyprogress", "label", getLanguage()));
try {
Thread.sleep((progressMonitor != null ? 1000 : 100));
} catch (InterruptedException e1) {
m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
for (int i = 0, j = m_prefilteredList.size(); i < j; i++) {
c = ((FritzBoxCallCsv) m_prefilteredList.get(i)).toCall();
if (c != null) {
if (getRuntime().getMsnManager().isMsnMonitored(c.getMSN())) {
if (progressMonitor != null) {
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "processing", "label", getLanguage()) + Formatter.getInstance(this.getRuntime()).parse(IJAMConst.GLOBAL_VARIABLE_CALLERNUMBER, c));
try {
Thread.sleep(75);
} catch (InterruptedException e1) {
m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
}
if (!m_callList.contains(c)) {
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Adding call imported from FRITZ!Box: " + c.toString());
m_callList.add(c);
} else {
if (m_logger.isLoggable(Level.WARNING))
m_logger.warning("Adding duplicated call imported from FRITZ!Box: " + c.toString());
c.setUUID(c.getUUID() + "-1");
ICip cip = c.getCIP();
// just a dirty hack
cip.setCIP("4");
c.setCIP(cip);
if (!m_callList.contains(c))
m_callList.add(c);
else {
c.setUUID(c.getUUID() + "-1");
if (!m_callList.contains(c))
m_callList.add(c);
}
}
}
}
}
}
if (m_callList != null && m_callList.size() > 0) {
if (progressMonitor != null)
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "geocodeprogress", "label", getLanguage()));
try {
Thread.sleep((progressMonitor != null ? 1000 : 100));
} catch (InterruptedException e1) {
m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
boolean synctam = SynchronizerService.this.m_configuration.getProperty(CFG_SYNCTAM, "false").equalsIgnoreCase("true");
if (synctam) {
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Sync TAM recordings: " + Boolean.toString(synctam));
if (progressMonitor != null)
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "tamprogress", "label", getLanguage()));
this.m_tamMap.putAll(fwm.getTamMessages(synctime));
try {
Thread.sleep((progressMonitor != null ? 1000 : 100));
} catch (InterruptedException e1) {
m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
}
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Processing modifier services on call list: " + getRuntime().getServiceFactory().getModifierServices());
processModifierServices(m_callList, progressMonitor);
if (progressMonitor != null)
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "synchprogress", "label", getLanguage()));
try {
Thread.sleep((progressMonitor != null ? 1000 : 100));
} catch (InterruptedException e1) {
m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
String repository = getRuntime().getConfigManagerFactory().getConfigManager().getProperty(Journal.NAMESPACE, "repository");
ICallManager cm = getRuntime().getCallManagerFactory().getCallManager(repository);
if (cm != null && cm.isActive() && cm.isSupported(IWriteCallRepository.class)) {
ICall ca = null;
boolean syncclean = SynchronizerService.this.m_configuration.getProperty(CFG_SYNCCLEAN, "false").equalsIgnoreCase("true");
if (synctime < 0) {
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Set syntime to oldest call time to eliminate duplicates.");
synctime = oldestCallTime;
}
if (syncclean && synctime > 0 && cm.isSupported(IReadCallRepository.class) && cm.isSupported(IWriteCallRepository.class)) {
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Remove duplicated entries (sync clean) option enabled.");
if (progressMonitor != null)
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "syncclean", "label", getLanguage()));
try {
Thread.sleep((progressMonitor != null ? 500 : 100));
} catch (InterruptedException e1) {
m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
IFilter syncFilter = new DateFilter(new Date(System.currentTimeMillis()), new Date(synctime));
ICallList cl = ((IReadCallRepository) cm).getCalls(syncFilter);
if (cl.size() > 0) {
// 2009/03/18: added backup of cleaned calls
IImExporter exp = ImExportFactory.getInstance().getExporter("DatFileCallExporter");
if (exp != null & exp instanceof ICallExporter) {
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Creating backup of cleaned call list...");
File backupdir = new File(PathResolver.getInstance(getRuntime()).getDataDirectory(), "fritzbox-sync-clean-backup");
if (!backupdir.exists()) {
backupdir.mkdirs();
}
File backupfile = new File(backupdir, Long.toString(synctime) + ".dat");
((ICallExporter) exp).setFilename(backupfile.getAbsolutePath());
((ICallExporter) exp).setCallList(cl);
if (((ICallExporter) exp).doExport()) {
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Backup of cleaned call list successfully finished: " + backupfile.getAbsolutePath());
} else {
if (m_logger.isLoggable(Level.WARNING))
m_logger.warning("Backup of cleaned call list failed: " + backupdir.getAbsolutePath());
}
}
((IWriteCallRepository) cm).removeCalls(createRedundancyList(m_callList, synctime));
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
}
for (int i = 0, j = m_callList.size(); i < j; i++) {
ca = m_callList.get(i);
try {
((IWriteCallRepository) cm).setCall(ca);
if (progressMonitor != null) {
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "processing2", "label", getLanguage()) + Formatter.getInstance(this.getRuntime()).parse(IJAMConst.GLOBAL_VARIABLE_CALLERNAME, ca));
try {
Thread.sleep(50);
} catch (InterruptedException e1) {
m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
}
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Call imported to repository: " + ca.toString());
} catch (Exception e) {
if (m_logger.isLoggable(Level.WARNING))
m_logger.warning("Call already in repository (skipped): " + ca.toString());
}
}
// added 2009/01/08: force refresh of journal, if opened
IEventBroker evtBroker = getRuntime().getEventBroker();
evtBroker.register(this);
evtBroker.send(this, evtBroker.createEvent(IEventConst.EVENT_TYPE_CALL_MANAGER_UPDATED));
evtBroker.unregister(this);
if (m_logger.isLoggable(Level.INFO))
m_logger.info("EventBroker notification sent: EVENT_TYPE_CALL_MANAGER_UPDATED");
}
boolean syncDelete = (m_configuration.getProperty(FritzBoxConst.CFG_SYNCDELETE, "false").equalsIgnoreCase("true") ? true : false);
if (syncDelete) {
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Delete after sync (sync delete) option enabled.");
if (progressMonitor != null)
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "deleteprogress", "label", getLanguage()));
fwm.deleteCallList();
}
// added 2009/01/07: send mail notification after sync with fritzbox
boolean syncNotify = (SynchronizerService.this.m_configuration.getProperty(FritzBoxConst.CFG_SYNC_NOTIFICATION, "false").equalsIgnoreCase("true") ? true : false);
if (syncNotify) {
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Send notification after sync (sync notification) option enabled.");
ICall ca = null;
if (progressMonitor != null)
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "sendnotificationprogress", "label", getLanguage()));
for (int i = 0, j = m_callList.size(); i < j; i++) {
ca = m_callList.get(i);
sendMailNotification(ca);
}
}
}
String text = getI18nManager().getString(getNamespace(), "finished", "label", getLanguage());
if (m_callList.size() == 0)
text = getI18nManager().getString(getNamespace(), "finished0", "label", getLanguage());
if (m_callList.size() == 1)
text = getI18nManager().getString(getNamespace(), "finished1", "label", getLanguage());
if (progressMonitor != null)
progressMonitor.setTaskName(StringUtils.replaceString(text, "{%1}", Integer.toString(m_callList.size())));
if (m_callList.size() > 0)
PropagationFactory.getInstance().fire(new Message(Message.INFO, getI18nManager().getString("monitor.FritzBoxMonitor", "title", "label", getLanguage()), new Exception(StringUtils.replaceString(text, "{%1}", Integer.toString(m_callList.size())))), "Tray");
SynchronizerService.this.m_configuration.setProperty(CFG_SYNCTIME, Long.toString(System.currentTimeMillis()));
getRuntime().getConfigManagerFactory().getConfigManager().setProperties(NAMESPACE, SynchronizerService.this.m_configuration);
getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
if (progressMonitor != null)
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
} else {
// no results from FB list
if (progressMonitor != null)
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "noresults", "label", getLanguage()));
try {
Thread.sleep((progressMonitor != null ? 1500 : 100));
} catch (InterruptedException e1) {
m_logger.log(Level.SEVERE, e1.getMessage(), e1);
}
}
} catch (IOException e) {
m_logger.warning(e.toString());
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "failedrefresh", e));
} catch (FritzBoxLoginException e) {
m_logger.warning(e.toString());
} catch (GetCallListException e) {
m_logger.warning(e.toString());
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "failedrefresh", e));
} catch (DeleteCallListException e) {
m_logger.warning(e.toString());
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "failedrefresh", e));
} catch (CloneNotSupportedException e) {
m_logger.warning(e.toString());
} finally {
if (progressMonitor != null)
progressMonitor.done();
this.m_activeSync = false;
}
if (m_logger.isLoggable(Level.INFO))
m_logger.info("--> Finished Synchronizing (" + (progressMonitor == null ? "w/o progress monitor" : "with progress monitor") + ") in " + ((System.currentTimeMillis() - start) / 1000) + " sec.");
}
use of de.janrufmonitor.repository.filter.DateFilter 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