← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14888: Logging for data value save

 

------------------------------------------------------------
revno: 14888
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-04-17 16:19:13 +0200
message:
  Logging for data value save
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.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-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueService.java	2014-04-17 14:19:13 +0000
@@ -61,11 +61,14 @@
     /**
      * Adds a DataValue. If both the value and the comment properties of the
      * specified DataValue object are null, then the object should not be
-     * persisted.
+     * persisted. The value will be validated and not be saved if not passing
+     * validation.
      * 
      * @param dataValue the DataValue to add.
+     * @return false whether the data value is null or invalid, true if value is
+     *         valid and attempted to be saved.
      */
-    void addDataValue( DataValue dataValue );
+    boolean addDataValue( DataValue dataValue );
 
     /**
      * Updates a DataValue. If both the value and the comment properties of the

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueService.java	2014-04-17 14:19:13 +0000
@@ -35,6 +35,8 @@
 import java.util.Date;
 import java.util.Map;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
@@ -51,6 +53,8 @@
 public class DefaultDataValueService
     implements DataValueService
 {
+    private static final Log log = LogFactory.getLog( DefaultDataValueService.class );
+    
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -73,22 +77,35 @@
     // Basic DataValue
     // -------------------------------------------------------------------------
 
-    public void addDataValue( DataValue dataValue )
+    public boolean addDataValue( DataValue dataValue )
     {
-        if ( !dataValue.isNullValue() && dataValueIsValid( dataValue.getValue(), dataValue.getDataElement() ) == null )
-        {
-            if ( dataValue.getCategoryOptionCombo() == null )
-            {
-                dataValue.setCategoryOptionCombo( categoryService.getDefaultDataElementCategoryOptionCombo() );
-            }
-            
-            if ( dataValue.getAttributeOptionCombo() == null )
-            {
-                dataValue.setAttributeOptionCombo( categoryService.getDefaultDataElementCategoryOptionCombo() );
-            }
-            
-            dataValueStore.addDataValue( dataValue );
-        }
+        if ( dataValue == null || dataValue.isNullValue() )
+        {
+            log.info( "Data value is null" );
+            return false;
+        }
+        
+        String result = dataValueIsValid( dataValue.getValue(), dataValue.getDataElement() );
+        
+        if ( result != null )
+        {
+            log.info( "Data value is not valid: " +  result );
+            return false;
+        }
+        
+        if ( dataValue.getCategoryOptionCombo() == null )
+        {
+            dataValue.setCategoryOptionCombo( categoryService.getDefaultDataElementCategoryOptionCombo() );
+        }
+        
+        if ( dataValue.getAttributeOptionCombo() == null )
+        {
+            dataValue.setAttributeOptionCombo( categoryService.getDefaultDataElementCategoryOptionCombo() );
+        }
+        
+        dataValueStore.addDataValue( dataValue );
+        
+        return true;
     }
 
     public void updateDataValue( DataValue dataValue )