=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java 2016-01-25 04:37:41 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/preheat/DefaultPreheatService.java 2016-01-25 04:52:11 +0000 @@ -28,6 +28,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import com.google.common.collect.Sets; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.schema.Property; @@ -117,93 +118,84 @@ } @Override + public Map, Set> scanObjectForReferences( Object object, PreheatIdentifier identifier ) + { + return scanObjectsForReferences( Sets.newHashSet( object ), identifier ); + } + + @Override @SuppressWarnings( "unchecked" ) - public Map, Set> scanObjectForReferences( Object object, PreheatIdentifier identifier ) + public Map, Set> scanObjectsForReferences( Set objects, PreheatIdentifier identifier ) { Map, Set> map = new HashMap<>(); - if ( object == null ) + if ( objects.isEmpty() ) { return map; } - Schema schema = schemaService.getDynamicSchema( object.getClass() ); + Schema schema = schemaService.getDynamicSchema( objects.iterator().next().getClass() ); List properties = schema.getProperties().stream() .filter( p -> p.isPersisted() && p.isOwner() && (PropertyType.REFERENCE == p.getPropertyType() || PropertyType.REFERENCE == p.getItemPropertyType()) ) .collect( Collectors.toList() ); properties.forEach( p -> { - if ( !p.isCollection() ) - { - Class klass = (Class) p.getKlass(); - if ( !map.containsKey( klass ) ) map.put( klass, new HashSet<>() ); - Object reference = ReflectionUtils.invokeMethod( object, p.getGetterMethod() ); - - if ( reference != null ) - { - IdentifiableObject identifiableObject = (IdentifiableObject) reference; - - if ( PreheatIdentifier.UID == identifier ) - { - if ( identifiableObject.getUid() != null ) - { - map.get( klass ).add( identifiableObject.getUid() ); - } - } - else if ( PreheatIdentifier.CODE == identifier ) - { - if ( identifiableObject.getCode() != null ) - { - map.get( klass ).add( identifiableObject.getCode() ); - } - } - } - } - else - { - Class klass = (Class) p.getItemKlass(); - if ( !map.containsKey( klass ) ) map.put( klass, new HashSet<>() ); - Collection reference = ReflectionUtils.invokeMethod( object, p.getGetterMethod() ); - - for ( IdentifiableObject identifiableObject : reference ) - { - if ( PreheatIdentifier.UID == identifier ) - { - if ( identifiableObject.getUid() != null ) - { - map.get( klass ).add( identifiableObject.getUid() ); - } - } - else if ( PreheatIdentifier.CODE == identifier ) - { - if ( identifiableObject.getCode() != null ) - { - map.get( klass ).add( identifiableObject.getCode() ); - } - } - } - } + for ( Object object : objects ) + { + if ( !p.isCollection() ) + { + Class klass = (Class) p.getKlass(); + if ( !map.containsKey( klass ) ) map.put( klass, new HashSet<>() ); + Object reference = ReflectionUtils.invokeMethod( object, p.getGetterMethod() ); + + if ( reference != null ) + { + IdentifiableObject identifiableObject = (IdentifiableObject) reference; + + if ( PreheatIdentifier.UID == identifier ) + { + if ( identifiableObject.getUid() != null ) + { + map.get( klass ).add( identifiableObject.getUid() ); + } + } + else if ( PreheatIdentifier.CODE == identifier ) + { + if ( identifiableObject.getCode() != null ) + { + map.get( klass ).add( identifiableObject.getCode() ); + } + } + } + } + else + { + Class klass = (Class) p.getItemKlass(); + if ( !map.containsKey( klass ) ) map.put( klass, new HashSet<>() ); + Collection reference = ReflectionUtils.invokeMethod( object, p.getGetterMethod() ); + + for ( IdentifiableObject identifiableObject : reference ) + { + if ( PreheatIdentifier.UID == identifier ) + { + if ( identifiableObject.getUid() != null ) + { + map.get( klass ).add( identifiableObject.getUid() ); + } + } + else if ( PreheatIdentifier.CODE == identifier ) + { + if ( identifiableObject.getCode() != null ) + { + map.get( klass ).add( identifiableObject.getCode() ); + } + } + } + } + } + } ); return map; } - - @Override - public Map, Set> scanObjectsForReferences( Set objects, PreheatIdentifier identifier ) - { - Map, Set> referenceMap = new HashMap<>(); - - for ( Object object : objects ) - { - Map, Set> references = scanObjectForReferences( object, identifier ); - - for ( Class klass : references.keySet() ) - { - if ( !referenceMap.containsKey( klass ) ) referenceMap.put( klass, new HashSet<>() ); - referenceMap.get( klass ).addAll( references.get( klass ) ); - } - } - - return referenceMap; - } }