这仅仅是保证了再报表的query里拉出了这个对象不能保证在报表层面也使用了这个对象,,检索的对象名称为“Domestic / International”,在BO4中SDK中已经不提供XI3中的Query对象所以采用另一种办法来做:
参考文档http://bukhantsov.org/2012/11/java-code-to-list-the-objects-used-in-a-webi-4-0-document/
主要用到了webi_client_toolkit.jar 这个包,这个包并不在SAP官网文档中提到,也不再客户端安装目录下,必须要服务器端安装目录下取得C:\Program Files (x86)\SAP BusinessObjects\Tomcat6\webapps\BOE\WEB-INF\eclipse\plugins\webpath.AnalyticalReporting\web\WEB-INF\lib\webi_client_toolkit.jar
<%@page import="java.io.FileOutputStream"%><%@ page language="java" errorPage="err_page.jsp"%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.List" %>
<%@ page import="java.io.*" %>
<%@ page import="jxl.Workbook" %>
<%@ page import="jxl.write.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.Collection" %>
<%@ page import="java.lang.Iterable" %>
<%@ page import="com.businessobjects.adv_ivcdzview.Utils"%>
<%@ page import="com.crystaldecisions.sdk.exception.SDKException" %>
<%@ page import="com.crystaldecisions.sdk.framework.CrystalEnterprise" %>
<%@ page import="com.crystaldecisions.sdk.framework.IEnterpriseSession" %>
<%@ page import="com.crystaldecisions.sdk.framework.ISessionMgr" %>
<%@ page import="com.crystaldecisions.sdk.occa.infostore.IEvents" %>
<%@ page import="com.crystaldecisions.sdk.occa.infostore.IInfoObject" %>
<%@ page import="com.crystaldecisions.sdk.occa.infostore.IInfoObjects" %>
<%@ page import="com.crystaldecisions.sdk.occa.infostore.IInfoStore" %>
<%@ page import="com.crystaldecisions.sdk.plugin.desktop.event.IEvent" %>
<%@ page import="com.crystaldecisions.sdk.properties.IProperties" %>
<%@ page import="com.businessobjects.sdk.plugin.desktop.webi.IWebi" %>
<%@ page import="com.crystaldecisions.sdk.plugin.desktop.report.IReport" %>
<%@ page import="com.businessobjects.rebean.wi.*" %>
<%@ page import="com.sap.webi.client.toolkit.reporting.ReportDictionaryHelper"%>
<%@ page import="com.businessobjects.sdk.core.Core"%>
<%@ page import="com.businessobjects.sdk.core.context.IContext"%>
<%@ page import="com.sap.sl.dictionary.DictionaryExpression"%>
<%@ page import="com.sap.sl.dictionary.Variable"%>
<%@ page import="com.sap.webi.client.toolkit.Deployment"%>
<%@ page import="com.sap.webi.client.toolkit.LoginKey"%>
<%@ page import="com.sap.webi.client.toolkit.SessionContext"%>
<%@ page import="com.businessobjects.rebean.wi.model.engine.IDocumentInstance"%>
<%@ page import="com.businessobjects.rebean.wi.services.IDocumentInstanceManagementService"%>
<%@ page import="java.util.Locale"%>
<%
IEnterpriseSession enterpriseSession=null ;
OutputStream os=null;
WritableWorkbook workbook=null;
try
{
// IEnterpriseSession enterpriseSession = LoginAndGetSession.getSession();
//String S_USER=request.getParameter("user").trim();
//String S_PASS=request.getParameter("pwd").trim();
//String startDate=request.getParameter("startDate").trim();
//String endDate=request.getParameter("endDate").trim();
//String S_HOST="@PPECLUSTER";
//String S_SECURITY="secEnterpris";
//System.out.println(S_USER);
//System.out.println(S_PASS);
//System.out.println(startDate);
//System.out.println(endDate);
//System.out.println(S_HOST);
//System.out.println(S_SECURITY);
ISessionMgr iSessionMgr = CrystalEnterprise.getSessionMgr();
System.out.println("start to log in");
enterpriseSession=iSessionMgr.logon("adtuser", "***", "*****", "secEnterprise");
// DocumentInstance doc;
ReportEngine objReportEngine=null;
try{
objReportEngine = (ReportEngine)enterpriseSession.getService("","WebiReportEngine"); ;
}catch(Exception e){
objReportEngine = (ReportEngine)enterpriseSession.getService("ReportEngine"); ;
}
System.out.println("start to log in2");
{
//test
}
IInfoStore infostore=(IInfoStore)enterpriseSession.getService("InfoStore");//2012.12.01.00.00.00
//get total of instance
IInfoObjects allReportcounts= infostore.query("SELECT count( SI_ID) FROM CI_INFOOBJECTS WHERE SI_KIND in('WEBI')AND SI_INSTANCE=0 and SI_CREATION_TIME<='2011.01.01.00.00.00'" );
IInfoObject allRportcount=(IInfoObject)allReportcounts.get(0);
//System.out.print("The total of instance is: "+allReports.size());
IProperties counts=(IProperties)allRportcount.properties().getProperties("SI_AGGREGATE_COUNT");
int IDCount=counts.getInt("SI_ID");
System.out.print("The total of instance is: "+IDCount);
int k=IDCount;
IInfoObjects allReports= infostore.query("SELECT top "+k+" * FROM CI_INFOOBJECTS WHERE SI_KIND in('Webi') and SI_INSTANCE=0 and SI_CREATION_TIME<='2011.01.01.00.00.00'" );
String targetfile = "D:\\reportwithLOB8.xls";
File f=new File(targetfile);
if(f.exists())f.delete();
os=new FileOutputStream(targetfile);
workbook = Workbook.createWorkbook(os);
WritableSheet sheet = workbook.createSheet("Hongrao",0);
int row=0;
String serializedSession = enterpriseSession.getSerializedSession();
SessionContext sessionContext = com.businessobjects.adv_ivcdzview.Utils.getSessionContextManager().matchSessionContext(Deployment.DHTML, serializedSession, true);
Locale localLocale = Locale.getDefault();
sessionContext.getLoginInfo().set(LoginKey.LOCALE, localLocale);
sessionContext.logonWithSerializedSession();
IContext context = sessionContext.getCoreContext();
IDocumentInstanceManagementService documentInstanceManagementService = Core.getService(IDocumentInstanceManagementService.class);
egencia:
for (int i=0;i<k;i++)
{
try{
IWebi a=(IWebi)allReports.get(i);
//doc= objReportEngine.openDocument(a.getID());
// a.getso
{}
String path="";
String docName="";
String createdate="as";
String lastdate="as";
SimpleDateFormat sdf = new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " );
{
IInfoObject reportFolder = a.getParent();
docName=a.getTitle();
createdate=sdf.format( a.properties().getDate("SI_CREATION_TIME"));
lastdate=sdf.format( a.properties().getDate("SI_UPDATE_TS"));
// System.out.print(a.getTitle()+"\n");
if (a.getParentID() == 0)
path="Public Folders";
else
{ try{
while (1 > 0)
{
path = reportFolder.getTitle() + "/" + path;
// System.out.print(" Report path "+reportFolder.getTitle());
if (reportFolder.getParentID() == 0)
{path = "Public Folders"+ "/" + path;
// System.out.print(path+"\n");
break;
}
else
{
reportFolder = reportFolder.getParent();
//System.out.print(reportFolder);
}
}
}catch(Exception es){}
}
}
if(path.toLowerCase().indexOf("egencia")<0) continue;
{
IDocumentInstance doc =documentInstanceManagementService.openDocument(context, a.getID());
List <DictionaryExpression>list = ReportDictionaryHelper.getDictionaryObjectsFlatList(context, doc);
int have=0;
if (list.size() > 0) {
System.out.println(a.getTitle()+" OBJECTS:"+i+":"+list.size());
// for(int g=0;g<list.size();g++){
//System.out.println(expr.getName());
// list.
//}
for (DictionaryExpression expr:list) {
if(expr.getName().indexOf("nternatio")>1 && expr.getName().indexOf("mestic")>1)
{ have=1;
System.out.println(expr.getName());
break;
}
}
}
documentInstanceManagementService.closeDocument(context, doc);
if(have==0) continue egencia;
}
Label labelcon1=new Label(0,row,path);
Label labelcon2=new Label(1,row,docName);
Label labelcon3=new Label(2,row,createdate);
Label labelcon4=new Label(3,row,lastdate);
sheet.addCell(labelcon1);
sheet.addCell(labelcon2);
sheet.addCell(labelcon3);
sheet.addCell(labelcon4);
row+=1;
}catch(Exception eh){}
}
workbook.write();
workbook.close();
os.close();
out.print("sucess!");
}
catch(SDKException sdk){
workbook.close();
os.close();
out.print(sdk.getMessage());}
finally{
enterpriseSession.logoff();
}
%>