dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #27805
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13849: Data browser, minor refactor and bugfix
------------------------------------------------------------
revno: 13849
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-01-25 16:05:26 +0200
message:
Data browser, minor refactor and bugfix
removed:
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/ActionSupport.java
modified:
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/DefaultDataBrowserGridService.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/jdbc/JDBCDataBrowserStore.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/DataBrowserAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataBrowserGrid.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-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/DefaultDataBrowserGridService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/DefaultDataBrowserGridService.java 2014-01-24 08:41:50 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/DefaultDataBrowserGridService.java 2014-01-25 14:05:26 +0000
@@ -34,7 +34,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
-import java.util.Iterator;
import java.util.List;
import org.hisp.dhis.common.Grid;
@@ -55,12 +54,9 @@
public class DefaultDataBrowserGridService
implements DataBrowserGridService
{
- private static final String STARTDATE = "1900-01-01";
-
- private static final String ENDDATE = "3000-01-01";
-
+ private static final String DEFAULT_STARTDATE = "1900-01-01";
+ private static final String DEFAULT_ENDDATE = "3000-01-01";
private static final String SPACE = " ";
-
private static final String DASH = " - ";
// -------------------------------------------------------------------------
@@ -83,15 +79,11 @@
// -------------------------------------------------------------------------
// DataBrowserGridService implementation
- //
- // Basic
// -------------------------------------------------------------------------
- public Grid getDataSetsInPeriod( String startDate, String endDate, PeriodType periodType, I18nFormat format,
- boolean isZeroAdded )
+ public Grid getDataSetsInPeriod( String startDate, String endDate, PeriodType periodType, I18nFormat format, boolean isZeroAdded )
{
- List<Integer> betweenPeriodIds = getAllPeriodIdsBetweenDatesOnPeriodType( startDate, endDate, periodType,
- format );
+ List<Integer> betweenPeriodIds = getAllPeriodIdsBetweenDatesOnPeriodType( startDate, endDate, periodType, format );
return dataBrowserGridStore.getDataSetsBetweenPeriods( betweenPeriodIds, periodType, isZeroAdded );
}
@@ -99,8 +91,7 @@
public Grid getDataElementGroupsInPeriod( String startDate, String endDate, PeriodType periodType,
I18nFormat format, boolean isZeroAdded )
{
- List<Integer> betweenPeriodIds = getAllPeriodIdsBetweenDatesOnPeriodType( startDate, endDate, periodType,
- format );
+ List<Integer> betweenPeriodIds = getAllPeriodIdsBetweenDatesOnPeriodType( startDate, endDate, periodType, format );
return dataBrowserGridStore.getDataElementGroupsBetweenPeriods( betweenPeriodIds, isZeroAdded );
}
@@ -108,8 +99,7 @@
public Grid getOrgUnitGroupsInPeriod( String startDate, String endDate, PeriodType periodType, I18nFormat format,
boolean isZeroAdded )
{
- List<Integer> betweenPeriodIds = getAllPeriodIdsBetweenDatesOnPeriodType( startDate, endDate, periodType,
- format );
+ List<Integer> betweenPeriodIds = getAllPeriodIdsBetweenDatesOnPeriodType( startDate, endDate, periodType, format );
return dataBrowserGridStore.getOrgUnitGroupsBetweenPeriods( betweenPeriodIds, isZeroAdded );
}
@@ -262,41 +252,34 @@
// Supportive methods
// -------------------------------------------------------------------------
/**
- * Helper-method that finds all PeriodIds between a given period. Uses
- * functionality already in the DHIS. Returns a list with all id's that was
- * found.
- *
- * @param startDate
- * @param endDate
- * @param periodType
- * @return List<Integer>
+ * Returns identifiers of periods between the given dates for the given period
+ * type.
*/
private List<Integer> getAllPeriodIdsBetweenDatesOnPeriodType( String startDate, String endDate,
PeriodType periodType, I18nFormat i18nFormat )
{
- if ( startDate == null || startDate.length() == 0 )
+ if ( startDate == null || startDate.isEmpty() )
{
- startDate = STARTDATE;
+ startDate = DEFAULT_STARTDATE;
}
- if ( endDate == null || endDate.length() == 0 )
+ if ( endDate == null || endDate.isEmpty() )
{
- endDate = ENDDATE;
+ endDate = DEFAULT_ENDDATE;
}
Date date1 = i18nFormat.parseDate( startDate );
Date date2 = i18nFormat.parseDate( endDate );
- Collection<Period> pp = periodService.getPeriodsBetweenDates( periodType, date1, date2 );
+ Collection<Period> periods = periodService.getPeriodsBetweenDates( periodType, date1, date2 );
- Iterator<Period> it = pp.iterator();
List<Integer> betweenPeriodIds = new ArrayList<Integer>();
- while ( it.hasNext() )
+ for ( Period period : periods )
{
- betweenPeriodIds.add( it.next().getId() );
+ betweenPeriodIds.add( period.getId() );
}
- if ( betweenPeriodIds.size() <= 0 )
+ if ( betweenPeriodIds.isEmpty() )
{
betweenPeriodIds.add( -1 );
}
@@ -322,8 +305,8 @@
Date date1 = sdf.parse( fromDate );
Date date2 = sdf.parse( toDate );
- List<Period> periods = new ArrayList<Period>( periodService.getPeriodsBetweenDates( periodType, date1,
- date2 ) );
+ List<Period> periods = new ArrayList<Period>( periodService.getPeriodsBetweenDates(
+ periodType, date1, date2 ) );
if ( periods.isEmpty() )
{
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/jdbc/JDBCDataBrowserStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/jdbc/JDBCDataBrowserStore.java 2013-08-23 16:00:30 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/databrowser/jdbc/JDBCDataBrowserStore.java 2014-01-25 14:05:26 +0000
@@ -31,6 +31,8 @@
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.common.GridHeader;
import org.hisp.dhis.databrowser.DataBrowserGridStore;
@@ -49,6 +51,8 @@
public class JDBCDataBrowserStore
implements DataBrowserGridStore
{
+ private static final Log log = LogFactory.getLog( JDBCDataBrowserStore.class );
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -92,15 +96,14 @@
sqlsb.append( "ORDER BY counts_of_aggregated_values DESC)" );
// Gets all the dataSets in a period with a count attached to the
- // dataSet. The table returned has only 2 columns. They are created here
- // in this method directly
+ // dataSet. The table returned has 2 columns.
Grid dataSetGrid = new ListGrid();
dataSetGrid.addHeader( new GridHeader( "drilldown_data_set", false, false ) );
dataSetGrid.addHeader( new GridHeader( "counts_of_aggregated_values", false, false ) );
- fillUpDataBasic( dataSetGrid, sqlsb, isZeroAdded, jdbcTemplate );
+ populateGrid( dataSetGrid, sqlsb.toString(), isZeroAdded, jdbcTemplate );
return dataSetGrid;
}
@@ -122,7 +125,7 @@
gridDEG.addHeader( new GridHeader( "drilldown_data_element_group", false, false ) );
gridDEG.addHeader( new GridHeader( "counts_of_aggregated_values", false, false ) );
- fillUpDataBasic( gridDEG, sqlsb, isZeroAdded, jdbcTemplate );
+ populateGrid( gridDEG, sqlsb.toString(), isZeroAdded, jdbcTemplate );
return gridDEG;
}
@@ -145,7 +148,7 @@
gridOUG.addHeader( new GridHeader( "drilldown_orgunit_group", false, false ) );
gridOUG.addHeader( new GridHeader( "counts_of_aggregated_values", false, false ) );
- fillUpDataBasic( gridOUG, sqlsb, isZeroAdded, jdbcTemplate );
+ populateGrid( gridOUG, sqlsb.toString(), isZeroAdded, jdbcTemplate );
return gridOUG;
}
@@ -165,7 +168,7 @@
sqlsb.append( "ORDER BY de.name) " );
grid.addHeader( new GridHeader( "drilldown_data_element", false, false ) );
- setMetaStructure( grid, sqlsb, metaIds, jdbcTemplate );
+ populateMetaStructure( grid, sqlsb.toString(), metaIds, jdbcTemplate );
}
public void setDataElementStructureForDataElementGroup( Grid grid, Integer dataElementGroupId, List<Integer> metaIds )
@@ -180,7 +183,7 @@
sqlsb.append( "ORDER BY de.name) " );
grid.addHeader( new GridHeader( "drilldown_data_element", false, false ) );
- setMetaStructure( grid, sqlsb, metaIds, jdbcTemplate );
+ populateMetaStructure( grid, sqlsb.toString(), metaIds, jdbcTemplate );
}
public void setDataElementGroupStructureForOrgUnitGroup( Grid grid, Integer orgUnitGroupId, List<Integer> metaIds )
@@ -198,7 +201,7 @@
sqlsb.append( "ORDER BY deg.name ASC) " );
grid.addHeader( new GridHeader( "drilldown_data_element_group", false, false ) );
- setMetaStructure( grid, sqlsb, metaIds, jdbcTemplate );
+ populateMetaStructure( grid, sqlsb.toString(), metaIds, jdbcTemplate );
}
@@ -212,7 +215,7 @@
sqlsb.append( "ORDER BY o.name)" );
grid.addHeader( new GridHeader( "drilldown_orgunit", false, false ) );
- setMetaStructure( grid, sqlsb, metaIds, jdbcTemplate );
+ populateMetaStructure( grid, sqlsb.toString(), metaIds, jdbcTemplate );
}
public void setDataElementStructureForOrgUnit( Grid grid, Integer orgUnitId, List<Integer> metaIds )
@@ -222,7 +225,7 @@
sqlsb.append( statementBuilder.queryDataElementStructureForOrgUnit() );
grid.addHeader( new GridHeader( "drilldown_data_element", false, false ) );
- setMetaStructure( grid, sqlsb, metaIds, jdbcTemplate );
+ populateMetaStructure( grid, sqlsb.toString(), metaIds, jdbcTemplate );
}
// -------------------------------------------------------------------------
@@ -259,7 +262,7 @@
sqlsb.append( i == betweenPeriodIds.size() ? "ORDER BY ColumnHeader" : " UNION " );
}
- return fillUpDataAdvance( grid, sqlsb, metaIds, isZeroAdded, jdbcTemplate );
+ return populateGridAdvanced( grid, sqlsb.toString(), metaIds, isZeroAdded, jdbcTemplate );
}
public Integer setCountDataElementsForDataElementGroupBetweenPeriods( Grid grid, Integer dataElementGroupId,
@@ -283,7 +286,7 @@
sqlsb.append( i == betweenPeriodIds.size() ? "ORDER BY ColumnHeader" : " UNION " );
}
- return fillUpDataAdvance( grid, sqlsb, metaIds, isZeroAdded, jdbcTemplate );
+ return populateGridAdvanced( grid, sqlsb.toString(), metaIds, isZeroAdded, jdbcTemplate );
}
public Integer setCountDataElementGroupsForOrgUnitGroupBetweenPeriods( Grid grid, Integer orgUnitGroupId,
@@ -308,18 +311,18 @@
sqlsb.append( i == betweenPeriodIds.size() ? "ORDER BY ColumnHeader" : " UNION " );
}
- return fillUpDataAdvance( grid, sqlsb, metaIds, isZeroAdded, jdbcTemplate );
+ return populateGridAdvanced( grid, sqlsb.toString(), metaIds, isZeroAdded, jdbcTemplate );
}
public Integer setCountOrgUnitsBetweenPeriods( Grid grid, Integer orgUnitParent, List<Integer> betweenPeriodIds,
Integer maxLevel, List<Integer> metaIds, boolean isZeroAdded )
{
- StringBuffer sqlsbDescentdants = new StringBuffer();
+ StringBuffer sql = new StringBuffer();
- boolean valid = this.setUpQueryForDrillDownDescendants( sqlsbDescentdants, orgUnitParent, betweenPeriodIds,
+ boolean valid = this.setUpQueryForDrillDownDescendants( sql, orgUnitParent, betweenPeriodIds,
maxLevel );
- return (valid ? fillUpDataAdvance( grid, sqlsbDescentdants, metaIds, isZeroAdded, jdbcTemplate ) : 0);
+ return valid ? populateGridAdvanced( grid, sql.toString(), metaIds, isZeroAdded, jdbcTemplate ) : 0;
}
@@ -330,23 +333,23 @@
sqlsb.append( statementBuilder.queryRawDataElementsForOrgUnitBetweenPeriods( orgUnitId, betweenPeriodIds ) );
- return fillUpDataAdvance( grid, sqlsb, metaIds, isZeroAdded, jdbcTemplate );
+ return populateGridAdvanced( grid, sqlsb.toString(), metaIds, isZeroAdded, jdbcTemplate );
}
// -------------------------------------------------------------------------
// Private methods
// -------------------------------------------------------------------------
- private static void setMetaStructure( Grid grid, StringBuffer sqlsb, List<Integer> metaIds, JdbcTemplate jdbcTemplate )
+ private static void populateMetaStructure( Grid grid, final String sql, List<Integer> metaIds, JdbcTemplate jdbcTemplate )
{
- Integer metaId = null;
- String metaName = null;
- SqlRowSet resultSet = jdbcTemplate.queryForRowSet( sqlsb.toString() );
+ log.info( "Meta SQL: " + sql );
+
+ SqlRowSet resultSet = jdbcTemplate.queryForRowSet( sql );
while ( resultSet.next() )
{
- metaId = resultSet.getInt( 1 );
- metaName = resultSet.getString( 2 );
+ Integer metaId = resultSet.getInt( 1 );
+ String metaName = resultSet.getString( 2 );
metaIds.add( metaId );
grid.addRow().addValue( new MetaValue( metaId, metaName ) );
@@ -378,9 +381,11 @@
}
}
- private static void fillUpDataBasic( Grid grid, StringBuffer sqlsb, boolean isZeroAdded, JdbcTemplate jdbcTemplate )
+ private static void populateGrid( Grid grid, final String sql, boolean isZeroAdded, JdbcTemplate jdbcTemplate )
{
- SqlRowSet resultSet = jdbcTemplate.queryForRowSet( sqlsb.toString() );
+ log.info( "Grid SQL: " + sql );
+
+ SqlRowSet resultSet = jdbcTemplate.queryForRowSet( sql );
while ( resultSet.next() )
{
@@ -390,15 +395,15 @@
}
}
- private static int fillUpDataAdvance( Grid grid, StringBuffer sqlsb, List<Integer> metaIds, boolean isZeroAdded,
+ private static int populateGridAdvanced( Grid grid, final String sql, List<Integer> metaIds, boolean isZeroAdded,
JdbcTemplate jdbcTemplate )
{
int countRows = 0;
- int rowIndex = -1;
- int columnIndex = -1;
int oldWidth = grid.getWidth();
- SqlRowSet rs = jdbcTemplate.queryForRowSet( sqlsb.toString() );
+ log.info( "Advanced SQL: " + sql );
+
+ SqlRowSet rs = jdbcTemplate.queryForRowSet( sql );
List<Integer> headerIds = new ArrayList<Integer>();
setHeaderStructure( grid, rs, headerIds, isZeroAdded );
@@ -412,8 +417,8 @@
while ( rs.next() )
{
- rowIndex = metaIds.indexOf( rs.getInt( 1 ) );
- columnIndex = headerIds.indexOf( rs.getInt( 4 ) ) + oldWidth;
+ int rowIndex = metaIds.indexOf( rs.getInt( 1 ) );
+ int columnIndex = headerIds.indexOf( rs.getInt( 4 ) ) + oldWidth;
grid.getRow( rowIndex ).set( columnIndex, checkValue( rs.getString( 3 ), isZeroAdded ) );
=== removed file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/ActionSupport.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/ActionSupport.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/ActionSupport.java 1970-01-01 00:00:00 +0000
@@ -1,457 +0,0 @@
-package org.hisp.dhis.dataadmin.action.databrowser;
-
-/*
- * Copyright (c) 2004-2013, 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.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.hisp.dhis.common.Grid;
-import org.hisp.dhis.common.GridHeader;
-import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
-import org.hisp.dhis.databrowser.DataBrowserGridService;
-import org.hisp.dhis.databrowser.MetaValue;
-import org.hisp.dhis.dataelement.DataElementGroup;
-import org.hisp.dhis.dataelement.DataElementService;
-import org.hisp.dhis.dataset.DataSetService;
-import org.hisp.dhis.i18n.I18n;
-import org.hisp.dhis.i18n.I18nFormat;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
-import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.oust.manager.SelectionTreeManager;
-import org.hisp.dhis.paging.ActionPagingSupport;
-import org.hisp.dhis.period.PeriodService;
-import org.hisp.dhis.period.PeriodType;
-
-/**
- * @author Dang Duy Hieu
- * @version $Id$
- */
-public abstract class ActionSupport
- extends ActionPagingSupport<Grid>
-{
- protected static final String KEY_DATABROWSERGRID = "dataBrowserGridResults";
-
- protected static final String TRUE = "on";
-
- protected static final String EMPTY = "";
-
- // -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
-
- protected OrganisationUnitService organisationUnitService;
-
- public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
- {
- this.organisationUnitService = organisationUnitService;
- }
-
- protected DataBrowserGridService dataBrowserGridService;
-
- public void setDataBrowserGridService( DataBrowserGridService dataBrowserGridService )
- {
- this.dataBrowserGridService = dataBrowserGridService;
- }
-
- protected DataElementService dataElementService;
-
- public void setDataElementService( DataElementService dataElementService )
- {
- this.dataElementService = dataElementService;
- }
-
- protected DataSetService dataSetService;
-
- public void setDataSetService( DataSetService dataSetService )
- {
- this.dataSetService = dataSetService;
- }
-
- protected OrganisationUnitGroupService organisationUnitGroupService;
-
- public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
- {
- this.organisationUnitGroupService = organisationUnitGroupService;
- }
-
- protected PeriodService periodService;
-
- public void setPeriodService( PeriodService periodService )
- {
- this.periodService = periodService;
- }
-
- protected SelectionTreeManager selectionTreeManager;
-
- public void setSelectionTreeManager( SelectionTreeManager selectionTreeManager )
- {
- this.selectionTreeManager = selectionTreeManager;
- }
-
- // -------------------------------------------------------------------------
- // I18n & I18nFormat
- // -------------------------------------------------------------------------
-
- protected I18n i18n;
-
- public void setI18n( I18n i18n )
- {
- this.i18n = i18n;
- }
-
- protected I18nFormat format;
-
- public void setFormat( I18nFormat format )
- {
- this.format = format;
- }
-
- // -------------------------------------------------------------------------
- // Parameters
- // -------------------------------------------------------------------------
-
- protected Grid grid;
-
- protected String mode;
-
- protected String toDate;
-
- protected String fromDate;
-
- protected String fromToDate;
-
- protected String periodTypeId;
-
- protected String parent;
-
- protected String tmpParent;
-
- protected String orgunitid;
-
- protected String selectedUnitChanger;
-
- protected String dataElementName;
-
- protected String drillDownCheckBox;
-
- protected String showZeroCheckBox;
-
- protected OrganisationUnit selectedUnit;
-
- protected boolean isSummary;
-
- // -------------------------------------------------------------------------
- // Input
- // -------------------------------------------------------------------------
-
- public void setMode( String mode )
- {
- this.mode = mode;
- }
-
- public void setToDate( String toDate )
- {
- this.toDate = toDate;
- }
-
- public void setFromDate( String fromDate )
- {
- this.fromDate = fromDate;
- }
-
- public void setPeriodTypeId( String periodTypeId )
- {
- this.periodTypeId = periodTypeId;
- }
-
- public void setParent( String parent )
- {
- this.parent = parent;
- }
-
- public void setSelectedUnitChanger( String selectedUnitChanger )
- {
- this.selectedUnitChanger = selectedUnitChanger.trim();
- }
-
- public void setOrgunitid( String orgunitid )
- {
- this.orgunitid = orgunitid;
- }
-
- public void setDrillDownCheckBox( String drillDownCheckBox )
- {
- this.drillDownCheckBox = drillDownCheckBox;
- }
-
- public void setShowZeroCheckBox( String showZeroCheckBox )
- {
- this.showZeroCheckBox = showZeroCheckBox;
- }
-
- public void setSummary( boolean isSummary )
- {
- this.isSummary = isSummary;
- }
-
- // -------------------------------------------------------------------------
- // Output
- // -------------------------------------------------------------------------
-
- public boolean isSummary()
- {
- return isSummary;
- }
-
- public Grid getGrid()
- {
- return grid;
- }
-
- public Collection<DataElementGroup> getDataElementGroups()
- {
- return dataElementService.getAllDataElementGroups();
- }
-
- public String getMode()
- {
- return mode;
- }
-
- public String getToDate()
- {
- return toDate;
- }
-
- public String getFromDate()
- {
- return fromDate;
- }
-
- public String getFromToDate()
- {
- return fromToDate;
- }
-
- public String getPeriodTypeId()
- {
- return periodTypeId;
- }
-
- public String getParent()
- {
- return parent;
- }
-
- public String getOrgunitid()
- {
- return orgunitid;
- }
-
- public String getTmpParent()
- {
- return tmpParent;
- }
-
- public String getDataElementName()
- {
- return dataElementName;
- }
-
- public String getShowZeroCheckBox()
- {
- return showZeroCheckBox;
- }
-
- public String getParentName()
- {
- if ( mode.equals( "OU" ) )
- {
- return selectedUnit.getName();
- }
-
- if ( parent == null )
- {
- return EMPTY;
- }
-
- if ( mode.equals( "DS" ) )
- {
- return dataSetService.getDataSet( Integer.parseInt( parent ) ).getName();
- }
-
- if ( mode.equals( "OUG" ) )
- {
- return organisationUnitGroupService.getOrganisationUnitGroup( Integer.parseInt( parent ) ).getName();
- }
-
- if ( mode.equals( "DEG" ) )
- {
- return dataElementService.getDataElementGroup( Integer.parseInt( parent ) ).getName();
- }
-
- return EMPTY;
- }
-
- public String getCurrentParentsParent()
- {
- try
- {
- return selectedUnit.getParent().getName();
- }
- catch ( Exception e )
- {
- return EMPTY;
- }
- }
-
- public List<OrganisationUnit> getCurrentChildren()
- {
- Set<OrganisationUnit> tmp = selectedUnit.getChildren();
- List<OrganisationUnit> list = new ArrayList<OrganisationUnit>();
-
- for ( OrganisationUnit o : tmp )
- {
- if ( o.getChildren().size() > 0 )
- {
- list.add( o );
- }
- }
- Collections.sort( list, IdentifiableObjectNameComparator.INSTANCE );
-
- return list;
- }
-
- public List<OrganisationUnit> getBreadCrumbOrgUnit()
- {
- List<OrganisationUnit> myList = new ArrayList<OrganisationUnit>();
-
- boolean loop = true;
- OrganisationUnit currentOrgUnit = selectedUnit;
-
- while ( loop )
- {
- myList.add( currentOrgUnit );
-
- if ( currentOrgUnit.getParent() == null )
- {
- loop = false;
- }
- else
- {
- currentOrgUnit = currentOrgUnit.getParent();
- }
- }
- Collections.reverse( myList );
-
- return myList;
- }
-
- public List<Object> getMetaValues()
- {
- return grid.getColumn( 0 );
- }
-
- public Map<Integer, List<Object>> getMetaValueMaps()
- {
- Map<Integer, List<Object>> maps = new Hashtable<Integer, List<Object>>();
-
- for ( List<Object> row : grid.getRows() )
- {
- if ( !row.isEmpty() && row.size() > 1 )
- {
- maps.put( ((MetaValue) row.get( 0 )).getId(), row.subList( 1, row.size() ) );
- }
- }
-
- return maps;
- }
-
- // -------------------------------------------------------------------------
- // Supportive methods
- // -------------------------------------------------------------------------
-
- /**
- * This is a helper method for populating a list of converted column names
- *
- * @param DataBrowserTable
- */
- protected void convertColumnNames( Grid grid )
- {
- PeriodType periodType = periodService.getPeriodTypeByName( periodTypeId );
-
- for ( GridHeader col : grid.getVisibleHeaders() )
- {
- col.setName( dataBrowserGridService.convertDate( periodType, col.getName(), i18n, format ) );
- }
- }
-
- protected void setGridTitle()
- {
- grid.setTitle( i18n.getString( mappingMode( mode ) )
- + (mode.equals( "OU" ) == true ? " - " + getParentName() : EMPTY) );
- grid.setSubtitle( i18n.getString( "from_date" ) + ": " + fromDate + " " + i18n.getString( "to_date" ) + ": "
- + toDate + ", " + i18n.getString( "period_type" ) + ": " + i18n.getString( periodTypeId ) );
- }
-
- protected void doPaging()
- {
- this.paging = this.createPaging( grid.getHeight() );
-
- grid.limitGrid( paging.getStartPos(), paging.getEndPos() );
- }
-
- private String mappingMode( String mode )
- {
- if ( mode.equals( "DS" ) )
- {
- return "data_sets";
- }
- else if ( mode.equals( "DEG" ) )
- {
- return "data_element_groups";
- }
- else if ( mode.equals( "OU" ) )
- {
- return "organisation_units";
- }
- else if ( mode.equals( "OUG" ) )
- {
- return "organisation_unit_groups";
- }
-
- return mode;
- }
-}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/DataBrowserAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/DataBrowserAction.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/DataBrowserAction.java 2014-01-25 14:05:26 +0000
@@ -30,18 +30,379 @@
import static org.hisp.dhis.system.util.TextUtils.nullIfEmpty;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.Grid;
+import org.hisp.dhis.common.GridHeader;
+import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
+import org.hisp.dhis.databrowser.DataBrowserGridService;
+import org.hisp.dhis.databrowser.MetaValue;
+import org.hisp.dhis.dataelement.DataElementGroup;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.oust.manager.SelectionTreeManager;
+import org.hisp.dhis.paging.ActionPagingSupport;
+import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.system.util.DateUtils;
import org.hisp.dhis.util.SessionUtils;
/**
* @author espenjac, joakibj, briane, eivinhb
- * @version $Id DataBrowerAction.java Apr 06, 2010 ddhieu
*/
public class DataBrowserAction
- extends ActionSupport
+ extends ActionPagingSupport<Grid>
{
- private boolean isZeroAdded = false;
+ private static final Log log = LogFactory.getLog( DataBrowserAction.class );
+
+ private static final String KEY_DATABROWSERGRID = "dataBrowserGridResults";
+ private static final String TRUE = "on";
+ private static final String EMPTY = "";
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ private DataBrowserGridService dataBrowserGridService;
+
+ public void setDataBrowserGridService( DataBrowserGridService dataBrowserGridService )
+ {
+ this.dataBrowserGridService = dataBrowserGridService;
+ }
+
+ private DataElementService dataElementService;
+
+ public void setDataElementService( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
+ private DataSetService dataSetService;
+
+ public void setDataSetService( DataSetService dataSetService )
+ {
+ this.dataSetService = dataSetService;
+ }
+
+ private OrganisationUnitGroupService organisationUnitGroupService;
+
+ public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+ {
+ this.organisationUnitGroupService = organisationUnitGroupService;
+ }
+
+ private PeriodService periodService;
+
+ public void setPeriodService( PeriodService periodService )
+ {
+ this.periodService = periodService;
+ }
+
+ private SelectionTreeManager selectionTreeManager;
+
+ public void setSelectionTreeManager( SelectionTreeManager selectionTreeManager )
+ {
+ this.selectionTreeManager = selectionTreeManager;
+ }
+
+ // -------------------------------------------------------------------------
+ // I18n & I18nFormat
+ // -------------------------------------------------------------------------
+
+ private I18n i18n;
+
+ public void setI18n( I18n i18n )
+ {
+ this.i18n = i18n;
+ }
+
+ private I18nFormat format;
+
+ public void setFormat( I18nFormat format )
+ {
+ this.format = format;
+ }
+
+ // -------------------------------------------------------------------------
+ // Parameters
+ // -------------------------------------------------------------------------
+
+ private Grid grid;
+
+ private String mode;
+
+ private String toDate;
+
+ private String fromDate;
+
+ private String fromToDate;
+
+ private String periodTypeId;
+
+ private String parent;
+
+ private String tmpParent;
+
+ private String orgunitid;
+
+ private String selectedUnitChanger;
+
+ private String dataElementName;
+
+ private String drillDownCheckBox;
+
+ private String showZeroCheckBox;
+
+ private OrganisationUnit selectedUnit;
+
+ private boolean isSummary;
+
+ // -------------------------------------------------------------------------
+ // Input
+ // -------------------------------------------------------------------------
+
+ public void setMode( String mode )
+ {
+ this.mode = mode;
+ }
+
+ public void setToDate( String toDate )
+ {
+ this.toDate = toDate;
+ }
+
+ public void setFromDate( String fromDate )
+ {
+ this.fromDate = fromDate;
+ }
+
+ public void setPeriodTypeId( String periodTypeId )
+ {
+ this.periodTypeId = periodTypeId;
+ }
+
+ public void setParent( String parent )
+ {
+ this.parent = parent;
+ }
+
+ public void setSelectedUnitChanger( String selectedUnitChanger )
+ {
+ this.selectedUnitChanger = selectedUnitChanger.trim();
+ }
+
+ public void setOrgunitid( String orgunitid )
+ {
+ this.orgunitid = orgunitid;
+ }
+
+ public void setDrillDownCheckBox( String drillDownCheckBox )
+ {
+ this.drillDownCheckBox = drillDownCheckBox;
+ }
+
+ public void setShowZeroCheckBox( String showZeroCheckBox )
+ {
+ this.showZeroCheckBox = showZeroCheckBox;
+ }
+
+ public void setSummary( boolean isSummary )
+ {
+ this.isSummary = isSummary;
+ }
+
+ // -------------------------------------------------------------------------
+ // Output
+ // -------------------------------------------------------------------------
+
+ public boolean isSummary()
+ {
+ return isSummary;
+ }
+
+ public Grid getGrid()
+ {
+ return grid;
+ }
+
+ public Collection<DataElementGroup> getDataElementGroups()
+ {
+ return dataElementService.getAllDataElementGroups();
+ }
+
+ public String getMode()
+ {
+ return mode;
+ }
+
+ public String getToDate()
+ {
+ return toDate;
+ }
+
+ public String getFromDate()
+ {
+ return fromDate;
+ }
+
+ public String getFromToDate()
+ {
+ return fromToDate;
+ }
+
+ public String getPeriodTypeId()
+ {
+ return periodTypeId;
+ }
+
+ public String getParent()
+ {
+ return parent;
+ }
+
+ public String getOrgunitid()
+ {
+ return orgunitid;
+ }
+
+ public String getTmpParent()
+ {
+ return tmpParent;
+ }
+
+ public String getDataElementName()
+ {
+ return dataElementName;
+ }
+
+ public String getShowZeroCheckBox()
+ {
+ return showZeroCheckBox;
+ }
+
+ public String getParentName()
+ {
+ if ( mode.equals( "OU" ) )
+ {
+ return selectedUnit.getName();
+ }
+
+ if ( parent == null )
+ {
+ return EMPTY;
+ }
+
+ if ( mode.equals( "DS" ) )
+ {
+ return dataSetService.getDataSet( Integer.parseInt( parent ) ).getName();
+ }
+
+ if ( mode.equals( "OUG" ) )
+ {
+ return organisationUnitGroupService.getOrganisationUnitGroup( Integer.parseInt( parent ) ).getName();
+ }
+
+ if ( mode.equals( "DEG" ) )
+ {
+ return dataElementService.getDataElementGroup( Integer.parseInt( parent ) ).getName();
+ }
+
+ return EMPTY;
+ }
+
+ public String getCurrentParentsParent()
+ {
+ try
+ {
+ return selectedUnit.getParent().getName();
+ }
+ catch ( Exception e )
+ {
+ return EMPTY;
+ }
+ }
+
+ public List<OrganisationUnit> getCurrentChildren()
+ {
+ Set<OrganisationUnit> tmp = selectedUnit.getChildren();
+ List<OrganisationUnit> list = new ArrayList<OrganisationUnit>();
+
+ for ( OrganisationUnit o : tmp )
+ {
+ if ( o.getChildren().size() > 0 )
+ {
+ list.add( o );
+ }
+ }
+ Collections.sort( list, IdentifiableObjectNameComparator.INSTANCE );
+
+ return list;
+ }
+
+ public List<OrganisationUnit> getBreadCrumbOrgUnit()
+ {
+ List<OrganisationUnit> myList = new ArrayList<OrganisationUnit>();
+
+ boolean loop = true;
+ OrganisationUnit currentOrgUnit = selectedUnit;
+
+ while ( loop )
+ {
+ myList.add( currentOrgUnit );
+
+ if ( currentOrgUnit.getParent() == null )
+ {
+ loop = false;
+ }
+ else
+ {
+ currentOrgUnit = currentOrgUnit.getParent();
+ }
+ }
+ Collections.reverse( myList );
+
+ return myList;
+ }
+
+ public List<Object> getMetaValues()
+ {
+ return grid.getColumn( 0 );
+ }
+
+ public Map<Integer, List<Object>> getMetaValueMaps()
+ {
+ Map<Integer, List<Object>> maps = new Hashtable<Integer, List<Object>>();
+
+ for ( List<Object> row : grid.getRows() )
+ {
+ if ( !row.isEmpty() && row.size() > 1 )
+ {
+ maps.put( ((MetaValue) row.get( 0 )).getId(), row.subList( 1, row.size() ) );
+ }
+ }
+
+ return maps;
+ }
// -------------------------------------------------------------------------
// Action implementation
@@ -50,10 +411,14 @@
@Override
public String execute()
{
- isZeroAdded = (showZeroCheckBox != null) && showZeroCheckBox.equals( TRUE );
-
- // Check if the second selected date is later than the first selected
- // date
+ // ---------------------------------------------------------------------
+ // Validation
+ // ---------------------------------------------------------------------
+
+ boolean isZeroAdded = (showZeroCheckBox != null) && showZeroCheckBox.equals( TRUE );
+
+ // Check if the second selected date is later than the first
+
if ( nullIfEmpty( fromDate ) == null && nullIfEmpty( toDate ) == null )
{
if ( DateUtils.checkDates( fromDate, toDate ) )
@@ -63,6 +428,7 @@
}
// If set, change the current selected unit
+
if ( selectedUnitChanger != null )
{
selectionTreeManager.setSelectedOrganisationUnit( organisationUnitService.getOrganisationUnit( Integer
@@ -71,20 +437,25 @@
selectedUnit = selectionTreeManager.getReloadedSelectedOrganisationUnit();
- // Checks if the selected unit is a leaf node of tree then
- // We must add parent as the same parameter value
+ // Checks if the selected unit is a leaf node, if so add parent
+
if ( parent == null && mode.equals( "OU" ) && selectedUnit != null && selectedUnit.getChildren().size() == 0 )
{
parent = selectedUnit.getId() + EMPTY;
}
- PeriodType periodType = periodService.getPeriodTypeByName( periodTypeId );
+ PeriodType periodType = periodService.reloadPeriodType( periodService.getPeriodTypeByName( periodTypeId ) );
+
+ // ---------------------------------------------------------------------
+ // Data set mode
+ // ---------------------------------------------------------------------
+ log.info( "Mode: " + mode + ", parent: " + parent );
+
if ( mode.equals( "DS" ) )
{
if ( parent != null )
{
- // Show DataElement for a given DataSet
Integer parentInt = Integer.parseInt( parent );
grid = dataBrowserGridService.getCountDataElementsForDataSetInPeriod( parentInt, fromDate, toDate,
@@ -92,18 +463,20 @@
}
else
{
- // Get all DataSets
grid = dataBrowserGridService.getDataSetsInPeriod( fromDate, toDate, periodType, format, isZeroAdded );
}
this.setSummary( true );
}
+
+ // ---------------------------------------------------------------------
+ // Data element group mode
+ // ---------------------------------------------------------------------
+
else if ( mode.equals( "DEG" ) )
{
- // Get all DataElementGroup objects
if ( parent != null )
{
- // Show DataElement
Integer parentInt = Integer.parseInt( parent );
grid = dataBrowserGridService.getCountDataElementsForDataElementGroupInPeriod( parentInt, fromDate,
@@ -117,11 +490,15 @@
this.setSummary( true );
}
+
+ // ---------------------------------------------------------------------
+ // Organisation unit group mode
+ // ---------------------------------------------------------------------
+
else if ( mode.equals( "OUG" ) )
{
if ( parent != null )
{
- // Show DataElementGroups
Integer parentInt = Integer.parseInt( parent );
grid = dataBrowserGridService.getCountDataElementGroupsForOrgUnitGroupInPeriod( parentInt, fromDate,
toDate, periodType, format, isZeroAdded );
@@ -134,6 +511,11 @@
this.setSummary( true );
}
+
+ // ---------------------------------------------------------------------
+ // Organisation unit mode
+ // ---------------------------------------------------------------------
+
else if ( mode.equals( "OU" ) )
{
selectedUnit = selectionTreeManager.getSelectedOrganisationUnit();
@@ -143,12 +525,12 @@
parent = String.valueOf( selectedUnit.getId() );
}
- // This one is used for itself
if ( parent != null )
{
Integer parentInt = Integer.parseInt( parent );
- // Show DataElement values entered for this specified unit only
+ // Show data values entered for this specified unit only
+
grid = dataBrowserGridService.getRawDataElementsForOrgUnitInPeriod( parentInt, fromDate, toDate,
periodType, format, isZeroAdded );
@@ -156,8 +538,8 @@
}
else if ( selectedUnit != null )
{
- // Show the summary values for the immediate and descendant
- // units of the specified unit
+ // Show the summary values for the immediate and descendant units of the specified unit
+
grid = dataBrowserGridService.getOrgUnitsInPeriod( selectedUnit.getId(), fromDate, toDate, periodType,
null, format, isZeroAdded );
@@ -173,18 +555,72 @@
return ERROR;
}
- // Set title to grid
setGridTitle();
- // Convert column date names
convertColumnNames( grid );
- // Do paging
doPaging();
// Set DataBrowserTable variable for PDF export
+
SessionUtils.setSessionVar( KEY_DATABROWSERGRID, grid );
return SUCCESS;
}
+
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * This is a helper method for populating a list of converted column names
+ *
+ * @param DataBrowserTable
+ */
+ private void convertColumnNames( Grid grid )
+ {
+ PeriodType periodType = periodService.getPeriodTypeByName( periodTypeId );
+
+ for ( GridHeader col : grid.getVisibleHeaders() )
+ {
+ col.setName( dataBrowserGridService.convertDate( periodType, col.getName(), i18n, format ) );
+ }
+ }
+
+ private void setGridTitle()
+ {
+ grid.setTitle( i18n.getString( mappingMode( mode ) )
+ + (mode.equals( "OU" ) == true ? " - " + getParentName() : EMPTY) );
+ grid.setSubtitle( i18n.getString( "from_date" ) + ": " + fromDate + " " + i18n.getString( "to_date" ) + ": "
+ + toDate + ", " + i18n.getString( "period_type" ) + ": " + i18n.getString( periodTypeId ) );
+ }
+
+ private void doPaging()
+ {
+ this.paging = this.createPaging( grid.getHeight() );
+
+ grid.limitGrid( paging.getStartPos(), paging.getEndPos() );
+ }
+
+ private String mappingMode( String mode )
+ {
+ if ( mode.equals( "DS" ) )
+ {
+ return "data_sets";
+ }
+ else if ( mode.equals( "DEG" ) )
+ {
+ return "data_element_groups";
+ }
+ else if ( mode.equals( "OU" ) )
+ {
+ return "organisation_units";
+ }
+ else if ( mode.equals( "OUG" ) )
+ {
+ return "organisation_unit_groups";
+ }
+
+ return mode;
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataBrowserGrid.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataBrowserGrid.vm 2013-02-01 04:45:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataBrowserGrid.vm 2014-01-25 14:05:26 +0000
@@ -1,35 +1,33 @@
<style type="text/css">
- div#drillDownMenu
- {
- position: absolute;
- display: none;
- }
-
- th.formatLabel
- {
- text-align: center;
- }
-
- .menuDropDownBox li
- {
- cursor:pointer
- }
-
- .menuDropDownBox li:hover
- {
- text-decoration: none;
- background-color: #4A89BA;
- }
+div#drillDownMenu
+{
+ position: absolute;
+ display: none;
+}
+
+th.formatLabel
+{
+ text-align: center;
+}
+
+.menuDropDownBox li
+{
+ cursor:pointer
+}
+
+.menuDropDownBox li:hover
+{
+ text-decoration: none;
+ background-color: #4A89BA;
+}
</style>
<script type="text/javascript">
-
- jQuery( document ).ready( function()
- {
- setTableStyles();
- loadListeners();
- } );
-
+jQuery( document ).ready( function()
+{
+ setTableStyles();
+ loadListeners();
+} );
</script>
#if ( $grid.getHeight() == 0 || $grid.getWidth() == 0 )