← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 957: Implemented include-sortorder-dhis14import

 

------------------------------------------------------------
revno: 957
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Mon 2009-11-02 16:55:44 +0100
message:
  Implemented include-sortorder-dhis14import
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java
  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/dhis14/xml/converter/DataElementConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/IndicatorConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/exporter/DefaultDhis14XMLExportService.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/resources/sqlmap/dataElement.sqlmap.xml
  dhis-2/dhis-services/dhis-service-importexport/src/main/resources/sqlmap/dataSet.sqlmap.xml
  dhis-2/dhis-services/dhis-service-importexport/src/main/resources/sqlmap/indicator.sqlmap.xml
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataElementBatchHandler.java
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataSetBatchHandler.java
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/IndicatorBatchHandler.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.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-api/src/main/java/org/hisp/dhis/indicator/Indicator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java	2009-10-27 18:39:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java	2009-11-02 15:55:44 +0000
@@ -106,6 +106,15 @@
     {
         return groupSets != null && groupSets.size() > 0;
     }
+
+    // -------------------------------------------------------------------------
+    // Logic
+    // -------------------------------------------------------------------------
+
+    public boolean isAnnualized()
+    {
+        return annualized != null && annualized;
+    }
     
     // -------------------------------------------------------------------------
     // hashCode and equals

=== 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	2009-10-17 18:32:20 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportPipeThread.java	2009-11-02 15:55:44 +0000
@@ -164,6 +164,12 @@
             
             log.info( "Export done" );
         }
+        catch ( Exception ex )
+        {
+            ex.printStackTrace();
+            
+            throw new RuntimeException( "Writing failed" + ex );
+        }
         finally
         {
             StreamUtils.finishZipEntry( zipOutputStream );

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementConverter.java	2009-03-09 14:11:42 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementConverter.java	2009-11-02 15:55:44 +0000
@@ -32,6 +32,7 @@
 import static org.hisp.dhis.importexport.dhis14.util.Dhis14TypeHandler.convertBooleanFromDhis14;
 import static org.hisp.dhis.importexport.dhis14.util.Dhis14TypeHandler.convertBooleanToDhis14;
 import static org.hisp.dhis.importexport.dhis14.util.Dhis14TypeHandler.convertTypeToDhis14;
+import static org.hisp.dhis.system.util.ConversionUtils.parseInt;
 
 import java.util.Collection;
 import java.util.HashSet;
@@ -161,7 +162,7 @@
                 writer.openElement( ELEMENT_NAME );
                 
                 writer.writeElement( FIELD_ID, String.valueOf( object.getId() ) );
-                writer.writeElement( FIELD_SORT_ORDER, String.valueOf( object.getId() ) );
+                writer.writeElement( FIELD_SORT_ORDER, object.getSortOrder() != null ? String.valueOf( object.getSortOrder() ) : EMPTY );
                 writer.writeElement( FIELD_CODE, object.getCode() );
                 writer.writeElement( FIELD_NAME, object.getName() );
                 writer.writeElement( FIELD_SHORT_NAME, object.getShortName() );
@@ -210,7 +211,8 @@
             element.setActive( true );        
             element.setType( Dhis14ObjectMappingUtil.getDataElementTypeMap().get( Integer.parseInt( values.get( FIELD_DATA_TYPE ) ) ) );
             element.setAggregationOperator( convertAggregationOperatorFromDhis14( values.get( FIELD_AGGREGATION_OPERATOR ) ) );
-            element.getCategoryCombo().setId( 1 );
+            element.setSortOrder( parseInt( values.get( FIELD_SORT_ORDER ) ) );
+            element.getCategoryCombo().setId( 1 ); //TODO hack
             element.setSaved( convertBooleanFromDhis14( values.get( FIELD_SAVE_CALCULATED ) ) );
             element.setExpression( new Expression( expressionMap.get( element.getId() ), null, new HashSet<DataElement>() ) );
             
@@ -231,7 +233,8 @@
             element.setActive( true );        
             element.setType( Dhis14ObjectMappingUtil.getDataElementTypeMap().get( Integer.parseInt( values.get( FIELD_DATA_TYPE ) ) ) );
             element.setAggregationOperator( convertAggregationOperatorFromDhis14( values.get( FIELD_AGGREGATION_OPERATOR ) ) );
-            element.getCategoryCombo().setId( 1 );
+            element.setSortOrder( parseInt( values.get( FIELD_SORT_ORDER ) ) );
+            element.getCategoryCombo().setId( 1 ); //TODO hack
             
             NameMappingUtil.addDataElementAggregationOperatorMapping( element.getId(), element.getAggregationOperator() );
             

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/IndicatorConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/IndicatorConverter.java	2009-03-19 14:31:44 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/IndicatorConverter.java	2009-11-02 15:55:44 +0000
@@ -32,6 +32,7 @@
 import static org.hisp.dhis.importexport.dhis14.util.Dhis14ExpressionConverter.convertExpressionToDhis14;
 import static org.hisp.dhis.importexport.dhis14.util.Dhis14ExpressionConverter.getFirstDataElementId;
 import static org.hisp.dhis.importexport.dhis14.util.Dhis14TypeHandler.convertBooleanFromDhis14;
+import static org.hisp.dhis.system.util.ConversionUtils.parseInt;
 
 import java.util.Collection;
 import java.util.Map;
@@ -144,7 +145,7 @@
                 writer.openElement( ELEMENT_NAME );
                 
                 writer.writeElement( FIELD_ID, String.valueOf( object.getId() ) );
-                writer.writeElement( FIELD_SORT_ORDER, String.valueOf( object.getId() ) );
+                writer.writeElement( FIELD_SORT_ORDER, object.getSortOrder() != null ? String.valueOf( object.getSortOrder() ) : EMPTY );
                 writer.writeElement( FIELD_NAME, object.getName() );
                 writer.writeElement( FIELD_SHORT_NAME, object.getShortName() );
                 writer.writeElement( FIELD_DOS, TextUtils.subString( object.getShortName(), 0, 8 ) );
@@ -154,7 +155,7 @@
                 writer.writeElement( FIELD_SELECTED, String.valueOf( 0 ) );
                 writer.writeElement( FIELD_INDICATOR_TYPE, String.valueOf( object.getIndicatorType().getId() ) );
                 writer.writeElement( FIELD_PERIOD_TYPE, String.valueOf( 1 ) );
-                writer.writeElement( FIELD_ANNUALISED, object.getAnnualized() ? String.valueOf( 1 ) : String.valueOf( 0 ) );
+                writer.writeElement( FIELD_ANNUALISED, object.isAnnualized() ? String.valueOf( 1 ) : String.valueOf( 0 ) );
                 writer.writeElement( FIELD_NUMERATOR, convertExpressionToDhis14( object.getNumerator(), mapping ) );
                 writer.writeElement( FIELD_NUMERATOR_AGG_LEVEL, String.valueOf( AGG_START_LEVEL ) );
                 writer.writeElement( FIELD_NUMERATOR_TIME_LAG, String.valueOf( 0 ) );
@@ -197,6 +198,8 @@
         
         indicator.setNumerator( convertExpressionFromDhis14( values.get( FIELD_NUMERATOR ), dataElementMapping, 1, indicator.getName() ) );
         indicator.setDenominator( convertExpressionFromDhis14( values.get( FIELD_DENOMINATOR ), dataElementMapping, 1, indicator.getName() ) );
+
+        indicator.setSortOrder( parseInt( values.get( FIELD_SORT_ORDER ) ) );
         
         read( indicator, GroupMemberType.NONE, params );
     }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/exporter/DefaultDhis14XMLExportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/exporter/DefaultDhis14XMLExportService.java	2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/exporter/DefaultDhis14XMLExportService.java	2009-11-02 15:55:44 +0000
