dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41991
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21449: moved SchemaUtils to support-system
------------------------------------------------------------
revno: 21449
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-12-15 08:17:11 +0100
message:
moved SchemaUtils to support-system
removed:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaUtils.java
added:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/SchemaUtils.java
modified:
dhis-2/dhis-api/pom.xml
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.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/pom.xml'
--- dhis-2/dhis-api/pom.xml 2015-10-20 22:50:17 +0000
+++ dhis-2/dhis-api/pom.xml 2015-12-15 07:17:11 +0000
@@ -16,8 +16,8 @@
<dependencies>
<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
@@ -87,9 +87,9 @@
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</dependency>
-
+
<!-- Test -->
-
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
=== removed 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-12-14 16:55:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/SchemaUtils.java 1970-01-01 00:00:00 +0000
@@ -1,159 +0,0 @@
-package org.hisp.dhis.schema;
-
-/*
- * Copyright (c) 2004-2015, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.google.common.collect.Sets;
-import com.google.common.primitives.Primitives;
-import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.schema.annotation.PropertyRange;
-import org.springframework.core.annotation.AnnotationUtils;
-import org.springframework.util.Assert;
-
-import java.util.Collection;
-import java.util.Date;
-import java.util.Set;
-
-import static org.hisp.dhis.schema.PropertyType.*;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public final class SchemaUtils
-{
- private static final Set<PropertyType> PROPS_IGNORE_MINMAX = Sets.newHashSet( REFERENCE, BOOLEAN, DATE, CONSTANT );
-
- public static void updatePropertyTypes( Property property )
- {
- Assert.notNull( property );
- Assert.notNull( property.getKlass() );
-
- property.setPropertyType( getPropertyType( property.getKlass() ) );
-
- if ( property.isCollection() )
- {
- property.setItemPropertyType( getPropertyType( property.getItemKlass() ) );
- }
-
- if ( property.isWritable() )
- {
- if ( AnnotationUtils.findAnnotation( property.getGetterMethod(), org.hisp.dhis.schema.annotation.Property.class ) != null )
- {
- property.setPropertyType( AnnotationUtils.findAnnotation( property.getGetterMethod(), org.hisp.dhis.schema.annotation.Property.class ).value() );
- }
-
- if ( AnnotationUtils.findAnnotation( property.getGetterMethod(), PropertyRange.class ) != null )
- {
- PropertyRange propertyRange = AnnotationUtils.findAnnotation( property.getGetterMethod(), PropertyRange.class );
-
- if ( property.getMax() == null || propertyRange.max() <= property.getMax() )
- {
- property.setMax( propertyRange.max() );
- }
-
- 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 );
- }
-
- if ( PROPS_IGNORE_MINMAX.contains( property.getPropertyType() ) )
- {
- property.setMin( null );
- property.setMax( null );
- }
- }
- else
- {
- property.setMin( null );
- property.setMax( null );
- }
- }
-
- private static PropertyType getPropertyType( Class<?> klass )
- {
- if ( isAssignableFrom( klass, String.class )
- || isAssignableFrom( klass, Character.class )
- || isAssignableFrom( klass, Byte.class ) )
- {
- return PropertyType.TEXT;
- }
- else if ( isAssignableFrom( klass, Integer.class ) )
- {
- return PropertyType.INTEGER;
- }
- else if ( isAssignableFrom( klass, Boolean.class ) )
- {
- return PropertyType.BOOLEAN;
- }
- else if ( isAssignableFrom( klass, Float.class )
- || isAssignableFrom( klass, Double.class ) )
- {
- return PropertyType.NUMBER;
- }
- else if ( isAssignableFrom( klass, Date.class )
- || isAssignableFrom( klass, java.sql.Date.class ) )
- {
- return PropertyType.DATE;
- }
- else if ( isAssignableFrom( klass, Enum.class ) )
- {
- return PropertyType.CONSTANT;
- }
- else if ( isAssignableFrom( klass, IdentifiableObject.class ) )
- {
- return PropertyType.REFERENCE;
- }
- else if ( isAssignableFrom( klass, Collection.class ) )
- {
- return PropertyType.COLLECTION;
- }
-
- // if klass is primitive (but unknown), fall back to text, if its not then assume reference
- return Primitives.isWrapperType( klass ) ? PropertyType.TEXT : PropertyType.COMPLEX;
- }
-
- private static boolean isAssignableFrom( Class<?> propertyKlass, Class<?> klass )
- {
- return klass.isAssignableFrom( propertyKlass );
- }
-
- private SchemaUtils()
- {
- }
-}
=== 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 2015-12-14 16:55:51 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java 2015-12-15 07:17:11 +0000
@@ -42,6 +42,7 @@
import org.hisp.dhis.common.NameableObject;
import org.hisp.dhis.common.annotation.Description;
import org.hisp.dhis.system.util.ReflectionUtils;
+import org.hisp.dhis.system.util.SchemaUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.StringUtils;
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java 2015-10-19 08:56:45 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java 2015-12-15 07:17:11 +0000
@@ -523,4 +523,24 @@
return klass;
}
+
+ public static boolean isAnnotationPresent( Class<?> klass, Class<? extends Annotation> annotationType )
+ {
+ return org.springframework.core.annotation.AnnotationUtils.findAnnotation( klass, annotationType ) != null;
+ }
+
+ public static boolean isAnnotationPresent( Method method, Class<? extends Annotation> annotationType )
+ {
+ return org.springframework.core.annotation.AnnotationUtils.findAnnotation( method, annotationType ) != null;
+ }
+
+ public static <A extends Annotation> A getAnnotation( Class<?> klass, Class<A> annotationType )
+ {
+ return org.springframework.core.annotation.AnnotationUtils.findAnnotation( klass, annotationType );
+ }
+
+ public static <A extends Annotation> A getAnnotation( Method method, Class<A> annotationType )
+ {
+ return org.springframework.core.annotation.AnnotationUtils.findAnnotation( method, annotationType );
+ }
}
=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/SchemaUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/SchemaUtils.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/SchemaUtils.java 2015-12-15 07:17:11 +0000
@@ -0,0 +1,161 @@
+package org.hisp.dhis.system.util;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.google.common.collect.Sets;
+import com.google.common.primitives.Primitives;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.schema.Property;
+import org.hisp.dhis.schema.PropertyType;
+import org.hisp.dhis.schema.annotation.PropertyRange;
+import org.springframework.core.annotation.AnnotationUtils;
+import org.springframework.util.Assert;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.Set;
+
+import static org.hisp.dhis.schema.PropertyType.*;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public final class SchemaUtils
+{
+ private static final Set<PropertyType> PROPS_IGNORE_MINMAX = Sets.newHashSet( REFERENCE, BOOLEAN, DATE, CONSTANT );
+
+ public static void updatePropertyTypes( Property property )
+ {
+ Assert.notNull( property );
+ Assert.notNull( property.getKlass() );
+
+ property.setPropertyType( getPropertyType( property.getKlass() ) );
+
+ if ( property.isCollection() )
+ {
+ property.setItemPropertyType( getPropertyType( property.getItemKlass() ) );
+ }
+
+ if ( property.isWritable() )
+ {
+ if ( AnnotationUtils.findAnnotation( property.getGetterMethod(), org.hisp.dhis.schema.annotation.Property.class ) != null )
+ {
+ property.setPropertyType( AnnotationUtils.findAnnotation( property.getGetterMethod(), org.hisp.dhis.schema.annotation.Property.class ).value() );
+ }
+
+ if ( AnnotationUtils.findAnnotation( property.getGetterMethod(), PropertyRange.class ) != null )
+ {
+ PropertyRange propertyRange = AnnotationUtils.findAnnotation( property.getGetterMethod(), PropertyRange.class );
+
+ if ( property.getMax() == null || propertyRange.max() <= property.getMax() )
+ {
+ property.setMax( propertyRange.max() );
+ }
+
+ 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 );
+ }
+
+ if ( PROPS_IGNORE_MINMAX.contains( property.getPropertyType() ) )
+ {
+ property.setMin( null );
+ property.setMax( null );
+ }
+ }
+ else
+ {
+ property.setMin( null );
+ property.setMax( null );
+ }
+ }
+
+ private static PropertyType getPropertyType( Class<?> klass )
+ {
+ if ( isAssignableFrom( klass, String.class )
+ || isAssignableFrom( klass, Character.class )
+ || isAssignableFrom( klass, Byte.class ) )
+ {
+ return PropertyType.TEXT;
+ }
+ else if ( isAssignableFrom( klass, Integer.class ) )
+ {
+ return PropertyType.INTEGER;
+ }
+ else if ( isAssignableFrom( klass, Boolean.class ) )
+ {
+ return PropertyType.BOOLEAN;
+ }
+ else if ( isAssignableFrom( klass, Float.class )
+ || isAssignableFrom( klass, Double.class ) )
+ {
+ return PropertyType.NUMBER;
+ }
+ else if ( isAssignableFrom( klass, Date.class )
+ || isAssignableFrom( klass, java.sql.Date.class ) )
+ {
+ return PropertyType.DATE;
+ }
+ else if ( isAssignableFrom( klass, Enum.class ) )
+ {
+ return PropertyType.CONSTANT;
+ }
+ else if ( isAssignableFrom( klass, IdentifiableObject.class ) )
+ {
+ return PropertyType.REFERENCE;
+ }
+ else if ( isAssignableFrom( klass, Collection.class ) )
+ {
+ return PropertyType.COLLECTION;
+ }
+
+ // if klass is primitive (but unknown), fall back to text, if its not then assume reference
+ return Primitives.isWrapperType( klass ) ? PropertyType.TEXT : PropertyType.COMPLEX;
+ }
+
+ private static boolean isAssignableFrom( Class<?> propertyKlass, Class<?> klass )
+ {
+ return klass.isAssignableFrom( propertyKlass );
+ }
+
+ private SchemaUtils()
+ {
+ }
+}