use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.
the class Map method renderAsImage.
public Image renderAsImage() {
if (this.m_o != null) {
if (this.m_o instanceof ICall) {
this.m_o = ((ICall) this.m_o).getCaller();
}
if (this.m_o instanceof ICaller) {
IAttribute lng = ((ICaller) this.m_o).getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG);
IAttribute lat = ((ICaller) this.m_o).getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT);
if (lng != null && lat != null) {
String maptype = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty("service.GoogleMaps", "type");
String zoom = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty("service.GoogleMaps", "zoom");
try {
File dir = new File(PathResolver.getInstance(PIMRuntime.getInstance()).getPhotoDirectory() + File.separator + "maps" + File.separator);
if (!dir.exists())
dir.mkdirs();
File img = new File(dir, lat.getValue() + lng.getValue() + maptype + zoom);
if (!img.exists()) {
URL url = new URL("http://maps.googleapis.com/maps/api/staticmap?center=" + lat.getValue() + "," + lng.getValue() + "&zoom=" + zoom + "&size=400x90&maptype=" + maptype + "&sensor=false&markers=color:blue%7Clabel:A%7C" + lat.getValue() + "," + lng.getValue());
URLConnection c = url.openConnection();
c.setDoInput(true);
c.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE; Windows NT)");
c.connect();
Object o = url.openStream();
if (o instanceof InputStream) {
BufferedInputStream bin = new BufferedInputStream((InputStream) o);
FileOutputStream fos = new FileOutputStream(img);
Stream.copy(bin, fos, true);
return new Image(DisplayManager.getDefaultDisplay(), img.getAbsolutePath());
}
return null;
}
return new Image(DisplayManager.getDefaultDisplay(), img.getAbsolutePath());
} catch (MalformedURLException e) {
} catch (IOException e) {
}
}
}
}
return null;
}
use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.
the class JournalBuilder method parseCallerImage.
/**
* Introduced for console version of html callmanager. Since no renderer are available on console,
* a mechanism is needed for rendering caller images.
*
* @param text
* @param call
* @return
* @throws IOException
*/
private static String parseCallerImage(String text, ICall call) throws IOException {
String prefix = "<!-- start_caller_image:";
String postfix = ":end_caller_image-->";
while (text.indexOf(prefix) >= 0) {
String token = text.substring(text.indexOf(prefix) + prefix.length(), text.indexOf(postfix));
String[] elements = token.split(";");
if (elements.length > 2) {
continue;
}
ICaller c = call.getCaller();
if (ImageHandler.getInstance().hasImage(c)) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Base64Encoder b64 = new Base64Encoder(bos);
InputStream fin = ImageHandler.getInstance().getImageStream(c);
Stream.copy(new BufferedInputStream(fin), b64, true);
text = StringUtils.replaceString(text, prefix + token + postfix, "<img src=\"data:image/jpeg;base64," + bos.toString() + "\" " + (elements.length == 2 ? "width=\"" + elements[0] + "\" height=\"" + elements[1] + "\" " : "") + "/>");
} else {
text = StringUtils.replaceString(text, prefix + token + postfix, "");
}
}
return text;
}
use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.
the class OutgoingCall method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
IPhonenumber pn = null;
try {
String phone = req.getParameter(OutgoingCall.PARAMETER_NUMBER);
if (phone == null || phone.length() == 0)
pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true);
else
pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(phone);
IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(name, pn);
ICip cip = PIMRuntime.getInstance().getCallFactory().createCip(req.getParameter(OutgoingCall.PARAMETER_CIP), "");
IMsn msn = PIMRuntime.getInstance().getCallFactory().createMsn(req.getParameter(OutgoingCall.PARAMETER_MSN), "");
Date date = new Date(Long.parseLong(req.getParameter(OutgoingCall.PARAMETER_DATE)));
ICall call = PIMRuntime.getInstance().getCallFactory().createCall(c, msn, cip, date);
call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STARTRING, Long.toString(new Date().getTime())));
call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_OUTGOING));
ClientCallMap.getInstance().setCall((pn.isClired() ? IJAMConst.CLIRED_CALL : pn.getTelephoneNumber()) + "/" + msn.getMSN(), call);
Thread sender = new Thread(new HandlerThread(call, this));
sender.start();
resp.getContentStreamForWrite().close();
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.
the class OutlookTransformer method createBusinessCallerList.
private ICallerList createBusinessCallerList(Dispatch contact) throws ComFailException {
ICallerList callerList = getRuntime().getCallerFactory().createCallerList();
IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
IAttribute attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, Dispatch.get(contact, "Firstname").toString().trim());
if (attribute != null)
m.add(attribute);
attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, Dispatch.get(contact, "Lastname").toString().trim());
if (attribute != null)
m.add(attribute);
if (m.size() == 0) {
attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, Dispatch.get(contact, "CompanyName").toString().trim());
if (attribute != null)
m.add(attribute);
} else {
attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL, Dispatch.get(contact, "CompanyName").toString().trim());
if (attribute != null)
m.add(attribute);
}
// check if business caller exists
if (m.size() > 0) {
m.addAll(createBusinessAddressAttributes(contact));
List phones = new ArrayList(businessPhones.length);
IPhonenumber phone = getRuntime().getCallerFactory().createPhonenumber(false);
String number = null;
for (int i = 0; i < businessPhones.length; i++) {
number = Dispatch.get(contact, businessPhones[i]).toString().trim();
if (number != null && number.length() > 0) {
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("OutlookTransformer raw number: " + number);
}
phone = PhonenumberAnalyzer.getInstance(getRuntime()).toIdentifiedPhonenumber(number);
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("OutlookTransformer identified number: " + phone);
}
if (phone != null) {
if (phone.getTelephoneNumber().trim().length() > 0 && !phone.isClired()) {
m.add(getNumberTypeAttribute(businessPhones[i], phone.getTelephoneNumber()));
phones.add(phone);
}
}
}
}
if (phones.size() > 0) {
ICaller outlookCaller = getRuntime().getCallerFactory().createCaller(null, phones, m);
// outlookCaller.setAttributes(m);
outlookCaller.setUUID(outlookCaller.getName().getLastname() + "_" + outlookCaller.getName().getFirstname() + "_" + outlookCaller.getPhoneNumber().getTelephoneNumber());
this.setPictureAttribute(outlookCaller, contact);
IAttribute cm = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, ID);
outlookCaller.setAttribute(cm);
this.m_logger.fine("Created Outlook contact: " + outlookCaller.toString());
callerList.add(outlookCaller);
}
}
return callerList;
}
use of de.janrufmonitor.framework.ICaller in project janrufmonitor by tbrandt77.
the class OutlookTransformer method createPrivateCallerList.
private ICallerList createPrivateCallerList(Dispatch contact) throws ComFailException {
ICallerList callerList = getRuntime().getCallerFactory().createCallerList();
IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
IAttribute attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, Dispatch.get(contact, "Firstname").toString().trim());
if (attribute != null)
m.add(attribute);
attribute = createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, Dispatch.get(contact, "Lastname").toString().trim());
if (attribute != null)
m.add(attribute);
// check if private caller exists
if (m.size() > 0) {
m.addAll(createPrivateAddressAttributes(contact));
List phones = new ArrayList(businessPhones.length);
IPhonenumber phone = getRuntime().getCallerFactory().createPhonenumber(false);
String number = null;
for (int i = 0; i < privatePhones.length; i++) {
number = Dispatch.get(contact, privatePhones[i]).toString().trim();
if (number != null && number.length() > 0) {
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("OutlookTransformer raw number: " + number);
}
phone = PhonenumberAnalyzer.getInstance(getRuntime()).toIdentifiedPhonenumber(number);
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("OutlookTransformer identified number: " + phone);
}
if (phone != null) {
if (phone.getTelephoneNumber().trim().length() > 0 && !phone.isClired()) {
m.add(getNumberTypeAttribute(privatePhones[i], phone.getTelephoneNumber()));
phones.add(phone);
}
}
}
}
if (phones.size() > 0) {
ICaller outlookCaller = getRuntime().getCallerFactory().createCaller(null, phones, m);
outlookCaller.setUUID(outlookCaller.getName().getLastname() + "_" + outlookCaller.getName().getFirstname() + "_" + outlookCaller.getPhoneNumber().getTelephoneNumber());
this.setPictureAttribute(outlookCaller, contact);
IAttribute cm = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER, ID);
outlookCaller.setAttribute(cm);
this.m_logger.fine("Created Outlook contact: " + outlookCaller.toString());
callerList.add(outlookCaller);
}
}
return callerList;
}
Aggregations