use of de.janrufmonitor.framework.ICallList in project janrufmonitor by tbrandt77.
the class GetCall method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallManager mgr = null;
String manager = null;
try {
manager = req.getParameter(GetCall.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 uuid = null;
try {
uuid = req.getParameter(GetCall.PARAMETER_UUID);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (uuid == null || uuid.length() == 0) {
this.m_logger.severe("Parameter &uuid= was empty or not set.");
throw new HandlerException("Parameter &uuid= was empty or not set.", 404);
}
try {
ICallList callList = ((IReadCallRepository) mgr).getCalls(new UUIDFilter(new String[] { uuid }));
if (callList.size() > 0) {
String xml = XMLSerializer.toXML(callList.get(0), false);
resp.setParameter("Content-Type", "text/xml");
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.framework.ICallList in project janrufmonitor by tbrandt77.
the class GetCallList method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallManager mgr = null;
String manager = null;
boolean isCompression = false;
try {
manager = req.getParameter(GetCallList.PARAMETER_CALLMANAGER);
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().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);
}
ICallList l = this.getRuntime().getCallFactory().createCallList();
String filter = null;
try {
filter = req.getParameter(GetCallList.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) {
this.m_logger.info("Filter parameter &filter= was not set.");
if (mgr.isSupported(ISearchableCallRepository.class)) {
l = ((ISearchableCallRepository) mgr).getCalls(getAllowedMsnFilter(req), -1, -1, searchterms);
} else
l = ((IReadCallRepository) mgr).getCalls(getAllowedMsnFilter(req));
} else {
IFilter[] f = new URLFilterManager().getFiltersFromString(filter);
f = mergeFilters(f, getAllowedMsnFilter(req));
if (mgr.isSupported(ISearchableCallRepository.class)) {
l = ((ISearchableCallRepository) mgr).getCalls(f, -1, -1, searchterms);
} else
l = ((IReadCallRepository) mgr).getCalls(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);
}
}
use of de.janrufmonitor.framework.ICallList in project janrufmonitor by tbrandt77.
the class SetCallList method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallManager mgr = null;
String manager = null;
boolean isCompression = false;
try {
manager = req.getParameter(RemoveCallList.PARAMETER_CALLMANAGER);
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().getCallManagerFactory().getDefaultCallManager();
if (manager != null && manager.length() > 0)
mgr = this.getRuntime().getCallManagerFactory().getCallManager(manager);
if (mgr == null || !mgr.isActive() || !mgr.isSupported(IWriteCallRepository.class)) {
throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
}
ICallList l;
try {
byte[] data = this.getPostData(req).getBytes();
if (isCompression) {
data = CompressBase64.decompressBase64Decode(data);
}
l = XMLSerializer.toCallList(new String(data));
if (l != null) {
this.m_logger.info("Setting call list with " + l.size() + " entries.");
((IWriteCallRepository) mgr).setCalls(l);
resp.getContentStreamForWrite().close();
} else {
this.m_logger.severe("Invalid call list transfered from client.");
throw new HandlerException("Invalid call list transfered from client.", 500);
}
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.framework.ICallList in project janrufmonitor by tbrandt77.
the class SynchronizerService method createRedundancyList.
private ICallList createRedundancyList(ICallList l, long lastsync) throws CloneNotSupportedException {
if (l == null)
return getRuntime().getCallFactory().createCallList();
ICallList cl = getRuntime().getCallFactory().createCallList(2 * l.size());
ICall c = null;
ICall cloneCall = null;
for (int i = 0, j = l.size(); i < j; i++) {
c = l.get(i);
if (c.getDate().getTime() >= lastsync) {
cloneCall = (ICall) c.clone();
cloneCall.setDate(new Date(c.getDate().getTime() - 60000));
// create UUID
cloneCall.setUUID(FritzBoxUUIDManager.getInstance().getUUID(cloneCall.getDate(), cloneCall.getCaller().getPhoneNumber(), cloneCall.getMSN()));
cl.add(c);
if (m_logger.isLoggable(Level.INFO))
m_logger.info("Cloned call with Date -60000 msec");
cl.add(cloneCall);
}
}
return cl;
}
use of de.janrufmonitor.framework.ICallList in project janrufmonitor by tbrandt77.
the class AbstractDatabaseCallManager method setCall.
public synchronized void setCall(ICall call) {
ICallList cl = this.getRuntime().getCallFactory().createCallList(1);
cl.add(call);
this.setCalls(cl);
}
Aggregations