use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class Editor method getTitleExtension.
protected String getTitleExtension() {
String id = this.m_configuration.getProperty(CFG_REPOSITORY, "");
if (id != null && id.length() > 0) {
ICallerManager cm = getRuntime().getCallerManagerFactory().getCallerManager(id);
if (cm != null && cm.isSupported(ILocalRepository.class)) {
String title = "";
if (cm instanceof IConfigurable) {
title = getI18nManager().getString(((IConfigurable) cm).getNamespace(), "title", "label", getLanguage()) + " - ";
}
title += ((ILocalRepository) cm).getFile();
return title;
}
if (cm != null && cm.isSupported(IRemoteRepository.class)) {
String title = "";
if (cm instanceof IConfigurable) {
title = getI18nManager().getString(((IConfigurable) cm).getNamespace(), "title", "label", getLanguage());
}
return title;
}
}
return null;
}
use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class EditorController method updateElement.
public synchronized void updateElement(Object element) {
if (element != null && element instanceof ICallerList) {
ICallerManager mgr = this._getRepository();
if (mgr != null) {
if (mgr.isSupported(IWriteCallerRepository.class)) {
for (int i = 0, j = ((ICallerList) element).size(); i < j; i++) {
((IWriteCallerRepository) mgr).updateCaller(((ICallerList) element).get(i));
}
}
}
}
if (element != null && element instanceof ICaller) {
List managers = this.getActiveCallerManagers();
ICallerManager mgr = null;
IAttribute att = ((ICaller) element).getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
for (int i = 0; i < managers.size(); i++) {
mgr = this.getRuntime().getCallerManagerFactory().getCallerManager((String) managers.get(i));
if (mgr != null) {
if (mgr.isSupported(IWriteCallerRepository.class)) {
if (att == null || att.getValue().equalsIgnoreCase(mgr.getManagerID()))
((IWriteCallerRepository) mgr).updateCaller((ICaller) element);
}
}
}
}
}
use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class EditorController method buildControllerData.
private void buildControllerData() {
ICallerManager cm = this._getRepository();
if (cm != null && cm.isActive() && cm.isSupported(IReadCallerRepository.class)) {
if (cm.isSupported(ISearchableCallerRepository.class)) {
this.m_data = ((ISearchableCallerRepository) cm).getCallers(new IFilter[] { this.getFilter() }, new SearchTermSeriarlizer().getSearchTermsFromString(StringUtils.urlEncode(this.m_configuration.getProperty(CFG_SEARCHTERMS, ""))));
} else {
this.m_data = ((IReadCallerRepository) cm).getCallers(this.getFilter());
}
if (this.m_data == null)
this.m_data = this.getRuntime().getCallerFactory().createCallerList();
this.doSorting();
List lastnames = new ArrayList(26);
List cities = new ArrayList(26);
List pcode = new ArrayList(9);
List countries = new ArrayList(12);
ICaller c = null;
for (int i = 0; i < this.m_data.size(); i++) {
c = this.m_data.get(i);
if (c instanceof ICaller) {
if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_LASTNAME) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue().trim().length() > 0) {
if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue().substring(0, 1).toUpperCase()))
lastnames.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_LASTNAME).getValue().substring(0, 1).toUpperCase());
}
if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_CITY) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_CITY).getValue().trim().length() > 0) {
if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_CITY).getValue().substring(0, 1).toUpperCase()))
cities.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_CITY).getValue().substring(0, 1).toUpperCase());
}
if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue().trim().length() > 0) {
if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue().substring(0, 1).toUpperCase()))
pcode.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE).getValue().substring(0, 1).toUpperCase());
}
if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_COUNTRY) && c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue().trim().length() > 0) {
if (!hasForbiddenFilterChars(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue().substring(0, 1).toUpperCase()))
countries.add(c.getAttributes().get(IJAMConst.ATTRIBUTE_NAME_COUNTRY).getValue().substring(0, 1).toUpperCase());
}
}
}
Collections.sort(lastnames);
Collections.sort(cities);
Collections.sort(pcode);
Collections.sort(countries);
for (int i = 0; i < lastnames.size(); i++) {
this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "_" + (String) lastnames.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "=" + (String) lastnames.get(i) + ")");
this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "_" + (String) lastnames.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "=" + (String) lastnames.get(i) + ")");
}
for (int i = 0; i < cities.size(); i++) {
this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_CITY + "_" + (String) cities.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_CITY + "=" + (String) cities.get(i) + ")");
this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_CITY + "_" + (String) cities.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_CITY + "=" + (String) cities.get(i) + ")");
}
for (int i = 0; i < pcode.size(); i++) {
this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE + "_" + (String) pcode.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE + "=" + (String) pcode.get(i) + ")");
this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE + "_" + (String) pcode.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_LASTNAME + "=" + (String) pcode.get(i) + ")");
}
for (int i = 0; i < countries.size(); i++) {
this.m_configuration.put("filter_" + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "_" + (String) countries.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "=" + (String) countries.get(i) + ")");
this.getRuntime().getConfigManagerFactory().getConfigManager().setProperty(Editor.NAMESPACE, "filter_" + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "_" + (String) countries.get(i), "(11," + IJAMConst.ATTRIBUTE_NAME_COUNTRY + "=" + (String) countries.get(i) + ")");
}
this.getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
}
if (this.m_data == null)
this.m_data = this.getRuntime().getCallerFactory().createCallerList();
}
use of de.janrufmonitor.repository.ICallerManager 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);
}
}
use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class RemoveCallerList method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallerManager mgr = null;
String manager = null;
try {
manager = req.getParameter(RemoveCallerList.PARAMETER_CALLERMANAGER);
} 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(IWriteCallerRepository.class)) {
throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
}
ICallerList l;
try {
l = XMLSerializer.toCallerList(this.getPostData(req));
if (l != null) {
this.m_logger.info("Removing caller list with " + l.size() + " entries.");
((IWriteCallerRepository) mgr).removeCaller(l);
resp.getContentStreamForWrite().close();
} else {
this.m_logger.severe("Invalid caller list transfered from client.");
throw new HandlerException("Invalid caller list transfered from client.", 500);
}
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
Aggregations