← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22183: proper fix for user/usercredentials and remove @ignore on tests

 

------------------------------------------------------------
revno: 22183
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2016-03-08 16:21:54 +0700
message:
  proper fix for user/usercredentials and remove @ignore on tests
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/UserObjectBundleHook.java
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.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/metadata2/objectbundle/hooks/UserObjectBundleHook.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/UserObjectBundleHook.java	2016-02-29 07:35:27 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/UserObjectBundleHook.java	2016-03-08 09:21:54 +0000
@@ -51,6 +51,8 @@
     @Autowired
     private UserService userService;
 
+    private UserCredentials userCredentials;
+
     @Override
     public void preCreate( IdentifiableObject identifiableObject, ObjectBundle objectBundle )
     {
@@ -60,7 +62,8 @@
         }
 
         User user = (User) identifiableObject;
-        UserCredentials userCredentials = user.getUserCredentials();
+        userCredentials = user.getUserCredentials();
+        user.setUserCredentials( null );
 
         if ( objectBundle.getPreheat().getUsernames().containsKey( userCredentials.getUsername() ) )
         {
@@ -73,9 +76,21 @@
         }
 
         preheatService.connectReferences( userCredentials, objectBundle.getPreheat(), objectBundle.getPreheatIdentifier() );
-        manager.save( userCredentials );
-
+    }
+
+    @Override
+    public void postCreate( IdentifiableObject identifiableObject, ObjectBundle objectBundle )
+    {
+        if ( !User.class.isInstance( identifiableObject ) || userCredentials == null )
+        {
+            return;
+        }
+
+        User user = (User) identifiableObject;
+        userCredentials.setUserInfo( user );
+        sessionFactory.getCurrentSession().save( userCredentials );
         user.setUserCredentials( userCredentials );
+        sessionFactory.getCurrentSession().update( userCredentials );
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java	2016-03-08 08:28:07 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java	2016-03-08 09:21:54 +0000
@@ -461,7 +461,6 @@
     }
 
     @Test
-    @Ignore
     public void testCreateSimpleMetadataUID() throws IOException
     {
         Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(
@@ -513,7 +512,6 @@
     }
 
     @Test
-    @Ignore
     public void testCreateSimpleMetadataAttributeValuesUID() throws IOException
     {
         Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(