From 8768719c9063c5e83e0d0d84b981897113b521ed Mon Sep 17 00:00:00 2001
From: Cyrille Bollu <cyrille.bollu@gmail.com>
Date: Wed, 12 Dec 2012 11:20:07 +0100
Subject: [PATCH] Fix to the jasperreports integration date format

===================
(Extract from the email to be sent for submitting this patch)

Hi list,

I would like to re-surface the date format problem that's affecting jasperreports integration for at least 5 months.

This problem is the cause of at least 3 opened issues:

http://issues.opennms.org/browse/NMS-5404
http://issues.opennms.org/browse/NMS-5379
http://issues.opennms.org/browse/NMS-5457

And makes the affected reports totally unusable for anyone not using english locales.

After analysis, the problem seems to be that Java's SimpleDateFormat is locale dependent while Postgresql's isn't (see http://www.postgresql.org/docs/8.3/static/datetime-appendix.html. More precisely, http://www.postgresql.org/docs/8.3/static/datetime-keywords.html)

So, in jasperreports' templates, all "EEE MMM d HH:mm:ss Z yyyy" date formats translate to something localized (eg: "Lun Juil 17 13:22:05 +002 2012") that postgresql doesn't understand (because "Lun" (Monday in French) and "Juil" (July in French) binary-search table lookups (see http://www.postgresql.org/docs/8.3/static/datetime-input-rules.html) don't succeed).

In current openNMS source code, there are 14 such instances of this date format in only 32 jrxml files!

From what I've read, it seems that using "yyyy-MM-d HH:mm:ss Z" (ISO 8601) would be much more appropriate; From http://www.postgresql.org/docs/8.1/static/datatype-datetime.html :

"Date and time input is accepted in almost any reasonable format, including ISO 8601, SQL-compatible, traditional POSTGRES, and others"

and:

Table 8-10. Date Input
Example 	Description
[...]
1999-01-08 	ISO 8601; January 8 in any mode (recommended format)
[...]

==============================
---
 .../etc/report-templates/AvailabilitySummary.jrxml |    4 ++--
 .../InterfaceAvailabilityReport.jrxml              |    2 +-
 .../SnmpInterfaceOperAvailabilityReport.jrxml      |    2 +-
 .../AvailabilitySummaryChart_subreport.jrxml       |    2 +-
 .../InterfaceAvailabilityReport_subreport1.jrxml   |    2 +-
 ...eSummary_Availability_Offenders_subreport.jrxml |    2 +-
 ...esponseTimeSummary_Availability_subreport.jrxml |    2 +-
 .../subreports/Top25PercentDown_subreport.jrxml    |    4 ++--
 8 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/opennms-base-assembly/src/main/filtered/etc/report-templates/AvailabilitySummary.jrxml b/opennms-base-assembly/src/main/filtered/etc/report-templates/AvailabilitySummary.jrxml
index 1bd57fe..4e4907e 100644
--- a/opennms-base-assembly/src/main/filtered/etc/report-templates/AvailabilitySummary.jrxml
+++ b/opennms-base-assembly/src/main/filtered/etc/report-templates/AvailabilitySummary.jrxml
@@ -84,10 +84,10 @@ new GregorianCalendar(new GregorianCalendar().get(Calendar.YEAR), new GregorianC
 )]]></defaultValueExpression>
 	</parameter>
 	<parameter name="START_TIME_STRING" class="java.lang.String" isForPrompting="false">
