← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18017: various fixes to validator, adds length to Property (for column-length)

 

------------------------------------------------------------
revno: 18017
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-01-16 16:30:50 +0700
message:
  various fixes to validator, adds length to Property (for column-length)
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaUtils.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/AbstractPropertyIntrospectorService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.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-api/src/main/java/org/hisp/dhis/schema/Property.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java	2014-12-22 13:52:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java	2015-01-16 09:30:50 +0000
@@ -178,12 +178,17 @@
     /**
      * Maximum length/size/value of this property.
      */
+    private int length = Integer.MAX_VALUE;
+
+    /**
+     * Minimum length/size/value of this property.
+     */
     private int max = Integer.MAX_VALUE;
 
     /**
      * Minimum length/size/value of this property.
      */
-    private int min;
+    private int min = Integer.MIN_VALUE;
 
     /**
      * Cascading used when doing CRUD operations.
@@ -482,6 +487,18 @@
 
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public int getLength()
+    {
+        return length;
+    }
+
+    public void setLength( int length )
+    {
+        this.length = length;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public int getMax()
     {
         return max;

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaUtils.java	2014-12-19 13:43:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaUtils.java	2015-01-16 09:30:50 +0000
@@ -64,7 +64,7 @@
             {
                 PropertyRange propertyRange = property.getGetterMethod().getAnnotation( PropertyRange.class );
 
-                if ( propertyRange.max() >= 0 && propertyRange.max() <= property.getMax() )
+                if ( propertyRange.max() <= property.getMax() )
                 {
                     property.setMax( propertyRange.max() );
                 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java	2015-01-16 05:41:13 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java	2015-01-16 09:30:50 +0000
@@ -53,7 +53,7 @@
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 @Component
-@Scope(value = "prototype", proxyMode = ScopedProxyMode.INTERFACES)
+@Scope( value = "prototype", proxyMode = ScopedProxyMode.INTERFACES )
 public class StAXNodeSerializer extends AbstractNodeSerializer
 {
     public static final String CONTENT_TYPE = "application/xml";
@@ -109,17 +109,26 @@
     @Override
     protected void startWriteSimpleNode( SimpleNode simpleNode ) throws Exception
     {
-        String value = String.format( "%s", simpleNode.getValue() );
+        String value;
 
         if ( simpleNode.getValue() != null && Date.class.isAssignableFrom( simpleNode.getValue().getClass() ) )
         {
             SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" );
-            dateFormat.setTimeZone( TimeZone.getTimeZone("UTC") );
+            dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
             value = dateFormat.format( (Date) simpleNode.getValue() );
         }
+        else
+        {
+            value = (String) simpleNode.getValue();
+        }
 
         if ( simpleNode.isAttribute() )
         {
+            if ( value == null )
+            {
+                return;
+            }
+
             if ( !StringUtils.isEmpty( simpleNode.getNamespace() ) )
             {
                 writer.writeAttribute( simpleNode.getNamespace(), simpleNode.getName(), value );
@@ -132,7 +141,11 @@
         else
         {
             writeStartElement( simpleNode );
-            writer.writeCharacters( value );
+
+            if ( value != null )
+            {
+                writer.writeCharacters( value );
+            }
         }
     }
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/AbstractPropertyIntrospectorService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/AbstractPropertyIntrospectorService.java	2015-01-15 09:50:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/AbstractPropertyIntrospectorService.java	2015-01-16 09:30:50 +0000
@@ -188,9 +188,7 @@
 
                 property.setUnique( column.isUnique() );
                 property.setRequired( !column.isNullable() );
-
-                property.setMax( column.getLength() );
-                property.setMin( 0 );
+                property.setLength( column.getLength() );
 
                 properties.put( property.getName(), property );
             }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java	2014-12-30 14:09:22 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java	2015-01-16 09:30:50 +0000
@@ -117,6 +117,7 @@
                 property.setWritable( true );
                 property.setUnique( hibernateProperty.isUnique() );
                 property.setRequired( hibernateProperty.isRequired() );
+                property.setLength( hibernateProperty.getLength() );
                 property.setMax( hibernateProperty.getMax() );
                 property.setMin( hibernateProperty.getMin() );
                 property.setCollection( hibernateProperty.isCollection() );

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2015-01-16 05:41:13 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2015-01-16 09:30:50 +0000
@@ -292,9 +292,10 @@
 
         List<ValidationViolation> validationViolations = schemaValidator.validate( object );
 
-        /*
+        /* disabled for 2.18 release
         if ( !validationViolations.isEmpty() )
         {
+            System.err.println( "violations: " + validationViolations );
             summaryType.getImportConflicts().add(
                 new ImportConflict( ImportUtils.getDisplayName( object ), "Validation Violations: " + validationViolations ) );
 
@@ -408,9 +409,10 @@
 
         List<ValidationViolation> validationViolations = schemaValidator.validate( object );
 
-        /*
+        /* disabled for 2.18 release
         if ( !validationViolations.isEmpty() )
         {
+            System.err.println( "violations: " + validationViolations );
             summaryType.getImportConflicts().add(
                 new ImportConflict( ImportUtils.getDisplayName( object ), "Validation Violations: " + validationViolations ) );
 

=== 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	2015-01-16 06:55:12 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/schema/DefaultSchemaValidator.java	2015-01-16 09:30:50 +0000
@@ -98,6 +98,15 @@
 
         String value = (String) object;
 
+        // check column max length
+        if ( value.length() > property.getLength() )
+        {
+            validationViolations.add( new ValidationViolation( property.getName(), "Maximum length for property is "
+                + property.getLength() + ", length is " + value.length(), value ) );
+
+            return validationViolations;
+        }
+
         if ( value.length() < property.getMin() || value.length() > property.getMax() )
         {
             validationViolations.add( new ValidationViolation( property.getName(), "Allowed range for length ["