← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4765: (mobile) made validation handling a bit more predictive

 

------------------------------------------------------------
revno: 4765
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-09-29 12:43:51 +0200
message:
  (mobile) made validation handling a bit more predictive
modified:
  dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.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-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java	2011-09-29 10:23:26 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java	2011-09-29 10:43:51 +0000
@@ -232,6 +232,8 @@
 
         String storedBy = currentUserService.getCurrentUsername();
 
+        boolean needsValidation = false;
+
         dataSet = dataSetService.getDataSet( dataSetId );
 
         if ( storedBy == null )
@@ -261,10 +263,12 @@
 
                 value = value.trim();
 
-                if ( dataValue == null )
+                if( dataValue == null )
                 {
-                    if ( value != null && value.length() != 0 )
+                    if( value != null && value.length() > 0 )
                     {
+                        needsValidation = true;
+
                         dataValue = new DataValue( dataElement, period, organisationUnit, value, storedBy, new Date(),
                             null, optionCombo );
                         dataValueService.addDataValue( dataValue );
@@ -272,11 +276,16 @@
                 }
                 else
                 {
-                    dataValue.setValue( value );
-                    dataValue.setTimestamp( new Date() );
-                    dataValue.setStoredBy( storedBy );
-
-                    dataValueService.updateDataValue( dataValue );
+                    if( !dataValue.getValue().equals( value ) )
+                    {
+                        needsValidation = true;
+
+                        dataValue.setValue( value );
+                        dataValue.setTimestamp( new Date() );
+                        dataValue.setStoredBy( storedBy );
+
+                        dataValueService.updateDataValue( dataValue );
+                    }
                 }
             }
         }
@@ -303,9 +312,8 @@
 
         validationErrors = sectionFormUtils.getValidationErrorMap( organisationUnit, dataSet, period );
 
-        if ( (validated == null || !validated) && validationErrors.size() > 0 )
+        if ( needsValidation )
         {
-            validated = true;
             return ERROR;
         }