← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6648: Minor fixes.

 

------------------------------------------------------------
revno: 6648
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-04-19 22:39:07 +0300
message:
  Minor fixes.
modified:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.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/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2012-04-19 16:40:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2012-04-19 19:39:07 +0000
@@ -128,9 +128,15 @@
         object.setId( 0 );
         object.setUid( CodeGenerator.generateCode() );
 
-        log.info( "Trying to save new object with UID: " + object.getUid() );
-
-        saveOrUpdateObjectWithReferences( object, false );
+        log.info( "Trying to save new object => " + getDisplayName( object ) );
+
+        Map<Field, Set<? extends IdentifiableObject>> identifiableObjectCollections = scanIdentifiableObjectCollections( object );
+
+        updateIdentifiableObjects( object, scanIdentifiableObjects( object ) );
+
+        manager.save( object );
+
+        updateIdentifiableObjectCollections( object, identifiableObjectCollections );
 
         manager.update( object );
         updateIdMaps( object );
@@ -158,7 +164,8 @@
 
         log.info( "Starting update of object " + getDisplayName( oldObject ) + " (" + oldObject.getClass().getSimpleName() + ")" );
 
-        saveOrUpdateObjectWithReferences( object, true );
+        updateIdentifiableObjects( object, scanIdentifiableObjects( object ) );
+        updateIdentifiableObjectCollections( object, scanIdentifiableObjectCollections( object ) );
 
         oldObject.mergeWith( object );
         manager.update( oldObject );
@@ -185,6 +192,7 @@
 
         reset();
 
+        // FIXME a bit too static.. implement "pre handler" for types?
         if ( OrganisationUnit.class.isAssignableFrom( objects.get( 0 ).getClass() ) )
         {
             OrganisationUnitUtils.updateParents( (Collection<OrganisationUnit>) objects );
@@ -388,7 +396,6 @@
         T nameObject = nameMap.get( object.getName() );
 
         T shortNameObject = null;
-        T alternativeNameObject = null;
 
         if ( nameable )
         {
@@ -410,7 +417,7 @@
         else if ( ImportStrategy.NEW_AND_UPDATES.equals( options.getImportStrategy() ) )
         {
             // if we have a match on at least one of the objects, then assume update
-            if ( uidObject != null || codeObject != null || nameObject != null || shortNameObject != null || alternativeNameObject != null )
+            if ( uidObject != null || codeObject != null || nameObject != null || shortNameObject != null )
             {
                 conflict = validateForUpdatesStrategy( object, options );
             }
@@ -430,7 +437,6 @@
         T nameObject = nameMap.get( object.getName() );
 
         T shortNameObject = null;
-        T alternativeNameObject = null;
 
         if ( nameable )
         {
@@ -463,11 +469,6 @@
             nonNullObjects.add( shortNameObject );
         }
 
-        if ( alternativeNameObject != null )
-        {
-            nonNullObjects.add( alternativeNameObject );
-        }
-
         if ( nonNullObjects.isEmpty() )
         {
             conflict = reportLookupConflict( object, options );
@@ -487,7 +488,6 @@
         T nameObject = nameMap.get( object.getName() );
 
         T shortNameObject = null;
-        T alternativeNameObject = null;
 
         if ( nameable )
         {
@@ -498,7 +498,7 @@
 
         ImportConflict conflict = null;
 
-        if ( uidObject != null || codeObject != null || nameObject != null || shortNameObject != null || alternativeNameObject != null )
+        if ( uidObject != null || codeObject != null || nameObject != null || shortNameObject != null )
         {
             conflict = reportConflict( object, options );
         }
@@ -687,21 +687,4 @@
             ReflectionUtils.invokeSetterMethod( field.getName(), identifiableObject, objects );
         }
     }
-
-    private void saveOrUpdateObjectWithReferences( T object, boolean update )
-    {
-        log.info( "-> Finding and updating references." );
-
-        Map<Field, IdentifiableObject> identifiableObjects = scanIdentifiableObjects( object );
-        Map<Field, Set<? extends IdentifiableObject>> identifiableObjectCollections = scanIdentifiableObjectCollections( object );
-
-        updateIdentifiableObjects( object, identifiableObjects );
-
-        if ( !update )
-        {
-            manager.save( object );
-        }
-
-        updateIdentifiableObjectCollections( object, identifiableObjectCollections );
-    }
 }