← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17071: Added last 6 months as relative period

 

------------------------------------------------------------
revno: 17071
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-10-13 14:13:36 +0200
message:
  Added last 6 months as relative period
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriodEnum.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/RelativePeriodTest.java
  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/resources/org/hisp/dhis/period/hibernate/RelativePeriods.hbm.xml
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/AbstractRelativePeriodsAction.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/RelativePeriodEnum.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriodEnum.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriodEnum.java	2014-10-13 12:13:36 +0000
@@ -46,6 +46,7 @@
     LAST_YEAR,
     LAST_5_YEARS,
     LAST_12_MONTHS,
+    LAST_6_MONTHS,
     LAST_3_MONTHS,
     LAST_6_BIMONTHS,
     LAST_4_QUARTERS,
@@ -61,7 +62,7 @@
     public static Set<String> OPTIONS = new HashSet<String>() { {
         addAll( Arrays.asList( LAST_MONTH.toString(), LAST_BIMONTH.toString(), LAST_QUARTER.toString(), LAST_SIX_MONTH.toString(),
             MONTHS_THIS_YEAR.toString(), QUARTERS_THIS_YEAR.toString(), THIS_YEAR.toString(), MONTHS_LAST_YEAR.toString(), QUARTERS_LAST_YEAR.toString(),
-            LAST_YEAR.toString(), LAST_5_YEARS.toString(), LAST_12_MONTHS.toString(), LAST_3_MONTHS.toString(), LAST_6_BIMONTHS.toString(), 
+            LAST_YEAR.toString(), LAST_5_YEARS.toString(), LAST_12_MONTHS.toString(), LAST_6_MONTHS.toString(), LAST_3_MONTHS.toString(), LAST_6_BIMONTHS.toString(), 
             LAST_4_QUARTERS.toString(), LAST_2_SIXMONTHS.toString(), THIS_FINANCIAL_YEAR.toString(), LAST_FINANCIAL_YEAR.toString(), 
             LAST_5_FINANCIAL_YEARS.toString(), LAST_WEEK.toString(), LAST_4_WEEKS.toString(), LAST_12_WEEKS.toString(), LAST_52_WEEKS.toString() ) );
     } };

=== 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	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java	2014-10-13 12:13:36 +0000
@@ -176,6 +176,8 @@
     private boolean last5Years = false;
 
     private boolean last12Months = false;
+
+    private boolean last6Months = false;
     
     private boolean last3Months = false;
 
@@ -235,7 +237,7 @@
     public RelativePeriods( boolean reportingMonth, boolean reportingBimonth, boolean reportingQuarter, boolean lastSixMonth,
                             boolean monthsThisYear, boolean quartersThisYear, boolean thisYear,
                             boolean monthsLastYear, boolean quartersLastYear, boolean lastYear, boolean last5Years,
-                            boolean last12Months, boolean last3Months, boolean last6BiMonths, boolean last4Quarters, boolean last2SixMonths,
+                            boolean last12Months, boolean last6Months, boolean last3Months, boolean last6BiMonths, boolean last4Quarters, boolean last2SixMonths,
                             boolean thisFinancialYear, boolean lastFinancialYear, boolean last5FinancialYears, 
                             boolean lastWeek, boolean last4Weeks, boolean last12Weeks, boolean last52Weeks )
     {
@@ -251,6 +253,7 @@
         this.lastYear = lastYear;
         this.last5Years = last5Years;
         this.last12Months = last12Months;
+        this.last6Months = last6Months;
         this.last3Months = last3Months;
         this.last6BiMonths = last6BiMonths;
         this.last4Quarters = last4Quarters;
@@ -285,6 +288,7 @@
         this.lastYear = false;
         this.last5Years = false;
         this.last12Months = false;
+        this.last6Months = false;
         this.last3Months = false;
         this.last6BiMonths = false;
         this.last4Quarters = false;
@@ -320,7 +324,7 @@
             return PeriodType.getPeriodTypeByName( WeeklyPeriodType.NAME );
         }
         
-        if ( isReportingMonth() || isLast12Months() || isLast3Months() )
+        if ( isReportingMonth() || isLast12Months() || isLast6Months() || isLast3Months() )
         {
             return PeriodType.getPeriodTypeByName( MonthlyPeriodType.NAME );
         }
@@ -508,6 +512,11 @@
             periods.addAll( getRollingRelativePeriodList( new MonthlyPeriodType(), MONTHS_LAST_12, monthDate, dynamicNames, format ) );
         }
 
