dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #04128
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1364: Pushed method getPeriods( Period, int) down from HistoryRetriver to PeriodService
------------------------------------------------------------
revno: 1364
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-01-28 20:59:57 +0100
message:
Pushed method getPeriods( Period, int) down from HistoryRetriver to PeriodService
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.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/PeriodService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodService.java 2009-06-02 12:13:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodService.java 2010-01-28 19:59:57 +0000
@@ -226,6 +226,15 @@
*/
Period getRelativePeriod( Date date, int months );
+ /**
+ * Returns historyLength number of Periods chronologically ending with lastPeriod.
+ *
+ * @param lastPeriod the last Period in the provided collection.
+ * @param historyLength the number of Periods in the provided collection.
+ * @return a collection of Periods.
+ */
+ Collection<Period> getPeriods( Period lastPeriod, int historyLength );
+
// -------------------------------------------------------------------------
// PeriodType
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java 2009-11-26 14:02:44 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/DefaultPeriodService.java 2010-01-28 19:59:57 +0000
@@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
+import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
@@ -294,6 +295,30 @@
return period;
}
+
+ public Collection<Period> getPeriods( Period lastPeriod, int historyLength )
+ {
+ List<Period> periods = new ArrayList<Period>( historyLength );
+
+ CalendarPeriodType periodType = (CalendarPeriodType) lastPeriod.getPeriodType();
+
+ Period period = lastPeriod;
+
+ Period p = new Period();
+
+ for ( int i = 0; i < historyLength; ++i )
+ {
+ p = getPeriodFromDates( period.getStartDate(), period.getEndDate(), periodType );
+
+ periods.add( p != null ? p : period );
+
+ period = periodType.getPreviousPeriod( period );
+ }
+
+ Collections.reverse( periods );
+
+ return periods;
+ }
// -------------------------------------------------------------------------
// PeriodType