=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java 2014-07-10 16:06:48 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java 2014-08-24 15:24:33 +0000 @@ -42,19 +42,22 @@ import org.hisp.dhis.period.Period; import org.hisp.dhis.scheduling.TaskId; +/** + * @author Lars Helge Overland + */ public interface DataValueSetService { - void writeDataValueSet( String dataSet, String period, String orgUnit, OutputStream out ); + void writeDataValueSetXml( String dataSet, String period, String orgUnit, OutputStream out ); - void writeDataValueSet( Set dataSets, Date startDate, Date endDate, Set orgUnits, OutputStream out ); + void writeDataValueSetXml( Set dataSets, Date startDate, Date endDate, Set orgUnits, boolean includeChildren, OutputStream out ); void writeDataValueSetJson( String ds, String period, String ou, OutputStream outputStream ); - void writeDataValueSetJson( Set dataSet, Date startDate, Date endDate, Set ous, OutputStream outputStream ); + void writeDataValueSetJson( Set dataSet, Date startDate, Date endDate, Set ous, boolean includeChildren, OutputStream outputStream ); void writeDataValueSetJson( Date lastUpdated, OutputStream outputStream ); - void writeDataValueSetCsv( Set dataSets, Date startDate, Date endDate, Set orgUnits, Writer writer ); + void writeDataValueSetCsv( Set dataSets, Date startDate, Date endDate, Set orgUnits, boolean includeChildren, Writer writer ); RootNode getDataValueSetTemplate( DataSet dataSet, Period period, List orgUnits, boolean writeComments, String ouScheme, String deScheme ); === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetStore.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetStore.java 2014-08-14 05:46:19 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetStore.java 2014-08-24 15:24:33 +0000 @@ -42,13 +42,13 @@ */ public interface DataValueSetStore { - public void writeDataValueSetXml(Set dataSets, Date completeDate, Period period, OrganisationUnit orgUnit, - Set periods, Set orgUnits, OutputStream out); - - public void writeDataValueSetCsv(Set periods, Set orgUnits, Writer writer); - - public void writeDataValueSetJson(Set dataSets, Date completeDate, Period period, OrganisationUnit orgUnit, - Set periods, Set orgUnits, OutputStream out); + public void writeDataValueSetXml( Set dataSets, Date completeDate, Period period, + OrganisationUnit orgUnit, Set periods, Set orgUnits, OutputStream out ); + + public void writeDataValueSetCsv( Set dataSets, Set periods, Set orgUnits, Writer writer ); + + public void writeDataValueSetJson( Set dataSets, Date completeDate, Period period, + OrganisationUnit orgUnit, Set periods, Set orgUnits, OutputStream out ); void writeDataValueSetJson( Date lastUpdated, OutputStream outputStream ); } === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2014-08-20 14:33:02 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2014-08-24 15:24:33 +0000 @@ -58,6 +58,7 @@ import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty; import org.hisp.dhis.common.IdentifiableObjectManager; +import org.hisp.dhis.common.IdentifiableObjectUtils; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; import org.hisp.dhis.dataelement.DataElementCategoryService; @@ -145,7 +146,7 @@ //-------------------------------------------------------------------------- @Override - public void writeDataValueSet( String dataSet, String period, String orgUnit, OutputStream out ) + public void writeDataValueSetXml( String dataSet, String period, String orgUnit, OutputStream out ) { DataSet dataSet_ = dataSetService.getDataSet( dataSet ); Period period_ = PeriodType.getPeriodFromIsoString( period ); @@ -180,18 +181,34 @@ } @Override - public void writeDataValueSet( Set dataSetUids, Date startDate, Date endDate, Set orgUnits, - OutputStream out ) + public void writeDataValueSetXml( Set dataSets, Date startDate, Date endDate, Set orgUnits, + boolean includeChildren, OutputStream out ) { - Set periods = new HashSet<>( periodService.getPeriodsBetweenDates( startDate, endDate ) ); - List dataSets = dataSetService.getDataSetsByUid( dataSetUids ); + Set ds = new HashSet<>( dataSetService.getDataSetsByUid( dataSets ) ); + Set pe = new HashSet<>( periodService.getPeriodsBetweenDates( startDate, endDate ) ); + Set ou = new HashSet<>( organisationUnitService.getOrganisationUnitsByUid( orgUnits ) ); - if ( periods.isEmpty() ) + if ( ds.isEmpty() ) + { + throw new IllegalArgumentException( "At least one data set must be specified" ); + } + + if ( pe.isEmpty() ) { throw new IllegalArgumentException( "At least one period must be specified" ); } - - dataValueSetStore.writeDataValueSetXml( newHashSet( dataSets ), null, null, null, periods, getOrgUnits( orgUnits ), out ); + + if ( ou.isEmpty() ) + { + throw new IllegalArgumentException( "At least one organisation unit must be specified" ); + } + + if ( includeChildren ) + { + ou = new HashSet<>( organisationUnitService.getOrganisationUnitsWithChildren( IdentifiableObjectUtils.getUids( ou ) ) ); + } + + dataValueSetStore.writeDataValueSetXml( ds, null, null, null, pe, ou, out ); } @Override @@ -236,33 +253,65 @@ } @Override - public void writeDataValueSetJson( Set dataSetUids, Date startDate, Date endDate, Set orgUnits, - OutputStream outputStream ) + public void writeDataValueSetJson( Set dataSets, Date startDate, Date endDate, Set orgUnits, + boolean includeChildren, OutputStream outputStream ) { - Set periods = new HashSet<>( periodService.getPeriodsBetweenDates( startDate, endDate ) ); - List dataSets = dataSetService.getDataSetsByUid( dataSetUids ); + Set ds = new HashSet<>( dataSetService.getDataSetsByUid( dataSets ) ); + Set pe = new HashSet<>( periodService.getPeriodsBetweenDates( startDate, endDate ) ); + Set ou = new HashSet<>( organisationUnitService.getOrganisationUnitsByUid( orgUnits ) ); - if ( periods.isEmpty() ) + if ( ds.isEmpty() ) + { + throw new IllegalArgumentException( "At least one data set must be specified" ); + } + + if ( pe.isEmpty() ) { throw new IllegalArgumentException( "At least one period must be specified" ); } + + if ( ou.isEmpty() ) + { + throw new IllegalArgumentException( "At least one organisation unit must be specified" ); + } + + if ( includeChildren ) + { + ou = new HashSet<>( organisationUnitService.getOrganisationUnitsWithChildren( IdentifiableObjectUtils.getUids( ou ) ) ); + } - dataValueSetStore.writeDataValueSetJson( newHashSet( dataSets ), null, null, null, periods, getOrgUnits( orgUnits ), - outputStream ); + dataValueSetStore.writeDataValueSetJson( ds, null, null, null, pe, ou, outputStream ); } @Override public void writeDataValueSetCsv( Set dataSets, Date startDate, Date endDate, Set orgUnits, - Writer writer ) + boolean includeChildren, Writer writer ) { - Set periods = new HashSet<>( periodService.getPeriodsBetweenDates( startDate, endDate ) ); + Set ds = new HashSet<>( dataSetService.getDataSetsByUid( dataSets ) ); + Set pe = new HashSet<>( periodService.getPeriodsBetweenDates( startDate, endDate ) ); + Set ou = new HashSet<>( organisationUnitService.getOrganisationUnitsByUid( orgUnits ) ); - if ( periods.isEmpty() ) + if ( ds.isEmpty() ) + { + throw new IllegalArgumentException( "At least one data set must be specified" ); + } + + if ( pe.isEmpty() ) { throw new IllegalArgumentException( "At least one period must be specified" ); } + + if ( ou.isEmpty() ) + { + throw new IllegalArgumentException( "At least one organisation unit must be specified" ); + } + + if ( includeChildren ) + { + ou = new HashSet<>( organisationUnitService.getOrganisationUnitsWithChildren( IdentifiableObjectUtils.getUids( ou ) ) ); + } - dataValueSetStore.writeDataValueSetCsv( periods, getOrgUnits( orgUnits ), writer ); + dataValueSetStore.writeDataValueSetCsv( ds, pe, ou, writer ); } @Override @@ -721,25 +770,6 @@ summary.setDataSetComplete( DateUtils.getMediumDateString( completeDate ) ); } - private Set getOrgUnits( Set orgUnits ) - { - Set organisationUnits = new HashSet<>(); - - for ( String ou : orgUnits ) - { - OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( ou ); - - if ( orgUnit == null ) - { - throw new IllegalArgumentException( ERROR_INVALID_ORG_UNIT + ou ); - } - - organisationUnits.add( orgUnit ); - } - - return organisationUnits; - } - private Map getUuidOrgUnitMap() { Map orgUnitMap = new HashMap<>(); === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java 2014-08-22 12:35:55 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java 2014-08-24 15:24:33 +0000 @@ -84,7 +84,8 @@ } @Override - public void writeDataValueSetJson( Set dataSets, Date completeDate, Period period, OrganisationUnit orgUnit, Set periods, Set orgUnits, OutputStream outputStream ) + public void writeDataValueSetJson( Set dataSets, Date completeDate, Period period, OrganisationUnit orgUnit, + Set periods, Set orgUnits, OutputStream outputStream ) { DataValueSet dataValueSet = new StreamingJsonDataValueSet( outputStream ); @@ -96,13 +97,13 @@ } @Override - public void writeDataValueSetCsv( Set periods, Set orgUnits, Writer writer ) + public void writeDataValueSetCsv( Set dataSets, Set periods, Set orgUnits, Writer writer ) { DataValueSet dataValueSet = new StreamingCsvDataValueSet( new CsvWriter( writer, CSV_DELIM ) ); - SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet( getDataValueSql( null, periods, orgUnits ) ); + SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet( getDataValueSql( dataSets, periods, orgUnits ) ); - writeDataValueSet( sqlRowSet, null, null, null, null, periods, orgUnits, dataValueSet ); + writeDataValueSet( sqlRowSet, dataSets, null, null, null, periods, orgUnits, dataValueSet ); } @Override === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java 2014-08-15 07:40:20 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java 2014-08-24 15:24:33 +0000 @@ -119,7 +119,7 @@ log.info( "Get XML data value set for data set: " + ds + ", period: " + period + ", org unit: " + ou ); - dataValueSetService.writeDataValueSet( ds, period, ou, response.getOutputStream() ); + dataValueSetService.writeDataValueSetXml( ds, period, ou, response.getOutputStream() ); } else { @@ -127,7 +127,7 @@ Set ous = getOrganisationUnits( orgUnit, children ); - dataValueSetService.writeDataValueSet( dataSet, startDate, endDate, ous, response.getOutputStream() ); + dataValueSetService.writeDataValueSetXml( dataSet, startDate, endDate, ous, false, response.getOutputStream() ); } } @@ -160,7 +160,7 @@ Set ous = getOrganisationUnits( orgUnit, children ); - dataValueSetService.writeDataValueSetJson( dataSet, startDate, endDate, ous, response.getOutputStream() ); + dataValueSetService.writeDataValueSetJson( dataSet, startDate, endDate, ous, false, response.getOutputStream() ); } } @@ -178,7 +178,7 @@ Set ous = getOrganisationUnits( orgUnit, children ); response.setContentType( CONTENT_TYPE_CSV ); - dataValueSetService.writeDataValueSetCsv( dataSet, startDate, endDate, ous, response.getWriter() ); + dataValueSetService.writeDataValueSetCsv( dataSet, startDate, endDate, ous, false, response.getWriter() ); } private Set getOrganisationUnits( Set orgUnits, boolean children ) === modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java' --- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java 2014-08-15 07:40:20 +0000 +++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java 2014-08-24 15:24:33 +0000 @@ -43,6 +43,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; +import org.hisp.dhis.common.IdentifiableObjectUtils; import org.hisp.dhis.dxf2.datavalueset.DataValueSetService; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; @@ -116,18 +117,8 @@ { //TODO reimplement to use web api - Set orgUnits = new HashSet<>(); - - for ( OrganisationUnit unit : selectionTreeManager.getReloadedSelectedOrganisationUnits() ) - { - Collection children = organisationUnitService.getOrganisationUnitWithChildren( unit.getId() ); - - for ( OrganisationUnit child : children ) - { - orgUnits.add( child.getUid() ); - } - } - + Set orgUnits = new HashSet<>( IdentifiableObjectUtils.getUids( selectionTreeManager.getSelectedOrganisationUnits() ) ); + HttpServletResponse response = ServletActionContext.getResponse(); if ( FORMAT_CSV.equals( exportFormat ) ) @@ -136,13 +127,13 @@ Writer writer = new OutputStreamWriter( getZipOut( response, getFileName( EXTENSION_CSV ) ) ); - dataValueSetService.writeDataValueSetCsv( selectedDataSets, getMediumDate( startDate ), getMediumDate( endDate ), orgUnits, writer ); + dataValueSetService.writeDataValueSetCsv( selectedDataSets, getMediumDate( startDate ), getMediumDate( endDate ), orgUnits, true, writer ); } else { ContextUtils.configureResponse( response, CONTENT_TYPE_XML, true, getFileName( EXTENSION_XML_ZIP ), true ); - dataValueSetService.writeDataValueSet( selectedDataSets, getMediumDate( startDate ), getMediumDate( endDate ), orgUnits, getZipOut( response, getFileName( EXTENSION_XML ) ) ); + dataValueSetService.writeDataValueSetXml( selectedDataSets, getMediumDate( startDate ), getMediumDate( endDate ), orgUnits, true, getZipOut( response, getFileName( EXTENSION_XML ) ) ); } return SUCCESS;