aspose file tools*
The moose likes Other Java Products and Servers and the fly likes Download & Attach Business object crystal reports to an Email Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "Download & Attach Business object crystal reports to an Email" Watch "Download & Attach Business object crystal reports to an Email" New topic
Author

Download & Attach Business object crystal reports to an Email

sudheer tekkalakota
Greenhorn

Joined: Aug 04, 2014
Posts: 1
Hello,

In our project we are creating some of the reports through SAP Crystal reports. These reports are accessed by their report ids using Business objects (Opendocument API).
In the application after clicking the submit button an email will be sent to the user with all the links to access the excel reports. These links use the Opendocument API and will be redirected through OpenDocument.jsp file to invoke the methods created by business objects.
Bellow is the Java and JSP code for this :
AdpExport.java :


EmailMessage payrollEmail = new EmailMessage();
EmailMessage accountingEmail = new EmailMessage();
payrollEmail.setFrom(EmailConstants.NOREPLY_EMAIL, EmailConstants.PORTAL_SUPPORT_ALIAS);
accountingEmail.setFrom(EmailConstants.NOREPLY_EMAIL, EmailConstants.PORTAL_SUPPORT_ALIAS);

payrollEmail.addTo(emailAddress, emailAddress);
accountingEmail.addTo(emailAddress, emailAddress);

for (String email : AppMgr.getCommissionConfig().getExportPayrollEmails()) {
payrollEmail.addTo(email, email);
}

for (String email : AppMgr.getCommissionConfig().getExportAccountingEmails()) {
accountingEmail.addTo(email, email);
}

// Add reports to emails
Map<String, Integer> payrollReports = new HashMap<String, Integer>();
payrollReports.put("Commission Export Pay", Param.Reports.EXPORT_PAY);
payrollReports.put("Payroll Commissions Detail", Param.Reports.DETAIL);
addReportsToMessage(payrollEmail, payrollReports);

Map<String, Integer> accountingReports = new HashMap<String, Integer>();
accountingReports.put("Accounting Charge Off", Param.Reports.CHARGE_OFF);
accountingReports.put("Accounting Accrual File", Param.Reports.ACCRUAL);
accountingReports.put("Payroll Commissions Detail", Param.Reports.DETAIL);
addReportsToMessage(accountingEmail, accountingReports);

EmailService.getInstance().send(payrollEmail);
EmailService.getInstance().send(accountingEmail);


private void addReportsToMessage(EmailMessage email, Map<String, Integer> reports) throws ServiceException {
StringBuilder sb = new StringBuilder();
sb.append("Commissions data has been exported.<br /><br />");
sb.append("Reports:<ul>");

for (String key : reports.keySet()) {
sb.append(buildReportListItem(key, getReportUrl(reports.get(key))));
}

sb.append("</ul>");

email.setHtml(true);
email.setBody(sb.toString());
email.setSubject("Commissions export data");
}

private String buildReportListItem(String name, URL url) {
StringBuilder sb = new StringBuilder();

sb.append("<li><a href='");
sb.append(url.toString());
sb.append("'>");
sb.append(name);
sb.append("<a /></li>");

return sb.toString();
}

private URL getReportUrl(int reportId) throws ServiceException {
try {
DataObject boReport = boService.sdoFindReport(AppMgr.APP_CD, reportId, true);

BOUrl boUrl = BOServices.newUrl(boReport.getString(BOConstants.Params.OPENDOC_URL), boReport.getString(BOConstants.Params.TOKEN));
boUrl.setDocId(boReport.getString(BOConstants.Params.DOC_ID));
boUrl.setFormat(BOUrl.FMT_EXCEL);

return new URL(boUrl.getUrl());
} catch (Exception e) {
throw new ServiceException(e);
}
}

These are the URLs created by the above code, which are displayed in that Email :
URL is :http://bobi-web1.abcsupply.com/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=4058889&sOutputFormat=E&token=BOBI-App2.abcsupply.com@4653888JYnKj9AKONRzxcNjF0XDFTL4653507JZJ78OtaLpNyrdmQ4m0IwqV&abcuver=1407176099926
exportPayFile Path is : /opt/IBM/WebSphere/wp_profile/exportPayFile08-04-14_13-14-59-927.xls (The file stored here in this path is Javascript code, its not actual xls file.)

(After clicking on the URLs, user will be redirected to the browser to download the Excel reports. But when session is expired then user will not be able to open or download the excel reports from that email URL links.)

