=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2014-04-29 09:26:28 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2014-06-23 11:10:21 +0000 @@ -305,7 +305,11 @@ public Collection getOrganisationUnitsWithChildren( String uid ) { - return getOrganisationUnitWithChildren( getOrganisationUnit( uid ).getId() ); + OrganisationUnit unit = getOrganisationUnit( uid ); + + int id = unit != null ? unit.getId() : -1; + + return getOrganisationUnitWithChildren( id ); } public Collection getOrganisationUnitWithChildren( int id ) === 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-06-06 09:06:24 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2014-06-23 11:10:21 +0000 @@ -103,6 +103,7 @@ private static final String ERROR_INVALID_DATA_SET = "Invalid data set: "; private static final String ERROR_INVALID_PERIOD = "Invalid period: "; private static final String ERROR_INVALID_ORG_UNIT = "Invalid org unit: "; + private static final String ERROR_INVALID_START_END_DATE = "Invalid start and/or end date: "; private static final String ERROR_OBJECT_NEEDED_TO_COMPLETE = "Must be provided to complete data set"; @Autowired @@ -139,6 +140,7 @@ // DataValueSet implementation //-------------------------------------------------------------------------- + @Override public void writeDataValueSet( String dataSet, String period, String orgUnit, OutputStream out ) { DataSet dataSet_ = dataSetService.getDataSet( dataSet ); @@ -169,18 +171,6 @@ dataValueSetStore.writeDataValueSetXml( dataSet_, completeDate, period_, orgUnit_, dataSet_.getDataElements(), wrap( period_ ), wrap( orgUnit_ ), out ); } - public void writeDataValueSet( Set dataSets, Date startDate, Date endDate, Set orgUnits, OutputStream out ) - { - Set periods = new HashSet( periodService.getPeriodsBetweenDates( startDate, endDate ) ); - - if ( periods.isEmpty() ) - { - throw new IllegalArgumentException( "At least one period must be specified" ); - } - - dataValueSetStore.writeDataValueSetXml( null, null, null, null, getDataElements( dataSets ), periods, getOrgUnits( orgUnits ), out ); - } - @Override public void writeDataValueSetJson( String dataSet, String period, String orgUnit, OutputStream outputStream ) { @@ -213,31 +203,23 @@ } @Override + public void writeDataValueSet( Set dataSets, Date startDate, Date endDate, Set orgUnits, OutputStream out ) + { + dataValueSetStore.writeDataValueSetXml( null, null, null, null, getDataElements( dataSets ), getPeriods( startDate, endDate ), getOrgUnits( orgUnits ), out ); + } + + @Override public void writeDataValueSetJson( Set dataSets, Date startDate, Date endDate, Set orgUnits, OutputStream outputStream ) { - Set periods = new HashSet( periodService.getPeriodsBetweenDates( startDate, endDate ) ); - - if ( periods.isEmpty() ) - { - throw new IllegalArgumentException( "At least one period must be specified" ); - } - - dataValueSetStore.writeDataValueSetJson( null, null, null, null, getDataElements( dataSets ), periods, getOrgUnits( orgUnits ), outputStream ); + dataValueSetStore.writeDataValueSetJson( null, null, null, null, getDataElements( dataSets ), getPeriods( startDate, endDate ), getOrgUnits( orgUnits ), outputStream ); } + @Override public void writeDataValueSetCsv( Set dataSets, Date startDate, Date endDate, Set orgUnits, Writer writer ) { - Set periods = new HashSet( periodService.getPeriodsBetweenDates( startDate, endDate ) ); - - if ( periods.isEmpty() ) - { - throw new IllegalArgumentException( "At least one period must be specified" ); - } - - dataValueSetStore.writeDataValueSetCsv( getDataElements( dataSets ), periods, getOrgUnits( orgUnits ), writer ); + dataValueSetStore.writeDataValueSetCsv( getDataElements( dataSets ), getPeriods( startDate, endDate ), getOrgUnits( orgUnits ), writer ); } - - + @Override public RootNode getDataValueSetTemplate( DataSet dataSet, Period period, List orgUnits, boolean writeComments, String ouScheme, String deScheme ) @@ -665,6 +647,23 @@ return dataElements; } + private Set getPeriods( Date startDate, Date endDate ) + { + if ( startDate == null || endDate == null || endDate.before( startDate ) ) + { + throw new IllegalArgumentException( ERROR_INVALID_START_END_DATE + startDate + ", " + endDate ); + } + + Set periods = new HashSet( periodService.getPeriodsBetweenDates( startDate, endDate ) ); + + if ( periods.isEmpty() ) + { + throw new IllegalArgumentException( "No periods exist for start/end date: " + startDate + ", " + endDate ); + } + + return periods; + } + private Set getOrgUnits( Set orgUnits ) { Set organisationUnits = new HashSet(); === 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-05-22 12:40:24 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java 2014-06-23 11:10:21 +0000 @@ -126,6 +126,7 @@ log.info( "Get XML bulk data value set for start date: " + startDate + ", end date: " + endDate ); Set ous = getOrganisationUnits( orgUnit, children ); + dataValueSetService.writeDataValueSet( dataSet, startDate, endDate, ous, response.getOutputStream() ); } } @@ -158,6 +159,7 @@ log.info( "Get JSON bulk data value set for start date: " + startDate + ", end date: " + endDate ); Set ous = getOrganisationUnits( orgUnit, children ); + dataValueSetService.writeDataValueSetJson( dataSet, startDate, endDate, ous, response.getOutputStream() ); } }