← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2914: Implemented financial period types with July and October base

 

------------------------------------------------------------
revno: 2914
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-02-24 23:01:50 +0100
message:
  Implemented financial period types with July and October base
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialJulyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialOctoberPeriodType.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialJulyPeriodTypeTest.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialOctoberPeriodTypeTest.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/period/hibernate/PeriodType.hbm.xml
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties


--
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/FinancialJulyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialJulyPeriodType.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialJulyPeriodType.java	2011-02-24 22:01:50 +0000
@@ -0,0 +1,51 @@
+package org.hisp.dhis.period;
+
+/*
+ * 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.Calendar;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class FinancialJulyPeriodType
+    extends FinancialPeriodType
+{
+    public static final String NAME = "FinancialJuly";
+
+    @Override
+    protected int getBaseMonth()
+    {
+        return Calendar.JULY;
+    }
+    
+    @Override
+    public String getName()
+    {
+        return NAME;
+    }
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialOctoberPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialOctoberPeriodType.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialOctoberPeriodType.java	2011-02-24 22:01:50 +0000
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.period;
+
+import java.util.Calendar;
+
+/**
+ * @author Chau Thu Tran
+ */
+public class FinancialOctoberPeriodType
+    extends FinancialPeriodType
+{
+    public static final String NAME = "FinancialOct";
+
+    @Override
+    protected int getBaseMonth()
+    {
+        return Calendar.OCTOBER;
+    }
+    
+    @Override
+    public String getName()
+    {
+        return NAME;
+    }
+}

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2011-02-24 21:01:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2011-02-24 22:01:50 +0000
@@ -63,6 +63,8 @@
         periodTypes.add( new SixMonthlyPeriodType() );
         periodTypes.add( new YearlyPeriodType() );
         periodTypes.add( new FinancialAprilPeriodType() );
+        periodTypes.add( new FinancialJulyPeriodType() );
+        periodTypes.add( new FinancialOctoberPeriodType() );
         //periodTypes.add( new OnChangePeriodType() );
         //periodTypes.add( new SurveyPeriodType() );
         