-		<defaultValueExpression><![CDATA[new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy").format($P{START_TIME})]]></defaultValueExpression>
+		<defaultValueExpression><![CDATA[new SimpleDateFormat("yyyy-MM-d HH:mm:ss Z").format($P{START_TIME})]]></defaultValueExpression>
 	</parameter>
 	<parameter name="END_TIME_STRING" class="java.lang.String" isForPrompting="false">
-		<defaultValueExpression><![CDATA[new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy").format($P{END_TIME})]]></defaultValueExpression>
+		<defaultValueExpression><![CDATA[new SimpleDateFormat("yyyy-MM-d HH:mm:ss Z").format($P{END_TIME})]]></defaultValueExpression>
 	</parameter>
 	<queryString>
 		<![CDATA[SELECT
diff --git a/opennms-base-assembly/src/main/filtered/etc/report-templates/InterfaceAvailabilityReport.jrxml b/opennms-base-assembly/src/main/filtered/etc/report-templates/InterfaceAvailabilityReport.jrxml
index 0e9a304..552a409 100755
--- a/opennms-base-assembly/src/main/filtered/etc/report-templates/InterfaceAvailabilityReport.jrxml
+++ b/opennms-base-assembly/src/main/filtered/etc/report-templates/InterfaceAvailabilityReport.jrxml
@@ -64,7 +64,7 @@
 		<defaultValueExpression><![CDATA["${install.dir}/etc/report-templates/subreports/"]]></defaultValueExpression>
 	</parameter>
 	<parameter name="START_TIME_STRING" class="java.lang.String" isForPrompting="false">
-		<defaultValueExpression><![CDATA[new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy").format($P{START_TIME})]]></defaultValueExpression>
+		<defaultValueExpression><![CDATA[new SimpleDateFormat("yyyy-MM-d HH:mm:ss Z").format($P{START_TIME})]]></defaultValueExpression>
 	</parameter>
 	<queryString>
 		<![CDATA[SELECT
diff --git a/opennms-base-assembly/src/main/filtered/etc/report-templates/SnmpInterfaceOperAvailabilityReport.jrxml b/opennms-base-assembly/src/main/filtered/etc/report-templates/SnmpInterfaceOperAvailabilityReport.jrxml
index 279b5ae..0d208a1 100755
--- a/opennms-base-assembly/src/main/filtered/etc/report-templates/SnmpInterfaceOperAvailabilityReport.jrxml
+++ b/opennms-base-assembly/src/main/filtered/etc/report-templates/SnmpInterfaceOperAvailabilityReport.jrxml
@@ -45,7 +45,7 @@
 		<defaultValueExpression><![CDATA["${install.dir}/etc/report-templates/subreports/"]]></defaultValueExpression>
 	</parameter>
 	<parameter name="START_TIME_STRING" class="java.lang.String" isForPrompting="false">
-		<defaultValueExpression><![CDATA[new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy").format($P{START_TIME})]]></defaultValueExpression>
+		<defaultValueExpression><![CDATA[new SimpleDateFormat("yyyy-MM-d HH:mm:ss Z").format($P{START_TIME})]]></defaultValueExpression>
 	</parameter>
 	<queryString>
 		<![CDATA[SELECT
diff --git a/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/AvailabilitySummaryChart_subreport.jrxml b/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/AvailabilitySummaryChart_subreport.jrxml
index 3535d43..085f4a0 100755
--- a/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/AvailabilitySummaryChart_subreport.jrxml
+++ b/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/AvailabilitySummaryChart_subreport.jrxml
@@ -15,7 +15,7 @@ new GregorianCalendar(new GregorianCalendar().get(Calendar.YEAR), new GregorianC
 )]]></defaultValueExpression>
 	</parameter>
 	<parameter name="TIME_SERIES_START_TIME_STRING" class="java.lang.String" isForPrompting="false">
-		<defaultValueExpression><![CDATA[new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy").format($P{TIME_SERIES_START_TIMESTAMP})]]></defaultValueExpression>
+		<defaultValueExpression><![CDATA[new SimpleDateFormat("yyyy-MM-d HH:mm:ss Z").format($P{TIME_SERIES_START_TIMESTAMP})]]></defaultValueExpression>
 	</parameter>
 	<queryString>
 		<![CDATA[select
diff --git a/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/InterfaceAvailabilityReport_subreport1.jrxml b/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/InterfaceAvailabilityReport_subreport1.jrxml
index d587752..f492ff9 100644
--- a/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/InterfaceAvailabilityReport_subreport1.jrxml
+++ b/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/InterfaceAvailabilityReport_subreport1.jrxml
@@ -34,7 +34,7 @@
 		<defaultValueExpression><![CDATA[95.0]]></defaultValueExpression>
 	</parameter>
 	<parameter name="START_TIME_STRING" class="java.lang.String" isForPrompting="false">
-		<defaultValueExpression><![CDATA[new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy").format($P{START_TIME})]]></defaultValueExpression>
+		<defaultValueExpression><![CDATA[new SimpleDateFormat("yyyy-MM-d HH:mm:ss Z").format($P{START_TIME})]]></defaultValueExpression>
 	</parameter>
 	<queryString>
 		<![CDATA[SELECT
diff --git a/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/ResponseTimeSummary_Availability_Offenders_subreport.jrxml b/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/ResponseTimeSummary_Availability_Offenders_subreport.jrxml
index a37d58a..e57acff 100755
--- a/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/ResponseTimeSummary_Availability_Offenders_subreport.jrxml
+++ b/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/ResponseTimeSummary_Availability_Offenders_subreport.jrxml
@@ -20,7 +20,7 @@
 		<defaultValueExpression><![CDATA["donaldo.local"]]></defaultValueExpression>
 	</parameter>
 	<parameter name="START_TIME_STRING" class="java.lang.String" isForPrompting="false">
-		<defaultValueExpression><![CDATA[new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy").format($P{START_TIME})]]></defaultValueExpression>
+		<defaultValueExpression><![CDATA[new SimpleDateFormat("yyyy-MM-d HH:mm:ss Z").format($P{START_TIME})]]></defaultValueExpression>
 	</parameter>
 	<queryString>
 		<![CDATA[SELECT
diff --git a/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/ResponseTimeSummary_Availability_subreport.jrxml b/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/ResponseTimeSummary_Availability_subreport.jrxml
index c61216e..b6185d6 100755
--- a/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/ResponseTimeSummary_Availability_subreport.jrxml
+++ b/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/ResponseTimeSummary_Availability_subreport.jrxml
@@ -20,7 +20,7 @@
 		<defaultValueExpression><![CDATA["donaldo.local"]]></defaultValueExpression>
 	</parameter>
 	<parameter name="START_TIME_STRING" class="java.lang.String" isForPrompting="false">
-		<defaultValueExpression><![CDATA[new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy").format($P{START_TIME})]]></defaultValueExpression>
+		<defaultValueExpression><![CDATA[new SimpleDateFormat("yyyy-MM-d HH:mm:ss Z").format($P{START_TIME})]]></defaultValueExpression>
 	</parameter>
 	<queryString>
 		<![CDATA[SELECT
diff --git a/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/Top25PercentDown_subreport.jrxml b/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/Top25PercentDown_subreport.jrxml
index 08e635e..89efcdc 100755
--- a/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/Top25PercentDown_subreport.jrxml
+++ b/opennms-base-assembly/src/main/filtered/etc/report-templates/subreports/Top25PercentDown_subreport.jrxml
@@ -19,10 +19,10 @@ new GregorianCalendar(new GregorianCalendar().get(Calendar.YEAR), new GregorianC
 )]]></defaultValueExpression>
 	</parameter>
 	<parameter name="START_TIME_STRING" class="java.lang.String" isForPrompting="false">
-		<defaultValueExpression><![CDATA[new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy").format($P{START_TIME})]]></defaultValueExpression>
+		<defaultValueExpression><![CDATA[new SimpleDateFormat("yyyy-MM-d HH:mm:ss Z").format($P{START_TIME})]]></defaultValueExpression>
 	</parameter>
 	<parameter name="END_TIME_STRING" class="java.lang.String" isForPrompting="false">
-		<defaultValueExpression><![CDATA[new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy").format($P{END_TIME})]]></defaultValueExpression>
+		<defaultValueExpression><![CDATA[new SimpleDateFormat("yyyy-MM-d HH:mm:ss Z").format($P{END_TIME})]]></defaultValueExpression>
 	</parameter>
 	<queryString>
 		<![CDATA[SELECT
-- 
1.7.9.5

