=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractIdentifiableObject.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractIdentifiableObject.java 2011-04-01 09:57:53 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractIdentifiableObject.java 2011-04-01 11:00:44 +0000 @@ -27,10 +27,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - /** * @author Bob Jolliffe - * @version $Id$ */ public abstract class AbstractIdentifiableObject implements IdentifiableObject @@ -61,9 +59,6 @@ this.name = name; } - /* (non-Javadoc) - * @see org.hisp.dhis.common.IdentifiableObject#getId() - */ @Override public int getId() { @@ -75,9 +70,6 @@ this.id = id; } - /* (non-Javadoc) - * @see org.hisp.dhis.common.IdentifiableObject#getUuid() - */ @Override public String getUuid() { @@ -89,9 +81,6 @@ this.uuid = uuid; } - /* (non-Javadoc) - * @see org.hisp.dhis.common.IdentifiableObject#getName() - */ @Override public String getName() { @@ -102,5 +91,4 @@ { this.name = name; } - } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractNameableObject.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractNameableObject.java 2011-04-01 09:57:53 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractNameableObject.java 2011-04-01 11:00:44 +0000 @@ -1,9 +1,38 @@ package org.hisp.dhis.common; +/* + * 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. + */ + +/** + * @author Bob Jolliffe + */ public class AbstractNameableObject extends AbstractIdentifiableObject implements NameableObject { - /** * An alternative name of this Object. Optional but unique. */ @@ -77,5 +106,4 @@ { this.description = description; } - } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObject.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObject.java 2011-04-01 09:57:53 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObject.java 2011-04-01 11:00:44 +0000 @@ -1,13 +1,38 @@ package org.hisp.dhis.common; +/* + * 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. + */ + public interface IdentifiableObject extends ImportableObject { - public abstract int getId(); public abstract String getUuid(); public abstract String getName(); - } \ No newline at end of file === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datasetreport/DataSetReportService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datasetreport/DataSetReportService.java 2011-03-20 13:57:42 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datasetreport/DataSetReportService.java 2011-04-01 11:00:44 +0000 @@ -29,7 +29,9 @@ import java.util.Map; +import org.hisp.dhis.common.Grid; import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.i18n.I18n; import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; @@ -62,4 +64,18 @@ * input fields. */ String prepareReportContent( String dataEntryFormCode, Map dataValues ); + + /** + * Generates a Grid representing a data set report with all data elements + * in the data set. The data elements are grouped by their category combo. + * + * @param dataSet the data set. + * @param unit the organisation unit. + * @param period the period. + * @param selectedUnitOnly indicators whether to use captured or aggregated data. + * @param format the i18n format. + * @param i18n the i18n object. + * @return a Grid. + */ + Grid getDefaultDataSetReport( DataSet dataSet, Period period, OrganisationUnit unit, boolean selectedUnitOnly, I18nFormat format, I18n i18n ); } === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java 2011-03-20 13:57:42 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java 2011-04-01 11:00:44 +0000 @@ -33,26 +33,37 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeMap; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.hisp.dhis.aggregation.AggregatedDataValueService; import org.hisp.dhis.aggregation.AggregationService; +import org.hisp.dhis.common.Grid; +import org.hisp.dhis.common.GridHeader; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryCombo; import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import org.hisp.dhis.dataelement.comparator.DataElementCategoryOptionComboNameComparator; +import org.hisp.dhis.dataelement.comparator.DataElementNameComparator; import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.datasetreport.DataSetReportService; import org.hisp.dhis.datavalue.DataValue; import org.hisp.dhis.datavalue.DataValueService; +import org.hisp.dhis.i18n.I18n; import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.options.SystemSettingManager; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; import org.hisp.dhis.system.filter.AggregatableDataElementFilter; +import org.hisp.dhis.system.grid.ListGrid; import org.hisp.dhis.system.util.FilterUtils; +import org.hisp.dhis.system.util.MathUtils; /** * @author Abyot Asalefew @@ -65,6 +76,7 @@ private static final Pattern OPERAND_PATTERN = Pattern.compile( "value\\[(.*)\\].value:value\\[(.*)\\].value" ); private static final String NULL_REPLACEMENT = ""; private static final String SEPARATOR = ":"; + private static final String DEFAULT_HEADER = "Value"; // ------------------------------------------------------------------------- // Dependencies @@ -202,4 +214,85 @@ return buffer.toString(); } + + public Grid getDefaultDataSetReport( DataSet dataSet, Period period, OrganisationUnit unit, boolean selectedUnitOnly, I18nFormat format, I18n i18n ) + { + List dataElements = new ArrayList( dataSet.getDataElements() ); + + Collections.sort( dataElements, new DataElementNameComparator() ); + FilterUtils.filter( dataElements, new AggregatableDataElementFilter() ); + + String aggregationStrategy = (String) systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY, + DEFAULT_AGGREGATION_STRATEGY ); + + // --------------------------------------------------------------------- + // Get the category-option-combos + // --------------------------------------------------------------------- + + Set optionCombos = new HashSet(); + + for ( DataElement dataElement : dataElements ) + { + optionCombos.addAll( dataElement.getCategoryCombo().getOptionCombos() ); + } + + List orderedOptionCombos = new ArrayList( + optionCombos ); + + Collections.sort( orderedOptionCombos, new DataElementCategoryOptionComboNameComparator() ); + + // --------------------------------------------------------------------- + // Create a GRID + // --------------------------------------------------------------------- + + Grid grid = new ListGrid().setTitle( dataSet.getName() ); + grid.setSubtitle( format.formatPeriod( period ) ); + + // --------------------------------------------------------------------- + // Headers for GRID + // --------------------------------------------------------------------- + + grid.addHeader( new GridHeader( i18n.getString( "dataelement" ), false, true ) ); + + for ( DataElementCategoryOptionCombo optionCombo : orderedOptionCombos ) + { + grid.addHeader( new GridHeader( optionCombo.isDefault() ? DEFAULT_HEADER : optionCombo.getName(), false, false ) ); + } + + // --------------------------------------------------------------------- + // Values for GRID + // --------------------------------------------------------------------- + + for ( DataElement dataElement : dataElements ) + { + grid.addRow(); + + grid.addValue( dataElement.getName() ); + + for ( DataElementCategoryOptionCombo optionCombo : orderedOptionCombos ) + { + String value = ""; + + if ( selectedUnitOnly ) + { + DataValue dataValue = dataValueService.getDataValue( unit, dataElement, period, optionCombo ); + value = (dataValue != null) ? dataValue.getValue() : null; + } + else + { + Double aggregatedValue = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ? aggregationService + .getAggregatedDataValue( dataElement, optionCombo, period.getStartDate(), period.getEndDate(), unit ) + : aggregatedDataValueService.getAggregatedValue( dataElement, optionCombo, period, unit ); + + value = (aggregatedValue != null) ? String.valueOf( MathUtils.getRounded( aggregatedValue, 0 ) ) + : null; + } + + grid.addValue( value ); + + } + } + + return grid; + } } === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/reporttable/ReportTableTest.java' --- dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/reporttable/ReportTableTest.java 2011-04-01 09:57:53 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/reporttable/ReportTableTest.java 2011-04-01 11:00:44 +0000 @@ -44,7 +44,6 @@ import org.hisp.dhis.DhisTest; import org.hisp.dhis.common.NameableObject; -import org.hisp.dhis.common.NameableObject; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryCombo; import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDefaultDataSetReportAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDefaultDataSetReportAction.java 2011-03-11 12:35:11 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDefaultDataSetReportAction.java 2011-04-01 11:00:44 +0000 @@ -27,36 +27,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import static org.hisp.dhis.options.SystemSettingManager.AGGREGATION_STRATEGY_REAL_TIME; -import static org.hisp.dhis.options.SystemSettingManager.DEFAULT_AGGREGATION_STRATEGY; -import static org.hisp.dhis.options.SystemSettingManager.KEY_AGGREGATION_STRATEGY; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.hisp.dhis.aggregation.AggregatedDataValueService; -import org.hisp.dhis.aggregation.AggregationService; import org.hisp.dhis.common.Grid; -import org.hisp.dhis.common.GridHeader; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; -import org.hisp.dhis.dataelement.comparator.DataElementCategoryOptionComboNameComparator; import org.hisp.dhis.dataset.DataSet; -import org.hisp.dhis.datavalue.DataValue; -import org.hisp.dhis.datavalue.DataValueService; +import org.hisp.dhis.datasetreport.DataSetReportService; import org.hisp.dhis.i18n.I18n; import org.hisp.dhis.i18n.I18nFormat; -import org.hisp.dhis.options.SystemSettingManager; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; -import org.hisp.dhis.system.filter.AggregatableDataElementFilter; -import org.hisp.dhis.system.grid.ListGrid; -import org.hisp.dhis.system.util.FilterUtils; -import org.hisp.dhis.system.util.MathUtils; import com.opensymphony.xwork2.Action; @@ -66,30 +43,11 @@ public class GenerateDefaultDataSetReportAction implements Action { - private static final String DEFAULT_HEADER = "Value"; - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- - private DataValueService dataValueService; - - private SystemSettingManager systemSettingManager; - - private AggregatedDataValueService aggregatedDataValueService; - - private AggregationService aggregationService; - - // ------------------------------------------------------------------------- - // Comparator - // ------------------------------------------------------------------------- - - private Comparator dataElementComparator; - - public void setDataElementComparator( Comparator dataElementComparator ) - { - this.dataElementComparator = dataElementComparator; - } + private DataSetReportService dataSetReportService; // ------------------------------------------------------------------------- // Input @@ -121,9 +79,9 @@ // Getters && Setters // ------------------------------------------------------------------------- - public void setAggregationService( AggregationService aggregationService ) + public void setDataSetReportService( DataSetReportService dataSetReportService ) { - this.aggregationService = aggregationService; + this.dataSetReportService = dataSetReportService; } public void setSelectedOrgunit( OrganisationUnit selectedOrgunit ) @@ -166,21 +124,6 @@ return grid; } - public void setAggregatedDataValueService( AggregatedDataValueService aggregatedDataValueService ) - { - this.aggregatedDataValueService = aggregatedDataValueService; - } - - public void setSystemSettingManager( SystemSettingManager systemSettingManager ) - { - this.systemSettingManager = systemSettingManager; - } - - public void setDataValueService( DataValueService dataValueService ) - { - this.dataValueService = dataValueService; - } - public void setSelectedUnitOnly( boolean selectedUnitOnly ) { this.selectedUnitOnly = selectedUnitOnly; @@ -193,90 +136,8 @@ public String execute() throws Exception { - List dataElements = new ArrayList( selectedDataSet.getDataElements() ); - - if ( dataElements.size() == 0 ) - { - return SUCCESS; - } - - Collections.sort( dataElements, dataElementComparator ); - FilterUtils.filter( dataElements, new AggregatableDataElementFilter() ); - - String aggregationStrategy = (String) systemSettingManager.getSystemSetting( KEY_AGGREGATION_STRATEGY, - DEFAULT_AGGREGATION_STRATEGY ); - - // --------------------------------------------------------------------- - // Get the category-option-combos - // --------------------------------------------------------------------- - - Set optionCombos = new HashSet(); - - for ( DataElement dataElement : dataElements ) - { - optionCombos.addAll( dataElement.getCategoryCombo().getOptionCombos() ); - } - - List orderedOptionCombos = new ArrayList( - optionCombos ); - - Collections.sort( orderedOptionCombos, new DataElementCategoryOptionComboNameComparator() ); - - // --------------------------------------------------------------------- - // Create a GRID - // --------------------------------------------------------------------- - - grid = new ListGrid().setTitle( selectedDataSet.getName() ); - grid.setSubtitle( format.formatPeriod( selectedPeriod ) ); - - // --------------------------------------------------------------------- - // Headers for GRID - // --------------------------------------------------------------------- - - grid.addHeader( new GridHeader( i18n.getString( "dataelement" ), false, true ) ); - - for ( DataElementCategoryOptionCombo optionCombo : orderedOptionCombos ) - { - grid.addHeader( new GridHeader( optionCombo.isDefault() ? DEFAULT_HEADER : optionCombo.getName(), false, false ) ); - } - - // --------------------------------------------------------------------- - // Values for GRID - // --------------------------------------------------------------------- - - for ( DataElement dataElement : dataElements ) - { - grid.addRow(); - - grid.addValue( dataElement.getName() ); - - for ( DataElementCategoryOptionCombo optionCombo : orderedOptionCombos ) - { - String value = ""; - - if ( selectedUnitOnly ) - { - DataValue dataValue = dataValueService.getDataValue( selectedOrgunit, dataElement, - selectedPeriod, optionCombo ); - value = (dataValue != null) ? dataValue.getValue() : null; - } - else - { - Double aggregatedValue = aggregationStrategy.equals( AGGREGATION_STRATEGY_REAL_TIME ) ? aggregationService - .getAggregatedDataValue( dataElement, optionCombo, selectedPeriod.getStartDate(), - selectedPeriod.getEndDate(), selectedOrgunit ) - : aggregatedDataValueService.getAggregatedValue( dataElement, optionCombo, selectedPeriod, - selectedOrgunit ); - - value = (aggregatedValue != null) ? String.valueOf( MathUtils.getRounded( aggregatedValue, 0 ) ) - : null; - } - - grid.addValue( value ); - - } - } - + dataSetReportService.getDefaultDataSetReport( selectedDataSet, selectedPeriod, selectedOrgunit, selectedUnitOnly, format, i18n ); + reportingUnit = selectedOrgunit.getName(); reportingPeriod = format.formatPeriod( selectedPeriod ); === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-03-29 20:06:47 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-04-01 11:00:44 +0000 @@ -347,7 +347,7 @@ ref="org.hisp.dhis.pivottable.PivotTableService"/> - + @@ -389,14 +389,8 @@ - - - - +