@@ -108,10 +108,10 @@
     {
         try
         {
-            // -------------------------------------------------------------------------
-            // Pipes are input/output pairs. Data written on the output stream shows 
-            // up on the input stream at the other end of the pipe. 
-            // -------------------------------------------------------------------------
+            // -----------------------------------------------------------------
+            // Pipes are input/output pairs. Data written on the output stream 
+            // shows up on the input stream at the other end of the pipe. 
+            // -----------------------------------------------------------------
             
             PipedOutputStream out = new PipedOutputStream();
             
@@ -123,9 +123,9 @@
 
             XMLWriter writer = XMLFactory.getPlainXMLWriter( zipOut );
             
-            // -------------------------------------------------------------------------
+            // -----------------------------------------------------------------
             // Writes to one end of the pipe 
-            // -------------------------------------------------------------------------
+            // -----------------------------------------------------------------
 
             ExportPipeThread thread = new Dhis14ExportPipeThread( sessionFactory );
             
@@ -136,8 +136,7 @@
             thread.setRootName( ROOT_NAME );
             thread.setRootProperties( ROOT_PROPERTIES );
 
-            thread.registerXSDConverter( new DataRootXSDConverter() );
-            
+            thread.registerXSDConverter( new DataRootXSDConverter() );            
             thread.registerXSDConverter( new PeriodTypeXSDConverter() );
             thread.registerXSDConverter( new DataElementXSDConverter() );
             thread.registerXSDConverter( new CalculatedDataElementAssociationXSDConverter() );
@@ -158,9 +157,9 @@
             
             thread.start();
 
-            // -------------------------------------------------------------------------
+            // -----------------------------------------------------------------
             // Reads at the other end of the pipe 
-            // -------------------------------------------------------------------------
+            // -----------------------------------------------------------------
             
             InputStream bis = new BufferedInputStream( in );
             

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/resources/sqlmap/dataElement.sqlmap.xml'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/resources/sqlmap/dataElement.sqlmap.xml	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/resources/sqlmap/dataElement.sqlmap.xml	2009-11-02 15:55:44 +0000
@@ -21,6 +21,7 @@
 		<result property="description" column="DataElementDescription"/>
 		<result property="type" column="DataTypeID" typeHandler="dataElementTypeTypeHandler"/>
 		<result property="aggregationOperator" column="AggregateOperator" typeHandler="aggregationOperatorTypeHandler"/>
+		<result property="sortOrder" column="SortOrder"/>
 	</resultMap>
 	
 	<!-- Statement -->

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/resources/sqlmap/dataSet.sqlmap.xml'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/resources/sqlmap/dataSet.sqlmap.xml	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/resources/sqlmap/dataSet.sqlmap.xml	2009-11-02 15:55:44 +0000
@@ -8,15 +8,16 @@
 	
 	<!-- TypeAlias -->
 
-  <typeAlias alias="dataSet" type="org.hisp.dhis.dataset.DataSet"/>
+	<typeAlias alias="dataSet" type="org.hisp.dhis.dataset.DataSet"/>
 	
 	<!-- ResultMap -->
 	
 	<resultMap class="dataSet" id="dataSetResultMap">
 		<result property="id" column="DataSetID"/>
 		<result property="name" column="DataSetName"/>
-    <result property="periodType" column="DataPeriodTypeID" typeHandler="periodTypeTypeHandler"/>
-  </resultMap>
+		<result property="periodType" column="DataPeriodTypeID" typeHandler="periodTypeTypeHandler"/>
+        <result property="sortOrder" column="SortOrder"/>
+	</resultMap>
 
 	<!-- Statement -->
 		

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/resources/sqlmap/indicator.sqlmap.xml'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/resources/sqlmap/indicator.sqlmap.xml	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/resources/sqlmap/indicator.sqlmap.xml	2009-11-02 15:55:44 +0000
@@ -23,7 +23,8 @@
 		<result property="numerator" column="IndicatorNumerator"/>
 		<result property="numeratorDescription" column="IndicatorNumeratorDescription"/>
 		<result property="denominator" column="IndicatorDenominator"/>
-		<result property="denominatorDescription" column="IndicatorDenominatorDescription"/>		
+		<result property="denominatorDescription" column="IndicatorDenominatorDescription"/>
+        <result property="sortOrder" column="SortOrder"/>
 	</resultMap>
 	
 	<!-- Statement -->

=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataElementBatchHandler.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataElementBatchHandler.java	2009-08-12 21:06:37 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataElementBatchHandler.java	2009-11-02 15:55:44 +0000
@@ -103,6 +103,7 @@
         statementBuilder.setColumn( "aggregationtype" );
         statementBuilder.setColumn( "extendeddataelementid" );
         statementBuilder.setColumn( "categorycomboid" );
+        statementBuilder.setColumn( "sortorder" );
     }
     
     protected void setValues( DataElement dataElement )
@@ -118,5 +119,6 @@
         statementBuilder.setValue( dataElement.getAggregationOperator() );
         statementBuilder.setValue( dataElement.getExtended() != null ? dataElement.getExtended().getId() : null );
         statementBuilder.setValue( dataElement.getCategoryCombo().getId() );
+        statementBuilder.setValue( dataElement.getSortOrder() );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataSetBatchHandler.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataSetBatchHandler.java	2009-08-12 21:06:37 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataSetBatchHandler.java	2009-11-02 15:55:44 +0000
@@ -94,6 +94,7 @@
         statementBuilder.setColumn( "shortName" );
         statementBuilder.setColumn( "code" );
         statementBuilder.setColumn( "periodtypeid" );
+        statementBuilder.setColumn( "sortorder" );
     }
     
     protected void setValues( DataSet dataSet )
