dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20654
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9561: Analytics, impl support for relative periods
------------------------------------------------------------
revno: 9561
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-01-18 17:00:12 +0100
message:
Analytics, impl support for relative periods
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriodEnum.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
resources/util/clean_cde.sh
--
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
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriodEnum.java 2013-01-18 16:00:12 +0000
@@ -0,0 +1,71 @@
+package org.hisp.dhis.period;
+
+/*
+ * Copyright (c) 2004-2012, 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.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+public enum RelativePeriodEnum
+{
+ LAST_MONTH,
+ LAST_BIMONTH,
+ LAST_QUARTER,
+ LAST_SIX_MONTH,
+ MONTHS_THIS_YEAR,
+ QUARTERS_THIS_YEAR,
+ THIS_YEAR,
+ MONTHS_LAST_YEAR,
+ QUARTERS_LAST_YEAR,
+ LAST_YEAR,
+ LAST_5_YEARS,
+ LAST_12_MONTHS,
+ LAST_3_MONTHS,
+ LAST_6_BIMONTHS,
+ LAST_4_QUARTERS,
+ LAST_2_SIXMONTHS,
+ THIS_FINANCIAL_YEAR,
+ LAST_FINANCIAL_YEAR,
+ LAST_5_FINANCIAL_YEARS,
+ LAST_4_WEEKS,
+ LAST_12_WEEKS,
+ LAST_52_WEEKS;
+
+ 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_4_QUARTERS.toString(), LAST_2_SIXMONTHS.toString(), THIS_FINANCIAL_YEAR.toString(), LAST_FINANCIAL_YEAR.toString(),
+ LAST_5_FINANCIAL_YEARS.toString(), LAST_4_WEEKS.toString(), LAST_12_WEEKS.toString(), LAST_52_WEEKS.toString() ) );
+ } };
+
+ public static boolean contains( String relativePeriod )
+ {
+ return OPTIONS.contains( relativePeriod );
+ }
+}
=== 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 2013-01-18 10:23:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/RelativePeriods.java 2013-01-18 16:00:12 +0000
@@ -715,6 +715,42 @@
return cal.getTime();
}
+
+ /**
+ * Returns a RelativePeriods instance based on the given list of RelativePeriodsEnum.
+ *
+ * @param relativePeriods a list of RelativePeriodsEnum.
+ * @return a RelativePeriods instance.
+ */
+ public static List<Period> getRelativePeriodsFromEnum( RelativePeriodEnum relativePeriod, I18nFormat format, boolean dynamicNames )
+ {
+ Map<RelativePeriodEnum, List<Period>> map = new HashMap<RelativePeriodEnum, List<Period>>();
+
+ map.put( RelativePeriodEnum.LAST_MONTH, new RelativePeriods().setReportingMonth( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.LAST_BIMONTH, new RelativePeriods().setReportingBimonth( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.LAST_QUARTER, new RelativePeriods().setReportingQuarter( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.LAST_SIX_MONTH, new RelativePeriods().setLastSixMonth( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.MONTHS_THIS_YEAR, new RelativePeriods().setMonthsThisYear( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.QUARTERS_THIS_YEAR, new RelativePeriods().setQuartersThisYear( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.THIS_YEAR, new RelativePeriods().setThisYear( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.MONTHS_LAST_YEAR, new RelativePeriods().setMonthsLastYear( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.QUARTERS_LAST_YEAR, new RelativePeriods().setQuartersLastYear( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.LAST_YEAR, new RelativePeriods().setLastYear( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.LAST_5_YEARS, new RelativePeriods().setLast5Years( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.LAST_12_MONTHS, new RelativePeriods().setLast12Months( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.LAST_3_MONTHS, new RelativePeriods().setLast3Months( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.LAST_6_BIMONTHS, new RelativePeriods().setLast6BiMonths( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.LAST_4_QUARTERS, new RelativePeriods().setLast4Quarters( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.LAST_2_SIXMONTHS, new RelativePeriods().setLast2SixMonths( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.THIS_FINANCIAL_YEAR, new RelativePeriods().setThisFinancialYear( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.LAST_FINANCIAL_YEAR, new RelativePeriods().setLastFinancialYear( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.LAST_5_FINANCIAL_YEARS, new RelativePeriods().setLast5FinancialYears( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.LAST_4_WEEKS, new RelativePeriods().setLast4Weeks( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.LAST_12_WEEKS, new RelativePeriods().setLast12Weeks( true ).getRelativePeriods( format, dynamicNames ) );
+ map.put( RelativePeriodEnum.LAST_52_WEEKS, new RelativePeriods().setLast52Weeks( true ).getRelativePeriods( format, dynamicNames ) );
+
+ return map.get( relativePeriod );
+ }
// -------------------------------------------------------------------------
// Getters & setters
@@ -776,9 +812,10 @@
return lastSixMonth;
}
- public void setLastSixMonth( boolean lastSixMonth )
+ public RelativePeriods setLastSixMonth( boolean lastSixMonth )
{
this.lastSixMonth = lastSixMonth;
+ return this;
}
@JsonProperty
@@ -983,9 +1020,10 @@
return last4Weeks;
}
- public void setLast4Weeks( boolean last4Weeks )
+ public RelativePeriods setLast4Weeks( boolean last4Weeks )
{
this.last4Weeks = last4Weeks;
+ return this;
}
@JsonProperty
@@ -995,9 +1033,10 @@
return last12Weeks;
}
- public void setLast12Weeks( boolean last12Weeks )
+ public RelativePeriods setLast12Weeks( boolean last12Weeks )
{
this.last12Weeks = last12Weeks;
+ return this;
}
@JsonProperty
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2013-01-18 14:18:49 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2013-01-18 16:00:12 +0000
@@ -70,6 +70,8 @@
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.period.RelativePeriodEnum;
+import org.hisp.dhis.period.RelativePeriods;
import org.hisp.dhis.system.grid.ListGrid;
import org.hisp.dhis.system.util.MathUtils;
import org.hisp.dhis.system.util.SystemUtils;
@@ -328,12 +330,24 @@
else if ( PERIOD_DIM_ID.equals( dimension ) )
{
List<IdentifiableObject> list = new ArrayList<IdentifiableObject>();
-
- for ( String isoPeriod : options )
+
+ periodLoop : for ( String isoPeriod : options )
{
Period period = PeriodType.getPeriodFromIsoString( isoPeriod );
- period.setName( format != null ? format.formatPeriod( period ) : null );
- list.add( period );
+
+ if ( period != null )
+ {
+ period.setName( format != null ? format.formatPeriod( period ) : null );
+ list.add( period );
+ continue periodLoop;
+ }
+
+ if ( RelativePeriodEnum.contains( isoPeriod ) )
+ {
+ RelativePeriodEnum relativePeriod = RelativePeriodEnum.valueOf( isoPeriod );
+ list.addAll( RelativePeriods.getRelativePeriodsFromEnum( relativePeriod, format, true ) );
+ continue periodLoop;
+ }
}
return list;
=== modified file 'resources/util/clean_cde.sh'
--- resources/util/clean_cde.sh 2012-08-29 08:49:10 +0000
+++ resources/util/clean_cde.sh 2013-01-18 16:00:12 +0000
@@ -44,7 +44,7 @@
sed -i 's/width="[^"]*"//g' $1
sed -i 's/nowrap="[^"]*"//g' $1
sed -i 's/valign="[^"]*"//g' $1
-sed -i 's/view="[^"]*"//g' $11
+sed -i 's/view="[^"]*"//g' $1
sed -i 's/bgcolor="[^"]*"//g' $1
# Remove weird stuff