• Generate PDF in Sourcing through concurrent request,在EBS java并发中调用指定am的方法


    package oracle.apps.pon.printing.cp;
    
    import java.io.InputStream;
    import java.io.FileOutputStream;
    import oracle.jbo.domain.BlobDomain;
    import oracle.apps.fnd.cp.request.CpContext;
    import oracle.apps.fnd.cp.request.LogFile;
    import oracle.apps.fnd.cp.request.OutFile;
    import oracle.apps.fnd.cp.request.ReqCompletion;
    import oracle.apps.fnd.util.ParameterList;
    import oracle.apps.fnd.util.NameValueType;
    import oracle.apps.fnd.framework.OAApplicationModuleFactory;
    import oracle.apps.fnd.framework.server.OADBTransaction;
    import oracle.apps.fnd.framework.server.OAApplicationModuleImpl;
    import oracle.apps.pon.printing.server.SourcingPrintingAMImpl;
    
    /**
    * This class is a JavaConcurrentProgram to generate a Sourcing Negotiation
    * PDF event from the ConcurrentRequest utility rather than from the webpage.
    * 
    * This tool allows sourcing events to be printed before they are published to
    * the suppliers so they may be reviewed by the team without the need to create
    * multiple revisions to the event before publishing.
    */
    public class GenerateNegotiationPdfCp 
    implements oracle.apps.fnd.cp.request.JavaConcurrentProgram 
    {
    //class level variables
    public static String sourcingPrintingAmName = 
    "oracle.apps.pon.printing.server.SourcingPrintingAM";
    private LogFile m_appsLogFile; 
    
    /**
    * Default Constructor, does nothing
    */
    public GenerateNegotiationPdfCp()
    {
    }//End of constructor GenerateNegotiationPdfCp()
    
    /**
    * Main entry point for the application. This will accept the conext
    * and run the tools needed to generate a PDF of a sourcing negotiation
    */
    public void runProgram(CpContext cpContext) 
    {
    //Local variables
    OutFile out = cpContext.getOutFile();
    m_appsLogFile = cpContext.getLogFile();
    ReqCompletion lRC = cpContext.getReqCompletion(); 
    BlobDomain pdf = null;
    Integer rfxId = null;
    
    //Grad the P_SOURCING_EVENT_ID catagory from the Concurrent context
    ParameterList list = cpContext.getParameterList();
    m_appsLogFile.writeln("Retrieving P_SOURCING_EVENT_ID parameter", LogFile.STATEMENT);
    try
    {
    while(list.hasMoreElements()) 
    {
    NameValueType namevaluetype = list.nextParameter();
    if(namevaluetype.getName().equalsIgnoreCase("P_SOUCING_EVENT_ID")) 
    {
    String val = namevaluetype.getValue();
    if(val != null)
    {
    rfxId = new Integer(Integer.parseInt(val));
    }
    } 
    }
    }
    catch(Exception ex)
    {
    m_appsLogFile.writeln("The following error occured while retrieving "
    + "the P_SOURCING_EVENT_ID parameter " + ex.getMessage(), LogFile.ERROR);
    lRC.setCompletion(ReqCompletion.ERROR, 
    "Failed to get P_SOURCING_EVENT_ID parameter");
    return;
    }
    
    //Call getNegotiationPdf(string, string, string, string, Boolean)
    m_appsLogFile.writeln("Retrieving PDF file", LogFile.STATEMENT);
    try
    {
    /** 
    * Get the BlobDomain so we can write it to the output file
    */
    SourcingPrintingAMImpl pdflib = (SourcingPrintingAMImpl)getSourcingAppModule(cpContext);
    OADBTransaction trans = pdflib.getOADBTransaction();
    String clientTimeZone = trans.getProfile("CLIENT_TIMEZONE_ID");
    String serverTimeZone = trans.getProfile("SERVER_TIMEZONE_ID");
    String dateFormat = trans.getProfile("ICX_DATE_FORMAT_MASK");
    pdf = pdflib.getNegotiationPdf(rfxId.toString(), clientTimeZone, serverTimeZone, dateFormat, new Boolean(true));
    }
    catch(Exception ex)
    {
    m_appsLogFile.writeln("The following error occured while retrieving the "
    + "PDF from BI Publisher: " + ex.getMessage(), LogFile.ERROR);
    lRC.setCompletion(ReqCompletion.ERROR, 
    "Failed to get PDF from BI Publisher parameter");
    return;
    }
    
    //Write the PDF to the output file 2k at a time
    m_appsLogFile.writeln("Writting the PDF to the output file", LogFile.STATEMENT);
    try
    {
    InputStream iStream = pdf.getBinaryStream();
    FileOutputStream oStream = new FileOutputStream(out.getFileName(), false);
    byte[] buff = new byte[2048];
    int count;
    while((count = iStream.read(buff)) >= 0)
    {
    oStream.write(buff, 0, count);
    }
    iStream.close();
    oStream.flush();
    oStream.close();
    lRC.setCompletion(ReqCompletion.NORMAL, "SUCCESS!");
    }
    catch(Exception ex)
    {
    m_appsLogFile.writeln("Failed to write PDF to output file [" 
    + out.getFileName() 
    + "] with the following error: " + ex.getMessage(), LogFile.ERROR);
    lRC.setCompletion(ReqCompletion.ERROR, 
    "Failed writing to the output file");
    return;
    }
    
    }//End of method runProgram(CpConext)
    
    /**
    * This method uses the OAApplicationModuleFactory to create an instance of
    * an Oracle Application Implimentation Module factory. The current context
    * of the ConcurrentRequest program is sent along so the Application Module
    * can initialize properly.
    */
    protected OAApplicationModuleImpl getSourcingAppModule(CpContext cpcontext) 
    {
    OAApplicationModuleImpl oaapplicationmoduleimpl = 
    (OAApplicationModuleImpl)
    OAApplicationModuleFactory.createRootOAApplicationModule(
    cpcontext, sourcingPrintingAmName);
    return oaapplicationmoduleimpl;
    }//End of getSourcingAppModule(CpContext)
    
    }//End of class GenerateNegotiationPdfCp

    其中最重要的方法便是在请求中调用AM。

    SourcingPrintingAMImpl pdflib = (SourcingPrintingAMImpl)getSourcingAppModule(cpContext);
    protected OAApplicationModuleImpl getSourcingAppModule(CpContext cpcontext) 
    {
    OAApplicationModuleImpl oaapplicationmoduleimpl = 
    (OAApplicationModuleImpl)
    OAApplicationModuleFactory.createRootOAApplicationModule(
    cpcontext, sourcingPrintingAmName);
    return oaapplicationmoduleimpl;
    }//End of getSourcingAppModule(CpContext)

    参考资料:

    Generate PDF in Sourcing through concurrent request

  • 相关阅读:
    Apache Kafka:下一代分布式消息系统
    深入理解Java之线程池
    JAVA中线程同步的方法(7种)汇总
    String、StringBuffer与StringBuilder之间区别
    Java中是否可以继承String类,为什么
    JAVA4种线程池的使用
    一分钟教你知道乐观锁和悲观锁的区别
    java常见面试题及答案 11-20(JVM)
    springmvc中的页面解析器ViewResolver不起作用,变量输出字符串的解决方案
    SpringMVC默认欢迎页面的问题
  • 原文地址:https://www.cnblogs.com/huanghongbo/p/4867491.html
Copyright © 2020-2023  润新知