使用JSON的脚本数据源在Java类中工作时不与BIRT一起使用

时间:2011-11-12 14:28:59

标签: java eclipse json birt alfresco

我将用几句话来谈论抛出代码,在露天我需要使用其作为JSON响应的工作流API创建报告,我找到了在此链接中使用JSON作为数据源的解决方案(这将是好的参考完全理解我的问题):

http://www.birt-exchange.org/org/devshare/designing-birt-reports/1053-scripted-data-source-using-json/

我下载了源码,我了解它是如何工作的,最后我遇到了“身份验证问题”并通过编辑源文件'JSONParser.java'来解决它,无论如何我现在有另一个问题,我有以下代码在Java中工作:

package com.actuate.json.test;
import java.io.IOException;
import com.actuate.json.JSONParser;
public class TestJSONParse_OutBound {
    public static void main(String[] args) {
        try{
            JSONParser theParser = new JSONParser();
            theParser.loadData("http://localhost:8080/alfresco/service/api/workflow-definitions/activiti$CS-Outbound-WFPD:5:403/workflow-instances?state=active&format=json","admin","admin");
            System.out.println("Number of jobs found: " + theParser.getChildCount("data") + "\n");
            for(int i = 0; i < theParser.getChildCount("data"); i++){
                System.out.println(String.valueOf(i + 1) + ")  " + theParser.getValue("data", "description", i));
                System.out.println("\tID: " + theParser.getValue("data", "id", i));
                System.out.println("\tURL: " + theParser.getValue("data", "url", i));
                System.out.println("\tUsername: " + theParser.getValue("data", "initiator/firstName", i));
            }
        }catch (IOException ioe) {
            // TODO: handle exception
        }catch(Exception ex){

        }
    }
}

结果:

Number of jobs found: 2

1)  CS-Outbound-WFPD
    ID: activiti$499
    URL: api/workflow-instances/activiti$499
    Username: Administrator
2)  CS-Outbound-WFPD
    ID: activiti$404
    URL: api/workflow-instances/activiti$404
    Username: Administrator

但是在eclipse IDE中的BIRT报告中没有运气1,在我编写的脚本数据源中:

count = 0;
controller = new Packages.com.actuate.json.JSONParser();
controller.loadData(params["JSONURL"],params["USERNAME"],params["PASSWORD"]);
totalCount = controller.getChildCount("data");

并获取数据集表中的行,如:

if(count < totalCount){
    row["id"] = controller.getValue("data", "id", count);
    row["url"] = controller.getValue("data", "url", count);

    count++;
    return true;
}
return false

但是仍然只给我带有头部标题的白页,空单元格。

为了获得例外我将其上传到与BIRT集成的Alfresco,我得到了:

WARNING: Fail to execute script in function __bm_OPEN(). Source:
------
" + count = 0;
controller = new Packages.com.actuate.json.JSONParser();
controller.loadData(params["JSONURL"],params["USERNAME"],params["PASSWORD"]);
totalCount = controller.getChildCount("data"); + "
-----
A BIRT exception occurred. See next exception for more information.
Error evaluating Javascript expression. Script engine error: TypeError: [JavaPackage com.actuate.json.JSONParser] is not a function, it is object. (/report/data-sources/script-data-source[@id="8"]/method[@name="open"]#2)
 Script source: /report/data-sources/script-data-source[@id="8"]/method[@name="open"], line: 0, text:
__bm_OPEN()
org.eclipse.birt.data.engine.core.DataException: Fail to execute script in function __bm_OPEN(). Source:
------
" + count = 0;
controller = new Packages.com.actuate.json.JSONParser();
controller.loadData(params["JSONURL"],params["USERNAME"],params["PASSWORD"]);
totalCount = controller.getChildCount("data"); + "
-----
A BIRT exception occurred. See next exception for more information.
Error evaluating Javascript expression. Script engine error: TypeError: [JavaPackage com.actuate.json.JSONParser] is not a function, it is object. (/report/data-sources/script-data-source[@id="8"]/method[@name="open"]#2)
 Script source: /report/data-sources/script-data-source[@id="8"]/method[@name="open"], line: 0, text:
__bm_OPEN()
    at org.eclipse.birt.data.engine.script.JSMethodRunner.runScript(JSMethodRunner.java:147)
.
.
.
Caused by: org.mozilla.javascript.EcmaError: TypeError: [JavaPackage com.actuate.json.JSONParser] is not a function, it is object. (/report/data-sources/script-data-source[@id="8"]/method[@name="open"]#2)
.
.
.

真的我不知道问题是什么,以及如何解决,如果有人对它有任何想法,我花了大约1个星期没有解决方案......

0 个答案:

没有答案
相关问题