if("generatereport".equals(pageContext.getParameter("event"))){
OADBTransactionImpl txn=(OADBTransactionImpl)am.getOADBTransaction();
OAViewObject vo = (OAViewObject)pageContext.getApplicationModule(webBean).findViewObject("AuctionHeadersAllVO"); //getting view object for AuctionHeadersAllVO
String DocumentNumber=(String)vo.getCurrentRow().getAttribute("DocumentNumber"); //getting document number from current row
int DocumentNumber1=Integer.parseInt(DocumentNumber);
pageContext.writeDiagnostics(this,"DocumentNumber in co:"+DocumentNumber,1); //display document number
/* call the method which runs the concurrent program and returns request id*/
int req_id= submitCPRequest(DocumentNumber,txn);
if(pageContext.isLoggingEnabled(1))
{
pageContext.writeDiagnostics(this,"req_id in CO:"+req_id,1); //display request id
}
//Make application sleep for 15 seconds to finish the concurrent program
try
{
CallableStatement cal=txn.createCallableStatement("begin dbms_lock.sleep(20); end;",1);
cal.execute();
cal.close();
}
catch(Exception e)
{
throw OAException.wrapperException(e);
}
//Get the output file name from the backend table
String file_name=null;
try
{
CallableStatement cal=txn.createCallableStatement("begin select file_name into :1 from FND_CONC_REQ_OUTPUTS where concurrent_request_id=:2; end;",1);
cal.setInt(2,req_id);
cal.registerOutParameter(1,Types.VARCHAR);
cal.execute();
file_name= cal.getString(1);
cal.close();
if(pageContext.isLoggingEnabled(1))
{
pageContext.writeDiagnostics(this,"file_name:"+file_name,1);
}
}
catch(Exception e)
{
//throw OAException.wrapperException(e);
System.out.println("no data found");
}
//Read data from output file and display
DataObject sessionDictionary = (DataObject)pageContext.getNamedDataObject("_SessionParameters");
HttpServletResponse response = (HttpServletResponse)sessionDictionary.selectValue(null,"HttpServletResponse");
String contentDisposition = "attachment;filename="+DocumentNumber+".xls";
response.setHeader("Content-Disposition",contentDisposition);
response.setContentType("application/vnd.ms-excel");
File f=new File(file_name);
// File f=new File("/u02/PROD/inst/apps/MPPMCL_bb02/logs/appl/conc/out/XXMPP_SCM_NIT_PUB_TEMP_878237_1.PDF");
if(pageContext.isLoggingEnabled(1))
{
pageContext.writeDiagnostics(this,"output file:"+f,1);
}
try {
if(pageContext.isLoggingEnabled(1))
{
pageContext.writeDiagnostics(this,"in try block:",1);
}
OutputStream os = response.getOutputStream();
byte[] buf = new byte[8192];
InputStream is = new FileInputStream(f);
int c = 0;
while ((c = is.read(buf, 0, buf.length)) > 0) {
os.write(buf, 0, c);
os.flush();
}
os.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public int submitCPRequest(String Rfq_num,OADBTransaction tx) {
try {
java.sql.Connection pConncection = tx.getJdbcConnection(); //get JDBC connection object
ConcurrentRequest cr = new ConcurrentRequest(pConncection); // get the concurrentrequest object
String applnName = "XXMPP"; //Application that contains the concurrent program
String cpName = "XXMPPTEQTRPT"; //Concurrent program name
String cpDesc = null; // concurrent Program description
Vector cpArgs = new Vector(); //create an object for vector
cpArgs.addElement(Rfq_num); //pass parameters by using vector
try
{
cr.addLayout("XXMPP","XXMPPTEQTRPT","EN","US","EXCEL",null); //addlayout to the concurrent program
}
catch(Exception e)
{
throw OAException.wrapperException(e);
}
int requestId = cr.submitRequest(applnName, cpName, cpDesc, null, false, cpArgs); //call submitRequest method in ConcurrentRequest class
tx.commit(); //commit
return requestId; //return request id
} catch (RequestSubmissionException e) {
OAException oe = new OAException(e.getMessage());
throw oe;
}
}