=== 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 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 );