← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6558: minor fixes

 

------------------------------------------------------------
revno: 6558
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-04-13 11:17:00 +0300
message:
  minor fixes
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/importers/DefaultImporter.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-04-13 01:16:51 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultImportService.java	2012-04-13 08:17:00 +0000
@@ -27,25 +27,15 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import org.hisp.dhis.common.BaseIdentifiableObject;
-import org.hisp.dhis.constant.Constant;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.dxf2.importsummary.ImportConflict;
 import org.hisp.dhis.dxf2.importsummary.ImportCount;
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
-import org.hisp.dhis.dxf2.metadata.importers.DefaultImporter;
-import org.hisp.dhis.indicator.Indicator;
-import org.hisp.dhis.indicator.IndicatorGroup;
-import org.hisp.dhis.indicator.IndicatorGroupSet;
-import org.hisp.dhis.indicator.IndicatorType;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
-import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
-import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import javax.annotation.PostConstruct;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -58,6 +48,8 @@
 public class DefaultImportService
     implements ImportService
 {
+    private static final Log log = LogFactory.getLog( DefaultImportService.class );
+
     //-------------------------------------------------------------------------------------------------------
     // Dependencies
     //-------------------------------------------------------------------------------------------------------
@@ -65,46 +57,6 @@
     @Autowired( required = false )
     private Set<Importer> importerClasses = new HashSet<Importer>();
 
-    private <T> Importer<T> findImporterClass( List<?> clazzes )
-    {
-        if ( !clazzes.isEmpty() )
-        {
-            return findImporterClass( clazzes.get( 0 ).getClass() );
-        }
-
-        return null;
-    }
-
-    private <T> Importer<T> findImporterClass( Class<?> clazz )
-    {
-        for ( Importer<T> i : importerClasses )
-        {
-            if ( i.canHandle( clazz ) )
-            {
-                return i;
-            }
-        }
-
-        return null;
-    }
-
-    private <T> void doImport( List<T> objects, ImportOptions importOptions, ImportSummary importSummary )
-    {
-        if ( !objects.isEmpty() )
-        {
-            Importer<T> importer = findImporterClass( objects );
-
-            if ( importer != null )
-            {
-                List<ImportConflict> conflicts = importer.importObjects( objects, importOptions );
-                ImportCount count = importer.getCurrentImportCount();
-
-                importSummary.getConflicts().addAll( conflicts );
-                // importSummary.getCounts().add( count ); //FIXME
-            }
-        }
-    }
-
     //-------------------------------------------------------------------------------------------------------
     // ImportService Implementation
     //-------------------------------------------------------------------------------------------------------
@@ -124,7 +76,11 @@
         // the correct order
 
         // FIXME this is not currently in the "correct" order
+        doImport( metaData.getConcepts(), importOptions, importSummary );
+        doImport( metaData.getConstants(), importOptions, importSummary );
+        doImport( metaData.getDocuments(), importOptions, importSummary );
         doImport( metaData.getAttributeTypes(), importOptions, importSummary );
+        doImport( metaData.getOptionSets(), importOptions, importSummary );
         doImport( metaData.getCategories(), importOptions, importSummary );
         doImport( metaData.getCategoryCombos(), importOptions, importSummary );
         doImport( metaData.getCategoryOptions(), importOptions, importSummary );
@@ -132,10 +88,6 @@
         doImport( metaData.getDataElements(), importOptions, importSummary );
         doImport( metaData.getDataElementGroups(), importOptions, importSummary );
         doImport( metaData.getDataElementGroupSets(), importOptions, importSummary );
-        doImport( metaData.getCharts(), importOptions, importSummary );
-        doImport( metaData.getConstants(), importOptions, importSummary );
-        doImport( metaData.getDataSets(), importOptions, importSummary );
-        doImport( metaData.getDocuments(), importOptions, importSummary );
         doImport( metaData.getIndicatorTypes(), importOptions, importSummary );
         doImport( metaData.getIndicators(), importOptions, importSummary );
         doImport( metaData.getIndicatorGroups(), importOptions, importSummary );
@@ -148,15 +100,66 @@
         doImport( metaData.getOrganisationUnits(), importOptions, importSummary );
         doImport( metaData.getOrganisationUnitGroups(), importOptions, importSummary );
         doImport( metaData.getOrganisationUnitGroupSets(), importOptions, importSummary );
-        doImport( metaData.getReports(), importOptions, importSummary );
-        doImport( metaData.getReportTables(), importOptions, importSummary );
         doImport( metaData.getSqlViews(), importOptions, importSummary );
         doImport( metaData.getUsers(), importOptions, importSummary );
         doImport( metaData.getUserGroups(), importOptions, importSummary );
         doImport( metaData.getUserAuthorityGroups(), importOptions, importSummary );
         doImport( metaData.getValidationRules(), importOptions, importSummary );
         doImport( metaData.getValidationRuleGroups(), importOptions, importSummary );
+        doImport( metaData.getDataDictionaries(), importOptions, importSummary );
+        doImport( metaData.getReports(), importOptions, importSummary );
+        doImport( metaData.getReportTables(), importOptions, importSummary );
+        doImport( metaData.getCharts(), importOptions, importSummary );
+        doImport( metaData.getDataSets(), importOptions, importSummary );
 
         return importSummary;
     }
