← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19036: Schema/Property cleanup, only give min/max values where it make sense (must be writable, int, str...

 

------------------------------------------------------------
revno: 19036
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-04-28 15:57:55 +0700
message:
  Schema/Property cleanup, only give min/max values where it make sense (must be writable, int, string, collection, etc)
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/schema/AbstractPropertyIntrospectorService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.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	2015-04-24 06:48:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Property.java	2015-04-28 08:57:55 +0000
@@ -180,17 +180,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 = Integer.MIN_VALUE;
+    private Integer length;
+
+    /**
+     * Minimum size/length of this property.
+     */
+    private Integer max;
+
+    /**
+     * Minimum size/length of this property.
+     */
+    private Integer min;
 
     /**
      * Cascading used when doing CRUD operations.
@@ -530,36 +530,36 @@
 
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public int getLength()
+    public Integer getLength()
     {
         return length;
     }
 
-    public void setLength( int length )
+    public void setLength( Integer length )
     {
         this.length = length;
     }
 
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public int getMax()
+    public Integer getMax()
     {
         return max;
     }
 
-    public void setMax( int max )
+    public void setMax( Integer max )
     {
         this.max = max;
     }
 
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
-    public int getMin()
+    public Integer getMin()
     {
         return min;
     }
 
-    public void setMin( int min )
+    public void setMin( Integer min )
     {
         this.min = min;
     }

=== 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	2015-03-23 07:10:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaUtils.java	2015-04-28 08:57:55 +0000
@@ -53,7 +53,7 @@
             property.setItemPropertyType( getPropertyType( property.getItemKlass() ) );
         }
 
-        if ( property.getGetterMethod() != null )
+        if ( property.isWritable() )
         {
             if ( property.getGetterMethod().isAnnotationPresent( org.hisp.dhis.schema.annotation.Property.class ) )
             {
@@ -64,16 +64,44 @@
             {
                 PropertyRange propertyRange = property.getGetterMethod().getAnnotation( PropertyRange.class );
 
-                if ( propertyRange.max() <= property.getMax() )
+                if ( property.getMax() == null || propertyRange.max() <= property.getMax() )
                 {
                     property.setMax( propertyRange.max() );
                 }
 
-                if ( propertyRange.min() >= property.getMin() && propertyRange.min() <= property.getMax() )
+                if ( property.getMin() == null || (propertyRange.min() >= property.getMin() && propertyRange.min() <= property.getMax()) )
                 {
                     property.setMin( propertyRange.min() > property.getMax() ? property.getMax() : propertyRange.min() );
                 }
             }
+
+            if ( property.getMin() == null )
+            {
+                property.setMin( 0 );
+            }
+
+            if ( property.getMax() == null )
+            {
+                property.setMax( Integer.MAX_VALUE );
+            }
+
+            switch ( property.getPropertyType() )
+            {
+                // min-max for these property types make no sense, so just clear it out
+                case REFERENCE:
+                case BOOLEAN:
+                case DATE:
+                case CONSTANT:
+                {
+                    property.setMin( null );
+                    property.setMax( null );
+                }
+            }
+        }
+        else
+        {
+            property.setMin( null );
+            property.setMax( null );
         }
     }
 

=== 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-03-31 15:04:51 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/AbstractPropertyIntrospectorService.java	2015-04-28 08:57:55 +0000
@@ -238,6 +238,9 @@
                 property.setOwner( !collection.isInverse() );
                 property.setManyToMany( collectionPersister.isManyToMany() );
 
+                property.setMin( 0 );
+                property.setMax( Integer.MAX_VALUE );
+
                 if ( property.isOwner() )
                 {
                     property.setOwningRole( collectionType.getRole() );
@@ -274,10 +277,14 @@
 
                 property.setUnique( column.isUnique() );
                 property.setRequired( !column.isNullable() );
+                property.setMin( 0 );
+                property.setMax( column.getLength() );
                 property.setLength( column.getLength() );
 
                 if ( TextType.class.isInstance( type ) )
                 {
+                    property.setMin( 0 );
+                    property.setMax( Integer.MAX_VALUE );
                     property.setLength( Integer.MAX_VALUE );
                 }
             }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java	2015-04-24 14:15:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/TrackedEntityInstanceController.java	2015-04-28 08:57:55 +0000
@@ -98,9 +98,6 @@
     private FieldFilterService fieldFilterService;
 
     @Autowired
-    private ObjectFilterService objectFilterService;
-
-    @Autowired
     private ContextService contextService;
 
     // -------------------------------------------------------------------------