From: Patrick Schmitz Date: Thu, 17 Jan 2013 01:20:04 +0000 (-0800) Subject: CSPACE-5305 Fixed bug that was not passing invocationContext params into the report... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=fe6810d21a7c7dc57e78947b8d18444e6a826322;p=tmp%2Fjakarta-migration.git CSPACE-5305 Fixed bug that was not passing invocationContext params into the report engine. Modified sample report to show how to pass in a param that is used in a query. Added a note with a sample invocationContext payload that specifies a param. --- diff --git a/services/report/3rdparty/jasper-cs-report/src/main/resources/Notes On Invocation.txt b/services/report/3rdparty/jasper-cs-report/src/main/resources/Notes On Invocation.txt new file mode 100644 index 000000000..619950952 --- /dev/null +++ b/services/report/3rdparty/jasper-cs-report/src/main/resources/Notes On Invocation.txt @@ -0,0 +1,18 @@ +As an example of invoking the acq_basic report from, e.g., poster, here is a payload that shows how to use parameters. The report has a parameter called "queryYear" that when invoked in the no-context mode, will restrict the acquisitions to that year. See the actual report for how the query is built. + +The invocation payload is: + + + + nocontext + Acquisition + + + queryYear + 2000 + + + + +Note that this can be used for a report with any output type - it only impacts the invocation properties. diff --git a/services/report/3rdparty/jasper-cs-report/src/main/resources/acq_basic.jasper b/services/report/3rdparty/jasper-cs-report/src/main/resources/acq_basic.jasper index ba00ecee6..f73c73c51 100644 Binary files a/services/report/3rdparty/jasper-cs-report/src/main/resources/acq_basic.jasper and b/services/report/3rdparty/jasper-cs-report/src/main/resources/acq_basic.jasper differ diff --git a/services/report/3rdparty/jasper-cs-report/src/main/resources/acq_basic.jrxml b/services/report/3rdparty/jasper-cs-report/src/main/resources/acq_basic.jrxml index fd1ec8de6..e6e705583 100644 --- a/services/report/3rdparty/jasper-cs-report/src/main/resources/acq_basic.jrxml +++ b/services/report/3rdparty/jasper-cs-report/src/main/resources/acq_basic.jrxml @@ -16,21 +16,29 @@ - - + + + + 0)? + (" AND hierarchy.name = '"+$P{csid}+"'") + :(($P{queryYear}==null || $P{queryYear}.length()==0)?" AND 1=1" + :" AND acquisitions_common.acquisitionauthorizerdate >= '"+$P{queryYear} + +"-1-1' AND acquisitions_common.acquisitionauthorizerdate <= '" + +$P{queryYear}+"-12-31'"))]]> + - - - - - - - + + + + + + + <band height="102" splitType="Stretch"> <frame> - <reportElement mode="Opaque" x="0" y="0" width="797" height="76" backcolor="#FFFFFF"/> + <reportElement mode="Opaque" x="0" y="0" width="797" height="90" backcolor="#FFFFFF"/> <staticText> <reportElement style="SubTitle" x="458" y="0" width="339" height="29"/> <textElement textAlignment="Right"> @@ -61,7 +69,7 @@ $P!{where_clause}]]> </staticText> <image> <reportElement x="0" y="0" width="349" height="67"/> - <imageExpression class="java.lang.String"><![CDATA["http://www.collectionspace.org/sites/all/themes/CStheme/images/CSpaceLogo.png"]]></imageExpression> + <imageExpression><![CDATA["http://www.collectionspace.org/sites/all/themes/CStheme/images/CSpaceLogo.png"]]></imageExpression> </image> </frame> <frame> @@ -127,46 +135,46 @@ $P!{where_clause}]]> <textElement textAlignment="Center"> <font fontName="DejaVu Serif" size="13"/> </textElement> - <textFieldExpression class="java.lang.String"><![CDATA[$F{acquisitions_common_originalobjectpurchasepricevalue}]]></textFieldExpression> + <textFieldExpression><![CDATA[$F{ac_originalobjectpurchasepricevalue}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true"> <reportElement style="Detail" positionType="Float" x="2" y="0" width="139" height="18"/> <textElement> <font fontName="DejaVu Serif" size="12"/> </textElement> - <textFieldExpression class="java.lang.String"><![CDATA[$F{acquisitions_common_acquisitionreferencenumber}]]></textFieldExpression> + <textFieldExpression><![CDATA[$F{ac_acquisitionreferencenumber}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true"> <reportElement style="Detail" positionType="Float" x="228" y="0" width="144" height="18"/> <textElement textAlignment="Center"> <font fontName="DejaVu Serif" size="13"/> </textElement> - <textFieldExpression class="java.lang.String"><![CDATA[$F{acquisitions_common_acquisitionauthorizerdate}]]></textFieldExpression> + <textFieldExpression><![CDATA[$F{ac_acqauth_date}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true"> <reportElement style="Detail" positionType="Float" x="372" y="0" width="155" height="18"/> <textElement textAlignment="Center"> <font fontName="DejaVu Serif" size="13"/> </textElement> - <textFieldExpression class="java.lang.String"><![CDATA[($F{acquisitions_common_acquisitionauthorizer}==null || - $F{acquisitions_common_acquisitionauthorizer}.isEmpty())? - "":$F{acquisitions_common_acquisitionauthorizer}.substring( - $F{acquisitions_common_acquisitionauthorizer}.lastIndexOf( ")" )+2, - $F{acquisitions_common_acquisitionauthorizer}.length()-1).replaceAll("[+]"," ")]]></textFieldExpression> + <textFieldExpression><![CDATA[($F{ac_acquisitionauthorizer}==null || + $F{ac_acquisitionauthorizer}.isEmpty())? + "":$F{ac_acquisitionauthorizer}.substring( + $F{ac_acquisitionauthorizer}.lastIndexOf( ")" )+2, + $F{ac_acquisitionauthorizer}.length()-1).replaceAll("[+]"," ")]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true"> <reportElement style="Detail" positionType="Float" x="527" y="0" width="150" height="18"/> <textElement textAlignment="Center"> <font fontName="DejaVu Serif" size="13"/> </textElement> - <textFieldExpression class="java.lang.String"><![CDATA[$F{acquisitions_common_acquisitionreason}]]></textFieldExpression> + <textFieldExpression><![CDATA[$F{ac_acquisitionreason}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true"> <reportElement style="Detail" positionType="Float" x="677" y="0" width="120" height="18"/> <textElement textAlignment="Center"> <font fontName="DejaVu Serif" size="13"/> </textElement> - <textFieldExpression class="java.lang.String"><![CDATA[$F{acquisitions_common_acquisitionmethod}]]></textFieldExpression> + <textFieldExpression><![CDATA[$F{ac_acquisitionmethod}]]></textFieldExpression> </textField> </frame> </band> @@ -190,21 +198,21 @@ $P!{where_clause}]]> <textElement verticalAlignment="Middle"> <font fontName="DejaVu Serif" size="10" isBold="false"/> </textElement> - <textFieldExpression class="java.lang.String"><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression> + <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression> </textField> <textField> <reportElement style="Column header" x="677" y="3" width="80" height="20" forecolor="#FFFFFF"/> <textElement textAlignment="Right" verticalAlignment="Middle"> <font fontName="DejaVu Serif" size="10" isBold="false"/> </textElement> - <textFieldExpression class="java.lang.String"><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression> + <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression> </textField> <textField pattern="EEEEE dd MMMMM yyyy"> <reportElement style="Column header" x="2" y="3" width="197" height="20" forecolor="#FFFFFF"/> <textElement verticalAlignment="Middle"> <font fontName="DejaVu Serif" size="10" isBold="false"/> </textElement> - <textFieldExpression class="java.lang.String"><![CDATA[new java.util.Date()]]></textFieldExpression> + <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression> </textField> </frame> </band> diff --git a/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java b/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java index d809de4b7..426014e46 100644 --- a/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java +++ b/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java @@ -31,6 +31,8 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.HashMap; import java.util.List; +import java.util.Map; + import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response.ResponseBuilder; @@ -105,6 +107,10 @@ public class ReportDocumentModelHandler extends DocHandlerBase<ReportsCommon> { HashMap<String, Object> params = new HashMap<String, Object>(); params.put(REPORTS_STD_TENANTID_PARAM, ctx.getTenantId()); boolean checkDocType = true; + + // Note we set before we put in the default ones, so they cannot override tenant or CSID. + setParamsFromContext(params, invContext); + if(Invocable.INVOCATION_MODE_SINGLE.equalsIgnoreCase(invocationMode)) { modeProperty = InvocableJAXBSchema.SUPPORTS_SINGLE_DOC; params.put(REPORTS_STD_CSID_PARAM, invContext.getSingleCSID()); @@ -196,6 +202,24 @@ public class ReportDocumentModelHandler extends DocHandlerBase<ReportsCommon> { } return buildReportResponse(csid, params, reportFileName, outputMimeType); } + + private void setParamsFromContext(Map<String, Object> params, InvocationContext invContext) { + InvocationContext.Params icParams = invContext.getParams(); + if(icParams!= null) { + List<InvocationContext.Params.Param> icParamList = icParams.getParam(); + if(icParamList != null) { + for(InvocationContext.Params.Param param:icParamList) { + String key = param.getKey(); + String value = param.getValue(); + if(!Tools.isEmpty(key) && !Tools.isEmpty(value)) { + params.put(key, value); + } + } + } + } + + } + private Response buildReportResponse(String reportCSID,