← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7249: Fixed bug: When update many attribute-values of a dataelement, the system create new attrubute-va...

 

------------------------------------------------------------
revno: 7249
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-06-08 17:35:59 +0700
message:
  Fixed bug: When update many attribute-values of a dataelement, the system create new attrubute-values, not update.
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/AttributeUtils.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-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/AttributeUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/AttributeUtils.java	2012-04-23 14:24:47 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/AttributeUtils.java	2012-06-08 10:35:59 +0000
@@ -45,10 +45,10 @@
     /**
      * Given a list of JSON formatted values (with keys: 'id' and 'value'), this
      * method will add/update {@link AttributeValue} into the given {@code Set}.
-     *
+     * 
      * @param jsonAttributeValues List of JSON formatted values, needs two keys:
-     *                            id => ID of attribute this value belongs to value => Actual value
-     * @param attributeValues     Set that will be updated
+     *        id => ID of attribute this value belongs to value => Actual value
+     * @param attributeValues Set that will be updated
      * @param attributeService
      */
     public static void updateAttributeValuesFromJson( Set<AttributeValue> attributeValues,
@@ -64,7 +64,7 @@
 
             Attribute attribute = attributeService.getAttribute( attributeValue.getId() );
 
-            if ( attribute == null || attributeValue.getValue() == null || attributeValue.getValue().length() == 0 )
+            if ( attribute == null )
             {
                 continue;
             }
@@ -73,15 +73,23 @@
 
             for ( AttributeValue attributeValueItem : attributeValues )
             {
-                if ( attributeValueItem.getAttribute().equals( attribute ) )
+                if ( attributeValueItem.getAttribute().getId() == attribute.getId() )
                 {
-                    attributeValueItem.setValue( attributeValue.getValue() );
-                    attributeService.updateAttributeValue( attributeValueItem );
-                    attributeValue = null;
+                    if ( attributeValue.getValue() == null || attributeValue.getValue().length() == 0 )
+                    {
+                    
+                        attributeService.deleteAttributeValue( attributeValueItem );
+                    }
+                    else
+                    {
+                        attributeValueItem.setValue( attributeValue.getValue() );
+                        attributeService.updateAttributeValue( attributeValueItem );
+                        attributeValue = null;
+                    }
                 }
             }
 
-            if ( attributeValue != null )
+            if ( attributeValue != null && attributeValue.getValue() != null && !attributeValue.getValue().isEmpty())
             {
                 attributeService.addAttributeValue( attributeValue );
                 attributeValues.add( attributeValue );