← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16184: TEI create and update. Trimming attribute values to null before saving/updating. This caused seve...

 

------------------------------------------------------------
revno: 16184
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-07-18 16:27:18 +0200
message:
  TEI create and update. Trimming attribute values to null before saving/updating. This caused several issues: The client is sending empty strings to the server for all empty fields. This causes validation errors, as the server reports import conflicts for numeric attributes, option set attributes, date attributes since the empty string does not validate against any of them.
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstance.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-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java	2014-07-18 13:59:41 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/AbstractTrackedEntityInstanceService.java	2014-07-18 14:27:18 +0000
@@ -177,6 +177,8 @@
     {
         ImportSummary importSummary = new ImportSummary();
         importSummary.setDataValueCount( null );
+        
+        trackedEntityInstance.trimValuesToNull();
 
         List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
         importConflicts.addAll( checkTrackedEntity( trackedEntityInstance ) );
@@ -215,6 +217,8 @@
         ImportSummary importSummary = new ImportSummary();
         importSummary.setDataValueCount( null );
 
+        trackedEntityInstance.trimValuesToNull();
+
         List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
         importConflicts.addAll( checkRelationships( trackedEntityInstance ) );
         importConflicts.addAll( checkAttributes( trackedEntityInstance ) );
@@ -340,6 +344,11 @@
     {
         List<ImportConflict> importConflicts = new ArrayList<ImportConflict>();
 
+        if ( attribute == null || value == null )
+        {
+            return importConflicts;
+        }
+            
         TrackedEntityInstanceQueryParams params = new TrackedEntityInstanceQueryParams();
 
         QueryItem queryItem = new QueryItem( attribute, QueryOperator.EQ, value, false );
@@ -462,6 +471,12 @@
     private List<ImportConflict> validateAttributeType( Attribute attribute )
     {
         List<ImportConflict> importConflicts = Lists.newArrayList();
+        
+        if ( attribute == null || attribute.getValue() == null )
+        {
+            return importConflicts;
+        }
+
         TrackedEntityAttribute teAttribute = trackedEntityAttributeService.getTrackedEntityAttribute( attribute.getAttribute() );
 
         if ( teAttribute == null )
@@ -469,7 +484,7 @@
             importConflicts.add( new ImportConflict( "Attribute.attribute", "Does not point to a valid attribute." ) );
             return importConflicts;
         }
-
+        
         if ( attribute.getValue().length() > 255 )
         {
             importConflicts.add( new ImportConflict( "Attribute.value", "Value length is greater than 256 chars for attribute: " + attribute ) );

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstance.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstance.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/trackedentity/TrackedEntityInstance.java	2014-07-18 14:27:18 +0000
@@ -28,13 +28,15 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.hisp.dhis.common.DxfNamespaces;
+
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.DxfNamespaces;
-
-import java.util.ArrayList;
-import java.util.List;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -56,6 +58,20 @@
     {
     }
 
+    /**
+     * Trims the value property of attribute values to null.
+     */
+    public void trimValuesToNull()
+    {
+        if ( attributes != null )
+        {
+            for ( Attribute attribute : attributes )
+            {
+                attribute.setValue( StringUtils.trimToNull( attribute.getValue() ) );
+            }
+        }
+    }
+    
     @JsonProperty( required = true )
     @JacksonXmlProperty( isAttribute = true )
     public String getTrackedEntity()