+
+    //-------------------------------------------------------------------------------------------------------
+    // Helpers
+    //-------------------------------------------------------------------------------------------------------
+
+    private <T> Importer<T> findImporterClass( List<?> clazzes )
+    {
+        if ( !clazzes.isEmpty() )
+        {
+            return findImporterClass( clazzes.get( 0 ).getClass() );
+        }
+
+        return null;
+    }
+
+    private <T> Importer<T> findImporterClass( Class<?> clazz )
+    {
+        for ( Importer<T> i : importerClasses )
+        {
+            if ( i.canHandle( clazz ) )
+            {
+                return i;
+            }
+        }
+
+        return null;
+    }
+
+    private <T> void doImport( List<T> objects, ImportOptions importOptions, ImportSummary importSummary )
+    {
+        if ( !objects.isEmpty() )
+        {
+            Importer<T> importer = findImporterClass( objects );
+
+            if ( importer != null )
+            {
+                List<ImportConflict> conflicts = importer.importObjects( objects, importOptions );
+                ImportCount count = importer.getCurrentImportCount();
+
+                importSummary.getConflicts().addAll( conflicts );
+                // importSummary.getCounts().add( count ); //FIXME
+            }
+            else
+            {
+                log.info( "Importer for object of type " + objects.get( 0 ).getClass().getSimpleName() + " not found." );
+            }
+        }
+    }
 }

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultImporter.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultImporter.java	2012-04-13 01:16:51 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultImporter.java	2012-04-13 08:17:00 +0000
@@ -154,54 +154,6 @@
         return null;
     }
 
