← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20129: Report, changed from String type to enum ReportType

 

------------------------------------------------------------
revno: 20129
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-09-14 12:33:55 +0200
message:
  Report, changed from String type to enum ReportType
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportType.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/Report.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/report/hibernate/Report.hbm.xml
  dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/report/ReportStoreTest.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportController.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/AddReportAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/GetReportParamsAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addReportForm.vm
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/report.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/Report.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/Report.java	2015-08-03 11:33:39 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/Report.java	2015-09-14 10:33:55 +0000
@@ -57,11 +57,7 @@
 
     public static final String TEMPLATE_DIR = "templates";
 
-    public static final String TYPE_JASPER_REPORT_TABLE = "jasperReportTable";
-    public static final String TYPE_JASPER_JDBC = "jasperJdbc";
-    public static final String TYPE_HTML = "html";
-
-    private String type;
+    private ReportType type;
 
     private String designContent;
 
@@ -81,16 +77,18 @@
     {
     }
 
-    public Report( String name, String type, String designContent, ReportTable reportTable )
+    public Report( String name, ReportType type, String designContent, ReportTable reportTable )
     {
         this.name = name;
+        this.type = type;
         this.designContent = designContent;
         this.reportTable = reportTable;
     }
 
-    public Report( String name, String type, String designContent, RelativePeriods relatives, ReportParams reportParams )
+    public Report( String name, ReportType type, String designContent, RelativePeriods relatives, ReportParams reportParams )
     {
         this.name = name;
+        this.type = type;
         this.designContent = designContent;
         this.relatives = relatives;
         this.reportParams = reportParams;
@@ -102,17 +100,17 @@
 
     public boolean isTypeReportTable()
     {
-        return type != null && TYPE_JASPER_REPORT_TABLE.equals( type );
+        return type != null && ReportType.JASPER_REPORT_TABLE.equals( type );
     }
 
     public boolean isTypeJdbc()
     {
-        return type != null && TYPE_JASPER_JDBC.equals( type );
+        return type != null && ReportType.JASPER_JDBC.equals( type );
     }
 
     public boolean isTypeHtml()
     {
-        return type != null && TYPE_HTML.equals( type );
+        return type != null && ReportType.HTML.equals( type );
     }
 
     public boolean hasReportTable()
@@ -149,12 +147,12 @@
     @JsonProperty
     @JsonView( { DetailedView.class, ExportView.class } )
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public String getType()
+    public ReportType getType()
     {
         return type;
     }
 
-    public void setType( String type )
+    public void setType( ReportType type )
     {
         this.type = type;
     }

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportType.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportType.java	2015-09-14 10:33:55 +0000
@@ -0,0 +1,37 @@
+package org.hisp.dhis.report;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Lars Helge Overland
+ */
+public enum ReportType
+{
+    JASPER_REPORT_TABLE, JASPER_JDBC, HTML;
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2015-09-13 17:45:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2015-09-14 10:33:55 +0000
@@ -869,6 +869,10 @@
         executeSql( "drop table aggregatedorgunitdatavalue_temp" );
         executeSql( "drop table aggregatedorgunitindicatorvalue" );
         executeSql( "drop table aggregatedorgunitindicatorvalue_temp" );
+        
+        executeSql( "update report set type='JASPER_REPORT_TABLE' where type='jasperReportTable'" );
+        executeSql( "update report set type='JASPER_JDBC' where type='jasperJdbc'" );
+        executeSql( "update report set type='HTML' where type='html'" );
 
         oauth2();
 
@@ -1337,22 +1341,6 @@
         }
     }
 
-    private int executeSql( String sql )
-    {
-        try
-        {
-            // TODO use jdbcTemplate
-
-            return statementManager.getHolder().executeUpdate( sql );
-        }
-        catch ( Exception ex )
-        {
-            log.debug( ex );
-
-            return -1;
-        }
-    }
-
     private Integer getDefaultOptionCombo()
     {
         String sql = "select coc.categoryoptioncomboid from categoryoptioncombo coc "
@@ -1382,4 +1370,20 @@
             executeSql( "drop table optionsetmembers" );
         }
     }
