dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #16385
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6221: bugfixes in zip import
------------------------------------------------------------
revno: 6221
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-03-08 14:54:20 +0100
message:
bugfixes in zip import
modified:
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/ImportController.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
=== 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-08 08:32:24 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ExportController.java 2012-03-08 13:54:20 +0000
@@ -89,29 +89,7 @@
@PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_EXPORT')" )
public String export( Model model )
{
- DXF2 dxf2 = new DXF2();
-
- dxf2.setDataElements( new ArrayList<DataElement>( dataElementService.getAllDataElements() ) );
- dxf2.setDataElementGroups( new ArrayList<DataElementGroup>( dataElementService.getAllDataElementGroups() ) );
- dxf2.setDataElementGroupSets( new ArrayList<DataElementGroupSet>( dataElementService.getAllDataElementGroupSets() ) );
- dxf2.setCategories( new ArrayList<DataElementCategory>( dataElementCategoryService.getAllDataElementCategories() ) );
- dxf2.setCategoryCombos( new ArrayList<DataElementCategoryCombo>( dataElementCategoryService.getAllDataElementCategoryCombos() ) );
- dxf2.setCategoryOptions( new ArrayList<DataElementCategoryOption>( dataElementCategoryService.getAllDataElementCategoryOptions() ) );
- dxf2.setCategoryOptionCombos( new ArrayList<DataElementCategoryOptionCombo>( dataElementCategoryService.getAllDataElementCategoryOptionCombos() ) );
-
- dxf2.setIndicators( new ArrayList<Indicator>( indicatorService.getAllIndicators() ) );
- dxf2.setIndicatorGroups( new ArrayList<IndicatorGroup>( indicatorService.getAllIndicatorGroups() ) );
- dxf2.setIndicatorGroupSets( new ArrayList<IndicatorGroupSet>( indicatorService.getAllIndicatorGroupSets() ) );
-
- dxf2.setOrganisationUnits( new ArrayList<OrganisationUnit>( organisationUnitService.getAllOrganisationUnits() ) );
- dxf2.setOrganisationUnitLevels( new ArrayList<OrganisationUnitLevel>( organisationUnitService.getOrganisationUnitLevels() ) );
- dxf2.setOrganisationUnitGroups( new ArrayList<OrganisationUnitGroup>( organisationUnitGroupService.getAllOrganisationUnitGroups() ) );
- dxf2.setOrganisationUnitGroupSets( new ArrayList<OrganisationUnitGroupSet>( organisationUnitGroupService.getAllOrganisationUnitGroupSets() ) );
-
- dxf2.setDataSets( new ArrayList<DataSet>( dataSetService.getAllDataSets() ) );
-
- dxf2.setValidationRules( new ArrayList<ValidationRule>( validationRuleService.getAllValidationRules() ) );
- dxf2.setValidationRuleGroups( new ArrayList<ValidationRuleGroup>( validationRuleService.getAllValidationRuleGroups() ) );
+ DXF2 dxf2 = getExportObject();
model.addAttribute( "model", dxf2 );
@@ -148,7 +126,7 @@
response.addHeader( "Content-Transfer-Encoding", "binary" );
ZipOutputStream zip = new ZipOutputStream( response.getOutputStream() );
- zip.putNextEntry( new ZipEntry( "export.xml" ) );
+ zip.putNextEntry( new ZipEntry( "export.json" ) );
JacksonUtils.writeObject( dxf2, zip );
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ImportController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ImportController.java 2012-03-07 12:10:37 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ImportController.java 2012-03-08 13:54:20 +0000
@@ -35,37 +35,83 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.JAXBException;
+import java.io.BufferedInputStream;
import java.io.IOException;
-import java.io.InputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@Controller
-@RequestMapping( value = ImportController.RESOURCE_PATH )
public class ImportController
{
public static final String RESOURCE_PATH = "/import";
- @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/xml, text/xml"} )
- @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_IMPORT')" )
- public String importXML( HttpServletResponse response, InputStream input ) throws JAXBException
- {
- DXF2 dxf2 = Jaxb2Utils.unmarshal( DXF2.class, input );
- System.err.println( dxf2.getDataSets().size() );
-
- return "import";
- }
-
- @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/json"} )
- @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_IMPORT')" )
- public String importJSON( HttpServletResponse response, InputStream input ) throws IOException
- {
- DXF2 dxf2 = JacksonUtils.readValueAs( DXF2.class, input );
- System.err.println( dxf2.getDataSets().size() );
-
- return "import";
+ @RequestMapping( value = ImportController.RESOURCE_PATH, method = RequestMethod.POST, headers = {"Content-Type=application/xml, text/*"} )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_IMPORT')" )
+ public void importXml( HttpServletResponse response, HttpServletRequest request ) throws JAXBException, IOException
+ {
+ DXF2 dxf2 = Jaxb2Utils.unmarshal( DXF2.class, request.getInputStream() );
+ print( dxf2 );
+ }
+
+ @RequestMapping( value = ImportController.RESOURCE_PATH, method = RequestMethod.POST, headers = {"Content-Type=application/json"} )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_IMPORT')" )
+ public void importJson( HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ DXF2 dxf2 = JacksonUtils.readValueAs( DXF2.class, request.getInputStream() );
+ print( dxf2 );
+ }
+
+ @RequestMapping( value = ImportController.RESOURCE_PATH + ".zip", method = RequestMethod.POST, headers = {"Content-Type=application/xml, text/xml"} )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_IMPORT')" )
+ public void importZippedXml( HttpServletResponse response, HttpServletRequest request ) throws JAXBException, IOException
+ {
+ ZipInputStream zip = new ZipInputStream( new BufferedInputStream( request.getInputStream() ) );
+ ZipEntry entry = zip.getNextEntry();
+
+ System.err.println( "(xml) Reading from file : " + entry.getName() );
+
+ DXF2 dxf2 = Jaxb2Utils.unmarshal( DXF2.class, zip );
+ print( dxf2 );
+ }
+
+ @RequestMapping( value = ImportController.RESOURCE_PATH + ".zip", method = RequestMethod.POST, headers = {"Content-Type=application/json"} )
+ @PreAuthorize( "hasRole('ALL') or hasRole('F_METADATA_IMPORT')" )
+ public void importZippedJson( HttpServletResponse response, HttpServletRequest request ) throws IOException
+ {
+ ZipInputStream zip = new ZipInputStream( request.getInputStream() );
+ ZipEntry entry = zip.getNextEntry();
+
+ System.err.println( "(json) Reading from file : " + entry.getName() );
+ DXF2 dxf2 = JacksonUtils.readValueAs( DXF2.class, zip );
+
+ print( dxf2 );
+ }
+
+ //-------------------------------------------------------------------------------------------------------
+ // Helpers
+ //-------------------------------------------------------------------------------------------------------
+
+ // just for debug..
+ private void print( DXF2 dxf2 )
+ {
+ System.err.println( "DataElements: " + dxf2.getDataElements().size() );
+ System.err.println( "DataElementGroups: " + dxf2.getDataElementGroups().size() );
+ System.err.println( "DataElementGroupSets: " + dxf2.getDataElementGroupSets().size() );
+
+ System.err.println( "DataSets: " + dxf2.getDataSets().size() );
+
+ System.err.println( "Indicators:" + dxf2.getIndicators().size() );
+ System.err.println( "IndicatorGroups:" + dxf2.getIndicatorGroups().size() );
+ System.err.println( "IndicatorGroupSets:" + dxf2.getIndicatorGroupSets().size() );
+
+ System.err.println( "OrganisationUnits: " + dxf2.getOrganisationUnits().size() );
+ System.err.println( "OrganisationUnitGroups: " + dxf2.getOrganisationUnitGroups().size() );
+ System.err.println( "OrganisationUnitGroupSets: " + dxf2.getOrganisationUnitGroupSets().size() );
}
}