+        if ( isLast6Months() )
+        {
+            periods.addAll( getRollingRelativePeriodList( new MonthlyPeriodType(), MONTHS_LAST_12, monthDate, dynamicNames, format ).subList( 6, 12 ) );
+        }
+        
         if ( isLast3Months() )
         {
             periods.addAll( getRollingRelativePeriodList( new MonthlyPeriodType(), MONTHS_LAST_12, monthDate, dynamicNames, format ).subList( 9, 12 ) );
@@ -749,6 +758,7 @@
         map.put( RelativePeriodEnum.LAST_YEAR, new RelativePeriods().setLastYear( true ) );
         map.put( RelativePeriodEnum.LAST_5_YEARS, new RelativePeriods().setLast5Years( true ) );
         map.put( RelativePeriodEnum.LAST_12_MONTHS, new RelativePeriods().setLast12Months( true ) );
+        map.put( RelativePeriodEnum.LAST_6_MONTHS, new RelativePeriods().setLast6Months( true ) );
         map.put( RelativePeriodEnum.LAST_3_MONTHS, new RelativePeriods().setLast3Months( true ) );
         map.put( RelativePeriodEnum.LAST_6_BIMONTHS, new RelativePeriods().setLast6BiMonths( true ) );
         map.put( RelativePeriodEnum.LAST_4_QUARTERS, new RelativePeriods().setLast4Quarters( true ) );
@@ -785,6 +795,7 @@
         add( list, RelativePeriodEnum.LAST_YEAR, lastYear );
         add( list, RelativePeriodEnum.LAST_5_YEARS, last5Years );
         add( list, RelativePeriodEnum.LAST_12_MONTHS, last12Months );
+        add( list, RelativePeriodEnum.LAST_6_MONTHS, last6Months );
         add( list, RelativePeriodEnum.LAST_3_MONTHS, last3Months );
         add( list, RelativePeriodEnum.LAST_6_BIMONTHS, last6BiMonths );
         add( list, RelativePeriodEnum.LAST_4_QUARTERS, last4Quarters );
@@ -816,6 +827,7 @@
             lastYear = relativePeriods.contains( RelativePeriodEnum.LAST_YEAR );
             last5Years = relativePeriods.contains( RelativePeriodEnum.LAST_5_YEARS );
             last12Months = relativePeriods.contains( RelativePeriodEnum.LAST_12_MONTHS );
+            last6Months = relativePeriods.contains( RelativePeriodEnum.LAST_6_MONTHS );
             last3Months = relativePeriods.contains( RelativePeriodEnum.LAST_3_MONTHS );
             last6BiMonths = relativePeriods.contains( RelativePeriodEnum.LAST_6_BIMONTHS );
             last4Quarters = relativePeriods.contains( RelativePeriodEnum.LAST_4_QUARTERS );
@@ -1009,7 +1021,20 @@
         this.last12Months = last12Months;
         return this;
     }
-    
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
+    public boolean isLast6Months()
+    {
+        return last6Months;
+    }
+
+    public RelativePeriods setLast6Months( boolean last6Months )
+    {
+        this.last6Months = last6Months;
+        return this;
+    }
+
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
     public boolean isLast3Months()
@@ -1176,6 +1201,7 @@
         result = prime * result + (lastYear ? 1 : 0);
         result = prime * result + (last5Years ? 1 : 0);
         result = prime * result + (last12Months ? 1 : 0);
+        result = prime * result + (last6Months ? 1 : 0);
         result = prime * result + (last3Months ? 1 : 0);
         result = prime * result + (last6BiMonths ? 1 : 0);
         result = prime * result + (last4Quarters ? 1 : 0);
@@ -1269,6 +1295,11 @@
         {
             return false;
         }
+
+        if ( !last6Months == other.last6Months )
+        {
+            return false;
+        }
         
         if ( !last3Months == other.last3Months )
         {

=== 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	2014-08-29 10:02:21 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/RelativePeriodTest.java	2014-10-13 12:13:36 +0000
@@ -56,11 +56,11 @@
     @Test
     public void getRelativePeriods()
     {
-        RelativePeriods periods = new RelativePeriods( true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true );
+        RelativePeriods periods = new RelativePeriods( true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true );
 
         List<Period> relatives = periods.getRelativePeriods( getDate( 2001, 1, 1 ), i18nFormat, false );
 
-        assertEquals( 143, relatives.size() );
+        assertEquals( 149, relatives.size() );
         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 ) ) ) );
         assertTrue( relatives.contains( new Period( new MonthlyPeriodType(), getDate( 2001, 3, 1 ), getDate( 2001, 3, 31 ) ) ) );
@@ -185,6 +185,22 @@
     }
 
     @Test
