BIP_开发案例09_结合JavaCP通过BIP API输出报表dataprocess / rtfprocess / foprocess(案例)
20150814 Created By BaoXinjian
一、摘要
通过Java Concurrent Program导入XML文件和RTF文件导出PDF报表,一种官方的源码解读,通过以下三个关键程序实现
1. 通过DataProcess设定XML数据来源
2. 通过RtfProcess设定RTF模板来源
3. 通过FoProcess产生PDF文件
二、方案设计 - 代码
Step1. 创建XML数据定义文件(EmpDataTemplate.xml),并上传至服务器的/u2/VIS/visappl/gavin/concprog/目录
<?xml version="1.0" encoding="UTF-8" ?>
<dataTemplate name="EmpData" description="Employee Details" Version="1.0">
<parameters>
<parameter name="p_DeptNo" dataType="character" />
</parameters>
<dataQuery>
<sqlStatement name="Q1">
<![CDATA[
SELECT d.DEPTNO DEPTNO
,d.DNAME DNAME
,d.LOC LOC
,e.EMPNO EMPNO
,e.ENAME ENAME
,e.JOB JOB
,e.MGR MGR
,TO_CHAR(e.HIREDATE,'YYYY/MM/DD') HIREDATE
,e.SAL SAL
,nvl(e.COMM, 0) COMM
FROM scott.dept d
,scott.emp e
WHERE d.deptno = e.deptno
AND d.deptno = nvl( :p_DeptNo, d.deptno)
]]>
</sqlStatement>
</dataQuery>
<dataStructure>
<group name="G_DEPT" source="Q1">
<element name="DEPT_NUMBER" value="DEPTNO" />
<element name="DEPT_NAME" value="DNAME" />
<element name="LOCATION" value="LOC" />
<element name="EMPLOYEE_NUMBER" value="EMPNO" />
<element name="NAME" value="ENAME" />
<element name="JOB" value="JOB" />
<element name="MANAGER" value="MGR" />
<element name="HIREDATE" value="HIREDATE" />
<element name="SALARY" value="SAL" />
<element name="COMMISSION" value="COMM" />
</group>
</dataStructure>
</dataTemplate>
Step2. 创建rtf模板(EmpDataTemplate.rtf)并上传至服务器的/u2/VIS/visappl/gavin/concprog/目录:
Step3. 创建java
concurrent程序(EmpDataTemplate.java)。如果不能编译通过,需到服务器上的$JAVA_TOP目录下载相关类文件(可使
用zip命令打包下载: zip -r ~/conclib ./oracle/apps/fnd/cp/*):
package bxj.oracle.apps.ap.java;
import java.sql.Connection;
import oracle.apps.fnd.cp.request.CpContext;
import oracle.apps.fnd.cp.request.JavaConcurrentProgram;
import oracle.apps.xdo.dataengine.DataProcessor;
import oracle.apps.fnd.util.ParameterList;
import oracle.apps.fnd.cp.request.ReqCompletion;
import oracle.apps.fnd.cp.request.OutFile;
import oracle.apps.fnd.cp.request.LogFile;
import oracle.apps.fnd.util.NameValueType;
import oracle.apps.xdo.template.RTFProcessor;
import oracle.apps.xdo.template.FOProcessor;
import com.sun.java.util.collections.Hashtable;
import java.io.File;
public class runEmpXMLConcProg implements JavaConcurrentProgram {
public runEmpXMLConcProg() {
}
String deptNo;
public void runProgram(CpContext cpContext) {
ParameterList params = cpContext.getParameterList();
ReqCompletion compl = cpContext.getReqCompletion();
OutFile outFile = cpContext.getOutFile();
LogFile logFile = cpContext.getLogFile();
logFile.writeln(">>1 start ..", LogFile.STATEMENT);
while (params.hasMoreElements()) {
NameValueType val = params.nextParameter();
if (val.getName().equals("P_DEPTNO"))
deptNo = val.getValue();
}
logFile.writeln(">>2 P_DEPTNO = " + deptNo, LogFile.STATEMENT);
Connection jdbcConnection = cpContext.getJDBCConnection();
try {
//Initialization – instantiate the DataProcessor class//
DataProcessor dataProcessor = new DataProcessor();
//Set Data Template to be executed
dataProcessor.setDataTemplate("/u2/VIS/visappl/gavin/concprog/EmpDataTemplate.xml");
logFile.writeln(">>3 dataProcessor.setDataTemplate", LogFile.STATEMENT);
// Assign parameter
Hashtable parameters = new Hashtable();
parameters.put("p_DeptNo", deptNo);
dataProcessor.setParameters(parameters);
logFile.writeln(">>4 dataProcessor.setParameters", LogFile.STATEMENT);
// Set the jdbc connection
dataProcessor.setConnection(jdbcConnection);
logFile.writeln(">>5 dataProcessor.setConnection", LogFile.STATEMENT);
// Specify the output directory and file for the data file
dataProcessor.setOutput("/u2/VIS/visappl/gavin/concprog/EmpDetails.xml");
logFile.writeln(">>6 dataProcessor.setOutput", LogFile.STATEMENT);
// Process the data template
dataProcessor.processData();
logFile.writeln(">>6.1 dataProcessor.processData", LogFile.STATEMENT);
// Convert rtf to xsl
RTFProcessor rtfProcessor = new RTFProcessor("/u2/VIS/visappl/gavin/concprog/EmpDataTemplate.rtf"); logFile.writeln(">>7 new RTFProcessor()", LogFile.STATEMENT);
rtfProcessor.setOutput("/u2/VIS/visappl/gavin/concprog/EmpDataTemplate.xsl");
rtfProcessor.process();
logFile.writeln(">>8 rtfProcessor.process()", LogFile.STATEMENT);
// Geneate PDF
FOProcessor foProcessor = new FOProcessor();
foProcessor.setData("/u2/VIS/visappl/gavin/concprog/EmpDetails.xml");
logFile.writeln(">>9 foProcessor.setData()", LogFile.STATEMENT);
foProcessor.setTemplate("/u2/VIS/visappl/gavin/concprog/EmpDataTemplate.xsl");
logFile.writeln(">>10 foProcessor.setTemplate()", LogFile.STATEMENT);
foProcessor.setOutput("/u2/VIS/visappl/gavin/concprog/EmpDetails001.pdf");
logFile.writeln(">>11 foProcessor.setOutput()", LogFile.STATEMENT);
foProcessor.setOutputFormat(FOProcessor.FORMAT_PDF);
foProcessor.generate();
logFile.writeln(">>12 foProcessor.generate() 001", LogFile.STATEMENT);
compl.setCompletion(ReqCompletion.NORMAL, "Concurrent Normal Completed!");
} catch (Exception e) {
logFile.writeln("Java Concurrent Program Error: "+e.toString(), LogFile.STATEMENT);
compl.setCompletion(ReqCompletion.ERROR, e.toString());
}
}
}
三、方案设计 - 应用设定
Step1. 将XML文件和RTF文件上传至服务器相应目录
Step2. 将RunProgram Class包上传至相应目录
Step3. 设定并发可执行程序
Step4. 设定并发程式及其参数
四、运行测试
Step1. 调用Request
Step2. 系统会自动依次产生三个文件xsl->xml->pdf
Step3. 查看xml data文件
Step4. 查看pdf
Thanks and Regards
参考:LiaoDunxia - http://blog.csdn.net/t0nsha/article/details/6336872
ERP技术讨论群: 288307890
技术交流,技术讨论,欢迎加入
Technology Blog Created By Oracle ERP - 鲍新建
技术交流,技术讨论,欢迎加入
Technology Blog Created By Oracle ERP - 鲍新建