← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19983: minor addition to ValueType

 

------------------------------------------------------------
revno: 19983
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-09-04 12:24:21 +0700
message:
  minor addition to ValueType
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.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/common/ValueType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java	2015-09-03 10:21:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/ValueType.java	2015-09-04 05:24:21 +0000
@@ -28,14 +28,13 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.google.common.collect.Lists;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.trackedentity.TrackedEntityInstance;
+
 import java.util.Date;
 import java.util.List;
 
-import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.trackedentity.TrackedEntityInstance;
-
-import com.google.common.collect.Lists;
-
 /**
  * @author Lars Helge Overland
  */
@@ -128,6 +127,111 @@
         return getFromDataElementTypes( dataElement.getType(), dataElement.getNumberType(), dataElement.getTextType() );
     }
 
+    public static void setDataElementTypes( DataElement dataElement, ValueType valueType )
+    {
+        switch ( valueType )
+        {
+            case INTEGER:
+            {
+                dataElement.setType( DataElement.VALUE_TYPE_INT );
+                dataElement.setNumberType( DataElement.VALUE_TYPE_INT );
+                dataElement.setTextType( null );
+                break;
+            }
+            case INTEGER_POSITIVE:
+            {
+                dataElement.setType( DataElement.VALUE_TYPE_INT );
+                dataElement.setNumberType( DataElement.VALUE_TYPE_POSITIVE_INT );
+                dataElement.setTextType( null );
+                break;
+            }
+            case INTEGER_NEGATIVE:
+            {
+                dataElement.setType( DataElement.VALUE_TYPE_INT );
+                dataElement.setNumberType( DataElement.VALUE_TYPE_NEGATIVE_INT );
+                dataElement.setTextType( null );
+                break;
+            }
+            case INTEGER_ZERO_OR_POSITIVE:
+            {
+                dataElement.setType( DataElement.VALUE_TYPE_INT );
+                dataElement.setNumberType( DataElement.VALUE_TYPE_ZERO_OR_POSITIVE_INT );
+                dataElement.setTextType( null );
+                break;
+            }
+            case NUMBER:
+            {
+                dataElement.setType( DataElement.VALUE_TYPE_INT );
+                dataElement.setNumberType( DataElement.VALUE_TYPE_NUMBER );
+                dataElement.setTextType( null );
+                break;
+            }
+            case UNIT_INTERVAL:
+            {
+                dataElement.setType( DataElement.VALUE_TYPE_INT );
+                dataElement.setNumberType( DataElement.VALUE_TYPE_UNIT_INTERVAL );
+                dataElement.setTextType( null );
+                break;
+            }
+            case PERCENTAGE:
+            {
+                dataElement.setType( DataElement.VALUE_TYPE_INT );
+                dataElement.setNumberType( DataElement.VALUE_TYPE_PERCENTAGE );
+                dataElement.setTextType( null );
+                break;
+            }
+            case TEXT:
+            {
+                dataElement.setType( DataElement.VALUE_TYPE_STRING );
+                dataElement.setTextType( DataElement.VALUE_TYPE_TEXT );
+                dataElement.setNumberType( null );
+                break;
+            }
+            case LONG_TEXT:
+            {
+                dataElement.setType( DataElement.VALUE_TYPE_STRING );
+                dataElement.setTextType( DataElement.VALUE_TYPE_LONG_TEXT );
+                dataElement.setNumberType( null );
+                break;
+            }
+            case BOOLEAN:
+            {
+                dataElement.setType( DataElement.VALUE_TYPE_BOOL );
+                dataElement.setNumberType( null );
+                dataElement.setTextType( null );
+                break;
+            }
+            case TRUE_ONLY:
+            {
+                dataElement.setType( DataElement.VALUE_TYPE_TRUE_ONLY );
+                dataElement.setNumberType( null );
+                dataElement.setTextType( null );
+                break;
+            }
+            case DATE:
+            {
+                dataElement.setType( DataElement.VALUE_TYPE_DATE );
+                dataElement.setNumberType( null );
+                dataElement.setTextType( null );
+                break;
+            }
+            case DATETIME:
+            {
+                dataElement.setType( DataElement.VALUE_TYPE_DATETIME );
+                dataElement.setNumberType( null );
+                dataElement.setTextType( null );
+                break;
+            }
+            case USERNAME:
+            {
+                dataElement.setType( DataElement.VALUE_TYPE_USER_NAME );
+                dataElement.setNumberType( null );
+                dataElement.setTextType( null );
+                break;
+            }
+        }
+    }
+
     public static ValueType getFromDataElementTypes( String type, String numberType, String textType )
     {
         if ( DataElement.VALUE_TYPE_STRING.equals( type ) )