← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22002: minor cleanup fixes for bundle create/delete commit

 

------------------------------------------------------------
revno: 22002
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2016-02-19 09:27:16 +0700
message:
  minor cleanup fixes for bundle create/delete commit
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/Preheat.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.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-api/src/main/java/org/hisp/dhis/preheat/Preheat.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/Preheat.java	2016-02-18 11:15:51 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/preheat/Preheat.java	2016-02-19 02:27:16 +0000
@@ -126,12 +126,26 @@
     public <T extends IdentifiableObject> Preheat put( PreheatIdentifier identifier, T object )
     {
         if ( object == null ) return this;
-        if ( !map.containsKey( identifier ) ) map.put( identifier, new HashMap<>() );
-        if ( !map.get( identifier ).containsKey( object.getClass() ) ) map.get( identifier ).put( object.getClass(), new HashMap<>() );
-
-        Map<String, IdentifiableObject> identifierMap = map.get( identifier ).get( object.getClass() );
-        String key = identifier.getIdentifier( object );
-        identifierMap.put( key, object );
+
+        if ( PreheatIdentifier.UID == identifier || PreheatIdentifier.AUTO == identifier )
+        {
+            if ( !map.containsKey( PreheatIdentifier.UID ) ) map.put( PreheatIdentifier.UID, new HashMap<>() );
+            if ( !map.get( PreheatIdentifier.UID ).containsKey( object.getClass() ) ) map.get( PreheatIdentifier.UID ).put( object.getClass(), new HashMap<>() );
+
+            Map<String, IdentifiableObject> identifierMap = map.get( PreheatIdentifier.UID ).get( object.getClass() );
+            String key = PreheatIdentifier.UID.getIdentifier( object );
+            identifierMap.put( key, object );
+        }
+
+        if ( PreheatIdentifier.CODE == identifier || PreheatIdentifier.AUTO == identifier )
+        {
+            if ( !map.containsKey( PreheatIdentifier.CODE ) ) map.put( PreheatIdentifier.CODE, new HashMap<>() );
+            if ( !map.get( PreheatIdentifier.CODE ).containsKey( object.getClass() ) ) map.get( PreheatIdentifier.CODE ).put( object.getClass(), new HashMap<>() );
+
+            Map<String, IdentifiableObject> identifierMap = map.get( PreheatIdentifier.CODE ).get( object.getClass() );
+            String key = PreheatIdentifier.CODE.getIdentifier( object );
+            identifierMap.put( key, object );
+        }
 
         return this;
     }
@@ -156,6 +170,33 @@
         return this;
     }
 
+    public Preheat remove( PreheatIdentifier identifier, IdentifiableObject object )
+    {
+        Class<? extends IdentifiableObject> klass = object.getClass();
+
+        if ( PreheatIdentifier.UID == identifier || PreheatIdentifier.AUTO == identifier )
+        {
+            String key = PreheatIdentifier.UID.getIdentifier( object );
+
+            if ( containsKey( PreheatIdentifier.UID, klass, key ) )
+            {
+                map.get( PreheatIdentifier.UID ).get( klass ).remove( key );
+            }
+        }
+
+        if ( PreheatIdentifier.CODE == identifier || PreheatIdentifier.AUTO == identifier )
+        {
+            String key = PreheatIdentifier.CODE.getIdentifier( object );
+
+            if ( containsKey( PreheatIdentifier.CODE, klass, key ) )
+            {
+                map.get( PreheatIdentifier.CODE ).get( klass ).remove( key );
+            }
+        }
+
+        return this;
+    }
+
     public Preheat remove( PreheatIdentifier identifier, Class<? extends IdentifiableObject> klass, Collection<String> keys )
     {
         for ( String key : keys )

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java	2016-02-18 13:44:33 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java	2016-02-19 02:27:16 +0000
@@ -267,7 +267,7 @@
             preheatService.connectReferences( object, bundle.getPreheat(), bundle.getPreheatIdentifier() );
             manager.save( object, bundle.getUser() );
 
-            bundle.getPreheat().put( PreheatIdentifier.UID, object );
+            bundle.getPreheat().put( bundle.getPreheatIdentifier(), object );
 
             if ( log.isDebugEnabled() )
             {
@@ -290,6 +290,8 @@
         {
             manager.delete( object, bundle.getUser() );
 
+            bundle.getPreheat().remove( bundle.getPreheatIdentifier(), object );
+
             if ( log.isDebugEnabled() )
             {
                 String msg = "Deleted object '" + IdentifiableObjectUtils.getDisplayName( object ) + "'";