Bellow is the OpenDocument.jsp file which is redirected when the java code is executed :
<body>
<script type="text/javascript" src="../../OpenDocument/1210291354/OpenDocument/js/shared_caf_utils.js"></script>
<script type="text/javascript" src="../../OpenDocument/1210291354/OpenDocument/js/openDocumentUtils.js"></script>
<script type="text/javascript">
function isApplication() {
// Try to find the specifc callback up the DOM tree
var invokeOpendocActionCallback;
try {
var appKindCallback = businessobjects.opendocument.findCallback("caf_callback_getAppKind");
var fromAppKind = null;
if (appKindCallback != null) {
fromAppKind = appKindCallback();
}

invokeOpendocActionCallback = businessobjects.opendocument.findCallback("caf_callback_opendoc");
}

catch(e) {
// Exception is due to trying to access members in parent frames that are in different domains
// Ignore exception object as it has no meaning in Firefox
invokeOpendocActionCallback = null;
}

var name="";
// OpenDoc invoked from apps other than InfoView (e.g. CMC) is considered standalone
if (invokeOpendocActionCallback == null) {

//check if we are already in an Opendoc window
var mywin=businessobjects.webutil.caf.getAppropriateOpenDocContainerFrame();

if ("OpenDocument" == mywin.appKind) {
//if appKind (or ses, or service, etc) is defined in the top window, then we are in opendoc already
//so we dont need to go to the logon page
//we need to get the enterprise session and other parameters from the top window,
//and we want to make sure that we load up in the top window
document.forms[0].action=mywin.getUrlWithApplicationParameters("openDocument.jsp");

//if we want to open a new window, this variable will be changed to the name of the new window
name = mywin.name;
}

document.forms[0].isApplication.value="true";
document.forms[0].appKind.value="OpenDocument";
document.forms[0].target=name;
document.forms[0].submit();

} else {

invokeOpendocActionCallback("/OpenDocument/opendoc/openDocument.jsp?bttoken=null",
"iDocID=4058889&sOutputFormat=E&token=BOBI-App1.abcsupply.com%404637918J6uZUQcevFNS23yjujbc4iv4636425JQY8qTLJ3SO8EGERvu1eVVb&abcuver=1406903836194&isApplication=false",
window,
"null");
return;
}
}
</script>
<form method="POST" action="../../OpenDocument/1210291354/OpenDocument/opendoc/openDocument.jsp" target="">
<input type="hidden" name="isApplication" id="isApplication">
<input type="hidden" name="appKind" id="appKind">
<input type='hidden' name="iDocID" value="4058889" >
<input type='hidden' name="sOutputFormat" value="E" >
<input type='hidden' name="token" value="BOBI-App1.abcsupply.com@4637918J6uZUQcevFNS23yjujbc4iv4636425JQY8qTLJ3SO8EGERvu1eVVb" >
<input type='hidden' name="abcuver" value="1406903836194" >

</form>

<script type="text/javascript">
isApplication();
</script>
</body>

I need to modify the code, so that the email is sent without the links but with the excel reports attached to it.
So in Java, i need to download the excel reports first and then attach them to the email.
So bellow is the code which I had modified :
AdpExport.java :

File exportPayFile = null;
File detailFile = null;
URL url = null;
// Add reports to emails
Map<String, Integer> payrollReports = new HashMap<String, Integer>();
payrollReports.put("Commission Export Pay", Param.Reports.EXPORT_PAY);
payrollReports.put("Payroll Commissions Detail", Param.Reports.DETAIL);
addReportsToMessage(payrollEmail, payrollReports);

for (String key : payrollReports.keySet()) {
url = getReportUrl(payrollReports.get(key));
if(payrollReports.get(key) == Param.Reports.EXPORT_PAY){
exportPayFile = new File("exportPayFile"+dateFmt.format(Calendar.getInstance().getTime()) + ".xls");
FileUtils.copyURLToFile(url, exportPayFile);
payrollEmail.addAttachment("Commission Export Pay", "EXPORT_PAY", exportPayFile.getAbsolutePath());
} else {
detailFile = new File("detailFile"+dateFmt.format(Calendar.getInstance().getTime()) + ".xls");
FileUtils.copyURLToFile(url, detailFile);
payrollEmail.addAttachment("Payroll Commissions Detail", "DETAIL", detailFile.getAbsolutePath());
}
if(!exportPayFile.isFile() && !detailFile.isFile()){
}
}
After above modification I was able to download the file from the URL created, but it was only the javascript file(as shown above).
Can anybody please tell me, how I can download the excel file created by Business objects or crystal reports ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Download & Attach Business object crystal reports to an Email