Monday, September 14, 2015

Oracle E-Business Suite R12.1.x | Integrating BI Publisher and OA Framework

Controller Code
================================================
// Import below classes in Controller
import java.util.Properties;import oracle.apps.xdo.oa.common.DocumentHelper;
import java.io.ByteArrayOutputStream;
import java.io.Serializable;
import java.util.Properties;
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.xdo.oa.common.DocumentHelper;
import oracle.apps.xdo.oa.schema.server.Template;
import oracle.jbo.XMLInterface;
import oracle.jbo.domain.BlobDomain;
import oracle.xml.parser.v2.XMLNode;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import oracle.apps.xdo.XDOException;
import oracle.apps.xdo.oa.schema.server.TemplateHelper;
import oracle.cabo.ui.data.DataObject;
import oracle.jbo.XMLInterface;
import oracle.apps.xdo.oa.schema.server.Template;
import oracle.jbo.domain.BlobDomain;

 ....
 ....
 ....

  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);


      OAApplicationModule am = pageContext.getApplicationModule(webBean);


    ////////////////////////////////////////
    ///////// For RTF Template
    ////////////////////////////////////////
               
    if ((pageContext.getParameter("BTNPrintReport") != null))  {

      String TemplateApplicationShortName = "PER";
      String TemplateCode = "XXARMSEMP"; //"XXARMS_IR_InterviewFeedback" ;

      Number LeadId = 494;
      Serializable aserializable2[] = {LeadId.toString()};
      Class aclass2[] = {String.class };
      BlobDomain result = (BlobDomain) am.invokeMethod("getXMLData",aserializable2,aclass2);

// Get the HttpServletResponse object from the PageContext. The report output is written to HttpServletResponse.
       DataObject sessionDictionary = (DataObject)pageContext.getNamedDataObject("_SessionParameters");
       HttpServletResponse response = (HttpServletResponse)sessionDictionary.selectValue(null,"HttpServletResponse");
       try {
       ServletOutputStream os = response.getOutputStream();

// Set the Output Report File Name and Content Type
      String contentDisposition = "attachment;filename=EmpReport.pdf";
      response.setHeader("Content-Disposition",contentDisposition);
      response.setContentType("application/pdf");
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      outputStream = (ByteArrayOutputStream)result.getOutputStream();

      ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
      ByteArrayOutputStream pdfFile = new ByteArrayOutputStream();

//Generate the PDF Report.
       TemplateHelper.processTemplate(
       ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getAppsContext(),
       TemplateApplicationShortName,
       TemplateCode,
       ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getLanguage(),
       ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getCountry(),
       inputStream,
       TemplateHelper.OUTPUT_TYPE_PDF,
       null,
       pdfFile);

// Write the PDF Report to the HttpServletResponse object and flush.
      byte[] b = pdfFile.toByteArray();
      response.setContentLength(b.length);
      os.write(b, 0, b.length);
      os.flush();
      os.close();
      }
      catch(Exception e)
      {
      response.setContentType("text/html");
      throw new OAException(e.getMessage(), OAException.ERROR);
      }
      pageContext.setDocumentRendered(false);

     }

  }




Application Module Code
================================================
 
    public BlobDomain getXMLData(String P_VacancyId)
    {
    BlobDomain blobDomain = new BlobDomain();
    OADBTransaction oadbtransaction = getOADBTransaction();
    try
    {
    String dataDefCode = "XXARMSEMP"; //"XXARMSInterviewFeedback" ;
    String dataDefApp = "PER";
    String outputString = null;
    DataTemplate datatemplate = new DataTemplate(((OADBTransactionImpl)getOADBTransaction()).getAppsContext(), dataDefApp, dataDefCode );
//    Hashtable parameters = new Hashtable();
//    parameters.put("P_VacancyId",P_VacancyId);
//    datatemplate.setParameters(parameters);
    datatemplate.setOutput(blobDomain.getBinaryOutputStream());
    datatemplate.processData();
    }
    catch(SQLException e)
    {
    throw new OAException("SQL Error=" + e.getMessage(),OAException.ERROR);
    }
    catch (XDOException e)
    {
    throw new OAException("XDOException" + e.getMessage(),OAException.ERROR);
    }
    catch(Exception e)
    {
    throw new OAException("Exception" + e.getMessage(),OAException.ERROR);
    }
    return blobDomain;
    }

5 comments:

  1. Dear Abbas

    hope to be very well
    Thank you so much for this useful topic
    kindly i have an issue when use this code as below

    Error(177,14): XDOException not found in class

    EBS Version : R12.2.4

    Best Regards
    Elsayed Abdelbadea

    ReplyDelete
  2. Dear Elsayed,
    You should use xdocore.jar for this. Inside xdocore.jar you will find XDOException class. This jar you can add in project libraries.

    Regards,
    Abbas Qureshi

    ReplyDelete
    Replies
    1. Thanks for the answer..

      Where we will find xdocore.jar file..

      I try on Find it on my EBS Instance (R12.2.5). But not found .. Kindly give me this Jar file for my Instance..

      Delete
  3. Dear Abbas,

    Even I ma having the same issue. We are in 12.2.7 version.

    Any ideas.

    ReplyDelete
  4. Simply copy the file from the server to your folder of myclasses

    oracle.apps.xdo.XDOException

    access to $JAVA_TOP\oracle\apps\xdo to the Unix server and copy the XDOException class
    TO
    D:\JDeveloper\jdevhome\jdev\myclasses\oracle\apps\xdo\

    ReplyDelete