+
+    private int executeSql( String sql )
+    {
+        try
+        {
+            // TODO use jdbcTemplate
+
+            return statementManager.getHolder().executeUpdate( sql );
+        }
+        catch ( Exception ex )
+        {
+            log.debug( ex );
+
+            return -1;
+        }
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/report/hibernate/Report.hbm.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/report/hibernate/Report.hbm.xml	2015-07-21 16:46:52 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/report/hibernate/Report.hbm.xml	2015-09-14 10:33:55 +0000
@@ -17,7 +17,12 @@
 
     <property name="name" column="name" not-null="true" unique="false" length="230" />
 
-    <property name="type" />
+    <property name="type" length="50">
+      <type name="org.hibernate.type.EnumType">
+        <param name="enumClass">org.hisp.dhis.report.ReportType</param>
+        <param name="type">12</param>
+      </type>
+    </property>
 
     <property name="designContent" type="text" />
 

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/report/ReportStoreTest.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/report/ReportStoreTest.java	2015-06-16 10:36:25 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/report/ReportStoreTest.java	2015-09-14 10:33:55 +0000
@@ -28,7 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.report.Report.TYPE_JASPER_REPORT_TABLE;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
@@ -79,8 +78,8 @@
     @Test
     public void testSaveGet()
     {
-        Report reportA = new Report( "ReportA", TYPE_JASPER_REPORT_TABLE, "DesignA", reportTableA );
-        Report reportB = new Report( "ReportB", TYPE_JASPER_REPORT_TABLE, "DesignB", reportTableA );
+        Report reportA = new Report( "ReportA", ReportType.JASPER_REPORT_TABLE, "DesignA", reportTableA );
+        Report reportB = new Report( "ReportB", ReportType.JASPER_REPORT_TABLE, "DesignB", reportTableA );
         
         int idA = reportStore.save( reportA );
         int idB = reportStore.save( reportB );
@@ -92,8 +91,8 @@
     @Test
     public void testSaveGetUpdate()
     {
-        Report reportA = new Report( "ReportA", TYPE_JASPER_REPORT_TABLE, "DesignA", reportTableA );
-        Report reportB = new Report( "ReportB", TYPE_JASPER_REPORT_TABLE, "DesignB", reportTableA );
+        Report reportA = new Report( "ReportA", ReportType.JASPER_REPORT_TABLE, "DesignA", reportTableA );
+        Report reportB = new Report( "ReportB", ReportType.JASPER_REPORT_TABLE, "DesignB", reportTableA );
         
         int idA = reportStore.save( reportA );
         int idB = reportStore.save( reportB );
@@ -117,8 +116,8 @@
     @Test
     public void testDelete()
     {
-        Report reportA = new Report( "ReportA", TYPE_JASPER_REPORT_TABLE, "DesignA", reportTableA );
-        Report reportB = new Report( "ReportB", TYPE_JASPER_REPORT_TABLE, "DesignB", reportTableA );
+        Report reportA = new Report( "ReportA", ReportType.JASPER_REPORT_TABLE, "DesignA", reportTableA );
+        Report reportB = new Report( "ReportB", ReportType.JASPER_REPORT_TABLE, "DesignB", reportTableA );
         
         int idA = reportStore.save( reportA );
         int idB = reportStore.save( reportB );
@@ -140,8 +139,8 @@
     @Test
     public void testGetAll()
     {
-        Report reportA = new Report( "ReportA", TYPE_JASPER_REPORT_TABLE, "DesignA", reportTableA );
-        Report reportB = new Report( "ReportB", TYPE_JASPER_REPORT_TABLE, "DesignB", reportTableA );
+        Report reportA = new Report( "ReportA", ReportType.JASPER_REPORT_TABLE, "DesignA", reportTableA );
+        Report reportB = new Report( "ReportB", ReportType.JASPER_REPORT_TABLE, "DesignB", reportTableA );
         
         reportStore.save( reportA );
         reportStore.save( reportB );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportController.java	2015-07-15 16:07:15 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/ReportController.java	2015-09-14 10:33:55 +0000
@@ -118,7 +118,7 @@
             throw new WebMessageException( WebMessageUtils.conflict( "Report has no design content: " + uid ) );
         }
 
-        if ( Report.TYPE_HTML.equals( report.getType() ) )
+        if ( report.isTypeHtml() )
         {
             contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.NO_CACHE, filenameEncode( report.getName() ) + ".html", true );
         }

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/AddReportAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/AddReportAction.java	2015-07-31 10:51:43 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/AddReportAction.java	2015-09-14 10:33:55 +0000
@@ -39,6 +39,7 @@
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.report.Report;
 import org.hisp.dhis.report.ReportService;
+import org.hisp.dhis.report.ReportType;
 import org.hisp.dhis.reporttable.ReportParams;
 import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.reporttable.ReportTableService;
@@ -98,9 +99,9 @@
         this.name = name;
     }
     
-    private String type;
+    private ReportType type;
 
-    public void setType( String type )
+    public void setType( ReportType type )
     {
         this.type = type;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/GetReportParamsAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/GetReportParamsAction.java	2015-06-15 13:44:20 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/GetReportParamsAction.java	2015-09-14 10:33:55 +0000
@@ -29,6 +29,7 @@
  */
 
 import com.opensymphony.xwork2.Action;
+
 import org.hisp.dhis.calendar.Calendar;
 import org.hisp.dhis.calendar.DateTimeUnit;
 import org.hisp.dhis.common.BaseIdentifiableObject;
@@ -40,6 +41,7 @@
 import org.hisp.dhis.period.RelativePeriods;
 import org.hisp.dhis.report.Report;
 import org.hisp.dhis.report.ReportService;
+import org.hisp.dhis.report.ReportType;
 import org.hisp.dhis.reporttable.ReportParams;
 import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.reporttable.ReportTableService;
@@ -113,14 +115,14 @@
         this.mode = mode;
     }
 
-    private String type;
+    private ReportType type;
 
-    public String getType()
+    public ReportType getType()
     {
         return type;
     }
 
-    public void setType( String type )
+    public void setType( ReportType type )
     {
         this.type = type;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addReportForm.vm'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addReportForm.vm	2015-07-31 12:46:03 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addReportForm.vm	2015-09-14 10:33:55 +0000
@@ -30,9 +30,9 @@
         <td><label for="type">$i18n.getString( "type" )</label></td>
         <td>
             <select id="type" name="type" onchange="setReportType()">
-                <option value="jasperReportTable"#if( ${report.type} == "jasperReportTable" ) selected="selected"#end>$i18n.getString( "jasper_report_report_table_data_source" )</option>
-                <option value="jasperJdbc"#if( ${report.type} == "jasperJdbc" ) selected="selected"#end>$i18n.getString( "jasper_report_jdbc_data_source" )</option>
-                <option value="html"#if( ${report.type} == "html" ) selected="selected"#end>$i18n.getString( "html_report" )</option>
+                <option value="JASPER_REPORT_TABLE"#if( ${report.type} == "JASPER_REPORT_TABLE" ) selected="selected"#end>$i18n.getString( "jasper_report_report_table_data_source" )</option>
+                <option value="JASPER_JDBC"#if( ${report.type} == "JASPER_JDBC" ) selected="selected"#end>$i18n.getString( "jasper_report_jdbc_data_source" )</option>
+                <option value="HTML"#if( ${report.type} == "HTML" ) selected="selected"#end>$i18n.getString( "html_report" )</option>
             </select>
         </td>
     </tr>

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/report.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/report.js	2014-06-13 09:11:39 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/report.js	2015-09-14 10:33:55 +0000
@@ -15,17 +15,17 @@
 function setReportType() {
   var type = $("#type :selected").val();
 
-  if( "jasperReportTable" == type ) {
+  if( "JASPER_REPORT_TABLE" == type ) {
     $(".jasperJdbcDataSource").hide();
     $(".htmlDataSource").hide();
     $(".jasperReportTableDataSource").show();
   }
-  else if( "jasperJdbc" == type ) {
+  else if( "JASPER_JDBC" == type ) {
     $(".jasperReportTableDataSource").hide();
     $(".htmlDataSource").hide();
     $(".jasperJdbcDataSource").show();
   }
-  else if( "html" == type ) {
+  else if( "HTML" == type ) {
     $(".jasperReportTableDataSource").hide();
     $(".jasperJdbcDataSource").hide();
     $(".htmlDataSource").show();