Jaspersoft Studio for DeployR中的新查询执行程序

时间:2016-07-15 14:03:45

标签: r jasper-reports jaspersoft-studio

我正在尝试将Jaspersoft Studio与DeployR脚本结合使用。我正在使用Microsoft here的这个教程,它实际上是用于iReport(以前的Jaspersoft Studio解决方案)。我已将教程中必要的jar文件添加到类路径中,并在DeployR中部署了R脚本。

在Jasper中运行报告后,报告中没有任何内容,没有给出任何错误。但我有一个警告说:No query executer factory class registered for deployrScript queries.所以我猜问题是Jaspersoft Studio无法找到deployrScript的类,尽管这个类jRQueryExecuter2在类路径中!

在jrxml中你可以看到声明:

    <queryString language="deployrScript">
        <![CDATA[<deployr url="http://127.0.0.1:8000/deployr">
           <script filename="Cluster_Demo_Jasperserver.R" directory="root"  author="testuser"/>
        </deployr>]]>
    </queryString>

整个jrxml是:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="deployrSample" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5a314889-9cd2-4943-ad5f-13ef1bd6ca74">
    <parameter name="RRP_plotwidth" class="java.lang.Double" isForPrompting="false">
        <defaultValueExpression><![CDATA[555]]></defaultValueExpression>
    </parameter>
    <parameter name="RRP_plotheight" class="java.lang.Double" isForPrompting="false">
        <defaultValueExpression><![CDATA[555]]></defaultValueExpression>
    </parameter>
    <parameter name="RRP_dataset" class="java.lang.String">
        <defaultValueExpression><![CDATA["iris"]]></defaultValueExpression>
    </parameter>
    <parameter name="RRP_clusters" class="java.lang.Integer">
        <defaultValueExpression><![CDATA[3]]></defaultValueExpression>
    </parameter>
    <parameter name="RRP_clustering_type" class="java.lang.String">
        <defaultValueExpression><![CDATA["hclust"]]></defaultValueExpression>
    </parameter>
    <queryString language="deployrScript">
        <![CDATA[<deployr url="http://127.0.0.1:8000/deployr">
    <script filename="Cluster_Demo_Jasperserver.R" directory="root" author="testuser"/>
</deployr>]]>
    </queryString>
    <field name="REPORT1" class="java.lang.String">
        <fieldDescription><![CDATA[file:cluster_output.png]]></fieldDescription>
    </field>
    <pageHeader>
        <band height="63" splitType="Stretch">
            <image>
                <reportElement x="30" y="10" width="50" height="37" uuid="4ce16c2b-5680-48b6-86e8-ce992c543a40"/>
                <imageExpression><![CDATA["C:/Users/aort.png"]]></imageExpression>
            </image>
        </band>
    </pageHeader>
    <detail>
        <band height="600" splitType="Stretch">
            <image scaleImage="RetainShape" hAlign="Center">
                <reportElement positionType="Float" x="100" y="40" width="353" height="218" uuid="f2294c37-5751-41f9-a3b4-fcfe80b69fec"/>
                <imageExpression><![CDATA[$F{REPORT1}]]></imageExpression>
            </image>
        </band>
    </detail>
</jasperReport>

和R脚本:

library(cluster)

#uncomment these lines to test in standalone mode
dataset <- "mtcars"
clusters <- 4
clustering_type <- 'hclust'
plotwidth<-555
plotheight<-555


if (dataset == 'iris') {
  data <- iris[,1:4]
  df <-data.frame(data$Sepal.Length, data$Sepal.Width)

} else if (dataset == 'mtcars') {
  data <- mtcars
  df <-data.frame(data$drat, data$disp)
} else {
  stop("Enter a valid dataset")
}

if (clustering_type == 'kmeans') {

  fit <- kmeans(df, clusters)
  png("cluster_output.png", width=plotwidth, height=plotheight);
  clusplot(df, fit$cluster, color=TRUE, shade=TRUE, labels=0, lines=0, main = dataset)
  dev.off()

} else if (clustering_type == "hclust") {

  d <- dist(as.matrix(df))
  fit <-hclust(d)
  png("cluster_output.png", width=plotwidth, height=plotheight);
  plot(fit, main = dataset)
  dev.off()

} else  {
  stop ("enter a valid clustering type")
}

DeployR代码:

library(cluster)

#uncomment these lines to test in standalone mode
#dataset <- "iris"
#clusters <- 4
#clustering_type <- 'hclust'
#plotwidth<-555
#plotheight<-555
if (dataset == 'iris') {
  data <- iris[,1:4]
  df <-data.frame(data$Sepal.Length, data$Sepal.Width)

} else if (dataset == 'mtcars') {


data <- mtcars
  df <-data.frame(data$drat, data$disp)
} else {
  stop("Enter a valid dataset")
}

if (clustering_type == 'kmeans') {

  fit <- kmeans(df, clusters)
  png("cluster_output.png", width=plotwidth, height=plotheight);
  clusplot(df, fit$cluster, color=TRUE, shade=TRUE, labels=0, lines=0, main = dataset)
  dev.off()

} else if (clustering_type == "hclust") {

  d <- dist(as.matrix(df))
  fit <-hclust(d)
  png("cluster_output.png", width=plotwidth, height=plotheight);
  plot(fit, main = dataset)
  dev.off()

} else  {
  stop ("enter a valid clustering type")
}

我已根据Narcis的建议将net.sf.jasperreports.query.executer.factory.deployrScript=com.revo.deployr.client.jasper.factory.RQueryExecuterFactory添加到属性中,但仍然REPORT1字段为空,我在报告中没有得到任何内容。
我的问题是如何将DeployR添加到Jaspersoft Studio?

1 个答案:

答案 0 :(得分:1)

您所遵循的教程似乎没有详细介绍如何注册查询执行程序( DeployR自定义客户端库部分中的第9点)。

除了将jar文件添加到类路径之外,还需要在Jaspersoft Studio中设置类似这样的属性:

net.sf.jasperreports.query.executer.factory.[your_query_language_name]=[the_canonical_name_of_your_query_executer_factory_class]

在你的情况下你应该:

net.sf.jasperreports.query.executer.factory.deployrScript=com.revo.deployr.client.jasper.factory.RQueryExecuterFactory

如果您打算在JasperReports Server实例上使用它,则需要在<webapp-path>/WEB-INF/classes/jasperreports.properties文件中为webapp设置相同的属性。在这种情况下,需要重新启动应用程序。