← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6561: Centralized code

 

------------------------------------------------------------
revno: 6561
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-04-13 12:21:57 +0200
message:
  Centralized code
modified:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/DataValueExportAction.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-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java	2012-04-01 12:24:57 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java	2012-04-13 10:21:57 +0000
@@ -55,7 +55,7 @@
     protected String orgUnit;
 
     protected List<DataValue> dataValues = new ArrayList<DataValue>();
-
+    
     //--------------------------------------------------------------------------
     // Constructors
     //--------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2012-04-12 12:39:47 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2012-04-13 10:21:57 +0000
@@ -39,6 +39,7 @@
 import java.io.OutputStream;
 import java.util.Date;
 import java.util.Map;
+import java.util.Set;
 
 import org.amplecode.quick.BatchHandler;
 import org.amplecode.quick.BatchHandlerFactory;

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java	2012-04-01 12:24:57 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java	2012-04-13 10:21:57 +0000
@@ -30,6 +30,7 @@
 import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
 import static org.hisp.dhis.system.util.DateUtils.getMediumDateString;
 import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
+import static org.hisp.dhis.system.util.TextUtils.ifNotNull;
 
 import java.io.OutputStream;
 import java.util.Collection;
@@ -68,10 +69,10 @@
         SqlRowSet rowSet = jdbcTemplate.queryForRowSet( getDataValueSql( dataElements, periods, orgUnits ) );
 
         DataValueSet dataValueSet = new StreamingDataValueSet( writer );
-        dataValueSet.setDataSet( dataSet.getUid() );
+        dataValueSet.setDataSet( ifNotNull( dataSet, dataSet.getUid() ) );
         dataValueSet.setCompleteDate( getMediumDateString( completeDate ) );
-        dataValueSet.setPeriod( period.getIsoDate() );
-        dataValueSet.setOrgUnit( orgUnit.getUid() );
+        dataValueSet.setPeriod( ifNotNull( period, period.getIsoDate() ) );
+        dataValueSet.setOrgUnit( ifNotNull( orgUnit, orgUnit.getUid() ) );
         
         while ( rowSet.next() )
         {

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java	2012-03-29 21:52:27 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java	2012-04-13 10:21:57 +0000
@@ -76,6 +76,18 @@
     }
     
     /**
+     * Returns the value argument if the object argument is not null, null otherwise.
+     * 
+     * @param object the object.
+     * @param value the value.
+     * @return the value or null.
+     */
+    public static <T> T ifNotNull( Object object, T value )
+    {
+        return object != null ? value: null;
+    }
+    
+    /**
      * Gets the sub string of the given string. If the beginIndex is larger than
      * the length of the string, the empty string is returned. If the beginIndex +
      * the length is larger than the length of the string, the part of the string

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/DataValueExportAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/DataValueExportAction.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/DataValueExportAction.java	2012-04-13 10:21:57 +0000
@@ -31,6 +31,7 @@
 import static org.hisp.dhis.system.util.ConversionUtils.getIntegerCollection;
 import static org.hisp.dhis.system.util.DateUtils.getMediumDate;
 import static org.hisp.dhis.system.util.DateUtils.getMediumDateString;
+import static org.hisp.dhis.system.util.CodecUtils.filenameEncode;
 
 import java.io.InputStream;
 import java.util.Collection;
@@ -275,28 +276,16 @@
         
         if ( selectionTreeManager.getSelectedOrganisationUnits().size() == 1 )
         {
-            fileName += FILE_SEPARATOR + fileNameEncode( selectionTreeManager.getSelectedOrganisationUnits().iterator().next().getShortName() );
+            fileName += FILE_SEPARATOR + filenameEncode( selectionTreeManager.getSelectedOrganisationUnits().iterator().next().getShortName() );
         }
         
         if ( params.getDataSets().size() == 1 )
         {
-            fileName += FILE_SEPARATOR + fileNameEncode( dataSetService.getDataSet( params.getDataSets().iterator().next() ).getName() );
+            fileName += FILE_SEPARATOR + filenameEncode( dataSetService.getDataSet( params.getDataSets().iterator().next() ).getName() );
         }
         
         fileName += FILE_EXTENSION;
         
         return fileName;
     }
-    
-    private String fileNameEncode( String in )
-    {
-        if ( in == null )
-        {
-            return "";
-        }
-        
-        in = in.replaceAll( " ", FILE_SEPARATOR );
-        
-        return in;
-    }
 }