use of de.janrufmonitor.repository.types.IReadCallRepository 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.types.IReadCallRepository 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.repository.types.IReadCallRepository 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.repository.types.IReadCallRepository 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.types.IReadCallRepository in project janrufmonitor by tbrandt77.
the class JournalController method updateElement.
public synchronized void updateElement(Object call, boolean isUpdateAll) {
if (call instanceof ICall) {
ICallManager cm = this._getRepository();
if (cm != null && cm.isActive() && cm.isSupported(IReadCallRepository.class) && cm.isSupported(IWriteCallRepository.class)) {
ICaller caller = ((ICall) call).getCaller();
if (!caller.getPhoneNumber().isClired() && isUpdateAll) {
ICallList cl = ((IReadCallRepository) cm).getCalls(new CallerFilter(caller));
ICall aCall = null;
for (int i = cl.size() - 1; i >= 0; i--) {
aCall = cl.get(i);
aCall.setCaller(caller);
}
((IWriteCallRepository) cm).updateCalls(cl);
} else {
// update a single CLIR call or isUpdateAll == false
if (cm.isSupported(IWriteCallRepository.class))
((IWriteCallRepository) cm).updateCall((ICall) call);
}
}
}
}
Aggregations