← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4460: Improved version handling for data sets

 

------------------------------------------------------------
revno: 4460
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-08-26 22:38:26 +0200
message:
  Improved version handling for data sets
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UpdateDataSetAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/AddSectionAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/RemoveSectionAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/UpdateSectionAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/index.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/menu.vm


--
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/dataset/DataSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2011-05-30 19:17:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2011-08-26 20:38:26 +0000
@@ -238,6 +238,12 @@
         return TYPE_DEFAULT;
     }
     
+    public DataSet increaseVersion()
+    {
+        this.version = this.version + 1;
+        return this;
+    }
+    
     // -------------------------------------------------------------------------
     // hashCode and equals
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java	2011-04-13 16:09:45 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java	2011-08-26 20:38:26 +0000
@@ -116,4 +116,16 @@
     {
         return string != null && string.trim().length() == 0 ? null : string;
     }
+    
+    /**
+     * Checks the two strings for equality.
+     * 
+     * @param s1 string 1.
+     * @param s2 string 2.
+     * @return true if strings are equal, false otherwise.
+     */
+    public static boolean equalsNullSafe( String s1, String s2 )
+    {
+        return s1 == null ? s2 == null : s1.equals( s2 );
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UpdateDataSetAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UpdateDataSetAction.java	2011-05-30 15:17:51 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/UpdateDataSetAction.java	2011-08-26 20:38:26 +0000
@@ -42,6 +42,8 @@
 
 import com.opensymphony.xwork2.Action;
 
+import static org.hisp.dhis.system.util.TextUtils.equalsNullSafe;
+
 /**
  * @author Kristian
  * @version $Id: UpdateDataSetAction.java 6255 2008-11-10 16:01:24Z larshelg $
@@ -173,6 +175,12 @@
 
         DataSet dataSet = dataSetService.getDataSet( dataSetId );
 
+        if ( !( equalsNullSafe( name, dataSet.getName() ) && periodType.equals( dataSet.getPeriodType() ) && 
+            dataElements.equals( dataSet.getDataElements() ) && indicators.equals( dataSet.getIndicators() ) ) )
+        {
+            dataSet.increaseVersion(); // Check if version must be updated            
+        }
+        
         dataSet.setName( name );
         dataSet.setShortName( shortName );
         dataSet.setCode( code );
@@ -180,11 +188,6 @@
         dataSet.updateDataElements( dataElements );
         dataSet.setIndicators( indicators );
 
-        if ( dataSet.isMobile() )
-        {
-            dataSet.setVersion( dataSet.getVersion() + 1 ); // TODO hack
-        }
-
         dataSetService.updateDataSet( dataSet );
 
         return SUCCESS;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/AddSectionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/AddSectionAction.java	2011-05-28 18:05:39 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/AddSectionAction.java	2011-08-26 20:38:26 +0000
@@ -118,11 +118,7 @@
         dataSet.getSections().add( section );
         sectionService.addSection( section );
 
-        if ( dataSet.getMobile() != null && dataSet.getMobile() ) // TODO Hack
-        {
-            dataSet.setVersion( dataSet.getVersion() + 1 );
-            dataSetService.updateDataSet( dataSet );
-        }
+        dataSetService.updateDataSet( dataSet.increaseVersion() );
         
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/RemoveSectionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/RemoveSectionAction.java	2011-05-28 11:57:54 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/RemoveSectionAction.java	2011-08-26 20:38:26 +0000
@@ -77,11 +77,7 @@
         
         DataSet dataSet = section.getDataSet();
 
-        if ( dataSet.getMobile() != null && dataSet.getMobile() ) //TODO hack
-        {
-            dataSet.setVersion( dataSet.getVersion() + 1 );
-            dataSetService.updateDataSet( dataSet );
-        }
+        dataSetService.updateDataSet( dataSet.increaseVersion() );
         
         sectionService.deleteSection( section );
         

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/UpdateSectionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/UpdateSectionAction.java	2011-01-25 21:25:39 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/section/UpdateSectionAction.java	2011-08-26 20:38:26 +0000
@@ -39,6 +39,8 @@
 
 import com.opensymphony.xwork2.Action;
 
+import static org.hisp.dhis.system.util.TextUtils.equalsNullSafe;
+
 public class UpdateSectionAction
     implements Action
 {
@@ -108,19 +110,21 @@
             DataElement d = dataElementService.getDataElement( Integer.parseInt( id ) );
             dataElements.add( d );
         }
+
+        DataSet dataSet = section.getDataSet();
+
+        if ( dataSet != null ) // Check if version must be updated
+        {
+            if ( !( equalsNullSafe( sectionName, section.getName() ) && dataElements.equals( section.getDataElements() ) ) )
+            {
+                dataSetService.updateDataSet( dataSet.increaseVersion() );
+            }
+        }
         
         section.setDataElements( dataElements );
         section.setName( sectionName );
 
         sectionService.updateSection( section );
-
-        DataSet dataSet = section.getDataSet();
-
-        if ( dataSet.getMobile() != null && dataSet.getMobile() ) // TODO Hack
-        {
-            dataSet.setVersion( dataSet.getVersion() + 1 );
-            dataSetService.updateDataSet( dataSet );
-        }
         
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/index.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/index.vm	2011-05-28 21:04:47 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/index.vm	2011-08-26 20:38:26 +0000
@@ -9,7 +9,7 @@
 
 <ul id="introList">
     #introListImgItem( "dataSet.action" "dataset" "dataset" )
-    #introListImgItem( "showMobileDataSet.action" "mobile_dataset" "dataset" )
     #introListImgItem( "section.action" "dataset_section" "dataset" )
     #introListImgItem( "displayEditorForm.action" "dataset_assignment_editor" "dataset" )
+    #introListImgItem( "showMobileDataSet.action" "mobile_dataset" "dataset" )
 </ul>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/menu.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/menu.vm	2011-03-21 14:30:16 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/webapp/dhis-web-maintenance-dataset/menu.vm	2011-08-26 20:38:26 +0000
@@ -2,7 +2,7 @@
 <h2>$i18n.getString( "dataset" )&nbsp;</h2>
 <ul>
 	<li><a href="dataSet.action">$i18n.getString( "dataset" )&nbsp;</a></li>
-	<li><a href="showMobileDataSet.action">$i18n.getString( "mobile_dataset" )&nbsp;</a></li>
 	<li><a href="section.action">$i18n.getString( "dataset_section" )&nbsp;</a></li>
 	<li><a href="displayEditorForm.action">$i18n.getString( "dataset_assignment_editor" )&nbsp;</a></li>
+	<li><a href="showMobileDataSet.action">$i18n.getString( "mobile_dataset" )&nbsp;</a></li>
 </ul>
\ No newline at end of file