use of de.janrufmonitor.repository.filter.IFilter in project janrufmonitor by tbrandt77.
the class History method getConfiguration.
public Properties getConfiguration() {
Properties saved = super.getConfiguration();
Properties journalConfig = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(Journal.NAMESPACE);
if (journalConfig != null && journalConfig.size() > 0) {
saved.setProperty(JournalConfigConst.CFG_REPOSITORY, journalConfig.getProperty(JournalConfigConst.CFG_REPOSITORY));
}
IFilter[] filters = null;
if (this.m_caller instanceof IMultiPhoneCaller) {
filters = new IFilter[((IMultiPhoneCaller) this.m_caller).getPhonenumbers().size()];
for (int i = 0, j = ((IMultiPhoneCaller) this.m_caller).getPhonenumbers().size(); i < j; i++) {
filters[i] = new PhonenumberFilter((IPhonenumber) ((IMultiPhoneCaller) this.m_caller).getPhonenumbers().get(i));
}
} else {
filters = new IFilter[1];
if (this.m_caller != null)
filters[0] = new PhonenumberFilter(this.m_caller.getPhoneNumber());
}
saved.setProperty("filter", new JournalFilterManager().getFiltersToString(filters));
return saved;
}
use of de.janrufmonitor.repository.filter.IFilter in project janrufmonitor by tbrandt77.
the class GetCallListCount method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallManager mgr = null;
String manager = null;
try {
manager = req.getParameter(GetCallListCount.PARAMETER_CALLMANAGER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (manager == null)
mgr = this.getRuntime().getCallManagerFactory().getDefaultCallManager();
if (manager != null && manager.length() > 0)
mgr = this.getRuntime().getCallManagerFactory().getCallManager(manager);
if (mgr == null || !mgr.isActive() || !mgr.isSupported(IReadCallRepository.class)) {
throw new HandlerException("Requested Callmanager does not exist or is not active.", 404);
}
String filter = null;
try {
filter = req.getParameter(GetCallListCount.PARAMETER_FILTER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
String s = null;
ISearchTerm[] searchterms = null;
try {
s = req.getParameter(GetCallList.PARAMETER_SEARCHTERMS);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (s != null && s.length() > 0) {
this.m_logger.info("SearchTerms: " + s);
searchterms = new SearchTermSeriarlizer().getSearchTermsFromString(s);
}
int count = 0;
if (filter == null || filter.length() == 0) {
this.m_logger.info("Filter parameter &filter= was not set.");
if (mgr.isSupported(ISearchableCallRepository.class)) {
count = ((ISearchableCallRepository) mgr).getCallCount(getAllowedMsnFilter(req), searchterms);
} else
count = ((IReadCallRepository) mgr).getCallCount(getAllowedMsnFilter(req));
} else {
IFilter[] f = new URLFilterManager().getFiltersFromString(filter);
f = mergeFilters(f, getAllowedMsnFilter(req));
if (mgr.isSupported(ISearchableCallRepository.class)) {
count = ((ISearchableCallRepository) mgr).getCallCount(f, searchterms);
} else
count = ((IReadCallRepository) mgr).getCallCount(f);
}
try {
String xml = Integer.toString(count);
resp.setParameter("Content-Type", "text/plain");
resp.setParameter("Content-Length", Long.toString(xml.length()));
OutputStream ps = resp.getContentStreamForWrite();
ps.write(xml.getBytes());
ps.flush();
ps.close();
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.repository.filter.IFilter in project janrufmonitor by tbrandt77.
the class GetCallListCount method mergeFilters.
private IFilter[] mergeFilters(IFilter[] urlFilters, IFilter[] allowedMsnFilter) {
if (urlFilters == null || urlFilters.length == 0)
return allowedMsnFilter;
if (allowedMsnFilter == null || allowedMsnFilter.length == 0)
return urlFilters;
List filters = new ArrayList();
for (int i = 0; i < allowedMsnFilter.length; i++) {
filters.add(allowedMsnFilter[i]);
}
for (int i = 0; i < urlFilters.length; i++) {
if (urlFilters[i].getType() != FilterType.MSN)
filters.add(urlFilters[i]);
}
m_logger.info("Merged list auf filters: " + filters.toString());
IFilter[] f = new IFilter[filters.size()];
for (int i = 0; i < filters.size(); i++) {
f[i] = (IFilter) filters.get(i);
}
return f;
}
use of de.janrufmonitor.repository.filter.IFilter in project janrufmonitor by tbrandt77.
the class GetCallList method getAllowedMsnFilter.
private IFilter[] getAllowedMsnFilter(IHttpRequest req) throws HandlerException {
try {
boolean allowedForAllMsns = (SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostName()) == null && SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostAddress()) == null);
if (!allowedForAllMsns) {
String[] allowedMSNs = SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostName());
if (allowedMSNs == null)
allowedMSNs = SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostAddress());
if (allowedMSNs != null) {
IFilter[] allowedMsnFilter = new IFilter[allowedMSNs.length];
IMsn msn = null;
for (int i = 0; i < allowedMSNs.length; i++) {
msn = getRuntime().getMsnManager().createMsn(allowedMSNs[i]);
allowedMsnFilter[i] = new MsnFilter(msn);
m_logger.info("Adding allowed MSN filter for client: " + allowedMsnFilter[i].toString());
}
return allowedMsnFilter;
}
}
} catch (Exception e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
throw new HandlerException(e.getMessage(), 500);
}
return new IFilter[0];
}
use of de.janrufmonitor.repository.filter.IFilter in project janrufmonitor by tbrandt77.
the class GetCallerList method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallerManager mgr = null;
String manager = null;
boolean isCompression = false;
try {
manager = req.getParameter(GetCallerList.PARAMETER_CALLERMANAGER);
isCompression = (req.getParameter(GetCallList.PARAMETER_COMPRESSION) != null ? req.getParameter(GetCallList.PARAMETER_COMPRESSION).equalsIgnoreCase("true") : false);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (manager == null)
mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
if (manager != null && manager.length() > 0)
mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
if (mgr == null || !mgr.isActive() || !mgr.isSupported(IReadCallerRepository.class)) {
throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
}
ICallerList l = this.getRuntime().getCallerFactory().createCallerList();
String filter = null;
try {
filter = req.getParameter(GetCallerList.PARAMETER_FILTER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
String s = null;
ISearchTerm[] searchterms = null;
try {
s = req.getParameter(GetCallList.PARAMETER_SEARCHTERMS);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (s != null && s.length() > 0) {
searchterms = new SearchTermSeriarlizer().getSearchTermsFromString(s);
}
if (filter == null || filter.length() == 0) {
if (mgr.isSupported(ISearchableCallerRepository.class)) {
l = ((ISearchableCallerRepository) mgr).getCallers(new IFilter[] {}, searchterms);
} else
l = ((IReadCallerRepository) mgr).getCallers((IFilter) null);
this.m_logger.info("Filter parameter &filter= was not set.");
} else {
IFilter[] f = new URLFilterManager().getFiltersFromString(filter);
if (mgr.isSupported(ISearchableCallerRepository.class)) {
l = ((ISearchableCallerRepository) mgr).getCallers(f, searchterms);
} else
l = ((IReadCallerRepository) mgr).getCallers(f);
}
try {
String xml = XMLSerializer.toXML(l, false);
if (isCompression && xml.length() > 1024) {
this.m_logger.info("Compressing requested data.");
this.m_logger.info("Uncompressed data size [bytes] : " + xml.length());
xml = CompressBase64.compressBase64Encode(xml);
this.m_logger.info("Compressed data size [bytes] : " + xml.length());
resp.setParameter("Content-Type", "application/janrufmonitor-compressed");
resp.setParameter(GetCallList.PARAMETER_COMPRESSION, "true");
} else {
resp.setParameter("Content-Type", "text/xml");
resp.setParameter(GetCallList.PARAMETER_COMPRESSION, "false");
}
resp.setParameter("Content-Length", Long.toString(xml.length()));
OutputStream ps = resp.getContentStreamForWrite();
ps.write(xml.getBytes());
ps.flush();
ps.close();
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
Aggregations