← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1895: Added namespace, minorVersion and exported attributes to DXF export

 

------------------------------------------------------------
revno: 1895
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Tue 2010-05-25 11:35:53 +0200
message:
  Added namespace, minorVersion and exported attributes to DXF export
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportPipeThread.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ImportParams.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/exporter/DefaultDXFExportService.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-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportPipeThread.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportPipeThread.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportPipeThread.java	2010-05-25 09:35:53 +0000
@@ -48,7 +48,7 @@
 {
     protected static final Log log = LogFactory.getLog( ExportPipeThread.class );
     
-    private static final String VERSION = "1.0";
+    private static final String XML_VERSION = "1.0";
     
     private List<XMLConverter> xsdConverters = new ArrayList<XMLConverter>();
     private List<XMLConverter> xmlConverters = new ArrayList<XMLConverter>();
@@ -223,7 +223,7 @@
     
     private void openDocument( XMLWriter writer )
     {
-        writer.openDocument( encoding, VERSION );
+        writer.openDocument( encoding, XML_VERSION );
         
         writer.openElement( rootName, rootProperties );
     }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ImportParams.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ImportParams.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ImportParams.java	2010-05-25 09:35:53 +0000
@@ -1,7 +1,5 @@
 package org.hisp.dhis.importexport;
 
-import java.util.Date;
-
 /*
  * Copyright (c) 2004-2010, University of Oslo
  * All rights reserved.
@@ -29,12 +27,22 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Date;
+
+import org.hisp.dhis.system.util.MathUtils;
+
 /**
  * @author Lars Helge Overland
  * @version $Id: ImportParams.java 6425 2008-11-22 00:08:57Z larshelg $
  */
 public class ImportParams
 {
+    public static final String ATTRIBUTE_NAMESPACE = "xmlns";
+    public static final String ATTRIBUTE_MINOR_VERSION = "minorVersion";
+    public static final String ATTRIBUTE_EXPORTED = "exported";
+    public static final String NAMESPACE_10 = "http://dhis2.org/schema/dxf/1.0";;
+    public static final String MINOR_VERSION_11 = "1.1";
+    
     private ImportType type;
     
     private boolean extendedMode;
@@ -47,6 +55,10 @@
     
     private Date lastUpdated;
     
+    private String namespace;
+    
+    private String minorVersion;
+    
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -59,6 +71,19 @@
     // Logic
     // -------------------------------------------------------------------------
 
+    public boolean minorVersionGreaterOrEqual( String version )
+    {
+        if ( version == null || !MathUtils.isNumeric( version ) )
+        {
+            throw new IllegalArgumentException( "Invalid version, must be numeric: " + version );            
+        }
+        
+        double _minorVersion = Double.parseDouble( minorVersion ) * 1000;
+        double _version = Double.parseDouble( version ) * 1000;
+        
+        return (int)_version >= (int)_minorVersion;
+    }
+    
     public boolean isImport()
     {
         return type.equals( ImportType.IMPORT );
@@ -142,4 +167,24 @@
     {
         this.lastUpdated = lastUpdated;
     }
+
+    public String getNamespace()
+    {
+        return namespace;
+    }
+
+    public void setNamespace( String namespace )
+    {
+        this.namespace = namespace;
+    }
+
+    public String getMinorVersion()
+    {
+        return minorVersion;
+    }
+
+    public void setMinorVersion( String minorVersion )
+    {
+        this.minorVersion = minorVersion;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/exporter/DefaultDXFExportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/exporter/DefaultDXFExportService.java	2010-05-18 19:22:26 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/exporter/DefaultDXFExportService.java	2010-05-25 09:35:53 +0000
@@ -94,9 +94,12 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.reporttable.ReportTableService;
+import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.validation.ValidationRuleService;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import static org.hisp.dhis.importexport.ImportParams.*;
+
 /**
  * @author Lars Helge Overland
  * @version $Id: DefaultDXFExportService.java 5960 2008-10-17 14:07:50Z larshelg $
@@ -107,6 +110,7 @@
     private static final String ZIP_ENTRY_NAME = "Export.xml";
     private static final String ROOT_NAME = "dxf";
     
+    
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -235,12 +239,15 @@
             // Writes to one end of the pipe 
             // -----------------------------------------------------------------
             
+            String[] rootProperties = { ATTRIBUTE_NAMESPACE, NAMESPACE_10, ATTRIBUTE_MINOR_VERSION, MINOR_VERSION_11, ATTRIBUTE_EXPORTED, DateUtils.getMediumDateString() };
+            
             ExportPipeThread thread = new ExportPipeThread( sessionFactory );
             
             thread.setZipOutputStream( zipOut );
             thread.setParams( params );
             thread.setWriter( writer );
             thread.setRootName( ROOT_NAME );
+            thread.setRootProperties( rootProperties );
             
             thread.registerXMLConverter( new DataElementCategoryOptionConverter( categoryService ) );
             thread.registerXMLConverter( new DataElementCategoryConverter( categoryService ) );