← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15451: wip, use SchemaService to get supported metadata types in importer/exporter

 

------------------------------------------------------------
revno: 15451
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-05-28 14:38:13 +0200
message:
  wip, use SchemaService to get supported metadata types in importer/exporter
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.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-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2014-04-02 11:36:07 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2014-05-28 12:38:13 +0000
@@ -28,7 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.google.common.collect.Lists;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hibernate.SessionFactory;
@@ -38,6 +37,8 @@
 import org.hisp.dhis.dxf2.timer.Timer;
 import org.hisp.dhis.importexport.ImportStrategy;
 import org.hisp.dhis.scheduling.TaskId;
+import org.hisp.dhis.schema.Schema;
+import org.hisp.dhis.schema.SchemaService;
 import org.hisp.dhis.system.notification.NotificationLevel;
 import org.hisp.dhis.system.notification.Notifier;
 import org.hisp.dhis.system.util.ReflectionUtils;
@@ -69,7 +70,7 @@
     // Dependencies
     //-------------------------------------------------------------------------------------------------------
 
-    @Autowired( required = false )
+    @Autowired(required = false)
     private Set<Importer> importerClasses = new HashSet<Importer>();
 
     @Autowired
@@ -87,6 +88,9 @@
     @Autowired
     private Notifier notifier;
 
+    @Autowired
+    private SchemaService schemaService;
+
     //-------------------------------------------------------------------------------------------------------
     // ImportService Implementation
     //-------------------------------------------------------------------------------------------------------
@@ -148,20 +152,9 @@
         objectBridge.setPreheatCache( importOptions.isPreheatCache() );
         objectBridge.init();
 
-        List<String> types;
-
-        if ( importOptions.getImportStrategy().isDelete() )
-        {
-            types = Lists.reverse( Lists.newArrayList( ExchangeClasses.getDeletableMap().values() ) );
-        }
-        else
-        {
-            types = Lists.newArrayList( ExchangeClasses.getImportMap().values() );
-        }
-
-        for ( String type : types )
-        {
-            Object value = ReflectionUtils.invokeGetterMethod( type, metaData );
+        for ( Schema schema : schemaService.getMetadataSchemas() )
+        {
+            Object value = ReflectionUtils.invokeGetterMethod( schema.getPlural(), metaData );
 
             if ( value != null )
             {
@@ -171,7 +164,7 @@
 
                     if ( !objects.isEmpty() )
                     {
-                        String message = "Importing " + objects.size() + " " + StringUtils.capitalize( type );
+                        String message = "Importing " + objects.size() + " " + StringUtils.capitalize( schema.getPlural() );
 
                         if ( taskId != null )
                         {
@@ -193,12 +186,12 @@
                 }
                 else
                 {
-                    log.warn( "Getter for '" + type + "' did not return a collection." );
+                    log.warn( "Getter for '" + schema.getPlural() + "' did not return a collection." );
                 }
             }
             else
             {
-                log.warn( "Can not find getter for '" + type + "'." );
+                log.warn( "Can not find getter for '" + schema.getPlural() + "'." );
             }
         }