=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/ReportTableXmlAdapter.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/ReportTableXmlAdapter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/ReportTableXmlAdapter.java 2011-12-14 10:03:38 +0000 @@ -0,0 +1,60 @@ +package org.hisp.dhis.common.adapter; + +/* + * Copyright (c) 2004-2011, 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 org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.reporttable.ReportTable; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.util.UUID; + +/** + * @author Morten Olav Hansen + */ +public class ReportTableXmlAdapter extends XmlAdapter +{ + private BaseIdentifiableObjectXmlAdapter baseIdentifiableObjectXmlAdapter = new BaseIdentifiableObjectXmlAdapter(); + + @Override + public ReportTable unmarshal( BaseIdentifiableObject identifiableObject ) throws Exception + { + ReportTable reportTable = new ReportTable(); + + reportTable.setUid( identifiableObject.getUid() ); + reportTable.setLastUpdated( identifiableObject.getLastUpdated() ); + reportTable.setName( identifiableObject.getName() == null ? UUID.randomUUID().toString() : identifiableObject.getName() ); + + return reportTable; + } + + @Override + public BaseIdentifiableObject marshal( ReportTable reportTable ) throws Exception + { + return baseIdentifiableObjectXmlAdapter.marshal( reportTable ); + } +} === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java 2011-11-22 16:17:49 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java 2011-12-14 10:03:38 +0000 @@ -113,6 +113,8 @@ ReportGroup getReportGroup( int id ); + ReportGroup getReportGroup( String uid ); + ReportGroup getReportGroupByName( String name ); Collection getAllReportGroups(); === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportParams.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportParams.java 2011-09-14 15:17:22 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportParams.java 2011-12-14 10:03:38 +0000 @@ -27,6 +27,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.codehaus.jackson.annotate.JsonProperty; +import org.hisp.dhis.common.Dxf2Namespace; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; /** @@ -37,6 +44,8 @@ * @author Lars Helge Overland * @version $Id$ */ +@XmlRootElement( name = "reportParams", namespace = Dxf2Namespace.NAMESPACE ) +@XmlAccessorType( value = XmlAccessType.NONE ) public class ReportParams implements Serializable { @@ -117,6 +126,8 @@ // Getters and setters // ------------------------------------------------------------------------- + @XmlElement + @JsonProperty public Boolean getParamReportingMonth() { return paramReportingMonth; @@ -127,6 +138,8 @@ this.paramReportingMonth = paramReportingMonth; } + @XmlElement + @JsonProperty public Boolean getParamLeafParentOrganisationUnit() { return paramLeafParentOrganisationUnit; @@ -137,6 +150,8 @@ this.paramLeafParentOrganisationUnit = paramLeafParentOrganisationUnit; } + @XmlElement + @JsonProperty public Boolean getParamGrandParentOrganisationUnit() { return paramGrandParentOrganisationUnit; @@ -147,6 +162,8 @@ this.paramGrandParentOrganisationUnit = paramGrandParentOrganisationUnit; } + @XmlElement + @JsonProperty public Boolean getParamParentOrganisationUnit() { return paramParentOrganisationUnit; @@ -157,6 +174,8 @@ this.paramParentOrganisationUnit = paramParentOrganisationUnit; } + @XmlElement + @JsonProperty public Boolean getParamOrganisationUnit() { return paramOrganisationUnit; === 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 2011-11-25 11:00:15 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java 2011-12-14 10:03:38 +0000 @@ -28,9 +28,13 @@ */ import org.apache.commons.lang.StringUtils; +import org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.map.annotate.JsonSerialize; import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.CombinationGenerator; +import org.hisp.dhis.common.Dxf2Namespace; import org.hisp.dhis.common.NameableObject; +import org.hisp.dhis.common.adapter.*; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryCombo; import org.hisp.dhis.dataelement.DataElementCategoryOption; @@ -44,6 +48,8 @@ import org.hisp.dhis.period.RelativePeriods; import org.hisp.dhis.period.comparator.AscendingPeriodComparator; +import javax.xml.bind.annotation.*; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.util.*; /** @@ -54,6 +60,8 @@ * @author Lars Helge Overland * @version $Id$ */ +@XmlRootElement( name = "reportTable", namespace = Dxf2Namespace.NAMESPACE ) +@XmlAccessorType( value = XmlAccessType.NONE ) public class ReportTable extends BaseIdentifiableObject { /** @@ -823,6 +831,8 @@ // Get- and set-methods for persisted properties // ------------------------------------------------------------------------- + @XmlElement + @JsonProperty public boolean isRegression() { return regression; @@ -833,6 +843,11 @@ this.regression = regression; } + @XmlElementWrapper( name = "dataElements" ) + @XmlElement( name = "dataElement" ) + @XmlJavaTypeAdapter( DataElementXmlAdapter.class ) + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) public List getDataElements() { return dataElements; @@ -843,6 +858,11 @@ this.dataElements = dataElements; } + @XmlElementWrapper( name = "categoryOptionCombos" ) + @XmlElement( name = "categoryOptionCombo" ) + @XmlJavaTypeAdapter( CategoryOptionComboXmlAdapter.class ) + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) public List getCategoryOptionCombos() { return categoryOptionCombos; @@ -853,6 +873,11 @@ this.categoryOptionCombos = categoryOptionCombos; } + @XmlElementWrapper( name = "indicators" ) + @XmlElement( name = "indicator" ) + @XmlJavaTypeAdapter( IndicatorXmlAdapter.class ) + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) public List getIndicators() { return indicators; @@ -868,6 +893,16 @@ return periods; } + public void setPeriods( List periods ) + { + this.periods = periods; + } + + @XmlElementWrapper( name = "dataSets" ) + @XmlElement( name = "dataSet" ) + @XmlJavaTypeAdapter( DataSetXmlAdapter.class ) + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) public List getDataSets() { return dataSets; @@ -878,11 +913,11 @@ this.dataSets = dataSets; } - public void setPeriods( List periods ) - { - this.periods = periods; - } - + @XmlElementWrapper( name = "organisationUnits" ) + @XmlElement( name = "organisationUnit" ) + @XmlJavaTypeAdapter( OrganisationUnitXmlAdapter.class ) + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) public List getUnits() { return units; @@ -893,16 +928,10 @@ this.units = units; } - public Set getGroups() - { - return groups; - } - - public void setGroups( Set groups ) - { - this.groups = groups; - } - + @XmlElement + @XmlJavaTypeAdapter( CategoryComboXmlAdapter.class ) + @JsonProperty + @JsonSerialize( as = BaseIdentifiableObject.class ) public DataElementCategoryCombo getCategoryCombo() { return categoryCombo; @@ -913,6 +942,8 @@ this.categoryCombo = categoryCombo; } + @XmlElement + @JsonProperty public boolean isDoIndicators() { return doIndicators; @@ -923,6 +954,8 @@ this.doIndicators = doIndicators; } + @XmlElement + @JsonProperty public boolean isDoPeriods() { return doPeriods; @@ -933,6 +966,8 @@ this.doPeriods = doPeriods; } + @XmlElement + @JsonProperty public boolean isDoUnits() { return doUnits; @@ -953,6 +988,8 @@ this.relatives = relatives; } + @XmlElement + @JsonProperty public ReportParams getReportParams() { return reportParams; @@ -963,6 +1000,8 @@ this.reportParams = reportParams; } + @XmlElement + @JsonProperty public Integer getSortOrder() { return sortOrder; @@ -973,6 +1012,8 @@ this.sortOrder = sortOrder; } + @XmlElement + @JsonProperty public Integer getTopLimit() { return topLimit; @@ -983,6 +1024,16 @@ this.topLimit = topLimit; } + public Set getGroups() + { + return groups; + } + + public void setGroups( Set groups ) + { + this.groups = groups; + } + // ------------------------------------------------------------------------- // Get- and set-methods for transient properties // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableGroup.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableGroup.java 2011-11-24 14:36:19 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableGroup.java 2011-12-14 10:03:38 +0000 @@ -30,12 +30,20 @@ import java.util.HashSet; import java.util.Set; +import org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.map.annotate.JsonSerialize; import org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.adapter.DataElementGroupXmlAdapter; + +import javax.xml.bind.annotation.*; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; /** * @author Dang Duy Hieu - * @version $Id$ */ +@XmlRootElement( name = "reportTableGroup", namespace = Dxf2Namespace.NAMESPACE ) +@XmlAccessorType( value = XmlAccessType.NONE ) public class ReportTableGroup extends BaseIdentifiableObject { @@ -134,6 +142,11 @@ // Getters and setters // ------------------------------------------------------------------------- + @XmlElementWrapper( name = "reportTables" ) + @XmlElement( name = "reportTable" ) + @XmlJavaTypeAdapter( DataElementGroupXmlAdapter.class ) + @JsonProperty( value = "reportTables" ) + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) public Set getMembers() { return members; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java 2011-11-22 16:17:49 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTableService.java 2011-12-14 10:03:38 +0000 @@ -161,6 +161,8 @@ ReportTableGroup getReportTableGroup( int id ); + ReportTableGroup getReportTableGroup( String uid); + ReportTableGroup getReportTableGroupByName( String name ); Collection getAllReportTableGroups(); === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTables.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTables.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTables.java 2011-12-14 10:03:38 +0000 @@ -0,0 +1,67 @@ +package org.hisp.dhis.reporttable; + +/* + * Copyright (c) 2004-2011, 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 org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.map.annotate.JsonSerialize; +import org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.common.BaseLinkableObject; +import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.adapter.ReportTableXmlAdapter; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Morten Olav Hansen + */ +@XmlRootElement( name = "reportTables", namespace = Dxf2Namespace.NAMESPACE ) +@XmlAccessorType( value = XmlAccessType.NONE ) +public class ReportTables extends BaseLinkableObject +{ + private List reportTables = new ArrayList(); + + @XmlElement( name = "reportTable" ) + @XmlJavaTypeAdapter( ReportTableXmlAdapter.class ) + @JsonProperty( value = "reportTables" ) + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + public List getReportTables() + { + return reportTables; + } + + public void setReportTables( List reportTables ) + { + this.reportTables = reportTables; + } +} === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java 2011-11-22 16:17:49 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java 2011-12-14 10:03:38 +0000 @@ -27,19 +27,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.io.OutputStream; -import java.sql.Connection; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - import net.sf.jasperreports.engine.JasperCompileManager; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperReport; - import org.amplecode.quick.StatementManager; import org.hisp.dhis.common.GenericIdentifiableObjectStore; import org.hisp.dhis.common.Grid; @@ -57,6 +48,10 @@ import org.hisp.dhis.system.util.StreamUtils; import org.springframework.transaction.annotation.Transactional; +import java.io.OutputStream; +import java.sql.Connection; +import java.util.*; + /** * @author Lars Helge Overland * @version $Id$ @@ -84,14 +79,14 @@ } private ReportTableService reportTableService; - + public void setReportTableService( ReportTableService reportTableService ) { this.reportTableService = reportTableService; } private ConstantService constantService; - + public void setConstantService( ConstantService constantService ) { this.constantService = constantService; @@ -115,57 +110,55 @@ // ReportService implementation // ------------------------------------------------------------------------- - public void renderReport( OutputStream out, Report report, Date reportingPeriod, - Integer organisationUnitId, String type, I18nFormat format ) + public void renderReport( OutputStream out, Report report, Date reportingPeriod, + Integer organisationUnitId, String type, I18nFormat format ) { Map params = new HashMap(); - + params.putAll( constantService.getConstantParameterMap() ); - + try { JasperReport jasperReport = JasperCompileManager.compileReport( StreamUtils.getInputStream( report.getDesignContent() ) ); - + JasperPrint print = null; - + if ( report.hasReportTable() ) // Use JR data source { ReportTable reportTable = report.getReportTable(); - + Grid grid = reportTableService.getReportTableGrid( reportTable.getId(), format, reportingPeriod, organisationUnitId ); - + if ( report.isUsingOrganisationUnitGroupSets() ) { params.putAll( reportTable.getOrganisationUnitGroupMap( organisationUnitGroupService.getCompulsoryOrganisationUnitGroupSets() ) ); } - + print = JasperFillManager.fillReport( jasperReport, params, grid ); } else // Assume SQL report and provide JDBC connection { Connection connection = statementManager.getHolder().getConnection(); - + try { print = JasperFillManager.fillReport( jasperReport, params, connection ); - } - finally - { + } finally + { connection.close(); } } - + if ( print != null ) { JRExportUtils.export( type, out, print ); } - } - catch ( Exception ex ) + } catch ( Exception ex ) { throw new RuntimeException( "Failed to render report", ex ); } } - + public int saveReport( Report report ) { return reportStore.save( report ); @@ -233,6 +226,11 @@ return reportGroupStore.get( id ); } + public ReportGroup getReportGroup( String uid ) + { + return reportGroupStore.getByUid( uid ); + } + public ReportGroup getReportGroupByName( String name ) { return reportGroupStore.getByName( name ); === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java 2011-12-13 14:04:12 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/reporttable/impl/DefaultReportTableService.java 2011-12-14 10:03:38 +0000 @@ -177,7 +177,7 @@ } public Grid getReportTableGrid( int id, I18nFormat format, Date reportingPeriod, Integer organisationUnitId ) - { + { ReportTable reportTable = getReportTable( id ); reportTable = initDynamicMetaObjects( reportTable, reportingPeriod, organisationUnitId, format ); @@ -295,6 +295,11 @@ return reportTableGroupStore.get( id ); } + public ReportTableGroup getReportTableGroup( String uid) + { + return reportTableGroupStore.getByUid( uid ); + } + public ReportTableGroup getReportTableGroupByName( String name ) { return reportTableGroupStore.getByName( name ); === added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ReportTableController.java 2011-12-14 10:03:38 +0000 @@ -0,0 +1,149 @@ +package org.hisp.dhis.api.controller; + +/* + * Copyright (c) 2004-2011, 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 org.hisp.dhis.api.utils.IdentifiableObjectParams; +import org.hisp.dhis.api.utils.WebLinkPopulator; +import org.hisp.dhis.reporttable.ReportTable; +import org.hisp.dhis.reporttable.ReportTableService; +import org.hisp.dhis.reporttable.ReportTables; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseStatus; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.InputStream; +import java.util.ArrayList; + +@Controller +@RequestMapping( value = ReportTableController.RESOURCE_PATH ) +public class ReportTableController +{ + public static final String RESOURCE_PATH = "/reportTables"; + + @Autowired + public ReportTableService reportTableService; + + //------------------------------------------------------------------------------------------------------- + // GET + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( method = RequestMethod.GET ) + public String getReportTables( IdentifiableObjectParams params, Model model, HttpServletRequest request ) + { + ReportTables reportTables = new ReportTables(); + + if ( params.hasNoPaging() ) + { + reportTables.setReportTables( new ArrayList( reportTableService.getAllReportTables() ) ); + } + else + { + reportTables.setReportTables( new ArrayList( reportTableService.getAllReportTables() ) ); + } + + if ( params.hasLinks() ) + { + WebLinkPopulator listener = new WebLinkPopulator( request ); + listener.addLinks( reportTables ); + } + + model.addAttribute( "model", reportTables ); + + return "reportTables"; + } + + @RequestMapping( value = "/{uid}", method = RequestMethod.GET ) + public String getReportTable( @PathVariable( "uid" ) String uid, IdentifiableObjectParams params, Model model, HttpServletRequest request ) + { + ReportTable reportTable = reportTableService.getReportTable( uid ); + + if ( params.hasLinks() ) + { + WebLinkPopulator listener = new WebLinkPopulator( request ); + listener.addLinks( reportTable ); + } + + model.addAttribute( "model", reportTable ); + + return "reportTable"; + } + //------------------------------------------------------------------------------------------------------- + // POST + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/xml, text/xml"} ) + @ResponseStatus( value = HttpStatus.CREATED ) + public void postReportTableXML( HttpServletResponse response, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() ); + } + + @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/json"} ) + @ResponseStatus( value = HttpStatus.CREATED ) + public void postReportTableJSON( HttpServletResponse response, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() ); + } + + //------------------------------------------------------------------------------------------------------- + // PUT + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, headers = {"Content-Type=application/xml, text/xml"} ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void putReportTableXML( @PathVariable( "uid" ) String uid, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() ); + } + + @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, headers = {"Content-Type=application/json"} ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void putReportTableJSON( @PathVariable( "uid" ) String uid, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() ); + } + + //------------------------------------------------------------------------------------------------------- + // DELETE + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void deleteReportTable( @PathVariable( "uid" ) String uid ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() ); + } +} === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java 2011-12-13 18:41:43 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java 2011-12-14 10:03:38 +0000 @@ -51,6 +51,10 @@ import org.hisp.dhis.organisationunit.*; import org.hisp.dhis.report.Report; import org.hisp.dhis.report.Reports; +import org.hisp.dhis.reporttable.ReportTable; +import org.hisp.dhis.reporttable.ReportTableGroup; +import org.hisp.dhis.reporttable.ReportTableGroups; +import org.hisp.dhis.reporttable.ReportTables; import org.hisp.dhis.sqlview.SqlView; import org.hisp.dhis.sqlview.SqlViews; import org.hisp.dhis.user.User; @@ -309,6 +313,73 @@ { populateUser( (User) source, true ); } + else if ( source instanceof ReportTables ) + { + populateReportTables( (ReportTables) source, true ); + } + else if ( source instanceof ReportTable ) + { + populateReportTable( (ReportTable) source, true ); + } + else if ( source instanceof ReportTableGroups ) + { + populateReportTableGroups( (ReportTableGroups) source, true ); + } + else if ( source instanceof ReportTableGroup ) + { + populateReportTableGroup( (ReportTableGroup) source, true ); + } + } + + private void populateReportTables( ReportTables reportTables, boolean root ) + { + reportTables.setLink( getBasePath( reportTables.getClass() ) ); + + if ( root ) + { + for ( ReportTable reportTable : reportTables.getReportTables() ) + { + populateReportTable( reportTable, false ); + } + } + } + + private void populateReportTable( ReportTable reportTable, boolean root ) + { + populateIdentifiableObject( reportTable ); + + if ( root ) + { + handleIdentifiableObjectCollection( reportTable.getPeriods() ); + handleIdentifiableObjectCollection( reportTable.getCategoryOptionCombos() ); + handleIdentifiableObjectCollection( reportTable.getDataElements() ); + handleIdentifiableObjectCollection( reportTable.getIndicators() ); + handleIdentifiableObjectCollection( reportTable.getGroups() ); + handleIdentifiableObjectCollection( reportTable.getDataSets() ); + } + } + + private void populateReportTableGroups( ReportTableGroups reportTableGroups, boolean root ) + { + reportTableGroups.setLink( getBasePath( reportTableGroups.getClass() ) ); + + if ( root ) + { + for ( ReportTableGroup reportTableGroup : reportTableGroups.getReportTableGroups() ) + { + populateReportTableGroup( reportTableGroup, false ); + } + } + } + + private void populateReportTableGroup( ReportTableGroup reportTableGroup, boolean root ) + { + populateIdentifiableObject( reportTableGroup ); + + if ( root ) + { + handleIdentifiableObjectCollection( reportTableGroup.getMembers() ); + } } private void populateUsers( Users users, boolean root ) === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/attributeType.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/attributeType.xsl 2011-12-09 18:08:05 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/attributeType.xsl 2011-12-14 10:03:38 +0000 @@ -18,6 +18,10 @@ + Code + + + Mandatory === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/category.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/category.xsl 2011-12-07 16:03:19 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/category.xsl 2011-12-14 10:03:38 +0000 @@ -17,6 +17,10 @@ Last Updated + + Code + + === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/categoryCombo.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/categoryCombo.xsl 2011-12-07 16:03:19 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/categoryCombo.xsl 2011-12-14 10:03:38 +0000 @@ -17,6 +17,10 @@ Last Updated + + Code + + === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/categoryOption.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/categoryOption.xsl 2011-12-07 16:03:19 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/categoryOption.xsl 2011-12-14 10:03:38 +0000 @@ -17,6 +17,10 @@ Last Updated + + Code + + === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/categoryOptionCombo.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/categoryOptionCombo.xsl 2011-12-07 16:03:19 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/categoryOptionCombo.xsl 2011-12-14 10:03:38 +0000 @@ -17,6 +17,10 @@ Last Updated + + Code + + === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/chart.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/chart.xsl 2011-12-07 16:03:19 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/chart.xsl 2011-12-14 10:03:38 +0000 @@ -21,6 +21,10 @@ + Code + + + Dimension === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/dataElement.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/dataElement.xsl 2011-12-07 16:03:19 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/dataElement.xsl 2011-12-14 10:03:38 +0000 @@ -18,6 +18,10 @@ + Code + + + Short Name === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/dataSet.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/dataSet.xsl 2011-12-13 17:44:28 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/dataSet.xsl 2011-12-14 10:03:38 +0000 @@ -19,6 +19,10 @@ + Code + + + Short Name === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/indicator.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/indicator.xsl 2011-12-07 16:03:19 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/indicator.xsl 2011-12-14 10:03:38 +0000 @@ -12,57 +12,43 @@ - + - + + + + + - + - + - + - + - + - + - +
ID - -
Last Updated - -
Code
Short Name - -
Denominator - -
Denominator Description - -
Numerator - -
Numerator Description - -
Annualized - -
Sort Order - -
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/indicatorType.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/indicatorType.xsl 2011-12-07 14:09:14 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/indicatorType.xsl 2011-12-14 10:03:38 +0000 @@ -12,27 +12,23 @@ - + - + + + + + - + - +
ID - -
Last Updated - -
Code
Factor - -
Number - -
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl 2011-12-13 18:41:43 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/list.xsl 2011-12-14 10:03:38 +0000 @@ -12,7 +12,7 @@ d:organisationUnits|d:dataElementGroups|d:dataElementGroupSets| d:indicatorGroups|d:indicatorGroupSets|d:organisationUnitGroups| d:organisationUnitGroupSets|d:indicatorTypes|d:attributeTypes|d:reports| - d:sqlViews|d:validationRules|d:validationRuleGroups|d:users"> + d:sqlViews|d:validationRules|d:validationRuleGroups|d:users|d:reportTables">

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl 2011-12-13 18:41:43 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/model2html.xsl 2011-12-14 10:03:38 +0000 @@ -36,6 +36,7 @@ + === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/organisationUnit.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/organisationUnit.xsl 2011-12-07 16:03:19 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/organisationUnit.xsl 2011-12-14 10:03:38 +0000 @@ -18,6 +18,10 @@ + + + + === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/report.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/report.xsl 2011-12-13 14:16:32 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/report.xsl 2011-12-14 10:03:38 +0000 @@ -18,6 +18,10 @@ + + + +
Code
Short Name
Last Updated
Code
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/reportTable.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/reportTable.xsl 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/reportTable.xsl 2011-12-14 10:03:38 +0000 @@ -0,0 +1,86 @@ + + + + +
+

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID
Last Updated
Code
DoIndicators
DoPeriods
DoUnits
Regression
SortOrder
TopLimit
+ + +
+
+ + +

ReportParams

+ + + + + + + + + + + + + + + + + +
ParamGrandParentOrganisationUnit
ParamOrganisationUnit
ParamParentOrganisationUnit
ParamReportingMonth
+
+ + + +

ReportTables

+ + +
+
+
+ +
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/sqlView.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/sqlView.xsl 2011-12-13 17:44:28 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/sqlView.xsl 2011-12-14 10:03:38 +0000 @@ -19,6 +19,10 @@ + Code + + + Description === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/user.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/user.xsl 2011-12-13 18:41:43 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/user.xsl 2011-12-14 10:03:38 +0000 @@ -18,6 +18,10 @@ + Code + + + First Name === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/validationRule.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/validationRule.xsl 2011-12-13 17:44:28 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/validationRule.xsl 2011-12-14 10:03:38 +0000 @@ -19,6 +19,10 @@ + Code + + + Description === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/validationRuleGroup.xsl' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/validationRuleGroup.xsl 2011-12-13 17:44:28 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/html/validationRuleGroup.xsl 2011-12-14 10:03:38 +0000 @@ -19,6 +19,10 @@ + Code + + + Description