← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6875: minor changes to metadata importer

 

------------------------------------------------------------
revno: 6875
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-05-07 22:02:54 +0530
message:
  minor changes to metadata importer
modified:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.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/DefaultImportService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2012-05-04 09:55:18 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2012-05-07 16:32:54 +0000
@@ -84,6 +84,11 @@
         ImportSummary importSummary = new ImportSummary();
         objectBridge.init();
 
+        if ( importOptions.isDryRun() )
+        {
+            objectBridge.setWriteEnabled( false );
+        }
+
         Date startDate = new Date();
 
         log.info( "User '" + currentUserService.getCurrentUsername() + "' started import at " + startDate );
@@ -97,7 +102,9 @@
         doImport( metaData.getUsers(), importOptions, importSummary );
         doImport( metaData.getUserGroups(), importOptions, importSummary );
         doImport( metaData.getUserAuthorityGroups(), importOptions, importSummary );
+*/
 
+        /*
         doImport( metaData.getConcepts(), importOptions, importSummary );
         doImport( metaData.getConstants(), importOptions, importSummary );
         doImport( metaData.getDocuments(), importOptions, importSummary );
@@ -136,7 +143,7 @@
         doImport( metaData.getDataSets(), importOptions, importSummary );
 */
 
-        cacheManager.clearCache();
+        // cacheManager.clearCache();
         objectBridge.destroy();
 
         Date endDate = new Date();

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java	2012-04-24 13:28:16 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java	2012-05-07 16:32:54 +0000
@@ -27,14 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.IdentifiableObject;
@@ -50,6 +42,8 @@
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.*;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -231,7 +225,7 @@
     @Transactional( readOnly = false )
     public void saveObject( Object object )
     {
-        if ( IdentifiableObject.class.isInstance( object ) )
+        if ( _typeSupported( object.getClass() ) && IdentifiableObject.class.isInstance( object ) )
         {
             if ( writeEnabled )
             {
@@ -248,7 +242,7 @@
     @Transactional( readOnly = false )
     public void updateObject( Object object )
     {
-        if ( IdentifiableObject.class.isInstance( object ) )
+        if ( _typeSupported( object.getClass() ) && IdentifiableObject.class.isInstance( object ) )
         {
             if ( writeEnabled )
             {
@@ -504,4 +498,17 @@
 
         return null;
     }
+
+    private boolean _typeSupported( Class<?> clazz )
+    {
+        for ( Class c : registeredTypes )
+        {
+            if ( c.isAssignableFrom( clazz ) )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
 }

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java	2012-05-07 14:57:43 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java	2012-05-07 16:32:54 +0000
@@ -113,9 +113,9 @@
         this.orgUnitIdScheme = scheme != null ? IdentifiableProperty.valueOf( scheme.toUpperCase() ) : null;
     }
 
-    public void setDryRun( Boolean dryRun )
+    public void setDryRun( boolean dryRun )
     {
-        this.dryRun = dryRun != null ? dryRun : false;
+        this.dryRun = dryRun;
     }
 
     public void setImportStrategy( String strategy )

=== 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-04-24 13:28:16 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2012-05-07 16:32:54 +0000
@@ -269,12 +269,6 @@
         totalImported = 0;
         totalUpdated = 0;
         totalIgnored = 0;
-
-        if ( options.isDryRun() )
-        {
-            // disable writing on the persistence layer
-            objectBridge.setWriteEnabled( false );
-        }
     }
 
     private List<ImportConflict> importObjectLocal( T object, ImportOptions options )

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java	2012-04-14 15:02:08 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java	2012-05-07 16:32:54 +0000
@@ -62,7 +62,7 @@
 
     @Autowired
     private ImportService importService;
-    
+
     @Autowired
     private ContextUtils contextUtils;
 
@@ -204,7 +204,7 @@
     public void importGZippedXml( ImportOptions importOptions, HttpServletResponse response, HttpServletRequest request ) throws JAXBException, IOException
     {
         GZIPInputStream gzip = new GZIPInputStream( request.getInputStream() );
-        
+
         MetaData metaData = JacksonUtils.fromXml( gzip, MetaData.class );
         System.err.println( metaData );