dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21120
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9916: Report table, using lists of dimensions instead of hard-coded boolean properties to determine whi...
------------------------------------------------------------
revno: 9916
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-02-27 17:14:56 +0100
message:
Report table, using lists of dimensions instead of hard-coded boolean properties to determine which dimensions go on columns, rows, filters
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml
dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.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/reporttable/ReportTable.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java 2013-02-27 11:10:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java 2013-02-27 16:14:56 +0000
@@ -27,16 +27,22 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonView;
-import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.apache.commons.lang.StringUtils;
-import org.hisp.dhis.common.*;
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.BaseNameableObject;
+import org.hisp.dhis.common.CombinationGenerator;
+import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.ListMap;
+import org.hisp.dhis.common.NameableObject;
import org.hisp.dhis.common.adapter.JacksonMapListIdentifiableObjectSerializer;
import org.hisp.dhis.common.adapter.JacksonPeriodDeserializer;
import org.hisp.dhis.common.adapter.JacksonPeriodSerializer;
@@ -58,7 +64,14 @@
import org.hisp.dhis.period.RelativePeriods;
import org.hisp.dhis.period.comparator.AscendingPeriodComparator;
-import java.util.*;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
/**
* The ReportTable object represents a customizable database table. It has
@@ -66,7 +79,6 @@
* columns.
*
* @author Lars Helge Overland
- * @version $Id$
*/
@JacksonXmlRootElement( localName = "reportTable", namespace = DxfNamespaces.DXF_2_0)
public class ReportTable
@@ -76,7 +88,12 @@
* Determines if a de-serialized file is compatible with this class.
*/
private static final long serialVersionUID = 5618655666320890565L;
-
+
+ public static final String DATA_X_DIM_ID = "dx"; // IN, DE, DS
+ public static final String CATEGORYOPTIONCOMBO_DIM_ID = "coc";
+ public static final String PERIOD_DIM_ID = "pe";
+ public static final String ORGUNIT_DIM_ID = "ou";
+
public static final String DATAELEMENT_ID = "dataelementid";
public static final String CATEGORYCOMBO_ID = "categoryoptioncomboid";
public static final String CATEGORYOPTION_ID = "categoryoptionid";
@@ -235,6 +252,20 @@
@Scanned
private List<OrganisationUnitGroup> organisationUnitGroups = new ArrayList<OrganisationUnitGroup>();
+ /**
+ * Dimensions to crosstabulate / use as columns.
+ */
+ private List<String> columnDimensions = new ArrayList<String>();
+
+ /**
+ * Dimensions to use as rows.
+ */
+ private List<String> rowDimensions = new ArrayList<String>();
+
+ /**
+ * Dimensions to use as filter.
+ */
+ private List<String> filterDimensions = new ArrayList<String>();
/**
* The DataElementCategoryCombo for the ReportTable.
@@ -242,22 +273,6 @@
private DataElementCategoryCombo categoryCombo;
/**
- * Whether to crosstabulate on the Indicator dimension, which also
- * represents DataElements and DataSets.
- */
- private boolean doIndicators;
-
- /**
- * Whether to crosstabulate on the Period dimension.
- */
- private boolean doPeriods;
-
- /**
- * Whether to crosstabulate on the OrganisationUnit dimension.
- */
- private boolean doUnits;
-
- /**
* The RelativePeriods of the ReportTable.
*/
private RelativePeriods relatives;
@@ -450,13 +465,25 @@
this.relativeUnits = relativeUnits;
this.organisationUnitGroups = organisationUnitGroups;
this.categoryCombo = categoryCombo;
- this.doIndicators = doIndicators;
- this.doPeriods = doPeriods;
- this.doUnits = doUnits;
this.relatives = relatives;
this.reportParams = reportParams;
this.i18nFormat = i18nFormat;
this.reportingPeriodName = reportingPeriodName;
+
+ if ( doIndicators )
+ {
+ columnDimensions.add( DATA_X_DIM_ID );
+ }
+
+ if ( doPeriods )
+ {
+ columnDimensions.add( PERIOD_DIM_ID );
+ }
+
+ if ( doUnits )
+ {
+ columnDimensions.add( ORGUNIT_DIM_ID );
+ }
}
// -------------------------------------------------------------------------
@@ -515,25 +542,25 @@
addIfEmpty( columns ); // Allow for all or none crosstab dimensions
addIfEmpty( rows );
- add( indexColumns, INDICATOR_ID, doIndicators );
- add( indexColumns, PERIOD_ID, doPeriods );
- add( indexColumns, ORGANISATIONUNIT_ID, doUnits );
-
- add( indexUidColumns, INDICATOR_UID, doIndicators );
- add( indexUidColumns, PERIOD_UID, doPeriods );
- add( indexUidColumns, ORGANISATIONUNIT_UID, doUnits );
-
- add( indexNameColumns, INDICATOR_NAME, doIndicators );
- add( indexNameColumns, PERIOD_NAME, doPeriods );
- add( indexNameColumns, ORGANISATIONUNIT_NAME, doUnits );
-
- add( indexCodeColumns, INDICATOR_CODE, doIndicators );
- add( indexCodeColumns, PERIOD_CODE, doPeriods );
- add( indexCodeColumns, ORGANISATIONUNIT_CODE, doUnits );
-
- add( indexDescriptionColumns, INDICATOR_DESCRIPTION, doIndicators );
- add( indexDescriptionColumns, PERIOD_DESCRIPTION, doPeriods );
- add( indexDescriptionColumns, ORGANISATIONUNIT_DESCRIPTION, doUnits );
+ add( indexColumns, INDICATOR_ID, isDoIndicators() );
+ add( indexColumns, PERIOD_ID, isDoPeriods() );
+ add( indexColumns, ORGANISATIONUNIT_ID, isDoUnits() );
+
+ add( indexUidColumns, INDICATOR_UID, isDoIndicators() );
+ add( indexUidColumns, PERIOD_UID, isDoPeriods() );
+ add( indexUidColumns, ORGANISATIONUNIT_UID, isDoUnits() );
+
+ add( indexNameColumns, INDICATOR_NAME, isDoIndicators() );
+ add( indexNameColumns, PERIOD_NAME, isDoPeriods() );
+ add( indexNameColumns, ORGANISATIONUNIT_NAME, isDoUnits() );
+
+ add( indexCodeColumns, INDICATOR_CODE, isDoIndicators() );
+ add( indexCodeColumns, PERIOD_CODE, isDoPeriods() );
+ add( indexCodeColumns, ORGANISATIONUNIT_CODE, isDoUnits() );
+
+ add( indexDescriptionColumns, INDICATOR_DESCRIPTION, isDoIndicators() );
+ add( indexDescriptionColumns, PERIOD_DESCRIPTION, isDoPeriods() );
+ add( indexDescriptionColumns, ORGANISATIONUNIT_DESCRIPTION, isDoUnits() );
}
// -------------------------------------------------------------------------
@@ -846,7 +873,49 @@
{
return relatives != null && !relatives.getRelativePeriods().isEmpty();
}
-
+
+ public boolean isDoIndicators()
+ {
+ return columnDimensions.contains( DATA_X_DIM_ID );
+ }
+
+ public void setDoIndicators( boolean doIndicators )
+ {
+ if ( doIndicators )
+ {
+ this.columnDimensions.remove( DATA_X_DIM_ID );
+ this.columnDimensions.add( DATA_X_DIM_ID );
+ }
+ }
+
+ public boolean isDoPeriods()
+ {
+ return columnDimensions.contains( PERIOD_DIM_ID );
+ }
+
+ public void setDoPeriods( boolean doPeriods )
+ {
+ if ( doPeriods )
+ {
+ this.columnDimensions.remove( PERIOD_DIM_ID );
+ this.columnDimensions.add( PERIOD_DIM_ID );
+ }
+ }
+
+ public boolean isDoUnits()
+ {
+ return columnDimensions.contains( ORGUNIT_DIM_ID );
+ }
+
+ public void setDoUnits( boolean doUnits )
+ {
+ if ( doUnits )
+ {
+ this.columnDimensions.remove( ORGUNIT_DIM_ID );
+ this.columnDimensions.add( ORGUNIT_DIM_ID );
+ }
+ }
+
public void removeAllDataElements()
{
dataElements.clear();
@@ -881,6 +950,21 @@
{
organisationUnitGroups.clear();
}
+
+ public void removeAllColumnDimensions()
+ {
+ columnDimensions.clear();
+ }
+
+ public void removeAllRowDimensions()
+ {
+ rowDimensions.clear();
+ }
+
+ public void removeAllFilterDimensions()
+ {
+ filterDimensions.clear();
+ }
// -------------------------------------------------------------------------
// Supportive methods
@@ -890,17 +974,17 @@
{
List<NameableObject[]> arrays = new ArrayList<NameableObject[]>();
- if ( (doIndicators && crosstab) || (!doIndicators && !crosstab) )
+ if ( (isDoIndicators() && crosstab) || (!isDoIndicators() && !crosstab) )
{
arrays.add( allIndicators.toArray( IRT ) );
}
- if ( (doPeriods && crosstab) || (!doPeriods && !crosstab) )
+ if ( (isDoPeriods() && crosstab) || (!isDoPeriods() && !crosstab) )
{
arrays.add( allPeriods.toArray( IRT ) );
}
- if ( (doUnits && crosstab) || (!doUnits && !crosstab) )
+ if ( (isDoUnits() && crosstab) || (!isDoUnits() && !crosstab) )
{
arrays.add( allUnits.toArray( IRT ) );
}
@@ -1165,6 +1249,48 @@
}
@JsonProperty
+ @JsonView( {DetailedView.class, ExportView.class} )
+ @JacksonXmlElementWrapper( localName = "columnDimensions", namespace = DxfNamespaces.DXF_2_0)
+ @JacksonXmlProperty( localName = "column", namespace = DxfNamespaces.DXF_2_0)
+ public List<String> getColumnDimensions()
+ {
+ return columnDimensions;
+ }
+
+ public void setColumnDimensions( List<String> columnDimensions )
+ {
+ this.columnDimensions = columnDimensions;
+ }
+
+ @JsonProperty
+ @JsonView( {DetailedView.class, ExportView.class} )
+ @JacksonXmlElementWrapper( localName = "rowDimensions", namespace = DxfNamespaces.DXF_2_0)
+ @JacksonXmlProperty( localName = "row", namespace = DxfNamespaces.DXF_2_0)
+ public List<String> getRowDimensions()
+ {
+ return rowDimensions;
+ }
+
+ public void setRowDimensions( List<String> rowDimensions )
+ {
+ this.rowDimensions = rowDimensions;
+ }
+
+ @JsonProperty
+ @JsonView( {DetailedView.class, ExportView.class} )
+ @JacksonXmlElementWrapper( localName = "filterDimensions", namespace = DxfNamespaces.DXF_2_0)
+ @JacksonXmlProperty( localName = "filter", namespace = DxfNamespaces.DXF_2_0)
+ public List<String> getFilterDimensions()
+ {
+ return filterDimensions;
+ }
+
+ public void setFilterDimensions( List<String> filterDimensions )
+ {
+ this.filterDimensions = filterDimensions;
+ }
+
+ @JsonProperty
@JsonSerialize( as = BaseIdentifiableObject.class )
@JsonView( {DetailedView.class, ExportView.class} )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
@@ -1178,45 +1304,6 @@
this.categoryCombo = categoryCombo;
}
- @JsonProperty
- @JsonView( {DetailedView.class, ExportView.class} )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
- public boolean isDoIndicators()
- {
- return doIndicators;
- }
-
- public void setDoIndicators( boolean doIndicators )
- {
- this.doIndicators = doIndicators;
- }
-
- @JsonProperty
- @JsonView( {DetailedView.class, ExportView.class} )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
- public boolean isDoPeriods()
- {
- return doPeriods;
- }
-
- public void setDoPeriods( boolean doPeriods )
- {
- this.doPeriods = doPeriods;
- }
-
- @JsonProperty
- @JsonView( {DetailedView.class, ExportView.class} )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
- public boolean isDoUnits()
- {
- return doUnits;
- }
-
- public void setDoUnits( boolean doUnits )
- {
- this.doUnits = doUnits;
- }
-
@JsonProperty( value = "relativePeriods" )
@JsonView( {DetailedView.class, ExportView.class} )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
@@ -1507,9 +1594,6 @@
regression = reportTable.isRegression();
cumulative = reportTable.isCumulative();
categoryCombo = reportTable.getCategoryCombo() == null ? categoryCombo : reportTable.getCategoryCombo();
- doIndicators = reportTable.isDoIndicators();
- doPeriods = reportTable.isDoPeriods();
- doUnits = reportTable.isDoUnits();
relatives = reportTable.getRelatives() == null ? relatives : reportTable.getRelatives();
reportParams = reportTable.getReportParams() == null ? reportParams : reportTable.getReportParams();
sortOrder = reportTable.getSortOrder() == null ? sortOrder : reportTable.getSortOrder();
@@ -1540,6 +1624,15 @@
removeAllOrganisationUnitGroups();
organisationUnitGroups.addAll( reportTable.getOrganisationUnitGroups() );
+
+ removeAllColumnDimensions();
+ columnDimensions.addAll( reportTable.getColumnDimensions() );
+
+ removeAllRowDimensions();
+ rowDimensions.addAll( reportTable.getRowDimensions() );
+
+ removeAllFilterDimensions();
+ filterDimensions.addAll( reportTable.getFilterDimensions() );
}
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2013-02-26 19:53:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2013-02-27 16:14:56 +0000
@@ -27,6 +27,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.amplecode.quick.StatementHolder;
import org.amplecode.quick.StatementManager;
import org.apache.commons.logging.Log;
@@ -34,13 +41,6 @@
import org.hisp.dhis.system.startup.AbstractStartupRoutine;
import org.springframework.transaction.annotation.Transactional;
-import java.sql.ResultSet;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
/**
* @author Lars Helge Overland
*/
@@ -176,10 +176,6 @@
executeSql( "update dataelement set texttype='text' where valuetype='string' and texttype is null" );
- // ---------------------------------------------------------------------
- // Update tables for dimensional model
- // ---------------------------------------------------------------------
-
// categories_categoryoptions
// set to 0 temporarily
int c1 = executeSql( "UPDATE categories_categoryoptions SET sort_order=0 WHERE sort_order is NULL OR sort_order=0" );
@@ -524,9 +520,56 @@
executeSql( "ALTER TABLE usergroup DROP CONSTRAINT usergroup_name_key" );
executeSql( "ALTER TABLE datadictionary DROP CONSTRAINT datadictionary_name_key" );
+ upgradeReportTableColumns();
+
log.info( "Tables updated" );
}
+ private void upgradeReportTableColumns()
+ {
+ try
+ {
+ String sql = "select reporttableid, doindicators, doperiods, dounits from reporttable";
+
+ ResultSet rs = statementManager.getHolder().getStatement().executeQuery( sql );
+
+ while ( rs.next() )
+ {
+ int id = rs.getInt( "reporttableid" );
+ boolean doIndicators = rs.getBoolean( "doindicators" );
+ boolean doPeriods = rs.getBoolean( "doperiods" );
+ boolean doUnits = rs.getBoolean( "dounits" );
+
+ int sortOrder = 0;
+
+ if ( doIndicators )
+ {
+ executeSql( "insert into reporttable_columns (reporttableid, dimension, sort_order) values (" + id + ",'dx'," + sortOrder + ");" );
+ sortOrder++;
+ }
+
+ if ( doPeriods )
+ {
+ executeSql( "insert into reporttable_columns (reporttableid, dimension, sort_order) values (" + id + ",'pe'," + sortOrder + ");" );
+ sortOrder++;
+ }
+
+ if ( doUnits )
+ {
+ executeSql( "insert into reporttable_columns (reporttableid, dimension, sort_order) values (" + id + ",'ou'," + sortOrder + ");" );
+ }
+ }
+
+ executeSql( "alter table reporttable drop column doindicators" );
+ executeSql( "alter table reporttable drop column doperiods" );
+ executeSql( "alter table reporttable drop column dounits" );
+ }
+ catch ( Exception ex )
+ {
+ log.debug( ex );
+ }
+ }
+
private List<Integer> getDistinctIdList( String table, String col1 )
{
StatementHolder holder = statementManager.getHolder();
@@ -686,7 +729,6 @@
if ( isUpdated.next() )
{
-
ResultSet resultSet = statement
.executeQuery( "SELECT associationid, dataentryformid FROM dataentryformassociation WHERE associationtablename = 'programstage'" );
@@ -707,7 +749,5 @@
{
holder.close();
}
-
}
-
}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml 2013-02-26 18:18:49 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/org/hisp/dhis/reporttable/hibernate/ReportTable.hbm.xml 2013-02-27 16:14:56 +0000
@@ -81,11 +81,26 @@
foreign-key="fk_reporttable_orgunitgroups_orgunitgroupid" />
</list>
- <property name="doIndicators" />
-
- <property name="doPeriods" />
-
- <property name="doUnits" />
+ <list name="columnDimensions" table="reporttable_columns">
+ <cache usage="read-write" />
+ <key column="reporttableid" foreign-key="fk_reporttable_columns_reporttableid" />
+ <list-index column="sort_order" base="0" />
+ <element type="string" column="dimension" />
+ </list>
+
+ <list name="rowDimensions" table="reporttable_rows">
+ <cache usage="read-write" />
+ <key column="reporttableid" foreign-key="fk_reporttable_rows_reporttableid" />
+ <list-index column="sort_order" base="0" />
+ <element type="string" column="dimension" />
+ </list>
+
+ <list name="filterDimensions" table="reporttable_filters">
+ <cache usage="read-write" />
+ <key column="reporttableid" foreign-key="fk_reporttable_filters_reporttableid" />
+ <list-index column="sort_order" base="0" />
+ <element type="string" column="dimension" />
+ </list>
<component name="relatives">
<property name="reportingMonth" />
=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java 2012-11-20 08:44:23 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java 2013-02-27 16:14:56 +0000
@@ -89,7 +89,11 @@
emptyTable( "reporttable_indicators" );
emptyTable( "reporttable_periods" );
emptyTable( "reporttable_organisationunits" );
+ emptyTable( "reporttable_dataelementgroups" );
emptyTable( "reporttable_orgunitgroups" );
+ emptyTable( "reporttable_columns" );
+ emptyTable( "reporttable_rows" );
+ emptyTable( "reporttable_filters" );
emptyTable( "reporttable" );
emptyTable( "orgunitgroupsetmembers" );
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java 2013-02-27 10:13:13 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java 2013-02-27 16:14:56 +0000
@@ -123,6 +123,8 @@
public void postJsonObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception
{
ReportTable reportTable = JacksonUtils.fromJson( input, ReportTable.class );
+ System.out.println("rt " + reportTable.getName());
+ System.out.println(reportTable.getColumnDimensions());
reportTable.readPresentationProps();