`

Cognos: get LOV of report parameters

阅读更多

简单介绍:
代码是通过构造XML, 模拟运行(runSpecification)获取运行XML,解析XML获取参数集合List.


package test;

import java.io.ByteArrayInputStream;
import java.util.List;

import org.dom4j.io.SAXReader;
import org.dom4j.tree.DefaultElement;

import com.cognos.developer.schemas.bibus._3.AsynchDetailParameters;
import com.cognos.developer.schemas.bibus._3.AsynchDetailReportOutput;
import com.cognos.developer.schemas.bibus._3.AsynchDetailReportStatus;
import com.cognos.developer.schemas.bibus._3.AsynchDetailReportStatusEnum;
import com.cognos.developer.schemas.bibus._3.AsynchReply;
import com.cognos.developer.schemas.bibus._3.AsynchReplyStatusEnum;
import com.cognos.developer.schemas.bibus._3.AsynchSecondaryRequest;
import com.cognos.developer.schemas.bibus._3.BaseParameter;
import com.cognos.developer.schemas.bibus._3.Option;
import com.cognos.developer.schemas.bibus._3.Parameter;
import com.cognos.developer.schemas.bibus._3.ParameterValue;
import com.cognos.developer.schemas.bibus._3.ReportServiceReportSpecification;
import com.cognos.developer.schemas.bibus._3.ReportServiceSpecification;
import com.cognos.developer.schemas.bibus._3.ReportService_PortType;
import com.cognos.developer.schemas.bibus._3.RunOptionBoolean;
import com.cognos.developer.schemas.bibus._3.RunOptionEnum;
import com.cognos.developer.schemas.bibus._3.RunOptionStringArray;
import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject;
import com.cognos.developer.schemas.bibus._3.Specification;

public class getLOVOfReportParameters
{
    // Report Service: Run Reports
    private ReportService_PortType reportService = null;

    public String executeReportAsXML(String spec)
    {

        String outXml = null;
        AsynchReply rsr;

        Option[] runOptions = new Option[3];

        RunOptionBoolean rob = new RunOptionBoolean();
        RunOptionStringArray rosa = new RunOptionStringArray();
        RunOptionBoolean rop = new RunOptionBoolean();

        // We do not want to save this output
        rob.setName(RunOptionEnum.saveOutput);
        rob.setValue(false);

        // What format do we want the report in: PDF, HTML, or XML?
        rosa.setName(RunOptionEnum.outputFormat);
        rosa.setValue(new String[]{ "XML" });

        // Set the report not to prompt as we pass the parameter if any
        rop.setName(RunOptionEnum.prompt);
        rop.setValue(false);

        // Fill the array with the run options.
        runOptions[0] = rob;
        runOptions[1] = rosa;
        runOptions[2] = rop;

        try
        {
            Specification reportSpec = new Specification();
            reportSpec.set_value(spec);
            ReportServiceSpecification asyncSpec = new ReportServiceReportSpecification();
            asyncSpec.setValue(reportSpec);

            rsr = this.reportService.runSpecification(asyncSpec, new ParameterValue[] {}, runOptions);
            if (!rsr.getStatus().equals(AsynchReplyStatusEnum.complete))
            {
                while (!rsr.getStatus().equals(AsynchReplyStatusEnum.complete))
                {
                    if (!hasSecondaryRequest(rsr, "wait"))
                    {
                        System.out.println("error on secondary request.");
                    }
                    rsr = this.reportService.wait(rsr.getPrimaryRequest(), new ParameterValue[] {}, new Option[] {});
                }

                if (outputIsReady(rsr))
                {
                    rsr = this.reportService.getOutput(rsr.getPrimaryRequest(), new ParameterValue[] {}, new Option[] {});
                }
                else
                {
                    System.out.println("output is not ready!");
                }
            }
            outXml = getOutputPage(rsr);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return outXml;
    }

    public String getOutputPage(AsynchReply response)
    {
        AsynchDetailReportOutput reportOutput = null;
        for (int i = 0; i < response.getDetails().length; i++)
        {
            if (response.getDetails()[i] instanceof AsynchDetailReportOutput)
            {
                reportOutput = (AsynchDetailReportOutput) response.getDetails()[i];
                break;
            }
        }
        // text based output is split into pages -- return the current page
        return reportOutput.getOutputPages()[0].toString();
    }

    public boolean outputIsReady(AsynchReply response)
    {
        for (int i = 0; i < response.getDetails().length; i++)
        {
            if ((response.getDetails()[i] instanceof AsynchDetailReportStatus) && (((AsynchDetailReportStatus) response.getDetails()[i]).getStatus() == AsynchDetailReportStatusEnum.responseReady) && (hasSecondaryRequest(response, "getOutput")))
            {
                return true;
            }
        }
        return false;
    }

    public static boolean hasSecondaryRequest(AsynchReply response, String secondaryRequest)
    {
        AsynchSecondaryRequest[] secondaryRequests = response.getSecondaryRequests();
        for (int i = 0; i < secondaryRequests.length; i++)
        {
            if (secondaryRequests[i].getName().compareTo(secondaryRequest) == 0)
            {
                return true;
            }
        }
        return false;
    }

    public BaseParameter[] getReportParameters(String reportPathString) throws java.rmi.RemoteException
    {
        BaseParameter params[] = new Parameter[] {};
        AsynchReply response;
        SearchPathSingleObject reportPath = new SearchPathSingleObject();
        reportPath.set_value(reportPathString);

        response = this.reportService.getParameters(reportPath, new ParameterValue[] {}, new Option[] {});

        // If response is not immediately complete, call wait until complete
        if (!response.getStatus().equals(AsynchReplyStatusEnum.conversationComplete))
        {
            while (!response.getStatus().equals(AsynchReplyStatusEnum.conversationComplete))
            {
                response = this.reportService.wait(response.getPrimaryRequest(), new ParameterValue[] {}, new Option[] {});
            }
        }
        for (int i = 0; i < response.getDetails().length; i++)
        {
            if (response.getDetails()[i] instanceof AsynchDetailParameters)
                params = ((AsynchDetailParameters) response.getDetails()[i]).getParameters();
        }
        return params;
    }

    public void createJobsAndViews(String searchPath)
    {
        try
        {
            BaseParameter myParams[] = getReportParameters(searchPath);
            String parmValues = ((Parameter) myParams[1]).getModelFilterItem();
            String modelPah ="";

            String  xml = "<report xmlns=\"http://developer.cognos.com/schemas/report/7.0/\" expressionLocale=\"en-ca\">";
            xml = xml + "  <modelPath>+modelPah+</modelPath>";
            xml = xml + "   <queries>";
            xml = xml + "  	<query name=\"TestQuery\">";
            xml = xml + "       <source><model/></source>";
            xml = xml + "           <selection>";
            xml = xml + "				<dataItem name=\"Product line\" aggregate=\"none\">";
            xml = xml + "               <expression>" + parmValues + "</expression>";
            xml = xml + "             </dataItem>";
            xml = xml + "			  </selection> <detailFilters>" + "<detailFilter>" + "<filterExpression>" + parmValues + "<>'ICG'</filterExpression>" + "</detailFilter>" + "</detailFilters> <queryHints>" + " <useForParameterInfo value=\"true\" />" + " <maxRowsRetrieved />" + "</queryHints>";
            xml = xml + " 	</query>";
            xml = xml + "	  </queries>";
            xml = xml + "   <layouts>";
            xml = xml + "     <layout>";
            xml = xml + "       <reportPages>";
            xml = xml + "       	<page name=\"Page1\"><style><defaultStyles><defaultStyle refStyle=\"pg\"/></defaultStyles></style>";
            xml = xml + "       		<pageBody><style><defaultStyles><defaultStyle refStyle=\"pb\"/></defaultStyles></style>";
            xml = xml + "       		<contents>";
            xml = xml + "       		  <list refQuery=\"<span style="font-family: Arial, Helvetica, sans-serif;">TestQuery</span>\">";
            xml = xml + "                  <style><defaultStyles><defaultStyle refStyle=\"ls\"/></defaultStyles><CSS value=\"border-collapse:collapse\"/></style>";
            xml = xml + "       			   <listColumns><listColumn><listColumnTitle><style><defaultStyles><defaultStyle refStyle=\"lt\"/></defaultStyles></style>";
            xml = xml + "						  <contents>";
            xml = xml + "								<textItem><dataSource><dataItemLabel refDataItem=\"Product line\"/></dataSource></textItem>";
            xml = xml + "							</contents></listColumnTitle>";
            xml = xml + "					   <listColumnBody><style><defaultStyles><defaultStyle refStyle=\"lc\"/></defaultStyles></style>";
            xml = xml + "						  <contents>";
            xml = xml + "							<textItem>";
            xml = xml + "								<dataSource>";
            xml = xml + "									<dataItemValue refDataItem=\"Product line\"/>";
            xml = xml + "								</dataSource>";
            xml = xml + "							</textItem>";
            xml = xml + "						 </contents>";
            xml = xml + "					  </listColumnBody>";
            xml = xml + "					</listColumn>";
            xml = xml + "					</listColumns>";
            xml = xml + "				</list>";
            xml = xml + "       	 </contents>";
            xml = xml + "       	</pageBody>";
            xml = xml + "       </page>";
            xml = xml + "      </reportPages>";
            xml = xml + "    </layout>";
            xml = xml + "  </layouts>";
            xml = xml + "</report>";

            String start = null;
            org.dom4j.Document oDocument;

            SAXReader xmlReader = new SAXReader();

            String sReportSpec = executeReportAsXML(xml);
            
            int index = sReportSpec.indexOf("xmlns=", 0);
            if (index >= 0)
            {
                start = sReportSpec.substring(0, index);
                String end = sReportSpec.substring(sReportSpec.indexOf("http://developer.cognos.com/schemas/xmldata/1/") + 47);
                sReportSpec = start + end;
            }

            ByteArrayInputStream bais1 = new ByteArrayInputStream(sReportSpec.getBytes("UTF-8"));
            oDocument = xmlReader.read(bais1);
            org.dom4j.Element e = (org.dom4j.Element) oDocument.selectSingleNode("//data");
            List<DefaultElement> els = e.selectNodes("//value");
            for (DefaultElement de : els)
            {
                System.out.println(de.getStringValue());
            }
            
            bais1.close();

        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static void main(String[] args)
    {
        String searchPath = "/content/folder[@name='Test']/report[@name='Test']";

        String endpoint = "http://XXXX/p2pd/servlet/dispatch";
        String nameSpaceID = "XXXX";

        String userName = "XXXX";

        String password = "XXXXXX";

        CRNConnect crn = new CRNConnect();
        crn.connectToCognosServer(endpoint);

        crn.quickLogon(nameSpaceID, userName, password);

        getLOVOfReportParameters cv = new getLOVOfReportParameters();
        cv.reportService = crn.getReportService();
        cv.createJobsAndViews(searchPath);

    }
}

详细见:

http://www-01.ibm.com/support/docview.wss?uid=swg21335437

分享到:
评论

相关推荐

    IBM Press.IBM Cognos 10 Report Studio:Practical Examples

    《IBM Cognos 10 Report Studio: Practical Examples》是一本深入探讨IBM Cognos 10 Report Studio的实用指南,旨在帮助用户充分利用这个强大的报表工具。这本书详细介绍了如何使用Cognos 10 Report Studio创建、...

    IBM Cognos10 Report Studio:Practical Examples

    ### IBM Cognos 10 Report Studio:实践实例解析 #### 概述 IBM Cognos 10 Report Studio 是一款强大的商务智能工具,用于创建、管理和发布各种类型的报告。本篇文章将根据提供的资料深入探讨《IBM Cognos 10 ...

    Cognos® 8 Business Intelligence REPORT STUDIO 专业创建用户指南

    《Cognos® 8 Business Intelligence REPORT STUDIO 专业创建用户指南》是针对Cognos 8.3版本的一份详尽的参考资料,旨在帮助用户深入理解和熟练掌握REPORT STUDIO的功能,以创建高质量的商业智能报告。这份570页的...

    Cognos Report Studio

    通过本文档,您可以: 1、了解Cognos Report Studio及其界面 2、了解不同的报表类型 3、创建一个简单的、经过排序和格式化的报表

    Cognos 8 Report Studio教程

    ### Cognos 8 Report Studio 教程 #### 一、Cognos 8 Report Studio 简介 Cognos 8 Report Studio 是 IBM Cognos 商业智能套件中的一个关键组件,用于创建、管理和发布交互式报表。本教程旨在通过一系列详细步骤和...

    Cognos Report Studio 用户指南.pdf

    根据提供的信息,我们可以了解到这份文档是关于IBM Cognos Report Studio V10.2.0版本的用户指南。以下是从标题、描述、标签以及部分内容中提取的关键知识点。 ### 关键知识点 #### IBM Cognos Report Studio 简介...

    Cognos Report

    通过学习IBM Cognos 8 BI Report Studio: Author Professional Reports Advanced (v8.4),用户不仅能够掌握如何创建高级报告的基本技能,还能深入了解如何通过高级功能提高报告的质量和效率。无论是对于初学者还是有...

    IBM Cognos 8 Report Studio Cookbook.pdf

    1. IBM Cognos Report Studio Cookbook是一本关于IBM Cognos 8 Report Studio的书籍,由Abhishek Sanghani撰写。该书提供了超过80个实用的配方(方法)来帮助读者掌握IBM Cognos 8 Report Studio的使用。 2. 书籍...

    cognos:与Cognos Analytics软件实施有关的所有事项

    Cognos 与过去,现在和将来实现Cognos软件有关的所有事情。

    Cognos8+Report+Studio创建地图报表.rar

    Cognos 8 Report Studio是一款强大的报表设计工具,它为企业用户提供了一种高效的方式来构建、自定义和呈现复杂的业务报告。本篇文章将深入探讨如何使用Cognos 8 Report Studio创建地图报表,以直观地展示地理位置...

    cognos 10 report stdio用户手册

    ### Cognos 10 Report Studio 用户手册关键知识点解析 #### 一、概述 IBM Cognos 10 Report Studio 是一款强大的商业智能工具,旨在帮助企业用户创建、管理和发布高质量的报表。本手册旨在帮助用户熟悉该软件的核心...

    Cognos® 8 Business Intelligence REPORT STUDIO 快速创建用户指南(中文版)

    本指南旨在帮助用户高效地利用Cognos 8 Report Studio来设计和创建专业、交互式的业务报告。Report Studio是Cognos BI套件中的一个关键组件,它提供了强大的报表设计功能,使得用户可以基于各种数据源构建复杂的分析...

    基于IBM Cognos Report studio技术的商业智能解决方案

    Cognos Report studio 是IBM Cognos BI 产品套件中为用户设计复杂的专业报表工具。本系列教程是为专业报表开发人员设计以帮助学习在Cognos 10平台上使用关系型模型进行报表开发的技能高阶篇。 相关官方认证课程...

    IBM cognos bi-scripting basic report execution using loadrunner

    本文档详细介绍了如何使用LoadRunner对IBM Cognos BI报告执行基本性能测试脚本的编写方法。在此过程中,将涵盖从录制测试用例、理解原始录制到Cognos报告执行,再到创建LoadRunner脚本的每个步骤。同时,文档将提供...

    cognos内容整理

    它提供了丰富的工具,如Cognos Analysis Studio、Cognos Report Studio和Cognos Connection,满足不同用户的需求,从分析师到决策者。 2. Cognos组件: - Cognos Connection:这是Cognos的主入口点,用户可以通过...

    cognos report studio中创建多行表头示例

    在Cognos Report Studio中创建多行表头是一项高级功能,它允许用户设计复杂且具有层次感的报表布局,使得数据展示更加清晰、有条理。以下是对如何在Cognos Report Studio中创建多行表头的详细步骤及知识点解析: ##...

    cognos report stuido

    【Cognos Report Studio】是IBM Cognos Business Intelligence(BI)套件中的核心组件,专门用于构建复杂的、自定义的报表。它是一款强大的报表设计工具,允许用户通过直观的界面来创建交互式报告,从而满足不同行业...

    Cognos:一堆通常不相关的工具和代码示例,可以帮助Cognos管理员,建模者或报表开发人员

    IBM Cognos Analytics 一堆大多数无关的工具和代码示例,可以帮助Cognos管理员,建模者或报表开发人员。 自行承担风险使用。 IBM不支持此处演示的大多数方法。 此信息位于此位置,因为它是我方便地存储有关IBM ...

    Cognos+8+Report+Studio教程

    ### Cognos 8 Report Studio 教程 #### 一、Cognos 8 Report Studio 简介 **Cognos 8 Report Studio** 是一款功能强大的商业智能(BI)工具,它允许用户创建复杂的数据报告并进行深入的数据分析。通过本教程,您将...

    Cognos_AnalysisStudio操作手册.doc

    ### Cognos Analysis Studio 操作手册关键知识点解析 #### 一、Cognos Analysis Studio 简介 Cognos Analysis Studio 是一款领先的业务智能工具,主要用于对企业数据进行多维度的深入分析,支持在线分析处理(OLAP...

Global site tag (gtag.js) - Google Analytics