← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12219: Impl dateperiodstructure resource table

 

------------------------------------------------------------
revno: 12219
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-09-24 09:05:03 +0200
message:
  Impl dateperiodstructure resource table
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/resourceTableForm.vm


--
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/PeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2013-09-24 07:05:03 +0000
@@ -54,6 +54,9 @@
     // Available PeriodTypes
     // -------------------------------------------------------------------------
 
+    /**
+     * All period types in descending order according to frequency.
+     */
     public static final List<PeriodType> PERIOD_TYPES = new ArrayList<PeriodType>()
     {
         {

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java	2013-09-24 07:05:03 +0000
@@ -76,6 +76,11 @@
      * Generates a resource table for all data elements.
      */
     void generateDataElementTable();
+
+    /**
+     * Generates a resource table for dates and associated periods.
+     */
+    void generateDatePeriodTable();
     
     /**
      * Generates a resource table for all periods.

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java	2013-09-24 07:05:03 +0000
@@ -46,6 +46,7 @@
     final String TABLE_NAME_ORGANISATION_UNIT_STRUCTURE = "_orgunitstructure";
     final String TABLE_NAME_DATA_ELEMENT_STRUCTURE = "_dataelementstructure";
     final String TABLE_NAME_PERIOD_STRUCTURE = "_periodstructure";
+    final String TABLE_NAME_DATE_PERIOD_STRUCTURE = "_dateperiodstructure";
     final String TABLE_NAME_DATA_ELEMENT_CATEGORY_OPTION_COMBO = "_dataelementcategoryoptioncombo";
     
     /**
@@ -99,6 +100,11 @@
      * Creates table.
      */
     void createDataElementStructure();
+
+    /**
+     * Creates table.
+     */
+    void createDatePeriodStructure();
     
     /**
      * Creates table.

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2013-09-03 19:11:14 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java	2013-09-24 07:05:03 +0000
@@ -30,6 +30,7 @@
 
 import static org.hisp.dhis.resourcetable.ResourceTableStore.TABLE_NAME_CATEGORY_OPTION_COMBO_NAME;
 import static org.hisp.dhis.resourcetable.ResourceTableStore.TABLE_NAME_DATA_ELEMENT_STRUCTURE;
+import static org.hisp.dhis.resourcetable.ResourceTableStore.TABLE_NAME_DATE_PERIOD_STRUCTURE;
 import static org.hisp.dhis.resourcetable.ResourceTableStore.TABLE_NAME_ORGANISATION_UNIT_STRUCTURE;
 import static org.hisp.dhis.resourcetable.ResourceTableStore.TABLE_NAME_PERIOD_STRUCTURE;
 
@@ -62,6 +63,8 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.Cal;
+import org.hisp.dhis.period.DailyPeriodType;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
@@ -71,6 +74,7 @@
 import org.hisp.dhis.resourcetable.statement.CreateOrganisationUnitGroupSetTableStatement;
 import org.hisp.dhis.sqlview.SqlViewService;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.Assert;
 
 /**
  * @author Lars Helge Overland
@@ -173,6 +177,9 @@
         generatePeriodTable();
         log.info( "Period table generated" );
         
+        generateDatePeriodTable();
+        log.info( "Date period table generated" );
+        
         generateDataElementCategoryOptionComboTable();
         log.info( "Data element category option combo table generated" );
         
@@ -487,6 +494,48 @@
     // PeriodTable
     // -------------------------------------------------------------------------
 
+    public void generateDatePeriodTable()
+    {
+        // ---------------------------------------------------------------------
+        // Create table
+        // ---------------------------------------------------------------------
+
+        resourceTableStore.createDatePeriodStructure();
+
+        // ---------------------------------------------------------------------
+        // Populate table
+        // ---------------------------------------------------------------------
+
+        List<PeriodType> periodTypes = PeriodType.getAvailablePeriodTypes();
+        
+        List<Object[]> batchArgs = new ArrayList<Object[]>();
+        
+        Date startDate = new Cal( 1970, 1, 1 ).time(); //TODO
+        Date endDate = new Cal( 2030, 1 , 1 ).time();
+        
+        List<Period> days = new DailyPeriodType().generatePeriods( startDate, endDate );
+        
+        for ( Period day : days )
+        {
+            List<Object> values = new ArrayList<Object>();
+            
+            values.add( day.getStartDate() );
+            
+            for ( PeriodType periodType : periodTypes )
+            {
+                Period period = periodType.createPeriod( day.getStartDate() );
+                
+                Assert.notNull( period );
+                
+                values.add( period.getIsoDate() );
+            }
+            
+            batchArgs.add( values.toArray() );
+        }
+        
+        resourceTableStore.batchUpdate( PeriodType.PERIOD_TYPES.size() + 1, TABLE_NAME_DATE_PERIOD_STRUCTURE, batchArgs );
+    }    
+    
     public void generatePeriodTable()
     {
         // ---------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java	2013-09-01 18:30:05 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java	2013-09-24 07:05:03 +0000
@@ -259,6 +259,31 @@
     // PeriodTable
     // -------------------------------------------------------------------------
 
+    public void createDatePeriodStructure()
+    {
+        try
+        {
+            jdbcTemplate.execute( "DROP TABLE IF EXISTS " + TABLE_NAME_DATE_PERIOD_STRUCTURE );            
+        }
+        catch ( BadSqlGrammarException ex )
+        {
+            // Do nothing, table does not exist
+        }
+        
+        String sql = "CREATE TABLE " + TABLE_NAME_DATE_PERIOD_STRUCTURE + " (dateperiod DATE NOT NULL PRIMARY KEY";
+        
+        for ( PeriodType periodType : PeriodType.PERIOD_TYPES )
+        {
+            sql += ", " + periodType.getName().toLowerCase() + " VARCHAR(10)";
+        }
+        
+        sql += ")";
+        
+        log.info( "Create date period structure SQL: " + sql );
+        
+        jdbcTemplate.execute( sql );
+    }
+
     public void createPeriodStructure()
     {
         try

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2013-07-22 11:47:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties	2013-09-24 07:05:03 +0000
@@ -321,4 +321,5 @@
 done=Done
 period_structure=Period structure
 data_element_category_option_combo=Data element category option combinations
-update_category_option_combos=Update category option combinations
\ No newline at end of file
+update_category_option_combos=Update category option combinations
+date_period_structure=Date period structure
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/resourceTableForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/resourceTableForm.vm	2013-09-03 19:11:14 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/resourceTableForm.vm	2013-09-24 07:05:03 +0000
@@ -29,6 +29,7 @@
 <li>$i18n.getString( "data_element_category_option_combo_name" ) <span style="color:#606060">(_categoryoptioncomboname)</span></li>
 <li>$i18n.getString( "data_element_structure" ) <span style="color:#606060">(_dataelementstructure)</span></li>
 <li>$i18n.getString( "period_structure" ) <span style="color:#606060">(_periodstructure)</span></li>
+<li>$i18n.getString( "date_period_structure" ) <span style="color:#606060">(_dateperiodstructure)</span></li>
 <li>$i18n.getString( "data_element_category_option_combo" ) <span style="color:#606060">(_dataelementcategoryoptioncombo)</span></li>
 </ul>