=== added file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialJulyPeriodTypeTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialJulyPeriodTypeTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialJulyPeriodTypeTest.java	2011-02-24 22:01:50 +0000
@@ -0,0 +1,139 @@
+package org.hisp.dhis.period;
+
+/*
+ * 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 static junit.framework.Assert.assertEquals;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class FinancialJulyPeriodTypeTest
+{
+    private Cal startCal;
+    private Cal endCal;
+    private Cal testCal;
+    private CalendarPeriodType periodType;
+    
+    @Before
+    public void before()
+    {
+        startCal = new Cal();
+        endCal = new Cal();
+        testCal = new Cal();
+        periodType = new FinancialJulyPeriodType();
+    }
+    
+    @Test
+    public void testCreatePeriod()
+    {
+        testCal.set( 2009, 2, 15 );
+
+        startCal.set( 2008, 7, 1 );
+        endCal.set( 2009, 6, 30 );
+        
+        Period period = periodType.createPeriod( testCal.time() );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+        
+        testCal.set( 2009, 9, 12 );
+
+        period = periodType.createPeriod( testCal.time() );
+
+        startCal.set( 2009, 7, 1 );
+        endCal.set( 2010, 6, 30 );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+    }
+
+    @Test
+    public void testGetNextPeriod()
+    {
+        testCal.set( 2009, 2, 15 );
+
+        Period period = periodType.createPeriod( testCal.time() );
+        
+        period = periodType.getNextPeriod( period );
+
+        startCal.set( 2009, 7, 1 );
+        endCal.set( 2010, 6, 30 );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+    }
+
+    @Test
+    public void testGetPreviousPeriod()
+    {
+        testCal.set( 2009, 2, 15 );
+
+        Period period = periodType.createPeriod( testCal.time() );
+        
+        period = periodType.getPreviousPeriod( period );
+
+        startCal.set( 2007, 7, 1 );
+        endCal.set( 2008, 6, 30 );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+    }
+
+    @Test
+    public void testGeneratePeriods()
+    {
+        testCal.set( 2009, 2, 15 );
+        
+        List<Period> periods = periodType.generatePeriods( testCal.time() );
+        
+        assertEquals( 11, periods.size() );
+        assertEquals( periodType.createPeriod( new Cal( 2003, 7, 1 ).time() ), periods.get( 0 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2004, 7, 1 ).time() ), periods.get( 1 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 7, 1 ).time() ), periods.get( 2 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2006, 7, 1 ).time() ), periods.get( 3 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2007, 7, 1 ).time() ), periods.get( 4 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2008, 7, 1 ).time() ), periods.get( 5 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 7, 1 ).time() ), periods.get( 6 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2010, 7, 1 ).time() ), periods.get( 7 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2011, 7, 1 ).time() ), periods.get( 8 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2012, 7, 1 ).time() ), periods.get( 9 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2013, 7, 1 ).time() ), periods.get( 10 ) );
+        
+        testCal.set( 2009, 9, 12 );
+        
+        periods = periodType.generatePeriods( testCal.time() );
+        
+        assertEquals( 11, periods.size() );
+        assertEquals( periodType.createPeriod( new Cal( 2004, 7, 1 ).time() ), periods.get( 0 ) );
+    }
+}

=== added file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialOctoberPeriodTypeTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialOctoberPeriodTypeTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialOctoberPeriodTypeTest.java	2011-02-24 22:01:50 +0000
@@ -0,0 +1,140 @@
+package org.hisp.dhis.period;
+
+/*
+ * 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 static junit.framework.Assert.assertEquals;
+
+import java.util.List;
+
+import org.hisp.dhis.period.Cal;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class FinancialOctoberPeriodTypeTest
+{
+    private Cal startCal;
+    private Cal endCal;
+    private Cal testCal;
+    private CalendarPeriodType periodType;
+    
+    @Before
+    public void before()
+    {
+        startCal = new Cal();
+        endCal = new Cal();
+        testCal = new Cal();
+        periodType = new FinancialOctoberPeriodType();
+    }
+    
+    @Test
+    public void testCreatePeriod()
+    {
+        testCal.set( 2009, 2, 15 );
+
+        startCal.set( 2008, 10, 1 );
+        endCal.set( 2009, 9, 30 );
+        
+        Period period = periodType.createPeriod( testCal.time() );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+        
+        testCal.set( 2009, 11, 12 );
+
+        period = periodType.createPeriod( testCal.time() );
+
+        startCal.set( 2009, 10, 1 );
+        endCal.set( 2010, 9, 30 );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+    }
+
+    @Test
+    public void testGetNextPeriod()
+    {
+        testCal.set( 2009, 2, 15 );
+
+        Period period = periodType.createPeriod( testCal.time() );
+        
+        period = periodType.getNextPeriod( period );
+
+        startCal.set( 2009, 10, 1 );
+        endCal.set( 2010, 9, 30 );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+    }
+
+    @Test
+    public void testGetPreviousPeriod()
+    {
+        testCal.set( 2009, 2, 15 );
+
+        Period period = periodType.createPeriod( testCal.time() );
+        
+        period = periodType.getPreviousPeriod( period );
+
+        startCal.set( 2007, 10, 1 );
+        endCal.set( 2008, 9, 30 );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+    }
+
+    @Test
+    public void testGeneratePeriods()
+    {
+        testCal.set( 2009, 2, 15 );
+        
+        List<Period> periods = periodType.generatePeriods( testCal.time() );
+        
+        assertEquals( 11, periods.size() );
+        assertEquals( periodType.createPeriod( new Cal( 2003, 10, 1 ).time() ), periods.get( 0 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2004, 10, 1 ).time() ), periods.get( 1 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 10, 1 ).time() ), periods.get( 2 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2006, 10, 1 ).time() ), periods.get( 3 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2007, 10, 1 ).time() ), periods.get( 4 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2008, 10, 1 ).time() ), periods.get( 5 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 10, 1 ).time() ), periods.get( 6 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2010, 10, 1 ).time() ), periods.get( 7 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2011, 10, 1 ).time() ), periods.get( 8 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2012, 10, 1 ).time() ), periods.get( 9 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2013, 10, 1 ).time() ), periods.get( 10 ) );
+        
+        testCal.set( 2009, 11, 12 );
+        
+        periods = periodType.generatePeriods( testCal.time() );
+        
+        assertEquals( 11, periods.size() );
+        assertEquals( periodType.createPeriod( new Cal( 2004, 10, 1 ).time() ), periods.get( 0 ) );
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/period/hibernate/PeriodType.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/period/hibernate/PeriodType.hbm.xml	2010-11-17 03:17:16 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/period/hibernate/PeriodType.hbm.xml	2011-02-24 22:01:50 +0000
@@ -9,7 +9,7 @@
       <generator class="native"/>
     </id>
     
-    <discriminator column="name" type="string" length="15" not-null="true"/>
+    <discriminator column="name" type="string" length="50" not-null="true"/>
     
     <subclass name="org.hisp.dhis.period.DailyPeriodType"
       discriminator-value="Daily"/>
@@ -31,5 +31,9 @@
       discriminator-value="Survey"/>
     <subclass name="org.hisp.dhis.period.FinancialAprilPeriodType"
       discriminator-value="FinancialApril"/>
+    <subclass name="org.hisp.dhis.period.FinancialJulyPeriodType"
+      discriminator-value="FinancialJuly"/>
+    <subclass name="org.hisp.dhis.period.FinancialOctoberPeriodType"
+      discriminator-value="FinancialOct"/>
   </class>
 </hibernate-mapping>

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties	2011-02-11 10:53:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties	2011-02-24 22:01:50 +0000
@@ -120,6 +120,8 @@
 Survey					= Survey
 Relative				= Relative
 FinancialApril			= Financial-April
+FinancialJuly			= Financial-July
+FinancialOct			= Financial-Oct
 
 format.Daily.startDate		= yyyy-MM-dd
 format.Daily.endDate		=