+    public void testGetLast6Months()
+    {
+        RelativePeriods relativePeriods = new RelativePeriods().setLast6Months( true );
+
+        List<Period> relatives = relativePeriods.getRelativePeriods( getDate( 2001, 7, 1 ), null, false );
+
+        assertEquals( 6, relatives.size() );
+        assertTrue( relatives.contains( new Period( new MonthlyPeriodType(), getDate( 2001, 2, 1 ), getDate( 2001, 2, 28 ) ) ) );
+        assertTrue( relatives.contains( new Period( new MonthlyPeriodType(), getDate( 2001, 3, 1 ), getDate( 2001, 3, 31 ) ) ) );
+        assertTrue( relatives.contains( new Period( new MonthlyPeriodType(), getDate( 2001, 4, 1 ), getDate( 2001, 4, 30 ) ) ) );
+        assertTrue( relatives.contains( new Period( new MonthlyPeriodType(), getDate( 2001, 5, 1 ), getDate( 2001, 5, 31 ) ) ) );
+        assertTrue( relatives.contains( new Period( new MonthlyPeriodType(), getDate( 2001, 6, 1 ), getDate( 2001, 6, 30 ) ) ) );
+        assertTrue( relatives.contains( new Period( new MonthlyPeriodType(), getDate( 2001, 7, 1 ), getDate( 2001, 7, 31 ) ) ) );
+    }
+
+    @Test
     public void testGetLast4Quarters()
     {
         List<Period> relatives = new RelativePeriods().setLast4Quarters( true ).getRelativePeriods( getDate( 2001, 1, 1 ), null, false );

=== 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	2014-10-09 07:58:13 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2014-10-13 12:13:36 +0000
@@ -663,6 +663,7 @@
         executeSql( "update relativeperiods set lastweek = false where lastweek is null" );
         executeSql( "update relativeperiods set last4weeks = false where last4weeks is null" );
         executeSql( "update relativeperiods set last12weeks = false where last12weeks is null" );
+        executeSql( "update relativeperiods set last6months = false where last6months is null" );
 
         upgradeChartRelativePeriods();
         upgradeReportTableRelativePeriods();
@@ -875,7 +876,7 @@
                     rs.getBoolean( "reportingquarter" ), rs.getBoolean( "lastsixmonth" ),
                     rs.getBoolean( "monthsthisyear" ), rs.getBoolean( "quartersthisyear" ),
                     rs.getBoolean( "thisyear" ), false, false, rs.getBoolean( "lastyear" ),
-                    rs.getBoolean( "last5years" ), rs.getBoolean( "last12months" ), rs.getBoolean( "last3months" ),
+                    rs.getBoolean( "last5years" ), rs.getBoolean( "last12months" ), false, rs.getBoolean( "last3months" ),
                     false, rs.getBoolean( "last4quarters" ), rs.getBoolean( "last2sixmonths" ), false, false, false,
                     false, false, false, false );
 
@@ -935,7 +936,7 @@
                     rs.getBoolean( "lastsixmonth" ), rs.getBoolean( "monthsthisyear" ),
                     rs.getBoolean( "quartersthisyear" ), rs.getBoolean( "thisyear" ),
                     rs.getBoolean( "monthslastyear" ), rs.getBoolean( "quarterslastyear" ),
-                    rs.getBoolean( "lastyear" ), rs.getBoolean( "last5years" ), rs.getBoolean( "last12months" ),
+                    rs.getBoolean( "lastyear" ), rs.getBoolean( "last5years" ), rs.getBoolean( "last12months" ), false,
                     rs.getBoolean( "last3months" ), false, rs.getBoolean( "last4quarters" ),
                     rs.getBoolean( "last2sixmonths" ), rs.getBoolean( "thisfinancialyear" ),
                     rs.getBoolean( "lastfinancialyear" ), rs.getBoolean( "last5financialyears" ), false, false, false,

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/period/hibernate/RelativePeriods.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/period/hibernate/RelativePeriods.hbm.xml	2013-03-14 12:24:38 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/period/hibernate/RelativePeriods.hbm.xml	2014-10-13 12:13:36 +0000
@@ -26,6 +26,7 @@
     
     <property name="last5Years" />
     <property name="last12Months" />
+    <property name="last6Months" />
     <property name="last3Months" />
     <property name="last6BiMonths" />
     <property name="last4Quarters" />

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/AbstractRelativePeriodsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/AbstractRelativePeriodsAction.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/AbstractRelativePeriodsAction.java	2014-10-13 12:13:36 +0000
@@ -121,6 +121,13 @@
         this.last12Months = last12Months;
     }
 
+    protected boolean last6Months;
+
+    public void setLast6Months( boolean last6Months )
+    {
+        this.last6Months = last6Months;
+    }
+
     protected boolean last4Quarters;
 
     public void setLast4Quarters( boolean last4Quarters )
@@ -203,7 +210,7 @@
         RelativePeriods relatives = new RelativePeriods( reportingMonth, reportingBimonth, reportingQuarter, lastSixMonth,
             monthsThisYear, quartersThisYear, thisYear, 
             monthsLastYear, quartersLastYear, lastYear, 
-            last5Years, last12Months, last3Months, last6BiMonths, last4Quarters, last2SixMonths,
+            last5Years, last12Months, last6Months, last3Months, last6BiMonths, last4Quarters, last2SixMonths,
             thisFinancialYear, lastFinancialYear, last5FinancialYears, 
             lastWeek, last4Weeks, last12Weeks, last52Weeks );