Showing posts with label Integrate. Show all posts
Showing posts with label Integrate. Show all posts

Monday, September 14, 2015

Oracle E-Business Suite R12.2.x | How to integrating OA Framework and BI Publisher



Controller Code
==============================
//Import below classes in controller

import oracle.xdo.XDOException;
import oracle.xdo.template.FOProcessor;
import oracle.xdo.template.RTFProcessor;
import oracle.cabo.ui.data.DataObject;
import oracle.xml.parser.v2.XMLNode;


/*
 * Handles functionality of Print button
 */

     if("printRpt".equals(pageContext.getParameter(EVENT_PARAM))) {

                DataObject sessionDictionary = pageContext.getNamedDataObject("_SessionParameters");
                HttpServletResponse response = (HttpServletResponse)sessionDictionary.selectValue(null,"HttpServletResponse");

                // Set the Output Report File Name and Content Type
                String contentDisposition = "attachment; filename=EmployeeReport.pdf";
                response.setHeader("Content-Disposition",contentDisposition);
                response.setCharacterEncoding("UTF-8");
                response.setContentType("application/pdf");

                  try {
                     
                      ServletOutputStream os = response.getOutputStream();

                //Calling RTF Processor
                //RTF Processor generate XSL

                      RTFProcessor rtfProcessor = new RTFProcessor("/u01/oracle/ERPDEV/fs2/EBSapps/comn/java/classes/xxmoh/oracle/apps/per/selfservice/hrorder/template/TEMPLATE_SOURCE_PER_XXMOH_HR_SUSP_ORD_ar_SA_OAF.rtf");

                      ByteArrayOutputStream xlsOutputStream = new ByteArrayOutputStream();
                      rtfProcessor.setOutput(xlsOutputStream);
                      rtfProcessor.process();
                     
                       ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();

                             byte bufutf[] ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".getBytes();
                             localByteArrayOutputStream.write(bufutf);
                             byte buf[] = "<XXMainPG>".getBytes();
                             localByteArrayOutputStream.write(buf);
                           
                            Serializable[] params = {pageContext.getParameter("P_OrderSeq")};                         
                            XMLNode Nodes = (XMLNode)am.invokeMethod("getPrintDataXML", params);
                            
                             Nodes.print(localByteArrayOutputStream);
                            
                             byte buf2[] = "</XXMainPG>".getBytes();
                             localByteArrayOutputStream.write(buf2);

// To generate file

                      ByteArrayInputStream xmlInputStream = new ByteArrayInputStream(localByteArrayOutputStream.toByteArray());
                     
                      System.out.println("XML : "+localByteArrayOutputStream.toString());
                    
//Calling FO Processor
//FO processor take XML data and RTF as XSL and generate PDF output
                      FOProcessor processor = new FOProcessor();
                     
                      ByteArrayOutputStream pdfOutputStream = new ByteArrayOutputStream();

                      processor.setData(xmlInputStream); //set xml input Stream
                      ByteArrayInputStream xlsInputStream = new ByteArrayInputStream(xlsOutputStream.toByteArray());
                      processor.setTemplate(xlsInputStream); //set xsl input file
                      processor.setOutput(pdfOutputStream);
                      processor.setOutputFormat(FOProcessor.FORMAT_PDF);
                     
                      processor.generate();
                     
     // Write the PDF Report to the HttpServletResponse object and flush.
                      byte[] b = pdfOutputStream.toByteArray();
                      response.setContentLength(b.length);
                      os.write(b, 0, b.length);
                      os.flush();
                      os.close();
                      pdfOutputStream.flush();
                      pdfOutputStream.close();
                     
                     
                  } catch (IOException e) {
                      // TODO
                      e.printStackTrace();
                  } catch (XDOException e) {
                        // TODO
                        e.printStackTrace();
                    }
                }



Application Module Code
==============================
import oracle.jbo.XMLInterface;
import oracle.xml.parser.v2.XMLNode;

    public XMLNode getPrintDataXML(String P_SeqNo) {

        try {

           OAViewObject vo = (OAViewObject)findViewObject("XxtstRptVO");

               vo.setWhereClause(null);
               vo.setWhereClause(" ORDER_SEQ = " + P_SeqNo);

             // Exceute VO
              vo.executeQuery();

              XMLNode xmlNode = (XMLNode)vo.writeXML(4, XMLInterface.XML_OPT_ALL_ROWS);

              return xmlNode;

             } catch (Exception e) {

               throw new OAException(e.getMessage() + "Custom Error in XML generation");
            }
 
      }



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;
    }