=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ExportController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ExportController.java 2012-03-07 12:10:37 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ExportController.java 2012-03-07 14:37:17 +0000 @@ -27,6 +27,8 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.hisp.dhis.api.utils.ContextUtils; +import org.hisp.dhis.api.view.Jaxb2Utils; import org.hisp.dhis.api.webdomain.DXF2; import org.hisp.dhis.dataelement.*; import org.hisp.dhis.dataset.DataSet; @@ -46,13 +48,18 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import javax.servlet.http.HttpServletResponse; +import javax.xml.bind.JAXBException; +import java.io.IOException; import java.util.ArrayList; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; /** * @author Morten Olav Hansen */ @Controller -@RequestMapping( value = ExportController.RESOURCE_PATH ) +// @RequestMapping( value = ExportController.RESOURCE_PATH ) public class ExportController { public static final String RESOURCE_PATH = "/export"; @@ -78,7 +85,7 @@ @Autowired private ValidationRuleService validationRuleService; - @RequestMapping( method = RequestMethod.GET ) + @RequestMapping( value = "/export", method = RequestMethod.GET ) @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) public String export( Model model ) { @@ -110,4 +117,47 @@ return "export"; } + + @RequestMapping( value = "/export.zip", method = RequestMethod.GET ) + @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" ) + public void exportZip( HttpServletResponse response ) throws IOException, JAXBException + { + System.err.println( "EXPORT ZIP!" ); + + DXF2 dxf2 = new DXF2(); + + dxf2.setDataElements( new ArrayList( dataElementService.getAllDataElements() ) ); + dxf2.setDataElementGroups( new ArrayList( dataElementService.getAllDataElementGroups() ) ); + dxf2.setDataElementGroupSets( new ArrayList( dataElementService.getAllDataElementGroupSets() ) ); + dxf2.setCategories( new ArrayList( dataElementCategoryService.getAllDataElementCategories() ) ); + dxf2.setCategoryCombos( new ArrayList( dataElementCategoryService.getAllDataElementCategoryCombos() ) ); + dxf2.setCategoryOptions( new ArrayList( dataElementCategoryService.getAllDataElementCategoryOptions() ) ); + dxf2.setCategoryOptionCombos( new ArrayList( dataElementCategoryService.getAllDataElementCategoryOptionCombos() ) ); + + dxf2.setIndicators( new ArrayList( indicatorService.getAllIndicators() ) ); + dxf2.setIndicatorGroups( new ArrayList( indicatorService.getAllIndicatorGroups() ) ); + dxf2.setIndicatorGroupSets( new ArrayList( indicatorService.getAllIndicatorGroupSets() ) ); + + dxf2.setOrganisationUnits( new ArrayList( organisationUnitService.getAllOrganisationUnits() ) ); + dxf2.setOrganisationUnitLevels( new ArrayList( organisationUnitService.getOrganisationUnitLevels() ) ); + dxf2.setOrganisationUnitGroups( new ArrayList( organisationUnitGroupService.getAllOrganisationUnitGroups() ) ); + dxf2.setOrganisationUnitGroupSets( new ArrayList( organisationUnitGroupService.getAllOrganisationUnitGroupSets() ) ); + + dxf2.setDataSets( new ArrayList( dataSetService.getAllDataSets() ) ); + + dxf2.setValidationRules( new ArrayList( validationRuleService.getAllValidationRules() ) ); + dxf2.setValidationRuleGroups( new ArrayList( validationRuleService.getAllValidationRuleGroups() ) ); + + response.setContentType( ContextUtils.CONTENT_TYPE_ZIP ); + response.addHeader( "Content-Disposition", "attachment; filename=\"export.zip\"" ); + response.addHeader( "Content-Transfer-Encoding", "binary" ); + + ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() ); + zip.putNextEntry( new ZipEntry( "export.xml" ) ); + + Jaxb2Utils.marshal( dxf2, zip ); + + zip.closeEntry(); + zip.close(); + } }