dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #17734
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7177: minor changes
------------------------------------------------------------
revno: 7177
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-06-04 15:02:01 +0200
message:
minor changes
modified:
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PredicateUtils.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-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java 2012-05-30 11:35:01 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ExchangeClasses.java 2012-06-04 13:02:01 +0000
@@ -119,9 +119,11 @@
exportClasses.put( MapLegendSet.class, "mapLegendSets" );
exportClasses.put( MapLayer.class, "mapLayers" );
+ /*
exportClasses.put( User.class, "users" );
exportClasses.put( UserGroup.class, "userGroups" );
exportClasses.put( UserAuthorityGroup.class, "userRoles" );
+ */
exportClasses.put( MessageConversation.class, "messageConversations" );
exportClasses.put( Interpretation.class, "interpretations" );
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2012-06-04 09:29:45 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2012-06-04 13:02:01 +0000
@@ -36,7 +36,6 @@
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.NameableObject;
-import org.hisp.dhis.common.annotation.Scanned;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.dataelement.DataElementOperandService;
import org.hisp.dhis.dxf2.importsummary.ImportConflict;
@@ -52,12 +51,17 @@
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.system.util.FunctionalUtils;
import org.hisp.dhis.system.util.ReflectionUtils;
+import org.hisp.dhis.system.util.functional.Function1;
import org.springframework.beans.factory.annotation.Autowired;
import java.lang.reflect.Field;
import java.util.*;
+import static org.hisp.dhis.system.util.PredicateUtils.idObjectCollectionsWithScanned;
+import static org.hisp.dhis.system.util.PredicateUtils.idObjects;
+
/**
* Importer that can handle IdentifiableObject and NameableObject.
*
@@ -679,14 +683,15 @@
return objectBridge.getObject( identifiableObject );
}
- private Map<Field, Object> detachFields( Object object )
+ private Map<Field, Object> detachFields( final Object object )
{
- Map<Field, Object> fieldMap = new HashMap<Field, Object>();
- Field[] fields = object.getClass().getDeclaredFields();
+ final Map<Field, Object> fieldMap = new HashMap<Field, Object>();
+ final Collection<Field> fieldCollection = ReflectionUtils.collectFields( object.getClass(), idObjects );
- for ( Field field : fields )
+ FunctionalUtils.forEach( fieldCollection, new Function1<Field>()
{
- if ( ReflectionUtils.isType( field, IdentifiableObject.class ) )
+ @Override
+ public void apply( Field field )
{
Object ref = ReflectionUtils.invokeGetterMethod( field.getName(), object );
@@ -696,8 +701,7 @@
ReflectionUtils.invokeSetterMethod( field.getName(), object, new Object[] { null } );
}
}
-
- }
+ } );
return fieldMap;
}
@@ -734,17 +738,15 @@
return importConflicts;
}
- private Map<Field, Collection<Object>> detachCollectionFields( Object object )
+ private Map<Field, Collection<Object>> detachCollectionFields( final Object object )
{
- Map<Field, Collection<Object>> collectionFields = new HashMap<Field, Collection<Object>>();
- Field[] fields = object.getClass().getDeclaredFields();
+ final Map<Field, Collection<Object>> collectionFields = new HashMap<Field, Collection<Object>>();
+ final Collection<Field> fieldCollection = ReflectionUtils.collectFields( object.getClass(), idObjectCollectionsWithScanned );
- for ( Field field : fields )
+ FunctionalUtils.forEach( fieldCollection, new Function1<Field>()
{
- boolean b = ReflectionUtils.isCollection( field.getName(), object, IdentifiableObject.class,
- Scanned.class );
-
- if ( b )
+ @Override
+ public void apply( Field field )
{
Collection<Object> objects = ReflectionUtils.invokeGetterMethod( field.getName(), object );
@@ -762,7 +764,7 @@
}
}
}
- }
+ } );
return collectionFields;
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2012-05-27 21:50:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2012-06-04 13:02:01 +0000
@@ -257,6 +257,13 @@
GenericIdentifiableObjectStore<T> store = (GenericIdentifiableObjectStore<T>) getIdentifiableObjectStore( clazz );
+ if ( store == null )
+ {
+ log.warn( "No IdentifiableObject store found for " + clazz + ", returning empty map (getIdMap)." );
+
+ return map;
+ }
+
Collection<T> objects = store.getAll();
for ( T object : objects )
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PredicateUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PredicateUtils.java 2012-06-04 09:29:45 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PredicateUtils.java 2012-06-04 13:02:01 +0000
@@ -33,6 +33,8 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
import java.util.Collection;
/**
@@ -40,7 +42,7 @@
*/
public class PredicateUtils
{
- public static Predicate<Field> idObjects= new ObjectWithTypePredicate( IdentifiableObject.class );
+ public static Predicate<Field> idObjects = new ObjectWithTypePredicate( IdentifiableObject.class );
public static Predicate<Field> collections = new CollectionPredicate();
@@ -77,9 +79,15 @@
{
if ( collectionPredicate.evaluate( field ) )
{
- if ( type.isAssignableFrom( field.getType() ) )
+ ParameterizedType parameterizedType = (ParameterizedType) field.getGenericType();
+ Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
+
+ if ( actualTypeArguments.length > 0 )
{
- return true;
+ if ( type.isAssignableFrom( (Class<?>) actualTypeArguments[0] ) )
+ {
+ return true;
+ }
}
}
@@ -102,9 +110,9 @@
@Override
public boolean evaluate( Field field )
{
- if ( collectionPredicate.evaluate( field ) )
+ if ( field.isAnnotationPresent( annotation ) )
{
- if ( field.isAnnotationPresent( annotation ) )
+ if ( collectionPredicate.evaluate( field ) )
{
return true;
}
@@ -130,9 +138,9 @@
@Override
public boolean evaluate( Field field )
{
- if ( collectionWithTypePredicate.evaluate( field ) )
+ if ( field.isAnnotationPresent( annotation ) )
{
- if ( field.isAnnotationPresent( annotation ) )
+ if ( collectionWithTypePredicate.evaluate( field ) )
{
return true;
}
@@ -153,9 +161,9 @@
}
@Override
- public boolean evaluate( Field object )
+ public boolean evaluate( Field field )
{
- return type.isAssignableFrom( object.getClass() );
+ return type.isAssignableFrom( field.getType() );
}
}
}
=== 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 2012-06-04 09:29:45 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java 2012-06-04 13:02:01 +0000
@@ -238,8 +238,6 @@
}
}
- System.err.println( "Did not find getter" );
-
return null;
}
@@ -422,7 +420,7 @@
for ( Field field : fields )
{
- if ( predicate != null && !predicate.evaluate( field ) )
+ if ( Modifier.isStatic( field.getModifiers() ) || (predicate != null && !predicate.evaluate( field )) )
{
continue;
}
@@ -445,7 +443,7 @@
for ( Field field : declaredFields )
{
- if ( predicate != null && !predicate.evaluate( field ) )
+ if ( Modifier.isStatic( field.getModifiers() ) || (predicate != null && !predicate.evaluate( field )) )
{
continue;
}