@@ -102,5 +103,6 @@
         statementBuilder.setValue( dataSet.getShortName() );
         statementBuilder.setValue( dataSet.getCode() );
         statementBuilder.setValue( dataSet.getPeriodType().getId() );
+        statementBuilder.setValue( dataSet.getSortOrder() );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/IndicatorBatchHandler.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/IndicatorBatchHandler.java	2009-08-12 21:06:37 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/IndicatorBatchHandler.java	2009-11-02 15:55:44 +0000
@@ -107,6 +107,7 @@
         statementBuilder.setColumn( "denominatordescription" );
         statementBuilder.setColumn( "denominatoraggregationtype" );
         statementBuilder.setColumn( "extendeddataelementid" );
+        statementBuilder.setColumn( "sortorder" );
     }
     
     protected void setValues( Indicator indicator )
@@ -126,5 +127,6 @@
         statementBuilder.setValue( indicator.getDenominatorDescription() );
         statementBuilder.setValue( indicator.getDenominatorAggregationOperator() );
         statementBuilder.setValue( indicator.getExtended() != null ? indicator.getExtended().getId() : null );
+        statementBuilder.setValue( indicator.getSortOrder() );
     }
 }

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.java	2009-03-09 12:11:46 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.java	2009-11-02 15:55:44 +0000
@@ -89,4 +89,21 @@
         
         return integers;
     }
+    
+    /**
+     * Parses the string argument as a signed decimal integer. Null is returedn 
+     * if the argument is null or has zero length.
+     * 
+     * @param string the string to parse.
+     * @return an integer or null.
+     */
+    public static Integer parseInt( String string )
+    {
+        if ( string == null || string.isEmpty() )
+        {
+            return null;
+        }
+        
+        return Integer.parseInt( string );
+    }
 }