← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2002: (DHIS-Mobile) Flattenning DataElement with CategoryOptionCombos before send to mobile.

 

------------------------------------------------------------
revno: 2002
committer: Tran Ng Minh Luan <Luan@MinhLuan-PC>
branch nick: dhis2
timestamp: Mon 2010-11-08 10:52:21 +0700
message:
  (DHIS-Mobile) Flattenning DataElement with CategoryOptionCombos before send to mobile.
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataElement.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Section.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultDataSetService.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-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataElement.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataElement.java	2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataElement.java	2010-11-08 03:52:21 +0000
@@ -7,6 +7,8 @@
 
 	private String type;
 
+	private AbstractModelList categoryOptionCombos;
+	
 	public DataElement() {
 
 	}	
@@ -18,5 +20,17 @@
 	public void setType(String type) {
 		this.type = type;
 	}
+
+        public AbstractModelList getCategoryOptionCombos()
+        {
+            return categoryOptionCombos;
+        }
+    
+        public void setCategoryOptionCombos( AbstractModelList categoryOptionCombos )
+        {
+            this.categoryOptionCombos = categoryOptionCombos;
+        }
+	
+	
 		
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Section.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Section.java	2010-11-02 03:53:54 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Section.java	2010-11-08 03:52:21 +0000
@@ -8,50 +8,69 @@
 
 /**
  * @author Tran Ng Minh Luan
- *
+ * 
  */
-public class Section extends AbstractModel{
-	
-	private List<DataElement> dataElements;
-
-	public Section() {
-	}
-
-	public List<DataElement> getDes() {
-		return dataElements;
-	}
-
-	public void setDes(List<DataElement> des) {
-		this.dataElements = des;
-	}
-	
-	public void serialize(OutputStream out) throws IOException{
-		ByteArrayOutputStream bout = new ByteArrayOutputStream();
-        DataOutputStream dout = new DataOutputStream(bout); 
-      
-      dout.writeInt(this.getId());
-      dout.writeUTF(getName());
-      
-      if(dataElements == null){
-    	  dout.writeInt(0);
-      }else{
-    	  dout.writeInt(dataElements.size());
-    	  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() );
-          }
-      }
-      bout.flush();
-      bout.writeTo(out);
-	}
-	
-	
-	
-	
-	
-	
-	
+public class Section
+    extends AbstractModel
+{
+
+    private List<DataElement> dataElements;
+
+    public Section()
+    {
+    }
+
+    public List<DataElement> getDes()
+    {
+        return dataElements;
+    }
+
+    public void setDes( List<DataElement> des )
+    {
+        this.dataElements = des;
+    }
+
+    public void serialize( OutputStream out )
+        throws IOException
+    {
+        ByteArrayOutputStream bout = new ByteArrayOutputStream();
+        DataOutputStream dout = new DataOutputStream( bout );
+
+        dout.writeInt( this.getId() );
+        dout.writeUTF( getName() );
+
+        if ( dataElements == null )
+        {
+            dout.writeInt( 0 );
+        }
+        else
+        {
+            dout.writeInt( dataElements.size() );
+            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() );
+                List<AbstractModel> cateOptCombos = de.getCategoryOptionCombos().getAbstractModels();
+                if ( cateOptCombos == null || cateOptCombos.size() <= 0 )
+                {
+                    dout.writeInt( 0 );
+                }
+                else
+                {
+                    dout.writeInt( cateOptCombos.size() );
+                    for ( AbstractModel each : cateOptCombos )
+                    {
+                        dout.writeInt( each.getId() );
+                        dout.writeUTF( each.getName() );
+                    }
+                }
+
+            }
+        }
+        bout.flush();
+        bout.writeTo( out );
+    }
+
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultDataSetService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultDataSetService.java	2010-11-04 09:49:46 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultDataSetService.java	2010-11-08 03:52:21 +0000
@@ -9,9 +9,12 @@
 import java.util.Locale;
 import java.util.Set;
 
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.comparator.DataElementSortOrderComparator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.web.api.model.AbstractModel;
+import org.hisp.dhis.web.api.model.AbstractModelList;
 import org.hisp.dhis.web.api.model.DataElement;
 import org.hisp.dhis.web.api.model.DataSet;
 import org.hisp.dhis.web.api.model.Section;
