← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21184: add validation to check that attribute values have a attribute that belongs to the object class type

 

------------------------------------------------------------
revno: 21184
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-11-24 15:36:54 +0700
message:
  add validation to check that attribute values have a attribute that belongs to the object class type
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.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-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-24 07:06:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java	2015-11-24 08:36:54 +0000
@@ -298,7 +298,7 @@
                     {
                         validationViolations.add( new ValidationViolation( attributeValue.getAttribute().getUid(),
                             "Value '" + av.getValue() + "' already exists for attribute '"
-                                + attributeValue.getAttribute().getName() + "' (" + attributeValue.getAttribute().getUid() + ")" ) );
+                                + attributeValue.getAttribute().getDisplayName() + "' (" + attributeValue.getAttribute().getUid() + ")" ) );
                     }
                 }
 
@@ -310,7 +310,17 @@
         for ( String uid : attributeValueMap.keySet() )
         {
             AttributeValue attributeValue = attributeValueMap.get( uid );
-            mandatoryAttributes.remove( attributeValue.getAttribute() );
+
+            if ( !attributeValue.getAttribute().getSupportedClasses().contains( object.getClass() ) )
+            {
+                validationViolations.add( new ValidationViolation( attributeValue.getAttribute().getUid(),
+                    "Attribute '" + attributeValue.getAttribute().getDisplayName() + "' (" + attributeValue.getAttribute().getUid() + ") is not supported for type "
+                        + object.getClass().getSimpleName() ) );
+            }
+            else
+            {
+                mandatoryAttributes.remove( attributeValue.getAttribute() );
+            }
         }
 
         mandatoryAttributes.stream()