← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6559: [mobile] apply optionset to dataelement

 

------------------------------------------------------------
revno: 6559
committer: Em <em.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-04-13 15:27:30 +0700
message:
  [mobile] apply optionset to dataelement
added:
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/OptionSet.java
modified:
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/DataElement.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/ProgramStage.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Section.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ModelMapping.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-mobile/src/main/java/org/hisp/dhis/api/mobile/model/DataElement.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/DataElement.java	2011-11-04 11:27:33 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/DataElement.java	2012-04-13 08:27:30 +0000
@@ -43,6 +43,8 @@
 
     private ModelList categoryOptionCombos;
 
+    private OptionSet optionSet;
+
     @XmlAttribute
     public String getType()
     {
@@ -64,6 +66,16 @@
         this.categoryOptionCombos = categoryOptionCombos;
     }
 
+    public OptionSet getOptionSet()
+    {
+        return optionSet;
+    }
+
+    public void setOptionSet( OptionSet optionSet )
+    {
+        this.optionSet = optionSet;
+    }
+
     @XmlAttribute
     public boolean isCompulsory()
     {
@@ -75,32 +87,39 @@
         this.compulsory = compulsory;
     }
 
-    public void serializeHack( DataOutputStream dout )
+    @Override
+    public void serialize( DataOutputStream dout )
         throws IOException
     {
-        dout.writeInt( getId() );
-        dout.writeUTF( getName() );
-        dout.writeUTF( type );
-        dout.writeBoolean( compulsory );
-
-        if ( categoryOptionCombos == null )
-        {
-            dout.writeInt( 0 );
-            return;
-        }
-
-        List<Model> cateOptCombos = categoryOptionCombos.getModels();
+        dout.writeInt( this.getId() );
+        dout.writeUTF( this.getName() );
+        dout.writeUTF( this.getType() );
+        dout.writeBoolean( this.isCompulsory() );
+
+        List<Model> cateOptCombos = this.getCategoryOptionCombos().getModels();
         if ( cateOptCombos == null || cateOptCombos.size() <= 0 )
         {
             dout.writeInt( 0 );
-            return;
-        }
-
-        dout.writeInt( cateOptCombos.size() );
-        for ( Model each : cateOptCombos )
-        {
-            dout.writeInt( each.getId() );
-            dout.writeUTF( each.getName() );
+        }
+        else
+        {
+            dout.writeInt( cateOptCombos.size() );
+            for ( Model each : cateOptCombos )
+            {
+                dout.writeInt( each.getId() );
+                dout.writeUTF( each.getName() );
+            }
+        }
+
+        OptionSet optionSet = this.getOptionSet();
+
+        if ( optionSet == null )
+        {
+            dout.writeInt( 0 );
+        }
+        else
+        {
+            optionSet.serialize( dout );
         }
     }
 

=== added file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/OptionSet.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/OptionSet.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/OptionSet.java	2012-04-13 08:27:30 +0000
@@ -0,0 +1,61 @@
+package org.hisp.dhis.api.mobile.model;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class OptionSet
+    extends Model
+    implements DataStreamSerializable
+{
+    private List<String> options = new ArrayList<String>();
+
+    public List<String> getOptions()
+    {
+        return options;
+    }
+
+    public void setOptions( List<String> options )
+    {
+        this.options = options;
+    }
+
+    @Override
+    public void serialize( DataOutputStream dout )
+        throws IOException
+    {
+
+        dout.writeInt( this.getId() );
+        dout.writeUTF( this.getName() );
+
+        dout.writeInt( this.options.size() );
+
+        for ( String option : this.options )
+        {
+            dout.writeUTF( option );
+        }
+
+    }
+
+    @Override
+    public void deSerialize( DataInputStream dataInputStream )
+        throws IOException
+    {
+
+        this.setId( dataInputStream.readInt() );
+        this.setName( dataInputStream.readUTF() );
+
+        int optionSize = dataInputStream.readInt();
+
+        for ( int i = 0; i < optionSize; i++ )
+        {
+            String option = dataInputStream.readUTF();
+            options.add( option );
+
+        }
+
+    }
+
+}

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/ProgramStage.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/ProgramStage.java	2011-11-04 11:27:33 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/ProgramStage.java	2012-04-13 08:27:30 +0000
@@ -61,25 +61,7 @@
         for ( int i = 0; i < dataElements.size(); i++ )
         {
             DataElement de = (DataElement) dataElements.get( i );
-            dout.writeInt( de.getId() );
-            dout.writeUTF( de.getName() );
-            dout.writeUTF( de.getType() );
-            dout.writeBoolean( de.isCompulsory() );
-
-            List<Model> cateOptCombos = de.getCategoryOptionCombos().getModels();
-            if ( cateOptCombos == null || cateOptCombos.size() <= 0 )
-            {
-                dout.writeInt( 0 );
-            }
-            else
-            {
-                dout.writeInt( cateOptCombos.size() );
-                for ( Model each : cateOptCombos )
-                {
-                    dout.writeInt( each.getId() );
-                    dout.writeUTF( each.getName() );
-                }
-            }
+            de.serialize( dout );
 
         }
     }

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Section.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Section.java	2011-11-04 11:27:33 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/api/mobile/model/Section.java	2012-04-13 08:27:30 +0000
@@ -67,7 +67,7 @@
             for ( int i = 0; i < dataElements.size(); i++ )
             {
                 DataElement de = (DataElement) dataElements.get( i );
-                de.serializeHack( dout );
+                de.serialize( dout );
             }
         }
     }

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ModelMapping.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ModelMapping.java	2011-11-14 12:19:36 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/ModelMapping.java	2012-04-13 08:27:30 +0000
@@ -33,6 +33,7 @@
 import org.hisp.dhis.api.mobile.model.DataElement;
 import org.hisp.dhis.api.mobile.model.Model;
 import org.hisp.dhis.api.mobile.model.ModelList;
+import org.hisp.dhis.api.mobile.model.OptionSet;
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 
@@ -53,13 +54,33 @@
         de.setType( dataElement.getType() );
 
         de.setCategoryOptionCombos( getCategoryOptionCombos( dataElement ) );
+        de.setOptionSet( getOptionSet( dataElement ) );
         return de;
     }
 
+    public OptionSet getOptionSet( org.hisp.dhis.dataelement.DataElement dataElement )
+    {
+        org.hisp.dhis.option.OptionSet dhisOptionSet = dataElement.getOptionSet();
+        OptionSet mobileOptionSet = new OptionSet();
+        if ( dhisOptionSet != null )
+        {
+            mobileOptionSet.setId( dhisOptionSet.getId() );
+            mobileOptionSet.setName( dhisOptionSet.getName() );
+            mobileOptionSet.setOptions( dhisOptionSet.getOptions() );
+        }
+        else
+        {
+            return null;
+        }
+
+        return mobileOptionSet;
+
+    }
+
     public ModelList getCategoryOptionCombos( org.hisp.dhis.dataelement.DataElement dataElement )
     {
         DataElementCategoryCombo categoryCombo = dataElement.getCategoryCombo();
-        
+
         // Set<DataElementCategoryOptionCombo> deCatOptCombs =
         // dataElement.getCategoryCombo().getOptionCombos();