@@ -21,8 +24,8 @@
 public class DefaultDataSetService implements IDataSetService {
 	
 	// -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
+        // Dependencies
+        // -------------------------------------------------------------------------
 	private DataElementSortOrderComparator dataElementComparator = new DataElementSortOrderComparator();
 	
 	@Autowired
@@ -32,21 +35,12 @@
 	private org.hisp.dhis.i18n.I18nService i18nService;	
 	
 	@Autowired
-	private org.hisp.dhis.order.manager.DataElementOrderManager dataElementOrderManager ;	
-	
-	@Autowired
-    private CurrentUserService currentUserService;
+        private CurrentUserService currentUserService;
 	
 	
 	// -------------------------------------------------------------------------
-    // MobileDataSetService
-    // -------------------------------------------------------------------------	
-	
-	
-	public void setDataElementOrderManager(
-			org.hisp.dhis.order.manager.DataElementOrderManager dataElementOrderManager) {
-		this.dataElementOrderManager = dataElementOrderManager;
-	}
+        // MobileDataSetService
+        // -------------------------------------------------------------------------
 
 	public List<DataSet> getAllMobileDataSetsForLocale(String localeString) {
 		Collection<OrganisationUnit> units = currentUserService.getCurrentUser().getOrganisationUnits();
@@ -60,8 +54,6 @@
         {
         	return null;
         }
-        
-        
 		
 		List<DataSet> datasets = new ArrayList<DataSet>();
 		Locale locale = LocaleUtil.getLocale(localeString);			
@@ -104,6 +96,8 @@
 		List<Section> sectionList = new ArrayList<Section>(); 
 		ds.setSections(sectionList);
 		
+		
+		
 			if(sections.size() == 0 || sections == null){
 //				Collection<org.hisp.dhis.dataelement.DataElement> dataElements = new ArrayList<org.hisp.dhis.dataelement.DataElement>();
 				List<org.hisp.dhis.dataelement.DataElement> dataElements = new ArrayList<org.hisp.dhis.dataelement.DataElement>(dataSet.getDataElements());
@@ -122,12 +116,26 @@
 				
 				for( org.hisp.dhis.dataelement.DataElement dataElement : dataElements )
 				{
-					dataElement = i18n( i18nService, locale, dataElement );
-					
+				        //Server DataElement
+				        dataElement = i18n( i18nService, locale, dataElement );
+				        Set<DataElementCategoryOptionCombo> deCatOptCombs = dataElement.getCategoryCombo().getOptionCombos();
+				        //Client DataElement
+				        AbstractModelList deCateOptCombo = new AbstractModelList();
+				        List<AbstractModel> listCateOptCombo = new ArrayList<AbstractModel>();
+				        deCateOptCombo.setAbstractModels( listCateOptCombo );
+				        
+				        for(DataElementCategoryOptionCombo oneCatOptCombo : deCatOptCombs){				                
+				                AbstractModel oneCateOptCombo = new AbstractModel();
+				                oneCateOptCombo.setId( oneCatOptCombo.getId() );
+				                oneCateOptCombo.setName( oneCatOptCombo.getName() );
+				                listCateOptCombo.add( oneCateOptCombo );
+	                                }
+				        
 					DataElement de = new DataElement();
 					de.setId( dataElement.getId() );
 					de.setName( dataElement.getName() );
 					de.setType( dataElement.getType() );
+					de.setCategoryOptionCombos( deCateOptCombo );
 					dataElementList.add( de );
 				}
 			}else{
@@ -144,12 +152,27 @@
 				
 				for( org.hisp.dhis.dataelement.DataElement dataElement : dataElements )
 				{
+				        //Server DataElement
 					dataElement = i18n( i18nService, locale, dataElement );
+					Set<DataElementCategoryOptionCombo> deCatOptCombs = dataElement.getCategoryCombo().getOptionCombos();
 					
+					//Client DataElement
+                                        AbstractModelList deCateOptCombo = new AbstractModelList();
+                                        List<AbstractModel> listCateOptCombo = new ArrayList<AbstractModel>();
+                                        deCateOptCombo.setAbstractModels( listCateOptCombo );
+                                        
+                                        for(DataElementCategoryOptionCombo oneCatOptCombo : deCatOptCombs){                                             
+                                            AbstractModel oneCateOptCombo = new AbstractModel();
+                                            oneCateOptCombo.setId( oneCatOptCombo.getId() );
+                                            oneCateOptCombo.setName( oneCatOptCombo.getName() );
+                                            listCateOptCombo.add( oneCateOptCombo );
+                                        }
+                                        
 					DataElement de = new DataElement();
 					de.setId( dataElement.getId() );
 					de.setName( dataElement.getName() );
 					de.setType( dataElement.getType() );
+					de.setCategoryOptionCombos( deCateOptCombo );
 					dataElementList.add( de );
 				}
 				sectionList.add(section);