← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22047: include value when reporting invalid values in TEA validation

 

------------------------------------------------------------
revno: 22047
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2016-02-26 08:34:51 +0700
message:
  include value when reporting invalid values in TEA validation
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.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/trackedentity/DefaultTrackedEntityAttributeService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentity/DefaultTrackedEntityAttributeService.java	2016-02-26 01:34:51 +0000
@@ -273,6 +273,8 @@
         Assert.notNull( trackedEntityAttribute, "trackedEntityAttribute is required." );
         ValueType valueType = trackedEntityAttribute.getValueType();
 
+        String errorValue = value.substring( 0, 30 );
+
         if ( value.length() > 255 )
         {
             return "Value length is greater than 256 chars for attribute " + trackedEntityAttribute.getUid();
@@ -280,30 +282,30 @@
 
         if ( ValueType.NUMBER == valueType && !MathUtils.isNumeric( value ) )
         {
-            return "Value is not numeric for attribute " + trackedEntityAttribute.getUid();
+            return "Value '" + errorValue + "'is not a valid numeric for attribute " + trackedEntityAttribute.getUid();
         }
         else if ( ValueType.BOOLEAN == valueType && !MathUtils.isBool( value ) )
         {
-            return "Value is not boolean for attribute " + trackedEntityAttribute.getUid();
+            return "Value '" + errorValue + "'is not a valid boolean for attribute " + trackedEntityAttribute.getUid();
         }
         else if ( ValueType.DATE == valueType && DateUtils.parseDate( value ) == null )
         {
-            return "Value is not date for attribute " + trackedEntityAttribute.getUid();
+            return "Value '" + errorValue + "'is not a valid date for attribute " + trackedEntityAttribute.getUid();
         }
         else if ( ValueType.TRUE_ONLY == valueType && !"true".equals( value ) )
         {
-            return "Value is not true (true-only value type) for attribute " + trackedEntityAttribute.getUid();
+            return "Value '" + errorValue + "'is not true (true-only value type) for attribute " + trackedEntityAttribute.getUid();
         }
         else if ( ValueType.USERNAME == valueType )
         {
             if ( userService.getUserCredentialsByUsername( value ) == null )
             {
-                return "Value is not pointing to a valid username for attribute " + trackedEntityAttribute.getUid();
+                return "Value '" + errorValue + "' is not a valid username for attribute " + trackedEntityAttribute.getUid();
             }
         }
         else if ( trackedEntityAttribute.hasOptionSet() && !trackedEntityAttribute.isValidOptionValue( value ) )
         {
-            return "Value is not pointing to a valid option for attribute " + trackedEntityAttribute.getUid();
+            return "Value '" + errorValue + "'is not a valid option for attribute " + trackedEntityAttribute.getUid();
         }
 
         return null;
@@ -317,38 +319,38 @@
     public ProgramTrackedEntityAttribute getOrAddProgramTrackedEntityAttribute( String programUid, String attributeUid )
     {
         Program program = programService.getProgram( programUid );
-        
+
         TrackedEntityAttribute attribute = getTrackedEntityAttribute( attributeUid );
-        
+
         if ( program == null || attribute == null )
         {
             return null;
         }
-        
+
         ProgramTrackedEntityAttribute programAttribute = programAttributeStore.get( program, attribute );
-        
+
         if ( programAttribute == null )
         {
             programAttribute = new ProgramTrackedEntityAttribute( program, attribute );
-            
+
             programAttributeStore.save( programAttribute );
         }
-        
+
         return programAttribute;
-    }        
-    
+    }
+
     @Override
     public ProgramTrackedEntityAttribute getProgramTrackedEntityAttribute( String programUid, String attributeUid )
     {
         Program program = programService.getProgram( programUid );
-        
+
         TrackedEntityAttribute attribute = getTrackedEntityAttribute( attributeUid );
-        
+
         if ( program == null || attribute == null )
         {
             return null;
         }
-        
+
         return new ProgramTrackedEntityAttribute( program, attribute );
     }
 }