-    private void findAndUpdateReferences( T object )
-    {
-        Field[] fields = object.getClass().getDeclaredFields();
-
-        for ( Field field : fields )
-        {
-            if ( ReflectionUtils.isType( field, IdentifiableObject.class ) )
-            {
-                IdentifiableObject identifiableObject = ReflectionUtils.invokeGetterMethod( field.getName(), object );
-
-                if ( identifiableObject != null )
-                {
-                    log.info( "VERIFYING: " + identifiableObject );
-                }
-            }
-            else
-            {
-                boolean b = ReflectionUtils.isCollection( field.getName(), object, IdentifiableObject.class );
-
-                if ( b )
-                {
-                    Collection<IdentifiableObject> identifiableObjects = ReflectionUtils.invokeGetterMethod( field.getName(), object );
-
-                    if ( !identifiableObjects.isEmpty() )
-                    {
-                        log.info( "VERIFYING: " + identifiableObjects );
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * Current object name, used to fill name part of a ImportConflict
-     *
-     * @return Name of object
-     */
-    protected String getObjectName()
-    {
-        return importerClass.getSimpleName();
-    }
-
-    @Override
-    public boolean canHandle( Class<?> clazz )
-    {
-        return importerClass.equals( clazz );
-    }
-
     //-------------------------------------------------------------------------------------------------------
     // Importer<T> Implementation
     //-------------------------------------------------------------------------------------------------------
@@ -245,8 +197,82 @@
         return new ImportCount( imported, updated, ignored );
     }
 
-    //-------------------------------------------------------------------------------------------------------
-    // Internal methods
+    @Override
+    public boolean canHandle( Class<?> clazz )
+    {
+        return importerClass.equals( clazz );
+    }
+
+    //-------------------------------------------------------------------------------------------------------
+    // Protected methods
+    //-------------------------------------------------------------------------------------------------------
+
+    protected void updateIdMaps( T object )
+    {
+        if ( object.getUid() != null )
+        {
+            uidMap.put( object.getUid(), object );
+        }
+
+        if ( object.getCode() != null )
+        {
+            codeMap.put( object.getCode(), object );
+        }
+
+        if ( object.getName() != null )
+        {
+            nameMap.put( object.getName(), object );
+        }
+
+        if ( nameable )
+        {
+            NameableObject nameableObject = (NameableObject) object;
+
+            if ( nameableObject.getShortName() != null )
+            {
+                shortNameMap.put( nameableObject.getShortName(), object );
+            }
+
+            if ( nameableObject.getAlternativeName() != null )
+            {
+                alternativeNameMap.put( nameableObject.getAlternativeName(), object );
+            }
+        }
+    }
+
+    protected void prepareIdentifiableObject( BaseIdentifiableObject object )
+    {
+        if ( object.getUid() == null && object.getLastUpdated() == null )
+        {
+            object.setAutoFields();
+        }
+        else if ( object.getUid() == null )
+        {
+            object.setUid( CodeGenerator.generateCode() );
+        }
+    }
+
+    /**
+     * @param object Object to get display name for
+     * @return A usable display name
+     */
+    protected String getDisplayName( IdentifiableObject object )
+    {
+        return object.getClass().getName();
+    }
+
+    /**
+     * Current object name, used to fill name part of a ImportConflict
+     *
+     * @return Name of object
+     */
+    protected String getObjectName()
+    {
+        return importerClass.getSimpleName();
+    }
+
+    //-------------------------------------------------------------------------------------------------------
+    // Helpers
     //-------------------------------------------------------------------------------------------------------
 
     private void reset()
@@ -529,61 +555,35 @@
         return matchedObject;
     }
 
-    //-------------------------------------------------------------------------------------------------------
-    // Protected methods
-    //-------------------------------------------------------------------------------------------------------
-
-    protected void updateIdMaps( T object )
-    {
-        if ( object.getUid() != null )
-        {
-            uidMap.put( object.getUid(), object );
-        }
-
-        if ( object.getCode() != null )
-        {
-            codeMap.put( object.getCode(), object );
-        }
-
-        if ( object.getName() != null )
-        {
-            nameMap.put( object.getName(), object );
-        }
-
-        if ( nameable )
-        {
-            NameableObject nameableObject = (NameableObject) object;
-
-            if ( nameableObject.getShortName() != null )
-            {
-                shortNameMap.put( nameableObject.getShortName(), object );
-            }
-
-            if ( nameableObject.getAlternativeName() != null )
-            {
-                alternativeNameMap.put( nameableObject.getAlternativeName(), object );
-            }
-        }
-    }
-
-    protected void prepareIdentifiableObject( BaseIdentifiableObject object )
-    {
-        if ( object.getUid() == null && object.getLastUpdated() == null )
-        {
-            object.setAutoFields();
-        }
-        else if ( object.getUid() == null )
-        {
-            object.setUid( CodeGenerator.generateCode() );
-        }
-    }
-
-    /**
-     * @param object Object to get display name for
-     * @return A usable display name
-     */
-    protected String getDisplayName( IdentifiableObject object )
-    {
-        return object.getClass().getName();
+    private void findAndUpdateReferences( T object )
+    {
+        Field[] fields = object.getClass().getDeclaredFields();
+
+        for ( Field field : fields )
+        {
+            if ( ReflectionUtils.isType( field, IdentifiableObject.class ) )
+            {
+                IdentifiableObject identifiableObject = ReflectionUtils.invokeGetterMethod( field.getName(), object );
+
+                if ( identifiableObject != null )
+                {
+                    log.info( "VERIFYING: " + identifiableObject );
+                }
+            }
+            else
+            {
+                boolean b = ReflectionUtils.isCollection( field.getName(), object, IdentifiableObject.class );
+
+                if ( b )
+                {
+                    Collection<IdentifiableObject> identifiableObjects = ReflectionUtils.invokeGetterMethod( field.getName(), object );
+
+                    if ( !identifiableObjects.isEmpty() )
+                    {
+                        log.info( "VERIFYING: " + identifiableObjects );
+                    }
+                }
+            }
+        }
     }
 }