← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2825: Simplification in report table

 

------------------------------------------------------------
revno: 2825
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-02-08 14:15:54 +0100
message:
  Simplification in report table
added:
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/mock/
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/mock/MockI18nFormat.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/RelativePeriodTest.java


--
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/period/Period.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java	2011-01-31 19:47:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java	2011-02-08 13:15:54 +0000
@@ -116,6 +116,9 @@
     public Period copyTransientProperties( Period other )
     {
         this.name = other.getName();
+        this.alternativeName = other.getAlternativeName();
+        this.shortName = other.getShortName();
+        this.code = other.getCode();
         
         return this;
     }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java	2011-01-11 13:11:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java	2011-02-08 13:15:54 +0000
@@ -184,9 +184,7 @@
         
         if ( isReportingMonth() )
         {
-            Period period = new MonthlyPeriodType().createPeriod( getDate( months, date ) );
-            period.setName( dynamicNames ? format.formatPeriod( period ) : REPORTING_MONTH );
-            periods.add( period );
+            periods.add( getRelativePeriod( new MonthlyPeriodType(), REPORTING_MONTH, current, dynamicNames, format ) );
         }
         
         if ( isMonthsThisYear() )
@@ -225,7 +223,8 @@
     }
 
     /**
-     * Returns a list of relative periods.
+     * Returns a list of relative periods. The name will be dynamic depending on
+     * the dynamicNames argument. The short name will always be dynamic.
      * 
      * @param periodType the period type.
      * @param periodNames the array of period names.
@@ -244,6 +243,7 @@
         for ( Period period : relatives )
         {
             period.setName( dynamicNames ? format.formatPeriod( period ) : MONTHS_THIS_YEAR[c++] );
+            period.setShortName( format.formatPeriod( period ) );
             periods.add( period );
         }
         
@@ -251,7 +251,8 @@
     }
 
     /**
-     * Returns relative period.
+     * Returns relative period. The name will be dynamic depending on the
+     * dynamicNames argument. The short name will always be dynamic.
      * 
      * @param periodType the period type.
      * @param periodName the period name.
@@ -264,6 +265,7 @@
     {
         Period period = periodType.createPeriod( current );
         period.setName( dynamicNames ? format.formatPeriod( period ) : periodName );
+        period.setShortName( format.formatPeriod( period ) );
         
         return period;
     }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2011-02-08 09:53:28 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2011-02-08 13:15:54 +0000
@@ -447,6 +447,7 @@
             if ( period.getName() == null ) // Crosstabulated relative periods
             {
                 period.setName( i18nFormat.formatPeriod( period ) ); // Static periods + indexed relative periods
+                period.setShortName( i18nFormat.formatPeriod( period ) );
             }
         }
         
@@ -556,7 +557,7 @@
                     for ( OrganisationUnit unit : crossTabUnits )
                     {
                         String columnName = getColumnName( indicator, categoryOptionCombo, period, unit, i18nFormat );
-                        String prettyColumnName = getPrettyColumnName( indicator, categoryOptionCombo, period, unit, i18nFormat );
+                        String prettyColumnName = getPrettyColumnName( indicator, categoryOptionCombo, period, unit );
                         String columnIdentifier = getColumnIdentifier( indicator, categoryOptionCombo, period, unit );
                         
                         if ( columnName != null && !columnName.isEmpty() )
@@ -744,31 +745,15 @@
         return list != null && list.size() > 0;
     }
     
-    /**
-     * Generates a pretty-print column name based on short-names of the argument
-     * objects. Null arguments are ignored in the name.
-     */
-    private static String getPrettyColumnName( IdentifiableObject metaObject, DataElementCategoryOptionCombo categoryOptionCombo, Period period, OrganisationUnit unit, I18nFormat format )
+    private static String getPrettyColumnName( IdentifiableObject... objects )
     {
         StringBuffer buffer = new StringBuffer();
         
-        if ( metaObject != null )
-        {
-            buffer.append( metaObject.getShortName() + SPACE );
-        }
-        if ( categoryOptionCombo != null )
-        {
-            buffer.append( categoryOptionCombo.getShortName() + SPACE );
-        }
-        if ( period != null )
-        {
-            buffer.append( format.formatPeriod( period ) + SPACE );
-        }
-        if ( unit != null )
-        {
-            buffer.append( unit.getShortName() + SPACE );
-        }
-
+        for ( IdentifiableObject object : objects )
+        {
+            buffer.append( object != null ? ( object.getShortName() + SPACE ) : EMPTY );
+        }
+        
         return buffer.length() > 0 ? buffer.substring( 0, buffer.lastIndexOf( SPACE ) ) : buffer.toString();
     }
     

=== added directory 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/mock'
=== added file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/mock/MockI18nFormat.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/mock/MockI18nFormat.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/mock/MockI18nFormat.java	2011-02-08 13:15:54 +0000
@@ -0,0 +1,60 @@
+package org.hisp.dhis.mock;
+
+/*
+ * Copyright (c) 2004-2010, 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.
+ */
+
+import java.util.Date;
+
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.period.Period;
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id$
+ */
+public class MockI18nFormat
+    extends I18nFormat
+{
+    public MockI18nFormat()
+    {
+        super( null );
+    }
+    
+    @Override
+    public String formatPeriod( Period period )
+    {
+        String name = period.getStartDate() + "-" + period.getEndDate();
+        
+        return name.toLowerCase().trim();
+    }
+    
+    @Override
+    public String formatDate( Date date )
+    {
+        return date.toString().toLowerCase().trim();
+    }
+}

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/RelativePeriodTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/RelativePeriodTest.java	2011-01-06 09:03:29 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/RelativePeriodTest.java	2011-02-08 13:15:54 +0000
@@ -34,6 +34,8 @@
 import java.util.Collection;
 import java.util.Date;
 
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.mock.MockI18nFormat;
 import org.junit.Test;
 
 /**
@@ -41,6 +43,8 @@
  */
 public class RelativePeriodTest
 {
+    private static final I18nFormat i18nFormat = new MockI18nFormat();
+    
     private static Date getDate( int year, int month, int day )
     {
         final Calendar calendar = Calendar.getInstance();
@@ -56,7 +60,7 @@
     {        
         RelativePeriods periods = new RelativePeriods( true, true, true, true, true, true, true );
         
-        Collection<Period> relatives = periods.getRelativePeriods( 1, getDate( 2002, 1, 1 ), null, false );
+        Collection<Period> relatives = periods.getRelativePeriods( 1, getDate( 2002, 1, 1 ), i18nFormat, false );
         
         assertTrue( relatives.contains( new Period( new MonthlyPeriodType(), getDate( 2001, 1, 1 ), getDate( 2001, 1, 31 ) ) ) );
         assertTrue( relatives.contains( new Period( new MonthlyPeriodType(), getDate( 2001, 2, 1 ), getDate( 2001, 2, 28 ) ) ) );