dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20194
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9118: Impl period structure resource table, a table with columns for each period type and iso values fo...
------------------------------------------------------------
revno: 9118
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-11-25 21:18:52 +0100
message:
Impl period structure resource table, a table with columns for each period type and iso values for each period on rows
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-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/resourcetable/GenerateResourceTableAction.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/javascript/resourceTable.js
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 2012-07-23 16:26:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2012-11-25 20:18:52 +0000
@@ -53,7 +53,7 @@
// Available PeriodTypes
// -------------------------------------------------------------------------
- private static final List<PeriodType> PERIOD_TYPES = new ArrayList<PeriodType>()
+ public static final List<PeriodType> PERIOD_TYPES = new ArrayList<PeriodType>()
{
{
add( new DailyPeriodType() );
=== 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 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableService.java 2012-11-25 20:18:52 +0000
@@ -71,4 +71,9 @@
* Generates a resource table for all data elements.
*/
void generateDataElementTable();
+
+ /**
+ * Generates a resource table for all periods.
+ */
+ void generatePeriodTable();
}
=== 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 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java 2012-11-25 20:18:52 +0000
@@ -44,6 +44,7 @@
final String TABLE_NAME_CATEGORY_OPTION_COMBO_NAME = "_categoryoptioncomboname";
final String TABLE_NAME_ORGANISATION_UNIT_STRUCTURE = "_orgunitstructure";
final String TABLE_NAME_DATA_ELEMENT_STRUCTURE = "_dataelementstructure";
+ final String TABLE_NAME_PERIOD_STRUCTURE = "_periodstructure";
// -------------------------------------------------------------------------
// OrganisationUnitStructure
@@ -98,5 +99,10 @@
/**
* Creates table.
*/
- void createDataElementStructure();
+ void createDataElementStructure();
+
+ /**
+ * Creates table.
+ */
+ void createPeriodStructure();
}
=== 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 2012-11-12 16:42:09 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java 2012-11-25 20:18:52 +0000
@@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -55,6 +56,8 @@
import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.resourcetable.statement.CreateCategoryTableStatement;
import org.hisp.dhis.resourcetable.statement.CreateDataElementGroupSetTableStatement;
@@ -114,6 +117,13 @@
{
this.indicatorService = indicatorService;
}
+
+ private PeriodService periodService;
+
+ public void setPeriodService( PeriodService periodService )
+ {
+ this.periodService = periodService;
+ }
private BatchHandlerFactory batchHandlerFactory;
@@ -425,4 +435,44 @@
batchHandler.flush();
}
+
+ // -------------------------------------------------------------------------
+ // PeriodTable
+ // -------------------------------------------------------------------------
+
+ public void generatePeriodTable()
+ {
+ // ---------------------------------------------------------------------
+ // Create table
+ // ---------------------------------------------------------------------
+
+ Collection<Period> periods = periodService.getAllPeriods();
+
+ resourceTableStore.createPeriodStructure();
+
+ // ---------------------------------------------------------------------
+ // Populate table
+ // ---------------------------------------------------------------------
+
+ BatchHandler<Object> batchHandler = batchHandlerFactory.createBatchHandler( GenericBatchHandler.class ).
+ setTableName( ResourceTableStore.TABLE_NAME_PERIOD_STRUCTURE ).init();
+
+ for ( Period period : periods )
+ {
+ final Date startDate = period.getStartDate();
+
+ final List<String> values = new ArrayList<String>();
+
+ values.add( String.valueOf( period.getId() ) );
+
+ for ( PeriodType periodType : PeriodType.PERIOD_TYPES )
+ {
+ values.add( periodType.createPeriod( startDate ).getIsoDate() );
+ }
+
+ batchHandler.addObject( values );
+ }
+
+ batchHandler.flush();
+ }
}
=== 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 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java 2012-11-25 20:18:52 +0000
@@ -36,6 +36,7 @@
import org.hisp.dhis.dataelement.DataElementGroupSet;
import org.hisp.dhis.indicator.IndicatorGroupSet;
import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
+import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.resourcetable.ResourceTableStore;
import org.hisp.dhis.resourcetable.statement.CreateCategoryTableStatement;
import org.hisp.dhis.resourcetable.statement.CreateDataElementGroupSetTableStatement;
@@ -112,7 +113,7 @@
// Do nothing, table does not exist
}
- String sql = "CREATE TABLE " + TABLE_NAME_CATEGORY_OPTION_COMBO_NAME +
+ final String sql = "CREATE TABLE " + TABLE_NAME_CATEGORY_OPTION_COMBO_NAME +
" ( categoryoptioncomboid INTEGER NOT NULL, categoryoptioncomboname VARCHAR(250) )";
log.info( "Create category option combo name table SQL: " + sql );
@@ -215,11 +216,38 @@
// Do nothing, table does not exist
}
- String sql = "CREATE TABLE " + TABLE_NAME_DATA_ELEMENT_STRUCTURE +
+ final String sql = "CREATE TABLE " + TABLE_NAME_DATA_ELEMENT_STRUCTURE +
" ( dataelementid INTEGER NOT NULL, dataelementname VARCHAR(250), periodtypeid INTEGER, periodtypename VARCHAR(250) )";
log.info( "Create data element structure SQL: " + sql );
jdbcTemplate.update( sql );
}
+
+ // -------------------------------------------------------------------------
+ // PeriodTable
+ // -------------------------------------------------------------------------
+
+ public void createPeriodStructure()
+ {
+ try
+ {
+ jdbcTemplate.update( "DROP TABLE " + TABLE_NAME_PERIOD_STRUCTURE );
+ }
+ catch ( BadSqlGrammarException ex )
+ {
+ // Do nothing, table does not exist
+ }
+
+ String sql = "CREATE TABLE " + TABLE_NAME_PERIOD_STRUCTURE + " (periodid INTEGER NOT NULL";
+
+ for ( PeriodType periodType : PeriodType.PERIOD_TYPES )
+ {
+ sql += ", " + periodType.getName().toLowerCase() + " VARCHAR(100)";
+ }
+
+ sql += ")";
+
+ jdbcTemplate.update( sql );
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml 2012-11-23 12:51:00 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml 2012-11-25 20:18:52 +0000
@@ -18,6 +18,7 @@
<property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
<property name="indicatorService" ref="org.hisp.dhis.indicator.IndicatorService" />
+ <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
<property name="batchHandlerFactory" ref="batchHandlerFactory" />
</bean>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/resourcetable/GenerateResourceTableAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/resourcetable/GenerateResourceTableAction.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/resourcetable/GenerateResourceTableAction.java 2012-11-25 20:18:52 +0000
@@ -113,6 +113,13 @@
{
this.dataElementStructure = dataElementStructure;
}
+
+ private boolean periodStructure;
+
+ public void setPeriodStructure( boolean periodStructure )
+ {
+ this.periodStructure = periodStructure;
+ }
// -------------------------------------------------------------------------
// Action implementation
@@ -160,6 +167,11 @@
resourceTableService.generateDataElementTable();
}
+ if ( periodStructure )
+ {
+ resourceTableService.generatePeriodTable();
+ }
+
log.info( "Generated resource tables" );
sqlViewService.createAllViewTables();
=== 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 2012-09-12 15:41:22 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/resources/org/hisp/dhis/dataadmin/i18n_module.properties 2012-11-25 20:18:52 +0000
@@ -309,4 +309,5 @@
update_option=Update option
removing_min_max_values=Removing min-max values
generating_min_max_values=Generating min-max values
-done=Done
\ No newline at end of file
+done=Done
+period_structure=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/javascript/resourceTable.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/resourceTable.js 2012-02-24 08:44:29 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/javascript/resourceTable.js 2012-11-25 20:18:52 +0000
@@ -10,22 +10,26 @@
var categoryStructure = document.getElementById( "categoryStructure" ).checked;
var categoryOptionComboName = document.getElementById( "categoryOptionComboName" ).checked;
var dataElementStructure = document.getElementById( "dataElementStructure" ).checked;
+ var periodStructure = document.getElementById( "periodStructure" ).checked;
- if ( organisationUnit || dataElementGroupSetStructure || indicatorGroupSetStructure ||
- organisationUnitGroupSetStructure || categoryStructure || categoryOptionComboName || dataElementStructure )
+ if ( organisationUnit || dataElementGroupSetStructure || indicatorGroupSetStructure || organisationUnitGroupSetStructure ||
+ categoryStructure || categoryOptionComboName || dataElementStructure || periodStructure )
{
setWaitMessage( i18n_generating_resource_tables );
- var params = "organisationUnit=" + organisationUnit +
- "&dataElementGroupSetStructure=" + dataElementGroupSetStructure +
- "&indicatorGroupSetStructure=" + indicatorGroupSetStructure +
- "&organisationUnitGroupSetStructure=" + organisationUnitGroupSetStructure +
- "&categoryStructure=" + categoryStructure +
- "&categoryOptionComboName=" + categoryOptionComboName +
- "&dataElementStructure=" + dataElementStructure;
+ var params = {
+ organisationUnit: organisationUnit,
+ dataElementGroupSetStructure: dataElementGroupSetStructure,
+ indicatorGroupSetStructure: indicatorGroupSetStructure,
+ organisationUnitGroupSetStructure: organisationUnitGroupSetStructure,
+ categoryStructure: categoryStructure,
+ categoryOptionComboName: categoryOptionComboName,
+ dataElementStructure: dataElementStructure,
+ periodStructure: periodStructure
+ };
$.ajax({
- type: "POST",
+ type: "post",
url: "generateResourceTable.action",
data: params,
dataType: "xml",
@@ -51,4 +55,5 @@
document.getElementById( "categoryStructure" ).checked = selected;
document.getElementById( "categoryOptionComboName" ).checked = selected;
document.getElementById( "dataElementStructure" ).checked = selected;
+ document.getElementById( "periodStructure" ).checked = selected;
}
=== 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 2012-07-24 06:41:17 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/resourceTableForm.vm 2012-11-25 20:18:52 +0000
@@ -42,6 +42,11 @@
<label for="dataElementStructure">$i18n.getString( "data_element_structure" ) <span style="color:#606060">(_dataelementstructure)</span></label>
</p>
+<p>
+ <input type="checkbox" name="resourceTableCheckBox" id="periodStructure"/>
+ <label for="periodStructure">$i18n.getString( "period_structure" ) <span style="color:#606060">(_periodstructure)</span></label>
+</p>
+
<table>
<tr>
<td>