dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41074
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20899: minor
------------------------------------------------------------
revno: 20899
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-10-30 13:47:40 +0700
message:
minor
removed:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/FilteredMetaDataController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MetaDataController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MetaDataFilterController.java
added:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/FilteredMetaDataController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetaDataController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetaDataFilterController.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/FilteredMetaDataController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/FilteredMetaDataController.java 2015-08-30 17:07:42 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/FilteredMetaDataController.java 1970-01-01 00:00:00 +0000
@@ -1,268 +0,0 @@
-package org.hisp.dhis.webapi.controller;
-
-/*
- * Copyright (c) 2004-2015, 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 com.fasterxml.jackson.databind.ObjectMapper;
-import net.sf.json.JSONObject;
-import org.hisp.dhis.common.view.ExportView;
-import org.hisp.dhis.common.filter.MetaDataFilter;
-import org.hisp.dhis.dxf2.common.FilterOptions;
-import org.hisp.dhis.dxf2.common.ImportOptions;
-import org.hisp.dhis.dxf2.common.JacksonUtils;
-import org.hisp.dhis.dxf2.metadata.ExportService;
-import org.hisp.dhis.dxf2.metadata.ImportService;
-import org.hisp.dhis.dxf2.metadata.MetaData;
-import org.hisp.dhis.dxf2.metadata.tasks.ImportMetaDataTask;
-import org.hisp.dhis.importexport.ImportStrategy;
-import org.hisp.dhis.scheduling.TaskCategory;
-import org.hisp.dhis.scheduling.TaskId;
-import org.hisp.dhis.system.scheduling.Scheduler;
-import org.hisp.dhis.user.CurrentUserService;
-import org.hisp.dhis.user.User;
-import org.hisp.dhis.common.cache.CacheStrategy;
-import org.hisp.dhis.webapi.utils.ContextUtils;
-import org.hisp.dhis.webapi.webdomain.WebOptions;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.zip.GZIPOutputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-/**
- * @author Ovidiu Rosu <rosu.ovi@xxxxxxxxx>
- */
-@Controller
-public class FilteredMetaDataController
-{
- public static final String RESOURCE_PATH = "/filteredMetaData";
-
- @Autowired
- private ExportService exportService;
-
- @Qualifier( "contextUtils" )
- @Autowired
- private ContextUtils contextUtils;
-
- @Autowired
- private Scheduler scheduler;
-
- @Autowired
- private ImportService importService;
-
- @Autowired
- private CurrentUserService currentUserService;
-
- private boolean dryRun;
-
- private ImportStrategy strategy;
-
- //--------------------------------------------------------------------------
- // Getters & Setters
- //--------------------------------------------------------------------------
-
- public void setDryRun( boolean dryRun )
- {
- this.dryRun = dryRun;
- }
-
- public void setStrategy( String strategy )
- {
- this.strategy = ImportStrategy.valueOf( strategy );
- }
-
- //--------------------------------------------------------------------------
- // Detailed MetaData Export - POST Requests
- //--------------------------------------------------------------------------
-
- @RequestMapping( value = FilteredMetaDataController.RESOURCE_PATH, headers = "Accept=application/json" )
- @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
- public String detailedExport( @RequestParam Map<String, String> parameters, Model model )
- {
- WebOptions options = new WebOptions( parameters );
- MetaData metaData = exportService.getMetaData( options );
-
- model.addAttribute( "model", metaData );
- model.addAttribute( "viewClass", "export" );
-
- return "export";
- }
-
- @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + ".xml", produces = "*/*" )
- @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
- public void exportXml( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException
- {
- FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) );
- MetaData metaData = exportService.getFilteredMetaData( filterOptions );
-
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.NO_CACHE, "metaData.xml", true );
- JacksonUtils.toXmlWithView( response.getOutputStream(), metaData, ExportView.class );
- }
-
- @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + ".json", produces = "*/*" )
- @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
- public void exportJson( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException
- {
- FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) );
- MetaData metaData = exportService.getFilteredMetaData( filterOptions );
-
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE, "metaData.json", true );
- JacksonUtils.toJsonWithView( response.getOutputStream(), metaData, ExportView.class );
- }
-
- @RequestMapping( method = RequestMethod.POST, value = { FilteredMetaDataController.RESOURCE_PATH + ".xml.zip" }, produces = "*/*" )
- @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
- public void exportZippedXML( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException
- {
- FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) );
- MetaData metaData = exportService.getFilteredMetaData( filterOptions );
-
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "metaData.xml.zip", true );
- response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
-
- ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() );
- zip.putNextEntry( new ZipEntry( "metaData.xml" ) );
-
- JacksonUtils.toXmlWithView( zip, metaData, ExportView.class );
- }
-
- @RequestMapping( method = RequestMethod.POST, value = { FilteredMetaDataController.RESOURCE_PATH + ".json.zip" }, produces = "*/*" )
- @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
- public void exportZippedJSON( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException
- {
- FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) );
- MetaData metaData = exportService.getFilteredMetaData( filterOptions );
-
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "metaData.json.zip", true );
- response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
-
- ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() );
- zip.putNextEntry( new ZipEntry( "metaData.json" ) );
-
- JacksonUtils.toJsonWithView( zip, metaData, ExportView.class );
- }
-
- @RequestMapping( method = RequestMethod.POST, value = { FilteredMetaDataController.RESOURCE_PATH + ".xml.gz" }, produces = "*/*" )
- @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
- public void exportGZippedXML( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException
- {
- FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) );
- MetaData metaData = exportService.getFilteredMetaData( filterOptions );
-
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_GZIP, CacheStrategy.NO_CACHE, "metaData.xml.gz", true );
- response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
-
- GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() );
- JacksonUtils.toXmlWithView( gzip, metaData, ExportView.class );
- }
-
- @RequestMapping( method = RequestMethod.POST, value = { FilteredMetaDataController.RESOURCE_PATH + ".json.gz" }, produces = "*/*" )
- @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
- public void exportGZippedJSON( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException
- {
- FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) );
- MetaData metaData = exportService.getFilteredMetaData( filterOptions );
-
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_GZIP, CacheStrategy.NO_CACHE, "metaData.json.gz", true );
- response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
-
- GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() );
- JacksonUtils.toJsonWithView( gzip, metaData, ExportView.class );
- }
-
- //--------------------------------------------------------------------------
- // Detailed MetaData Export - Filter functionality
- //--------------------------------------------------------------------------
-
- @RequestMapping( method = RequestMethod.GET, value = FilteredMetaDataController.RESOURCE_PATH + "/getMetaDataFilters" )
- @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
- public @ResponseBody String getFilters( HttpServletRequest request, HttpServletResponse response ) throws IOException
- {
- List<MetaDataFilter> metaDataFilters = exportService.getFilters();
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE );
- return JacksonUtils.toJsonAsString( metaDataFilters );
- }
-
- @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + "/saveFilter" )
- @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
- public void saveFilter( @RequestBody JSONObject json, HttpServletResponse response ) throws IOException
- {
- exportService.saveFilter( json );
- }
-
- @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + "/updateFilter" )
- @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
- public void updateFilter( @RequestBody JSONObject json, HttpServletResponse response ) throws IOException
- {
- exportService.updateFilter( json );
- }
-
- @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + "/deleteFilter" )
- @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
- public void deleteFilter( @RequestBody JSONObject json, HttpServletResponse response ) throws IOException
- {
- exportService.deleteFilter( json );
- }
-
- //--------------------------------------------------------------------------
- // Detailed MetaData Import - POST Requests
- //--------------------------------------------------------------------------
-
- @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + "/importDetailedMetaData" )
- @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_IMPORT')" )
- public void importDetailedMetaData( @RequestBody JSONObject json, HttpServletResponse response ) throws IOException
- {
- strategy = ImportStrategy.valueOf( json.getString( "strategy" ) );
- dryRun = json.getBoolean( "dryRun" );
-
- TaskId taskId = new TaskId( TaskCategory.METADATA_IMPORT, currentUserService.getCurrentUser() );
- User user = currentUserService.getCurrentUser();
-
- MetaData metaData = new ObjectMapper().readValue( json.getString( "metaData" ), MetaData.class );
-
- ImportOptions importOptions = new ImportOptions();
- importOptions.setStrategy( strategy );
- importOptions.setDryRun( dryRun );
-
- scheduler.executeTask( new ImportMetaDataTask( user.getUid(), importService, importOptions, taskId, metaData ) );
- }
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MetaDataController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MetaDataController.java 2015-08-30 17:07:42 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MetaDataController.java 1970-01-01 00:00:00 +0000
@@ -1,413 +0,0 @@
-package org.hisp.dhis.webapi.controller;
-
-/*
- * Copyright (c) 2004-2015, 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.dxf2.common.ImportOptions;
-import org.hisp.dhis.dxf2.common.JacksonUtils;
-import org.hisp.dhis.dxf2.metadata.ExportService;
-import org.hisp.dhis.dxf2.metadata.ImportService;
-import org.hisp.dhis.dxf2.metadata.ImportSummary;
-import org.hisp.dhis.dxf2.metadata.MetaData;
-import org.hisp.dhis.dxf2.metadata.tasks.ImportMetaDataTask;
-import org.hisp.dhis.importexport.ImportStrategy;
-import org.hisp.dhis.scheduling.TaskCategory;
-import org.hisp.dhis.scheduling.TaskId;
-import org.hisp.dhis.system.scheduling.Scheduler;
-import org.hisp.dhis.user.CurrentUserService;
-import org.hisp.dhis.webapi.utils.ContextUtils;
-import org.hisp.dhis.common.cache.CacheStrategy;
-import org.hisp.dhis.webapi.webdomain.WebOptions;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.MediaType;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.Map;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.GZIPOutputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import java.util.zip.ZipOutputStream;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@Controller
-@RequestMapping( method = RequestMethod.GET )
-public class MetaDataController
-{
- public static final String RESOURCE_PATH = "/meta{xyz:[Dd]}ata";
-
- @Autowired
- private ExportService exportService;
-
- @Autowired
- private ImportService importService;
-
- @Autowired
- private ContextUtils contextUtils;
-
- @Autowired
- private Scheduler scheduler;
-
- @Autowired
- private CurrentUserService currentUserService;
-
- //--------------------------------------------------------------------------
- // Export
- //--------------------------------------------------------------------------
-
- @RequestMapping( value = MetaDataController.RESOURCE_PATH )
- public String export( @RequestParam Map<String, String> parameters, Model model )
- {
- WebOptions options = new WebOptions( parameters );
- MetaData metaData = exportService.getMetaData( options );
-
- model.addAttribute( "model", metaData );
- model.addAttribute( "viewClass", options.getViewClass( "export" ) );
-
- return "export";
- }
-
- @RequestMapping( value = MetaDataController.RESOURCE_PATH + ".xml", produces = "*/*" )
- public void exportXml( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
- {
- WebOptions options = new WebOptions( parameters );
- MetaData metaData = exportService.getMetaData( options );
-
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.NO_CACHE, "metadata.xml", true );
-
- Class<?> viewClass = JacksonUtils.getViewClass( options.getViewClass( "export" ) );
- JacksonUtils.toXmlWithView( response.getOutputStream(), metaData, viewClass );
- }
-
- @RequestMapping( value = MetaDataController.RESOURCE_PATH + ".json", produces = "*/*" )
- public void exportJson( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
- {
- WebOptions options = new WebOptions( parameters );
- MetaData metaData = exportService.getMetaData( options );
-
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE, "metadata.json", true );
-
- Class<?> viewClass = JacksonUtils.getViewClass( options.getViewClass( "export" ) );
- JacksonUtils.toJsonWithView( response.getOutputStream(), metaData, viewClass );
- }
-
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".zip" }, produces = "*/*" )
- public void exportZipped( @RequestParam Map<String, String> parameters, HttpServletResponse response, HttpServletRequest request ) throws IOException
- {
- String accept = request.getHeader( "Accept" );
-
- if ( isJson( accept ) )
- {
- exportZippedJSON( parameters, response );
- }
- else
- {
- exportZippedXML( parameters, response );
- }
- }
-
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".xml.zip" }, produces = "*/*" )
- public void exportZippedXML( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
- {
- WebOptions options = new WebOptions( parameters );
- MetaData metaData = exportService.getMetaData( options );
-
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "metadata.xml.zip", true );
- response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
-
- ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() );
- zip.putNextEntry( new ZipEntry( "metadata.xml" ) );
-
- Class<?> viewClass = JacksonUtils.getViewClass( options.getViewClass( "export" ) );
- JacksonUtils.toXmlWithView( zip, metaData, viewClass );
- }
-
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".json.zip" }, produces = "*/*" )
- public void exportZippedJSON( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
- {
- WebOptions options = new WebOptions( parameters );
- MetaData metaData = exportService.getMetaData( options );
-
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "metadata.json.zip", true );
- response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
-
- ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() );
- zip.putNextEntry( new ZipEntry( "metadata.json" ) );
-
- Class<?> viewClass = JacksonUtils.getViewClass( options.getViewClass( "export" ) );
- JacksonUtils.toJsonWithView( zip, metaData, viewClass );
- }
-
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".gz" }, produces = "*/*" )
- public void exportGZipped( @RequestParam Map<String, String> parameters, HttpServletResponse response, HttpServletRequest request ) throws IOException
- {
- String accept = request.getHeader( "Accept" );
-
- if ( isJson( accept ) )
- {
- exportGZippedJSON( parameters, response );
- }
- else
- {
- exportGZippedXML( parameters, response );
- }
- }
-
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".xml.gz" }, produces = "*/*" )
- public void exportGZippedXML( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
- {
- WebOptions options = new WebOptions( parameters );
- MetaData metaData = exportService.getMetaData( options );
-
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_GZIP, CacheStrategy.NO_CACHE, "metadata.xml.gz", true );
- response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
-
- GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() );
-
- Class<?> viewClass = JacksonUtils.getViewClass( options.getViewClass( "export" ) );
- JacksonUtils.toXmlWithView( gzip, metaData, viewClass );
- }
-
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".json.gz" }, produces = "*/*" )
- public void exportGZippedJSON( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
- {
- WebOptions options = new WebOptions( parameters );
- MetaData metaData = exportService.getMetaData( options );
-
- contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_GZIP, CacheStrategy.NO_CACHE, "metadata.json.gz", true );
- response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
-
- GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() );
-
- Class<?> viewClass = JacksonUtils.getViewClass( options.getViewClass( "export" ) );
- JacksonUtils.toJsonWithView( gzip, metaData, viewClass );
- }
-
- //--------------------------------------------------------------------------
- // Import
- //--------------------------------------------------------------------------
-
- @RequestMapping( value = MetaDataController.RESOURCE_PATH, method = RequestMethod.POST, consumes = { "application/xml", "text/*" } )
- public void importXml( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
- {
- MetaData metaData = JacksonUtils.fromXml( request.getInputStream(), MetaData.class );
-
- if ( importOptions.isAsync() )
- {
- startAsyncImport( importOptions, response, request, metaData );
- }
- else
- {
- startSyncImportXml( importOptions, response, metaData );
- }
- }
-
- @RequestMapping( value = MetaDataController.RESOURCE_PATH, method = RequestMethod.DELETE, consumes = { "application/xml", "text/*" } )
- public void deleteXml( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
- {
- importOptions.setImportStrategy( ImportStrategy.DELETE );
- importXml( importOptions, response, request );
- }
-
- @RequestMapping( value = MetaDataController.RESOURCE_PATH, method = RequestMethod.POST, consumes = "application/json" )
- public void importJson( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
- {
- MetaData metaData = JacksonUtils.fromJson( request.getInputStream(), MetaData.class );
-
- if ( importOptions.isAsync() )
- {
- startAsyncImport( importOptions, response, request, metaData );
- }
- else
- {
- startSyncImportJson( importOptions, response, metaData );
- }
- }
-
- @RequestMapping( value = MetaDataController.RESOURCE_PATH, method = RequestMethod.DELETE, consumes = "application/json" )
- public void deleteJson( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
- {
- importOptions.setImportStrategy( ImportStrategy.DELETE );
- importJson( importOptions, response, request );
- }
-
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".zip", MetaDataController.RESOURCE_PATH + ".xml.zip" }, method = RequestMethod.POST, consumes = { "application/xml", "text/*" } )
- public void importZippedXml( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
- {
- ZipInputStream zip = new ZipInputStream( request.getInputStream() );
- zip.getNextEntry();
-
- MetaData metaData = JacksonUtils.fromXml( zip, MetaData.class );
-
- if ( importOptions.isAsync() )
- {
- startAsyncImport( importOptions, response, request, metaData );
- }
- else
- {
- startSyncImportXml( importOptions, response, metaData );
- }
- }
-
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".zip", MetaDataController.RESOURCE_PATH + ".xml.zip" }, method = RequestMethod.DELETE, consumes = { "application/xml", "text/*" } )
- public void deleteZippedXml( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
- {
- importOptions.setImportStrategy( ImportStrategy.DELETE );
- importZippedXml( importOptions, response, request );
- }
-
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".zip", MetaDataController.RESOURCE_PATH + ".json.zip" }, method = RequestMethod.POST, consumes = "application/json" )
- public void importZippedJson( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
- {
- ZipInputStream zip = new ZipInputStream( request.getInputStream() );
- zip.getNextEntry();
-
- MetaData metaData = JacksonUtils.fromJson( zip, MetaData.class );
-
- if ( importOptions.isAsync() )
- {
- startAsyncImport( importOptions, response, request, metaData );
- }
- else
- {
- startSyncImportJson( importOptions, response, metaData );
- }
- }
-
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".zip", MetaDataController.RESOURCE_PATH + ".json.zip" }, method = RequestMethod.DELETE, consumes = "application/json" )
- public void deleteZippedJson( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
- {
- importOptions.setImportStrategy( ImportStrategy.DELETE );
- importZippedJson( importOptions, response, request );
- }
-
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".gz", MetaDataController.RESOURCE_PATH + ".xml.gz" }, method = RequestMethod.POST, consumes = { "application/xml", "text/*" } )
- public void importGZippedXml( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
- {
- GZIPInputStream gzip = new GZIPInputStream( request.getInputStream() );
- MetaData metaData = JacksonUtils.fromXml( gzip, MetaData.class );
-
- if ( importOptions.isAsync() )
- {
- startAsyncImport( importOptions, response, request, metaData );
- }
- else
- {
- startSyncImportXml( importOptions, response, metaData );
- }
- }
-
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".gz", MetaDataController.RESOURCE_PATH + ".xml.gz" }, method = RequestMethod.DELETE, consumes = { "application/xml", "text/*" } )
- public void deleteGZippedXml( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
- {
- importOptions.setImportStrategy( ImportStrategy.DELETE );
- importGZippedXml( importOptions, response, request );
- }
-
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".gz", MetaDataController.RESOURCE_PATH + ".json.gz" }, method = RequestMethod.POST, consumes = "application/json" )
- public void importGZippedJson( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
- {
- GZIPInputStream gzip = new GZIPInputStream( request.getInputStream() );
- MetaData metaData = JacksonUtils.fromJson( gzip, MetaData.class );
-
- if ( importOptions.isAsync() )
- {
- startAsyncImport( importOptions, response, request, metaData );
- }
- else
- {
- startSyncImportJson( importOptions, response, metaData );
- }
- }
-
- @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".gz", MetaDataController.RESOURCE_PATH + ".json.gz" }, method = RequestMethod.DELETE, consumes = "application/json" )
- public void deleteGZippedJson( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
- {
- importOptions.setImportStrategy( ImportStrategy.DELETE );
- importGZippedJson( importOptions, response, request );
- }
-
- //--------------------------------------------------------------------------
- // Helpers
- //--------------------------------------------------------------------------
-
- private void startSyncImportXml( ImportOptions importOptions, HttpServletResponse response, MetaData metaData ) throws IOException
- {
- String userUid = currentUserService.getCurrentUser().getUid();
-
- ImportSummary importSummary = importService.importMetaData( userUid, metaData, importOptions, null );
- response.setStatus( HttpServletResponse.SC_OK );
- response.setContentType( ContextUtils.CONTENT_TYPE_XML );
- JacksonUtils.toXml( response.getOutputStream(), importSummary );
- }
-
- private void startSyncImportJson( ImportOptions importOptions, HttpServletResponse response, MetaData metaData ) throws IOException
- {
- String userUid = currentUserService.getCurrentUser().getUid();
-
- ImportSummary importSummary = importService.importMetaData( userUid, metaData, importOptions, null );
- response.setStatus( HttpServletResponse.SC_OK );
- response.setContentType( ContextUtils.CONTENT_TYPE_JSON );
- JacksonUtils.toJson( response.getOutputStream(), importSummary );
- }
-
- private void startAsyncImport( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request, MetaData metaData )
- {
- String userUid = currentUserService.getCurrentUser().getUid();
-
- TaskId taskId = new TaskId( TaskCategory.METADATA_IMPORT, currentUserService.getCurrentUser() );
-
- scheduler.executeTask( new ImportMetaDataTask( userUid, importService, importOptions, taskId, metaData ) );
-
- response.setHeader( "Location", ContextUtils.getRootPath( request ) + "/system/tasks/" + TaskCategory.METADATA_IMPORT );
- response.setStatus( HttpServletResponse.SC_ACCEPTED );
- }
-
- //--------------------------------------------------------------------------
- // Supportive Methods
- //--------------------------------------------------------------------------
-
- public boolean isJson( String accept )
- {
- return accept != null && MediaType.parseMediaType( accept ).isCompatibleWith( MediaType.APPLICATION_JSON );
- }
-
- public boolean isXml( String accept )
- {
- return accept != null && MediaType.parseMediaType( accept ).isCompatibleWith( MediaType.APPLICATION_XML );
- }
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MetaDataFilterController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MetaDataFilterController.java 2015-07-14 07:33:21 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/MetaDataFilterController.java 1970-01-01 00:00:00 +0000
@@ -1,44 +0,0 @@
-package org.hisp.dhis.webapi.controller;
-
-/*
- * Copyright (c) 2004-2015, 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.filter.MetaDataFilter;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-
-/**
- * @author Ovidiu Rosu <rosu.ovi@xxxxxxxxx>
- */
-@Controller
-@RequestMapping( value = MetaDataFilterController.RESOURCE_PATH )
-public class MetaDataFilterController
- extends AbstractCrudController<MetaDataFilter>
-{
- public static final String RESOURCE_PATH = "/metaDataFilters";
-}
=== added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata'
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/FilteredMetaDataController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/FilteredMetaDataController.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/FilteredMetaDataController.java 2015-10-30 06:47:40 +0000
@@ -0,0 +1,268 @@
+package org.hisp.dhis.webapi.controller.metadata;
+
+/*
+ * Copyright (c) 2004-2015, 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 com.fasterxml.jackson.databind.ObjectMapper;
+import net.sf.json.JSONObject;
+import org.hisp.dhis.common.view.ExportView;
+import org.hisp.dhis.common.filter.MetaDataFilter;
+import org.hisp.dhis.dxf2.common.FilterOptions;
+import org.hisp.dhis.dxf2.common.ImportOptions;
+import org.hisp.dhis.dxf2.common.JacksonUtils;
+import org.hisp.dhis.dxf2.metadata.ExportService;
+import org.hisp.dhis.dxf2.metadata.ImportService;
+import org.hisp.dhis.dxf2.metadata.MetaData;
+import org.hisp.dhis.dxf2.metadata.tasks.ImportMetaDataTask;
+import org.hisp.dhis.importexport.ImportStrategy;
+import org.hisp.dhis.scheduling.TaskCategory;
+import org.hisp.dhis.scheduling.TaskId;
+import org.hisp.dhis.system.scheduling.Scheduler;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.user.User;
+import org.hisp.dhis.common.cache.CacheStrategy;
+import org.hisp.dhis.webapi.utils.ContextUtils;
+import org.hisp.dhis.webapi.webdomain.WebOptions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.GZIPOutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * @author Ovidiu Rosu <rosu.ovi@xxxxxxxxx>
+ */
+@Controller
+public class FilteredMetaDataController
+{
+ public static final String RESOURCE_PATH = "/filteredMetaData";
+
+ @Autowired
+ private ExportService exportService;
+
+ @Qualifier( "contextUtils" )
+ @Autowired
+ private ContextUtils contextUtils;
+
+ @Autowired
+ private Scheduler scheduler;
+
+ @Autowired
+ private ImportService importService;
+
+ @Autowired
+ private CurrentUserService currentUserService;
+
+ private boolean dryRun;
+
+ private ImportStrategy strategy;
+
+ //--------------------------------------------------------------------------
+ // Getters & Setters
+ //--------------------------------------------------------------------------
+
+ public void setDryRun( boolean dryRun )
+ {
+ this.dryRun = dryRun;
+ }
+
+ public void setStrategy( String strategy )
+ {
+ this.strategy = ImportStrategy.valueOf( strategy );
+ }
+
+ //--------------------------------------------------------------------------
+ // Detailed MetaData Export - POST Requests
+ //--------------------------------------------------------------------------
+
+ @RequestMapping( value = FilteredMetaDataController.RESOURCE_PATH, headers = "Accept=application/json" )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
+ public String detailedExport( @RequestParam Map<String, String> parameters, Model model )
+ {
+ WebOptions options = new WebOptions( parameters );
+ MetaData metaData = exportService.getMetaData( options );
+
+ model.addAttribute( "model", metaData );
+ model.addAttribute( "viewClass", "export" );
+
+ return "export";
+ }
+
+ @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + ".xml", produces = "*/*" )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
+ public void exportXml( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException
+ {
+ FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) );
+ MetaData metaData = exportService.getFilteredMetaData( filterOptions );
+
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.NO_CACHE, "metaData.xml", true );
+ JacksonUtils.toXmlWithView( response.getOutputStream(), metaData, ExportView.class );
+ }
+
+ @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + ".json", produces = "*/*" )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
+ public void exportJson( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException
+ {
+ FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) );
+ MetaData metaData = exportService.getFilteredMetaData( filterOptions );
+
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE, "metaData.json", true );
+ JacksonUtils.toJsonWithView( response.getOutputStream(), metaData, ExportView.class );
+ }
+
+ @RequestMapping( method = RequestMethod.POST, value = { FilteredMetaDataController.RESOURCE_PATH + ".xml.zip" }, produces = "*/*" )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
+ public void exportZippedXML( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException
+ {
+ FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) );
+ MetaData metaData = exportService.getFilteredMetaData( filterOptions );
+
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "metaData.xml.zip", true );
+ response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
+
+ ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() );
+ zip.putNextEntry( new ZipEntry( "metaData.xml" ) );
+
+ JacksonUtils.toXmlWithView( zip, metaData, ExportView.class );
+ }
+
+ @RequestMapping( method = RequestMethod.POST, value = { FilteredMetaDataController.RESOURCE_PATH + ".json.zip" }, produces = "*/*" )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
+ public void exportZippedJSON( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException
+ {
+ FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) );
+ MetaData metaData = exportService.getFilteredMetaData( filterOptions );
+
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "metaData.json.zip", true );
+ response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
+
+ ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() );
+ zip.putNextEntry( new ZipEntry( "metaData.json" ) );
+
+ JacksonUtils.toJsonWithView( zip, metaData, ExportView.class );
+ }
+
+ @RequestMapping( method = RequestMethod.POST, value = { FilteredMetaDataController.RESOURCE_PATH + ".xml.gz" }, produces = "*/*" )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
+ public void exportGZippedXML( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException
+ {
+ FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) );
+ MetaData metaData = exportService.getFilteredMetaData( filterOptions );
+
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_GZIP, CacheStrategy.NO_CACHE, "metaData.xml.gz", true );
+ response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
+
+ GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() );
+ JacksonUtils.toXmlWithView( gzip, metaData, ExportView.class );
+ }
+
+ @RequestMapping( method = RequestMethod.POST, value = { FilteredMetaDataController.RESOURCE_PATH + ".json.gz" }, produces = "*/*" )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
+ public void exportGZippedJSON( @RequestParam String exportJsonValue, HttpServletResponse response ) throws IOException
+ {
+ FilterOptions filterOptions = new FilterOptions( JSONObject.fromObject( exportJsonValue ) );
+ MetaData metaData = exportService.getFilteredMetaData( filterOptions );
+
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_GZIP, CacheStrategy.NO_CACHE, "metaData.json.gz", true );
+ response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
+
+ GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() );
+ JacksonUtils.toJsonWithView( gzip, metaData, ExportView.class );
+ }
+
+ //--------------------------------------------------------------------------
+ // Detailed MetaData Export - Filter functionality
+ //--------------------------------------------------------------------------
+
+ @RequestMapping( method = RequestMethod.GET, value = FilteredMetaDataController.RESOURCE_PATH + "/getMetaDataFilters" )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
+ public @ResponseBody String getFilters( HttpServletRequest request, HttpServletResponse response ) throws IOException
+ {
+ List<MetaDataFilter> metaDataFilters = exportService.getFilters();
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE );
+ return JacksonUtils.toJsonAsString( metaDataFilters );
+ }
+
+ @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + "/saveFilter" )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
+ public void saveFilter( @RequestBody JSONObject json, HttpServletResponse response ) throws IOException
+ {
+ exportService.saveFilter( json );
+ }
+
+ @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + "/updateFilter" )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
+ public void updateFilter( @RequestBody JSONObject json, HttpServletResponse response ) throws IOException
+ {
+ exportService.updateFilter( json );
+ }
+
+ @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + "/deleteFilter" )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
+ public void deleteFilter( @RequestBody JSONObject json, HttpServletResponse response ) throws IOException
+ {
+ exportService.deleteFilter( json );
+ }
+
+ //--------------------------------------------------------------------------
+ // Detailed MetaData Import - POST Requests
+ //--------------------------------------------------------------------------
+
+ @RequestMapping( method = RequestMethod.POST, value = FilteredMetaDataController.RESOURCE_PATH + "/importDetailedMetaData" )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_IMPORT')" )
+ public void importDetailedMetaData( @RequestBody JSONObject json, HttpServletResponse response ) throws IOException
+ {
+ strategy = ImportStrategy.valueOf( json.getString( "strategy" ) );
+ dryRun = json.getBoolean( "dryRun" );
+
+ TaskId taskId = new TaskId( TaskCategory.METADATA_IMPORT, currentUserService.getCurrentUser() );
+ User user = currentUserService.getCurrentUser();
+
+ MetaData metaData = new ObjectMapper().readValue( json.getString( "metaData" ), MetaData.class );
+
+ ImportOptions importOptions = new ImportOptions();
+ importOptions.setStrategy( strategy );
+ importOptions.setDryRun( dryRun );
+
+ scheduler.executeTask( new ImportMetaDataTask( user.getUid(), importService, importOptions, taskId, metaData ) );
+ }
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetaDataController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetaDataController.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetaDataController.java 2015-10-30 06:47:40 +0000
@@ -0,0 +1,413 @@
+package org.hisp.dhis.webapi.controller.metadata;
+
+/*
+ * Copyright (c) 2004-2015, 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.dxf2.common.ImportOptions;
+import org.hisp.dhis.dxf2.common.JacksonUtils;
+import org.hisp.dhis.dxf2.metadata.ExportService;
+import org.hisp.dhis.dxf2.metadata.ImportService;
+import org.hisp.dhis.dxf2.metadata.ImportSummary;
+import org.hisp.dhis.dxf2.metadata.MetaData;
+import org.hisp.dhis.dxf2.metadata.tasks.ImportMetaDataTask;
+import org.hisp.dhis.importexport.ImportStrategy;
+import org.hisp.dhis.scheduling.TaskCategory;
+import org.hisp.dhis.scheduling.TaskId;
+import org.hisp.dhis.system.scheduling.Scheduler;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.webapi.utils.ContextUtils;
+import org.hisp.dhis.common.cache.CacheStrategy;
+import org.hisp.dhis.webapi.webdomain.WebOptions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Map;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@Controller
+@RequestMapping( method = RequestMethod.GET )
+public class MetaDataController
+{
+ public static final String RESOURCE_PATH = "/meta{xyz:[Dd]}ata";
+
+ @Autowired
+ private ExportService exportService;
+
+ @Autowired
+ private ImportService importService;
+
+ @Autowired
+ private ContextUtils contextUtils;
+
+ @Autowired
+ private Scheduler scheduler;
+
+ @Autowired
+ private CurrentUserService currentUserService;
+
+ //--------------------------------------------------------------------------
+ // Export
+ //--------------------------------------------------------------------------
+
+ @RequestMapping( value = MetaDataController.RESOURCE_PATH )
+ public String export( @RequestParam Map<String, String> parameters, Model model )
+ {
+ WebOptions options = new WebOptions( parameters );
+ MetaData metaData = exportService.getMetaData( options );
+
+ model.addAttribute( "model", metaData );
+ model.addAttribute( "viewClass", options.getViewClass( "export" ) );
+
+ return "export";
+ }
+
+ @RequestMapping( value = MetaDataController.RESOURCE_PATH + ".xml", produces = "*/*" )
+ public void exportXml( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
+ {
+ WebOptions options = new WebOptions( parameters );
+ MetaData metaData = exportService.getMetaData( options );
+
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.NO_CACHE, "metadata.xml", true );
+
+ Class<?> viewClass = JacksonUtils.getViewClass( options.getViewClass( "export" ) );
+ JacksonUtils.toXmlWithView( response.getOutputStream(), metaData, viewClass );
+ }
+
+ @RequestMapping( value = MetaDataController.RESOURCE_PATH + ".json", produces = "*/*" )
+ public void exportJson( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
+ {
+ WebOptions options = new WebOptions( parameters );
+ MetaData metaData = exportService.getMetaData( options );
+
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE, "metadata.json", true );
+
+ Class<?> viewClass = JacksonUtils.getViewClass( options.getViewClass( "export" ) );
+ JacksonUtils.toJsonWithView( response.getOutputStream(), metaData, viewClass );
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".zip" }, produces = "*/*" )
+ public void exportZipped( @RequestParam Map<String, String> parameters, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ String accept = request.getHeader( "Accept" );
+
+ if ( isJson( accept ) )
+ {
+ exportZippedJSON( parameters, response );
+ }
+ else
+ {
+ exportZippedXML( parameters, response );
+ }
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".xml.zip" }, produces = "*/*" )
+ public void exportZippedXML( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
+ {
+ WebOptions options = new WebOptions( parameters );
+ MetaData metaData = exportService.getMetaData( options );
+
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "metadata.xml.zip", true );
+ response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
+
+ ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() );
+ zip.putNextEntry( new ZipEntry( "metadata.xml" ) );
+
+ Class<?> viewClass = JacksonUtils.getViewClass( options.getViewClass( "export" ) );
+ JacksonUtils.toXmlWithView( zip, metaData, viewClass );
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".json.zip" }, produces = "*/*" )
+ public void exportZippedJSON( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
+ {
+ WebOptions options = new WebOptions( parameters );
+ MetaData metaData = exportService.getMetaData( options );
+
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_ZIP, CacheStrategy.NO_CACHE, "metadata.json.zip", true );
+ response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
+
+ ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() );
+ zip.putNextEntry( new ZipEntry( "metadata.json" ) );
+
+ Class<?> viewClass = JacksonUtils.getViewClass( options.getViewClass( "export" ) );
+ JacksonUtils.toJsonWithView( zip, metaData, viewClass );
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".gz" }, produces = "*/*" )
+ public void exportGZipped( @RequestParam Map<String, String> parameters, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ String accept = request.getHeader( "Accept" );
+
+ if ( isJson( accept ) )
+ {
+ exportGZippedJSON( parameters, response );
+ }
+ else
+ {
+ exportGZippedXML( parameters, response );
+ }
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".xml.gz" }, produces = "*/*" )
+ public void exportGZippedXML( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
+ {
+ WebOptions options = new WebOptions( parameters );
+ MetaData metaData = exportService.getMetaData( options );
+
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_GZIP, CacheStrategy.NO_CACHE, "metadata.xml.gz", true );
+ response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
+
+ GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() );
+
+ Class<?> viewClass = JacksonUtils.getViewClass( options.getViewClass( "export" ) );
+ JacksonUtils.toXmlWithView( gzip, metaData, viewClass );
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".json.gz" }, produces = "*/*" )
+ public void exportGZippedJSON( @RequestParam Map<String, String> parameters, HttpServletResponse response ) throws IOException
+ {
+ WebOptions options = new WebOptions( parameters );
+ MetaData metaData = exportService.getMetaData( options );
+
+ contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_GZIP, CacheStrategy.NO_CACHE, "metadata.json.gz", true );
+ response.addHeader( ContextUtils.HEADER_CONTENT_TRANSFER_ENCODING, "binary" );
+
+ GZIPOutputStream gzip = new GZIPOutputStream( response.getOutputStream() );
+
+ Class<?> viewClass = JacksonUtils.getViewClass( options.getViewClass( "export" ) );
+ JacksonUtils.toJsonWithView( gzip, metaData, viewClass );
+ }
+
+ //--------------------------------------------------------------------------
+ // Import
+ //--------------------------------------------------------------------------
+
+ @RequestMapping( value = MetaDataController.RESOURCE_PATH, method = RequestMethod.POST, consumes = { "application/xml", "text/*" } )
+ public void importXml( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ MetaData metaData = JacksonUtils.fromXml( request.getInputStream(), MetaData.class );
+
+ if ( importOptions.isAsync() )
+ {
+ startAsyncImport( importOptions, response, request, metaData );
+ }
+ else
+ {
+ startSyncImportXml( importOptions, response, metaData );
+ }
+ }
+
+ @RequestMapping( value = MetaDataController.RESOURCE_PATH, method = RequestMethod.DELETE, consumes = { "application/xml", "text/*" } )
+ public void deleteXml( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ importOptions.setImportStrategy( ImportStrategy.DELETE );
+ importXml( importOptions, response, request );
+ }
+
+ @RequestMapping( value = MetaDataController.RESOURCE_PATH, method = RequestMethod.POST, consumes = "application/json" )
+ public void importJson( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ MetaData metaData = JacksonUtils.fromJson( request.getInputStream(), MetaData.class );
+
+ if ( importOptions.isAsync() )
+ {
+ startAsyncImport( importOptions, response, request, metaData );
+ }
+ else
+ {
+ startSyncImportJson( importOptions, response, metaData );
+ }
+ }
+
+ @RequestMapping( value = MetaDataController.RESOURCE_PATH, method = RequestMethod.DELETE, consumes = "application/json" )
+ public void deleteJson( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ importOptions.setImportStrategy( ImportStrategy.DELETE );
+ importJson( importOptions, response, request );
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".zip", MetaDataController.RESOURCE_PATH + ".xml.zip" }, method = RequestMethod.POST, consumes = { "application/xml", "text/*" } )
+ public void importZippedXml( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ ZipInputStream zip = new ZipInputStream( request.getInputStream() );
+ zip.getNextEntry();
+
+ MetaData metaData = JacksonUtils.fromXml( zip, MetaData.class );
+
+ if ( importOptions.isAsync() )
+ {
+ startAsyncImport( importOptions, response, request, metaData );
+ }
+ else
+ {
+ startSyncImportXml( importOptions, response, metaData );
+ }
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".zip", MetaDataController.RESOURCE_PATH + ".xml.zip" }, method = RequestMethod.DELETE, consumes = { "application/xml", "text/*" } )
+ public void deleteZippedXml( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ importOptions.setImportStrategy( ImportStrategy.DELETE );
+ importZippedXml( importOptions, response, request );
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".zip", MetaDataController.RESOURCE_PATH + ".json.zip" }, method = RequestMethod.POST, consumes = "application/json" )
+ public void importZippedJson( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ ZipInputStream zip = new ZipInputStream( request.getInputStream() );
+ zip.getNextEntry();
+
+ MetaData metaData = JacksonUtils.fromJson( zip, MetaData.class );
+
+ if ( importOptions.isAsync() )
+ {
+ startAsyncImport( importOptions, response, request, metaData );
+ }
+ else
+ {
+ startSyncImportJson( importOptions, response, metaData );
+ }
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".zip", MetaDataController.RESOURCE_PATH + ".json.zip" }, method = RequestMethod.DELETE, consumes = "application/json" )
+ public void deleteZippedJson( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ importOptions.setImportStrategy( ImportStrategy.DELETE );
+ importZippedJson( importOptions, response, request );
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".gz", MetaDataController.RESOURCE_PATH + ".xml.gz" }, method = RequestMethod.POST, consumes = { "application/xml", "text/*" } )
+ public void importGZippedXml( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ GZIPInputStream gzip = new GZIPInputStream( request.getInputStream() );
+ MetaData metaData = JacksonUtils.fromXml( gzip, MetaData.class );
+
+ if ( importOptions.isAsync() )
+ {
+ startAsyncImport( importOptions, response, request, metaData );
+ }
+ else
+ {
+ startSyncImportXml( importOptions, response, metaData );
+ }
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".gz", MetaDataController.RESOURCE_PATH + ".xml.gz" }, method = RequestMethod.DELETE, consumes = { "application/xml", "text/*" } )
+ public void deleteGZippedXml( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ importOptions.setImportStrategy( ImportStrategy.DELETE );
+ importGZippedXml( importOptions, response, request );
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".gz", MetaDataController.RESOURCE_PATH + ".json.gz" }, method = RequestMethod.POST, consumes = "application/json" )
+ public void importGZippedJson( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ GZIPInputStream gzip = new GZIPInputStream( request.getInputStream() );
+ MetaData metaData = JacksonUtils.fromJson( gzip, MetaData.class );
+
+ if ( importOptions.isAsync() )
+ {
+ startAsyncImport( importOptions, response, request, metaData );
+ }
+ else
+ {
+ startSyncImportJson( importOptions, response, metaData );
+ }
+ }
+
+ @RequestMapping( value = { MetaDataController.RESOURCE_PATH + ".gz", MetaDataController.RESOURCE_PATH + ".json.gz" }, method = RequestMethod.DELETE, consumes = "application/json" )
+ public void deleteGZippedJson( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ importOptions.setImportStrategy( ImportStrategy.DELETE );
+ importGZippedJson( importOptions, response, request );
+ }
+
+ //--------------------------------------------------------------------------
+ // Helpers
+ //--------------------------------------------------------------------------
+
+ private void startSyncImportXml( ImportOptions importOptions, HttpServletResponse response, MetaData metaData ) throws IOException
+ {
+ String userUid = currentUserService.getCurrentUser().getUid();
+
+ ImportSummary importSummary = importService.importMetaData( userUid, metaData, importOptions, null );
+ response.setStatus( HttpServletResponse.SC_OK );
+ response.setContentType( ContextUtils.CONTENT_TYPE_XML );
+ JacksonUtils.toXml( response.getOutputStream(), importSummary );
+ }
+
+ private void startSyncImportJson( ImportOptions importOptions, HttpServletResponse response, MetaData metaData ) throws IOException
+ {
+ String userUid = currentUserService.getCurrentUser().getUid();
+
+ ImportSummary importSummary = importService.importMetaData( userUid, metaData, importOptions, null );
+ response.setStatus( HttpServletResponse.SC_OK );
+ response.setContentType( ContextUtils.CONTENT_TYPE_JSON );
+ JacksonUtils.toJson( response.getOutputStream(), importSummary );
+ }
+
+ private void startAsyncImport( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request, MetaData metaData )
+ {
+ String userUid = currentUserService.getCurrentUser().getUid();
+
+ TaskId taskId = new TaskId( TaskCategory.METADATA_IMPORT, currentUserService.getCurrentUser() );
+
+ scheduler.executeTask( new ImportMetaDataTask( userUid, importService, importOptions, taskId, metaData ) );
+
+ response.setHeader( "Location", ContextUtils.getRootPath( request ) + "/system/tasks/" + TaskCategory.METADATA_IMPORT );
+ response.setStatus( HttpServletResponse.SC_ACCEPTED );
+ }
+
+ //--------------------------------------------------------------------------
+ // Supportive Methods
+ //--------------------------------------------------------------------------
+
+ public boolean isJson( String accept )
+ {
+ return accept != null && MediaType.parseMediaType( accept ).isCompatibleWith( MediaType.APPLICATION_JSON );
+ }
+
+ public boolean isXml( String accept )
+ {
+ return accept != null && MediaType.parseMediaType( accept ).isCompatibleWith( MediaType.APPLICATION_XML );
+ }
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetaDataFilterController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetaDataFilterController.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/metadata/MetaDataFilterController.java 2015-10-30 06:47:40 +0000
@@ -0,0 +1,45 @@
+package org.hisp.dhis.webapi.controller.metadata;
+
+/*
+ * Copyright (c) 2004-2015, 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.filter.MetaDataFilter;
+import org.hisp.dhis.webapi.controller.AbstractCrudController;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+/**
+ * @author Ovidiu Rosu <rosu.ovi@xxxxxxxxx>
+ */
+@Controller
+@RequestMapping( value = MetaDataFilterController.RESOURCE_PATH )
+public class MetaDataFilterController
+ extends AbstractCrudController<MetaDataFilter>
+{
+ public static final String RESOURCE_PATH = "/metaDataFilters";
+}