← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19966: Value type fixes

 

------------------------------------------------------------
revno: 19966
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-09-03 14:15:43 +0200
message:
  Value type fixes
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java
  dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueController.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetProgramMetaDataAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetHistoryAction.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-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java	2015-09-03 04:17:55 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java	2015-09-03 12:15:43 +0000
@@ -309,7 +309,7 @@
             return null;
         }
 
-        if ( dataElement == null || dataElement.getType() == null || dataElement.getType().isEmpty() )
+        if ( dataElement == null || dataElement.getValueType() == null )
         {
             return "data_element_or_type_null_or_empty";
         }
@@ -390,7 +390,7 @@
     {
         String aggOperator = dataElement.getAggregationOperator();
 
-        return VALUE_TYPE_INT.equals( dataElement.getType() ) && MathUtils.isZero( value ) && !dataElement.isZeroIsSignificant() &&
+        return dataElement.getValueType().isNumeric() && MathUtils.isZero( value ) && !dataElement.isZeroIsSignificant() &&
             !(AGGREGATION_OPERATOR_AVERAGE_SUM.equals( aggOperator ) || AGGREGATION_OPERATOR_AVERAGE.equals( aggOperator ));
     }
 

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java	2015-07-19 15:50:46 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/ValidationUtilsTest.java	2015-09-03 12:15:43 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.common.ValueType;
 import org.hisp.dhis.dataelement.DataElement;
 import org.junit.Test;
 
@@ -104,7 +105,7 @@
     public void testDataValueIsZeroAndInsignificant()
     {
         DataElement de = new DataElement( "DEA" );
-        de.setType( DataElement.VALUE_TYPE_INT );
+        de.setValueType( ValueType.INTEGER );
         de.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM );
 
         assertTrue( dataValueIsZeroAndInsignificant( "0", de ) );
@@ -118,7 +119,7 @@
     public void testDataValueIsValid()
     {
         DataElement de = new DataElement( "DEA" );
-        de.setType( DataElement.VALUE_TYPE_INT );
+        de.setValueType( ValueType.INTEGER );
 
         assertNull( dataValueIsValid( null, de ) );
         assertNull( dataValueIsValid( "", de ) );
@@ -126,46 +127,46 @@
         assertNull( dataValueIsValid( "34", de ) );
         assertNotNull( dataValueIsValid( "Yes", de ) );
 
-        de.setNumberType( DataElement.VALUE_TYPE_NUMBER );
+        de.setValueType( ValueType.NUMBER );
 
         assertNull( dataValueIsValid( "3.7", de ) );
         assertNotNull( dataValueIsValid( "No", de ) );
 
-        de.setNumberType( DataElement.VALUE_TYPE_POSITIVE_INT );
-
-        assertNull( dataValueIsValid( "3", de ) );
-        assertNotNull( dataValueIsValid( "-4", de ) );
-
-        de.setNumberType( DataElement.VALUE_TYPE_ZERO_OR_POSITIVE_INT );
-
-        assertNull( dataValueIsValid( "3", de ) );
-        assertNotNull( dataValueIsValid( "-4", de ) );
-
-        de.setNumberType( DataElement.VALUE_TYPE_NEGATIVE_INT );
+        de.setValueType( ValueType.INTEGER_POSITIVE );
+
+        assertNull( dataValueIsValid( "3", de ) );
+        assertNotNull( dataValueIsValid( "-4", de ) );
+
+        de.setValueType( ValueType.INTEGER_ZERO_OR_POSITIVE );
+
+        assertNull( dataValueIsValid( "3", de ) );
+        assertNotNull( dataValueIsValid( "-4", de ) );
+
+        de.setValueType( ValueType.INTEGER_NEGATIVE );
 
         assertNull( dataValueIsValid( "-3", de ) );
         assertNotNull( dataValueIsValid( "4", de ) );
 
-        de.setType( DataElement.VALUE_TYPE_TEXT );
+        de.setValueType( ValueType.TEXT );
 
         assertNull( dataValueIsValid( "0", de ) );
 
-        de.setType( DataElement.VALUE_TYPE_BOOL );
+        de.setValueType( ValueType.BOOLEAN );
 
         assertNull( dataValueIsValid( "true", de ) );
         assertNotNull( dataValueIsValid( "yes", de ) );
 
-        de.setType( DataElement.VALUE_TYPE_TRUE_ONLY );
+        de.setValueType( ValueType.TRUE_ONLY );
 
         assertNull( dataValueIsValid( "true", de ) );
         assertNotNull( dataValueIsValid( "false", de ) );
 
-        de.setType( DataElement.VALUE_TYPE_DATE );
+        de.setValueType( ValueType.DATE );
         assertNull( dataValueIsValid( "2013-04-01", de ) );
         assertNotNull( dataValueIsValid( "2012304-01", de ) );
         assertNotNull( dataValueIsValid( "Date", de ) );
 
-        de.setType( DataElement.VALUE_TYPE_DATETIME );
+        de.setValueType( ValueType.DATETIME );
         assertNull( dataValueIsValid( "2013-04-01T11:00:00.000Z", de ) );
         assertNotNull( dataValueIsValid( "2013-04-01", de ) );
         assertNotNull( dataValueIsValid( "abcd", de ) );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueController.java	2015-09-02 14:05:25 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueController.java	2015-09-03 12:15:43 +0000
@@ -41,6 +41,7 @@
 
 import org.apache.commons.lang3.StringUtils;
 import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.common.ValueType;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
@@ -252,7 +253,7 @@
         }
         else
         {
-            if ( value == null && DataElement.VALUE_TYPE_TRUE_ONLY.equals( dataElement.getType() ) )
+            if ( value == null && ValueType.TRUE_ONLY.equals( dataElement.getValueType() ) )
             {
                 if ( comment == null )
                 {

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetProgramMetaDataAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetProgramMetaDataAction.java	2015-09-03 03:11:47 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/GetProgramMetaDataAction.java	2015-09-03 12:15:43 +0000
@@ -28,8 +28,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.opensymphony.xwork2.Action;
-import org.hisp.dhis.dataelement.DataElement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.hisp.dhis.common.ValueType;
 import org.hisp.dhis.option.OptionSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.program.Program;
@@ -38,12 +44,7 @@
 import org.hisp.dhis.program.ProgramStageDataElement;
 import org.hisp.dhis.program.ProgramType;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import com.opensymphony.xwork2.Action;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -143,7 +144,7 @@
                     optionSets.add( programStageDataElement.getDataElement().getOptionSet() );
                 }
 
-                if ( programStageDataElement.getDataElement().getType().equals( DataElement.VALUE_TYPE_USER_NAME ) )
+                if ( ValueType.USERNAME.equals( programStageDataElement.getDataElement().getValueType() ) )
                 {
                     usernames = true;
                 }

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetHistoryAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetHistoryAction.java	2015-07-10 19:12:53 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/GetHistoryAction.java	2015-09-03 12:15:43 +0000
@@ -273,7 +273,7 @@
 
         historyInvalid = dataElementHistory == null;
 
-        minMaxInvalid = !DataElement.VALUE_TYPE_INT.equals( dataElement.getType() );
+        minMaxInvalid = !dataElement.getValueType().isNumeric();
 
         commentOptionSet = dataElement.getCommentOptionSet();