=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeService.java 2015-11-23 09:06:48 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeService.java 2015-11-24 02:56:45 +0000 @@ -182,7 +182,7 @@ */ int getAttributeValueCount(); - void updateAttributeValues( T object, List jsonAttributeValues ) throws NonUniqueAttributeValueException; + void updateAttributeValues( T object, List jsonAttributeValues ) throws Exception; - void updateAttributeValues( T object, Set attributeValues ) throws NonUniqueAttributeValueException; + void updateAttributeValues( T object, Set attributeValues ) throws Exception; } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/exception/MissingMandatoryAttributeValueException.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/exception/MissingMandatoryAttributeValueException.java 2015-11-23 07:21:18 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/exception/MissingMandatoryAttributeValueException.java 2015-11-24 02:56:45 +0000 @@ -28,15 +28,20 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import org.hisp.dhis.attribute.AttributeValue; +import org.hisp.dhis.attribute.Attribute; + +import java.util.List; +import java.util.stream.Collectors; /** * @author Morten Olav Hansen */ public class MissingMandatoryAttributeValueException extends Exception { - public MissingMandatoryAttributeValueException( AttributeValue attributeValue ) + public MissingMandatoryAttributeValueException( List mandatoryAttributes ) { - super( "Missing mandatory attribute " + attributeValue.getAttribute().getName() + "(" + attributeValue.getAttribute().getUid() + ")" ); + super( String.valueOf( mandatoryAttributes.stream() + .map( att -> "Attribute " + att.getDisplayName() + " (" + att.getUid() + ")" ) + .collect( Collectors.toList() ) ) ); } } === modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java 2015-11-23 09:11:11 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java 2015-11-24 02:56:45 +0000 @@ -29,6 +29,7 @@ */ import net.sf.json.JSONObject; +import org.hisp.dhis.attribute.exception.MissingMandatoryAttributeValueException; import org.hisp.dhis.attribute.exception.NonUniqueAttributeValueException; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.IdentifiableObjectManager; @@ -272,18 +273,19 @@ } @Override - public void updateAttributeValues( T object, List jsonAttributeValues ) throws NonUniqueAttributeValueException + public void updateAttributeValues( T object, List jsonAttributeValues ) throws Exception { updateAttributeValues( object, getJsonAttributeValues( jsonAttributeValues ) ); } @Override - public void updateAttributeValues( T object, Set attributeValues ) throws NonUniqueAttributeValueException + public void updateAttributeValues( T object, Set attributeValues ) throws Exception { Map attributeValueMap = attributeValues.stream() .collect( Collectors.toMap( av -> av.getAttribute().getUid(), av -> av ) ); Iterator iterator = object.getAttributeValues().iterator(); + List mandatoryAttributes = getMandatoryAttributes( object.getClass() ); while ( iterator.hasNext() ) { @@ -310,6 +312,7 @@ } attributeValueMap.remove( attributeValue.getAttribute().getUid() ); + mandatoryAttributes.remove( attributeValue.getAttribute() ); } else { @@ -321,6 +324,12 @@ { AttributeValue attributeValue = attributeValueMap.get( uid ); addAttributeValue( object, attributeValue ); + mandatoryAttributes.remove( attributeValue.getAttribute() ); + } + + if ( !mandatoryAttributes.isEmpty() ) + { + throw new MissingMandatoryAttributeValueException( mandatoryAttributes ); } }