use of de.janrufmonitor.repository.types.IIdentifyCallerRepository in project janrufmonitor by tbrandt77.
the class GetCaller method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallerManager mgr = null;
String manager = null;
try {
manager = req.getParameter(GetCaller.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(IIdentifyCallerRepository.class)) {
throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
}
String number = null;
try {
number = req.getParameter(GetCaller.PARAMETER_NUMBER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (number == null || number.length() == 0) {
this.m_logger.severe("Parameter &number= was empty or not set.");
throw new HandlerException("Parameter &number= was empty or not set.", 404);
}
IPhonenumber pn = null;
StringTokenizer st = new StringTokenizer(number, ";");
if (st.countTokens() == 3) {
pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), st.nextToken().trim(), st.nextToken().trim());
}
if (st.countTokens() == 2) {
pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), "", st.nextToken().trim());
}
if (st.countTokens() == 1) {
pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim());
}
try {
ICaller caller = ((IIdentifyCallerRepository) mgr).getCaller(pn);
String xml = XMLSerializer.toXML(caller, 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 (CallerNotFoundException e) {
throw new HandlerException(e.getMessage(), 404);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.repository.types.IIdentifyCallerRepository in project janrufmonitor by tbrandt77.
the class Image method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallerManager mgr = null;
String manager = null;
try {
manager = req.getParameter(Image.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(IIdentifyCallerRepository.class)) {
throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
}
String number = null;
try {
number = req.getParameter(Image.PARAMETER_NUMBER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (number == null || number.length() == 0) {
this.m_logger.severe("Parameter &number= was empty or not set.");
throw new HandlerException("Parameter &number= was empty or not set.", 404);
}
IPhonenumber pn = null;
StringTokenizer st = new StringTokenizer(number, ";");
if (st.countTokens() == 3) {
pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), st.nextToken().trim(), st.nextToken().trim());
}
if (st.countTokens() == 2) {
pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), "", st.nextToken().trim());
}
if (st.countTokens() == 1) {
pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim());
}
try {
ICaller caller = ((IIdentifyCallerRepository) mgr).getCaller(pn);
IAttribute imageAtt = caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH);
if (ImageHandler.getInstance().hasImage(caller)) {
InputStream in = ImageHandler.getInstance().getImageStream(caller);
if (in != null) {
resp.setParameter("Content-Type", this.getMimetype("jpg"));
OutputStream ps = resp.getContentStreamForWrite();
byte[] buffer = new byte[8092];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
ps.write(buffer, 0, bytesRead);
}
in.close();
ps.flush();
ps.close();
}
} else if (imageAtt != null) {
String pathToImage = PathResolver.getInstance(getRuntime()).resolve(imageAtt.getValue());
File image = new File(pathToImage);
if (image.exists()) {
resp.setParameter("Content-Type", this.getMimetype(pathToImage));
resp.setParameter("Content-Length", Long.toString(image.length()));
OutputStream ps = resp.getContentStreamForWrite();
FileInputStream in = new FileInputStream(image);
byte[] buffer = new byte[8092];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
ps.write(buffer, 0, bytesRead);
}
in.close();
ps.flush();
ps.close();
} else {
throw new CallerNotFoundException("Image " + pathToImage + " not found");
}
} else {
throw new CallerNotFoundException("No image assigned for caller " + caller);
}
} catch (CallerNotFoundException e) {
throw new HandlerException(e.getMessage(), 404);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.repository.types.IIdentifyCallerRepository in project janrufmonitor by tbrandt77.
the class Identifier method identify.
/**
* Identifies a caller with all active caller managers specified in the configuration.
*
* @param r the current runtime
* @param pn a valid number, should not be a clired number or null
* @param activeCallerManagers a list of active caller managers
* @return an identified ICaller object or null, if not identified by any caller manager
*/
public static ICaller identify(IRuntime r, IPhonenumber pn, List activeCallerManagers) {
if (activeCallerManagers == null || activeCallerManagers.size() == 0)
return null;
long start = System.currentTimeMillis();
Identifier.logger.info("<---- Begin caller identification ---->");
Identifier.logger.info("Order of identification: " + activeCallerManagers.toString());
ICaller identifiedCaller = null;
int i = 0;
Object obj = null;
ICallerManager cm = null;
while (identifiedCaller == null && i < activeCallerManagers.size()) {
obj = activeCallerManagers.get(i);
i++;
if (obj != null && obj instanceof ICallerManager) {
cm = (ICallerManager) obj;
try {
if (cm.isActive() && cm.isSupported(IIdentifyCallerRepository.class)) {
identifiedCaller = ((IIdentifyCallerRepository) cm).getCaller(pn);
Identifier.logger.info("Caller identified by [" + cm.getManagerID() + "]: " + identifiedCaller);
}
} catch (CallerNotFoundException e) {
Identifier.logger.info("Caller was not identified by [" + cm.getManagerID() + "]: " + e.getMessage());
}
} else {
Identifier.logger.severe("Invalid caller manager object: " + obj);
}
}
Identifier.logger.info("<---- Finished caller identification (" + (System.currentTimeMillis() - start) + " msec.) ---->");
return identifiedCaller;
}
use of de.janrufmonitor.repository.types.IIdentifyCallerRepository in project janrufmonitor by tbrandt77.
the class OutlookImportAction method run.
public void run() {
String filter = this.m_app.getApplication().getConfiguration().getProperty("filter", "");
EditorFilterManager efm = new EditorFilterManager();
final IAttribute category = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, "");
if (filter.length() > 0) {
String cat = null;
IFilter[] filters = efm.getFiltersFromString(filter);
for (int z = 0; z < filters.length; z++) {
if (filters[z].getType().equals(FilterType.ATTRIBUTE)) {
AttributeFilter cf = ((AttributeFilter) filters[z]);
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_CATEGORY)) {
cat = a.getValue();
}
}
}
}
}
if (cat != null) {
int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
String text = this.getI18nManager().getString("ui.jface.application.editor.action.ImportAction", "assigncategoryconfirm", "label", this.getLanguage());
text = StringUtils.replaceString(text, "{%1}", cat);
messageBox.setMessage(text);
if (messageBox.open() == SWT.YES) {
category.setValue(cat);
}
}
}
// determine subfolders
OutlookTransformer ot = new OutlookTransformer();
List folders = ot.getAllContactFolders();
if (folders.size() > 0) {
int itemCount = 0;
String folder = null;
for (int i = 0, j = folders.size(); i < j; i++) {
folder = (String) folders.get(i);
itemCount = ot.getContactCount(folder);
if (itemCount > 0) {
getRuntime().getConfigManagerFactory().getConfigManager().setProperty(OutlookContactManager.NAMESPACE, "subfolder_" + folder, "true");
}
}
getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
}
ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
try {
IRunnableWithProgress r = new IRunnableWithProgress() {
public void run(IProgressMonitor progressMonitor) {
progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "importprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
progressMonitor.worked(1);
OutlookTransformer otf = new OutlookTransformer();
ICallerList callers = otf.getCallerListFromAllContacts();
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "reduce", "label", getLanguage()));
otf.removeCallerManagerID(callers);
// determine duplicates
String currentCallerManagerID = m_app.getApplication().getConfiguration().getProperty(CFG_REPOSITORY);
if (currentCallerManagerID != null && currentCallerManagerID.trim().length() > 0) {
ICallerManager currentCallerManager = getRuntime().getCallerManagerFactory().getCallerManager(currentCallerManagerID);
if (currentCallerManager != null && currentCallerManager.isSupported(IWriteCallerRepository.class) && currentCallerManager.isSupported(IIdentifyCallerRepository.class)) {
ICallerList addCallers = getRuntime().getCallerFactory().createCallerList();
// ICallerList removeCallers = getRuntime().getCallerFactory().createCallerList();
ICaller currentCaller = null;
String text = null;
for (int i = 0, j = callers.size(); i < j; i++) {
// ICaller testCaller = null;
currentCaller = callers.get(i);
text = getI18nManager().getString(getNamespace(), "check", "label", getLanguage());
text = StringUtils.replaceString(text, "{%1}", Formatter.getInstance(getRuntime()).parse("%a:ln%, %a:fn%", currentCaller));
progressMonitor.setTaskName(text);
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
}
try {
// testCaller = ((IIdentifyCallerRepository)currentCallerManager).getCaller(currentCaller.getPhoneNumber());
((IIdentifyCallerRepository) currentCallerManager).getCaller(currentCaller.getPhoneNumber());
} catch (CallerNotFoundException e) {
if (category != null && category.getValue().length() > 0)
currentCaller.setAttribute(category);
addCallers.add(currentCaller);
}
// if (testCaller!=null) {
// removeCallers.add(testCaller);
// }
}
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "add", "label", getLanguage()));
try {
Thread.sleep(1250);
} catch (InterruptedException e1) {
}
// if (removeCallers.size()>0)
// m_app.getController().deleteElements(removeCallers);
m_app.getController().addElements(addCallers);
}
} else {
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "add", "label", getLanguage()));
m_app.getController().addElements(callers);
}
progressMonitor.done();
}
};
pmd.setBlockOnOpen(false);
pmd.run(true, false, r);
// ModalContext.run(r, true, pmd.getProgressMonitor(), DisplayManager.getDefaultDisplay());
} catch (InterruptedException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (InvocationTargetException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
}
m_app.updateViews(true);
return;
}
use of de.janrufmonitor.repository.types.IIdentifyCallerRepository in project janrufmonitor by tbrandt77.
the class OldDatFileCallImporter method parsePhone.
private IPhonenumber parsePhone(String caller) {
if (caller.indexOf("(0") > -1) {
IPhonenumber phone = null;
String pn = caller.substring(caller.indexOf("(0") + 2, caller.lastIndexOf(")"));
if (pn.length() > 0) {
phone = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(pn);
ICallerManager cm = PIMRuntime.getInstance().getCallerManagerFactory().getDefaultCallerManager();
if (cm != null && cm.isActive() && cm.isSupported(IIdentifyCallerRepository.class)) {
try {
ICaller parsedCaller = ((IIdentifyCallerRepository) cm).getCaller(phone);
return parsedCaller.getPhoneNumber();
} catch (CallerNotFoundException e) {
this.m_logger.warning(e.getMessage());
}
}
}
}
return PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true);
}
Aggregations