← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17777: minor fixes to ValidationViolation

 

------------------------------------------------------------
revno: 17777
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-12-22 16:37:24 +0100
message:
  minor fixes to ValidationViolation
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/ValidationViolation.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-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java	2014-12-22 14:39:58 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java	2014-12-22 15:37:24 +0000
@@ -69,7 +69,7 @@
             {
                 if ( property.isRequired() )
                 {
-                    validationViolations.add( new ValidationViolation( "Property '" + property.getName() + "' can not be null." ) );
+                    validationViolations.add( new ValidationViolation( property.getName(), "Required property missing." ) );
                 }
 
                 continue;
@@ -98,28 +98,28 @@
 
         if ( value.length() < property.getMin() || value.length() > property.getMax() )
         {
-            validationViolations.add( new ValidationViolation( "Value violates allowed range for length ["
+            validationViolations.add( new ValidationViolation( property.getName(), "Allowed range for length ["
                 + property.getMin() + ", " + property.getMax() + "], length is " + value.length() ) );
         }
 
         if ( PropertyType.EMAIL == property.getPropertyType() && !GenericValidator.isEmail( value ) )
         {
-            validationViolations.add( new ValidationViolation( "Value is not a valid email." ) );
+            validationViolations.add( new ValidationViolation( property.getName(), "Not a valid email." ) );
         }
 
         if ( PropertyType.URL == property.getPropertyType() && !GenericValidator.isUrl( value ) )
         {
-            validationViolations.add( new ValidationViolation( "Value is not a valid URL." ) );
+            validationViolations.add( new ValidationViolation( property.getName(), "Not a valid URL." ) );
         }
 
         if ( PropertyType.PASSWORD == property.getPropertyType() && !ValidationUtils.passwordIsValid( value ) )
         {
-            validationViolations.add( new ValidationViolation( "Value is not a valid password." ) );
+            validationViolations.add( new ValidationViolation( property.getName(), "Not a valid password." ) );
         }
 
         if ( PropertyType.COLOR == property.getPropertyType() && !ValidationUtils.isValidHexColor( value ) )
         {
-            validationViolations.add( new ValidationViolation( "Value is not a valid color (in hex format)." ) );
+            validationViolations.add( new ValidationViolation( property.getName(), "Not a valid color (in hex format)." ) );
         }
 
         /* TODO add proper validation for both Points and Polygons, ValidationUtils only supports points at this time
@@ -145,8 +145,8 @@
 
         if ( value.size() < property.getMin() || value.size() > property.getMax() )
         {
-            validationViolations.add( new ValidationViolation( "Value violates allowed range for size ["
-                + property.getMin() + ", " + property.getMax() + "], length is " + value.size() ) );
+            validationViolations.add( new ValidationViolation( property.getName(), "Invalid range for size ["
+                + property.getMin() + ", " + property.getMax() + "], size is " + value.size() ) );
         }
 
         return validationViolations;
@@ -165,7 +165,7 @@
 
         if ( !GenericValidator.isInRange( value, property.getMin(), property.getMax() ) )
         {
-            validationViolations.add( new ValidationViolation( "Value violates allowed range for value ["
+            validationViolations.add( new ValidationViolation( property.getName(), "Invalid range for value ["
                 + property.getMin() + ", " + property.getMax() + "], value is " + value ) );
         }
 
@@ -185,7 +185,7 @@
 
         if ( !GenericValidator.isInRange( value, property.getMin(), property.getMax() ) )
         {
-            validationViolations.add( new ValidationViolation( "Value violates allowed range for value ["
+            validationViolations.add( new ValidationViolation( property.getName(), "Invalid range for value ["
                 + property.getMin() + ", " + property.getMax() + "], value is " + value ) );
         }
 
@@ -205,7 +205,7 @@
 
         if ( !GenericValidator.isInRange( value, property.getMin(), property.getMax() ) )
         {
-            validationViolations.add( new ValidationViolation( "Value violates allowed range for value ["
+            validationViolations.add( new ValidationViolation( property.getName(), "Invalid range for value ["
                 + property.getMin() + ", " + property.getMax() + "], value is " + value ) );
         }
 

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/ValidationViolation.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/ValidationViolation.java	2014-12-22 13:52:51 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/ValidationViolation.java	2014-12-22 15:37:24 +0000
@@ -41,15 +41,30 @@
 } )
 public class ValidationViolation
 {
+    private String property;
+
     private String message;
 
-    public ValidationViolation( String message )
+    public ValidationViolation( String property, String message )
     {
+        this.property = property;
         this.message = message;
     }
 
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public String getProperty()
+    {
+        return property;
+    }
+
+    public void setProperty( String property )
+    {
+        this.property = property;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public String getMessage()
     {
         return message;
@@ -64,7 +79,8 @@
     public String toString()
     {
         final StringBuilder sb = new StringBuilder( "ValidationViolation{" );
-        sb.append( "message='" ).append( message ).append( '\'' );
+        sb.append( "property='" ).append( property ).append( '\'' );
+        sb.append( ", message='" ).append( message ).append( '\'' );
         sb.append( '}' );
         return sb.toString();
     }