← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1984: Sort DataElement in DataSet (without section) before send to mobile

 

------------------------------------------------------------
revno: 1984
fixes bug(s): https://launchpad.net/bugs/664390
committer: Tran Ng Minh Luan <Luan@MinhLuan-PC>
branch nick: dhis2
timestamp: Tue 2010-11-02 10:53:54 +0700
message:
  Sort DataElement in DataSet (without section) before send to mobile
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSet.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSetValue.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/DataSet.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSet.java	2010-11-01 06:32:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSet.java	2010-11-02 03:53:54 +0000
@@ -1,16 +1,12 @@
 package org.hisp.dhis.web.api.model;
 
-import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.List;
 
 import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlAccessType;

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSetValue.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSetValue.java	2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSetValue.java	2010-11-02 03:53:54 +0000
@@ -21,10 +21,22 @@
    
     private String pName;
     
+    private boolean completed;
+    
     @XmlElement(name = "dv")
 	private List<DataValue> dataValues = new ArrayList<DataValue>();
 
     public DataSetValue(){}	
+    
+    public boolean isCompleted()
+    {
+        return completed;
+    }
+
+    public void setCompleted( boolean completed )
+    {
+        this.completed = completed;
+    }
 
 	public String getpName() {
 		return pName;
@@ -50,6 +62,7 @@
         dout.writeInt(this.getId());
         dout.writeUTF(this.getName());
         dout.writeUTF(this.getpName());
+        dout.writeBoolean( this.isCompleted() );
         dout.writeInt(dataValues.size());
 
         for(int i=0; i<dataValues.size(); i++)
@@ -70,7 +83,7 @@
         this.setId( din.readInt() ) ;
         this.setName( din.readUTF() );
         this.setpName( din.readUTF() ) ;
-
+        this.setCompleted( din.readBoolean() );
         int size = din.readInt();
 
         for(int i=0; i<size; i++)
@@ -89,7 +102,7 @@
         this.setId( din.readInt() ) ;
         this.setName( din.readUTF() );
         this.setpName( din.readUTF() ) ;
-
+        this.setCompleted( din.readBoolean() );
         int size = din.readInt();
 
         for(int i=0; i<size; i++)

=== 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-10-28 09:25:22 +0000
+++ 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
@@ -29,6 +29,9 @@
 		ByteArrayOutputStream bout = new ByteArrayOutputStream();
         DataOutputStream dout = new DataOutputStream(bout); 
       
+      dout.writeInt(this.getId());
+      dout.writeUTF(getName());
+      
       if(dataElements == null){
     	  dout.writeInt(0);
       }else{

=== 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-01 06:32:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultDataSetService.java	2010-11-02 03:53:54 +0000
@@ -4,11 +4,12 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 import java.util.Set;
 
-import org.hisp.dhis.order.manager.DataElementOrderManagerException;
+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.DataElement;
@@ -22,6 +23,7 @@
 	// -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
+	private DataElementSortOrderComparator dataElementComparator = new DataElementSortOrderComparator();
 	
 	@Autowired
 	private org.hisp.dhis.dataset.DataSetService dataSetService;
@@ -34,10 +36,18 @@
 	
 	@Autowired
     private CurrentUserService currentUserService;
+	
+	
 	// -------------------------------------------------------------------------
     // MobileDataSetService
     // -------------------------------------------------------------------------	
 	
+	
+	public void setDataElementOrderManager(
+			org.hisp.dhis.order.manager.DataElementOrderManager dataElementOrderManager) {
+		this.dataElementOrderManager = dataElementOrderManager;
+	}
+
 	public List<DataSet> getAllMobileDataSetsForLocale(String localeString) {
 		Collection<OrganisationUnit> units = currentUserService.getCurrentUser().getOrganisationUnits();
         OrganisationUnit unit = null;
@@ -74,7 +84,7 @@
 		
 		return datasets;
 	}
-	
+
 	public DataSet getDataSetForLocale(int dataSetId, Locale locale) {
 		org.hisp.dhis.dataset.DataSet dataSet = dataSetService.getDataSet( dataSetId );
 		dataSet = i18n( i18nService, locale, dataSet );
@@ -94,12 +104,11 @@
 		ds.setSections(sectionList);
 		
 			if(sections.size() == 0 || sections == null){
-				Collection<org.hisp.dhis.dataelement.DataElement> dataElements = new ArrayList<org.hisp.dhis.dataelement.DataElement>();
-				try {
-					dataElements = dataElementOrderManager.getOrderedDataElements(dataSet);
-				} catch (DataElementOrderManagerException e) {
-					e.printStackTrace();
-				}
+//				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());
+									
+				Collections.sort(dataElements, dataElementComparator);
+				
 				//Fake Section to store Data Elements
 				Section section = new Section();