dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41992
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21450: minor fixes
------------------------------------------------------------
revno: 21450
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-12-15 08:38:12 +0100
message:
minor fixes
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.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/DefaultMetaDataDependencyService.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/AnnotationUtils.java
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/SchemaUtils.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/schema/DefaultSchemaService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java 2015-12-14 16:55:51 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java 2015-12-15 07:38:12 +0000
@@ -33,11 +33,11 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.hibernate.SessionFactory;
+import org.hisp.dhis.system.util.AnnotationUtils;
import org.hisp.dhis.system.util.ReflectionUtils;
import org.hisp.dhis.translation.TranslationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.OrderComparator;
-import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
@@ -153,9 +153,9 @@
private String getName( Class<?> klass )
{
- if ( AnnotationUtils.findAnnotation( klass, JacksonXmlRootElement.class ) != null )
+ if ( AnnotationUtils.isAnnotationPresent( klass, JacksonXmlRootElement.class ) )
{
- JacksonXmlRootElement rootElement = AnnotationUtils.findAnnotation( klass, JacksonXmlRootElement.class );
+ JacksonXmlRootElement rootElement = AnnotationUtils.getAnnotation( klass, JacksonXmlRootElement.class );
if ( !StringUtils.isEmpty( rootElement.localName() ) )
{
=== 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-15 07:17:11 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/Jackson2PropertyIntrospectorService.java 2015-12-15 07:38:12 +0000
@@ -41,9 +41,9 @@
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.NameableObject;
import org.hisp.dhis.common.annotation.Description;
+import org.hisp.dhis.system.util.AnnotationUtils;
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;
import java.lang.reflect.Method;
@@ -79,11 +79,11 @@
List<String> classFieldNames = ReflectionUtils.getAllFieldNames( clazz );
// TODO this is quite nasty, should find a better way of exposing properties at class-level
- if ( AnnotationUtils.findAnnotation( clazz, JacksonXmlRootElement.class ) != null )
+ if ( AnnotationUtils.isAnnotationPresent( clazz, JacksonXmlRootElement.class ) )
{
Property property = new Property();
- JacksonXmlRootElement jacksonXmlRootElement = AnnotationUtils.findAnnotation( clazz, JacksonXmlRootElement.class );
+ JacksonXmlRootElement jacksonXmlRootElement = AnnotationUtils.getAnnotation( clazz, JacksonXmlRootElement.class );
if ( !StringUtils.isEmpty( jacksonXmlRootElement.localName() ) )
{
@@ -103,7 +103,7 @@
for ( Property property : properties )
{
Method getterMethod = property.getGetterMethod();
- JsonProperty jsonProperty = AnnotationUtils.findAnnotation( getterMethod, JsonProperty.class );
+ JsonProperty jsonProperty = AnnotationUtils.getAnnotation( getterMethod, JsonProperty.class );
String fieldName = getFieldName( getterMethod );
property.setName( !StringUtils.isEmpty( jsonProperty.value() ) ? jsonProperty.value() : fieldName );
@@ -146,15 +146,15 @@
property.setSetterMethod( hibernateProperty.getSetterMethod() );
}
- if ( AnnotationUtils.findAnnotation( property.getGetterMethod(), Description.class ) != null )
+ if ( AnnotationUtils.isAnnotationPresent( property.getGetterMethod(), Description.class ) )
{
- Description description = AnnotationUtils.findAnnotation( property.getGetterMethod(), Description.class );
+ Description description = AnnotationUtils.getAnnotation( property.getGetterMethod(), Description.class );
property.setDescription( description.value() );
}
- if ( AnnotationUtils.findAnnotation( property.getGetterMethod(), JacksonXmlProperty.class ) != null )
+ if ( AnnotationUtils.isAnnotationPresent( property.getGetterMethod(), JacksonXmlProperty.class ) )
{
- JacksonXmlProperty jacksonXmlProperty = AnnotationUtils.findAnnotation( getterMethod, JacksonXmlProperty.class );
+ JacksonXmlProperty jacksonXmlProperty = AnnotationUtils.getAnnotation( getterMethod, JacksonXmlProperty.class );
if ( StringUtils.isEmpty( jacksonXmlProperty.localName() ) )
{
@@ -215,9 +215,9 @@
if ( property.isCollection() )
{
- if ( AnnotationUtils.findAnnotation( property.getGetterMethod(), JacksonXmlElementWrapper.class ) != null )
+ if ( AnnotationUtils.isAnnotationPresent( property.getGetterMethod(), JacksonXmlElementWrapper.class ) )
{
- JacksonXmlElementWrapper jacksonXmlElementWrapper = AnnotationUtils.findAnnotation( getterMethod, JacksonXmlElementWrapper.class );
+ JacksonXmlElementWrapper jacksonXmlElementWrapper = AnnotationUtils.getAnnotation( getterMethod, JacksonXmlElementWrapper.class );
property.setCollectionWrapping( jacksonXmlElementWrapper.useWrapping() );
// TODO what if element-wrapper have different namespace?
@@ -289,7 +289,7 @@
Map<String, Method> methodMap = multimap.keySet().stream()
.filter( key -> {
List<Method> methods = multimap.get( key ).stream()
- .filter( method -> AnnotationUtils.findAnnotation( method, JsonProperty.class ) != null && method.getParameterTypes().length == 0 )
+ .filter( method -> AnnotationUtils.isAnnotationPresent( method, JsonProperty.class ) && method.getParameterTypes().length == 0 )
.collect( Collectors.toList() );
if ( methods.size() > 1 )
@@ -304,7 +304,7 @@
} )
.collect( Collectors.toMap( Function.<String>identity(), key -> {
List<Method> collect = multimap.get( key ).stream()
- .filter( method -> AnnotationUtils.findAnnotation( method, JsonProperty.class ) != null && method.getParameterTypes().length == 0 )
+ .filter( method -> AnnotationUtils.isAnnotationPresent( method, JsonProperty.class ) && method.getParameterTypes().length == 0 )
.collect( Collectors.toList() );
return collect.get( 0 );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultMetaDataDependencyService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultMetaDataDependencyService.java 2015-12-14 16:57:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultMetaDataDependencyService.java 2015-12-15 07:38:12 +0000
@@ -50,11 +50,11 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.schema.Schema;
import org.hisp.dhis.schema.SchemaService;
+import org.hisp.dhis.system.util.AnnotationUtils;
import org.hisp.dhis.system.util.ReflectionUtils;
import org.hisp.dhis.user.User;
import org.hisp.dhis.validation.ValidationRule;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.annotation.AnnotationUtils;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -417,9 +417,9 @@
public boolean isExportView( Method method )
{
- if ( AnnotationUtils.findAnnotation( method, JsonView.class ) != null )
+ if ( AnnotationUtils.isAnnotationPresent( method, JsonView.class ) )
{
- Class<?>[] viewClasses = AnnotationUtils.findAnnotation( method, JsonView.class ).value();
+ Class<?>[] viewClasses = AnnotationUtils.getAnnotation( method, JsonView.class ).value();
for ( Class<?> viewClass : viewClasses )
{
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/AnnotationUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/AnnotationUtils.java 2015-09-14 18:06:48 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/AnnotationUtils.java 2015-12-15 07:38:12 +0000
@@ -41,30 +41,78 @@
/**
* Returns methods on the given target object which are annotated with the
* annotation of the given class.
- *
- * @param target the target object.
+ *
+ * @param target the target object.
* @param annotationType the annotation class type.
* @return a list of methods annotated with the given annotation.
*/
public static List<Method> getAnnotatedMethods( Object target, Class<? extends Annotation> annotationType )
{
final List<Method> methods = new ArrayList<>();
-
+
if ( target == null || annotationType == null )
{
return methods;
}
-
+
for ( Method method : target.getClass().getMethods() )
{
Annotation annotation = org.springframework.core.annotation.AnnotationUtils.findAnnotation( method, annotationType );
-
+
if ( annotation != null )
{
methods.add( method );
}
}
-
+
return methods;
}
+
+ /**
+ * Check to see if annotation is present on a given Class, take into account class hierarchy.
+ *
+ * @param klass Class
+ * @param annotationType Annotation
+ * @return true/false depending on if annotation is present
+ */
+ public static boolean isAnnotationPresent( Class<?> klass, Class<? extends Annotation> annotationType )
+ {
+ return org.springframework.core.annotation.AnnotationUtils.findAnnotation( klass, annotationType ) != null;
+ }
+
+ /**
+ * Check to see if annotation is present on a given Method, take into account class hierarchy.
+ *
+ * @param method Method
+ * @param annotationType Annotation
+ * @return true/false depending on if annotation is present
+ */
+ public static boolean isAnnotationPresent( Method method, Class<? extends Annotation> annotationType )
+ {
+ return org.springframework.core.annotation.AnnotationUtils.findAnnotation( method, annotationType ) != null;
+ }
+
+ /**
+ * Gets annotation on a given Class, takes into account class hierarchy.
+ *
+ * @param klass Class
+ * @param annotationType Annotation
+ * @return Annotation instance on Class
+ */
+ public static <A extends Annotation> A getAnnotation( Class<?> klass, Class<A> annotationType )
+ {
+ return org.springframework.core.annotation.AnnotationUtils.findAnnotation( klass, annotationType );
+ }
+
+ /**
+ * Gets annotation on a given Method, takes into account class hierarchy.
+ *
+ * @param method Method
+ * @param annotationType Annotation
+ * @return Annotation instance on Method
+ */
+ public static <A extends Annotation> A getAnnotation( Method method, Class<A> annotationType )
+ {
+ return org.springframework.core.annotation.AnnotationUtils.findAnnotation( method, annotationType );
+ }
}
=== 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-12-15 07:17:11 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java 2015-12-15 07:38:12 +0000
@@ -523,24 +523,4 @@
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 );
- }
}
=== modified 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 2015-12-15 07:17:11 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/SchemaUtils.java 2015-12-15 07:38:12 +0000
@@ -34,7 +34,6 @@
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;
@@ -64,14 +63,14 @@
if ( property.isWritable() )
{
- if ( AnnotationUtils.findAnnotation( property.getGetterMethod(), org.hisp.dhis.schema.annotation.Property.class ) != null )
+ if ( AnnotationUtils.isAnnotationPresent( property.getGetterMethod(), org.hisp.dhis.schema.annotation.Property.class ) )
{
- property.setPropertyType( AnnotationUtils.findAnnotation( property.getGetterMethod(), org.hisp.dhis.schema.annotation.Property.class ).value() );
+ property.setPropertyType( AnnotationUtils.getAnnotation( property.getGetterMethod(), org.hisp.dhis.schema.annotation.Property.class ).value() );
}
- if ( AnnotationUtils.findAnnotation( property.getGetterMethod(), PropertyRange.class ) != null )
+ if ( AnnotationUtils.isAnnotationPresent( property.getGetterMethod(), PropertyRange.class ) )
{
- PropertyRange propertyRange = AnnotationUtils.findAnnotation( property.getGetterMethod(), PropertyRange.class );
+ PropertyRange propertyRange = AnnotationUtils.getAnnotation( property.getGetterMethod(), PropertyRange.class );
if ( property.getMax() == null || propertyRange.max() <= property.getMax() )
{