← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22137: support update of UGA/AV in dxf2 importer

 

------------------------------------------------------------
revno: 22137
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2016-03-04 13:13:25 +0700
message:
  support update of UGA/AV in dxf2 importer
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroupAccess.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/IdentifiableObjectBundleHook.java
  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/resources/dxf2/de_update1.json
  dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_update2.json
  dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.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/user/UserGroupAccess.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroupAccess.java	2016-03-03 10:04:35 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserGroupAccess.java	2016-03-04 06:13:25 +0000
@@ -119,7 +119,6 @@
         this.userGroup = userGroup;
     }
 
-
     @Override
     public String toString()
     {

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/IdentifiableObjectBundleHook.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/IdentifiableObjectBundleHook.java	2016-02-29 08:22:45 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/hooks/IdentifiableObjectBundleHook.java	2016-03-04 06:13:25 +0000
@@ -50,11 +50,19 @@
     public void preCreate( IdentifiableObject identifiableObject, ObjectBundle objectBundle )
     {
         Schema schema = schemaService.getDynamicSchema( identifiableObject.getClass() );
-        handleAttributeValuesCreate( identifiableObject, objectBundle, schema );
-        handleUserGroupAccessesCreate( identifiableObject, objectBundle, schema );
-    }
-
-    public void handleAttributeValuesCreate( IdentifiableObject identifiableObject, ObjectBundle bundle, Schema schema )
+        handleAttributeValues( identifiableObject, objectBundle, schema );
+        handleUserGroupAccesses( identifiableObject, objectBundle, schema );
+    }
+
+    @Override
+    public void postUpdate( IdentifiableObject identifiableObject, ObjectBundle objectBundle )
+    {
+        Schema schema = schemaService.getDynamicSchema( identifiableObject.getClass() );
+        handleAttributeValues( identifiableObject, objectBundle, schema );
+        handleUserGroupAccesses( identifiableObject, objectBundle, schema );
+    }
+
+    public void handleAttributeValues( IdentifiableObject identifiableObject, ObjectBundle bundle, Schema schema )
     {
         if ( !schema.havePersistedProperty( "attributeValues" ) ) return;
         Session session = sessionFactory.getCurrentSession();
@@ -67,7 +75,7 @@
         }
     }
 
-    public void handleUserGroupAccessesCreate( IdentifiableObject identifiableObject, ObjectBundle bundle, Schema schema )
+    public void handleUserGroupAccesses( IdentifiableObject identifiableObject, ObjectBundle bundle, Schema schema )
     {
         if ( !schema.havePersistedProperty( "userGroupAccesses" ) ) return;
         Session session = sessionFactory.getCurrentSession();

=== 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-04 04:07:55 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata2/objectbundle/ObjectBundleServiceTest.java	2016-03-04 06:13:25 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.google.common.collect.Sets;
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.attribute.Attribute;
 import org.hisp.dhis.common.IdScheme;
@@ -629,16 +630,19 @@
 
         ObjectBundleParams params = new ObjectBundleParams();
         params.setObjectBundleMode( ObjectBundleMode.COMMIT );
+        params.setPreheatMode( PreheatMode.REFERENCE );
         params.setImportMode( ImportStrategy.UPDATE );
         params.setObjects( metadata );
 
+        Map<String, DataElement> dataElementMap = manager.getIdMap( DataElement.class, IdScheme.UID );
+        UserGroup userGroup = manager.get( UserGroup.class, "ugabcdefghA" );
+        assertEquals( 4, dataElementMap.size() );
+        assertNotNull( userGroup );
+
         ObjectBundle bundle = objectBundleService.create( params );
         objectBundleService.validate( bundle );
         objectBundleService.commit( bundle );
 
-        Map<String, DataElement> dataElementMap = manager.getIdMap( DataElement.class, IdScheme.UID );
-        assertEquals( 4, dataElementMap.size() );
-
         DataElement dataElementA = dataElementMap.get( "deabcdefghA" );
         DataElement dataElementB = dataElementMap.get( "deabcdefghB" );
         DataElement dataElementC = dataElementMap.get( "deabcdefghC" );
@@ -668,6 +672,11 @@
         assertEquals( "DEDB", dataElementB.getDescription() );
         assertEquals( "DEDC", dataElementC.getDescription() );
         assertEquals( "DEDD", dataElementD.getDescription() );
+
+        assertEquals( 1, dataElementA.getUserGroupAccesses().size() );
+        assertEquals( 0, dataElementB.getUserGroupAccesses().size() );
+        assertEquals( 1, dataElementC.getUserGroupAccesses().size() );
+        assertEquals( 0, dataElementD.getUserGroupAccesses().size() );
     }
 
     @Test
@@ -684,13 +693,15 @@
         params.setImportMode( ImportStrategy.UPDATE );
         params.setObjects( metadata );
 
+        Map<String, DataElement> dataElementMap = manager.getIdMap( DataElement.class, IdScheme.UID );
+        UserGroup userGroup = manager.get( UserGroup.class, "ugabcdefghA" );
+        assertEquals( 4, dataElementMap.size() );
+        assertNotNull( userGroup );
+
         ObjectBundle bundle = objectBundleService.create( params );
         objectBundleService.validate( bundle );
         objectBundleService.commit( bundle );
 
-        Map<String, DataElement> dataElementMap = manager.getIdMap( DataElement.class, IdScheme.UID );
-        assertEquals( 4, dataElementMap.size() );
-
         DataElement dataElementA = dataElementMap.get( "deabcdefghA" );
         DataElement dataElementB = dataElementMap.get( "deabcdefghB" );
         DataElement dataElementC = dataElementMap.get( "deabcdefghC" );
@@ -720,6 +731,11 @@
         assertEquals( "DEDB", dataElementB.getDescription() );
         assertEquals( "DEDC", dataElementC.getDescription() );
         assertEquals( "DEDD", dataElementD.getDescription() );
+
+        assertEquals( 1, dataElementA.getUserGroupAccesses().size() );
+        assertEquals( 0, dataElementB.getUserGroupAccesses().size() );
+        assertEquals( 1, dataElementC.getUserGroupAccesses().size() );
+        assertEquals( 0, dataElementD.getUserGroupAccesses().size() );
     }
 
     private void defaultSetup()
@@ -736,5 +752,8 @@
 
         User user = createUser( 'A' );
         manager.save( user );
+
+        UserGroup userGroup = createUserGroup( 'A', Sets.newHashSet( user ) );
+        manager.save( userGroup );
     }
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_update1.json'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_update1.json	2016-03-04 03:55:19 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_update1.json	2016-03-04 06:13:25 +0000
@@ -16,7 +16,15 @@
       "categoryCombo": {
         "id": "hmqVMxvDKUD"
       },
-      "userGroupAccesses": [],
+      "userGroupAccesses": [
+        {
+          "userGroup": {
+            "id": "ugabcdefghA",
+            "code": "UserGroupCodeA"
+          },
+          "access": "r-------"
+        }
+      ],
       "attributeValues": [],
       "aggregationLevels": []
     },
@@ -56,7 +64,15 @@
       "categoryCombo": {
         "id": "hmqVMxvDKUD"
       },
-      "userGroupAccesses": [],
+      "userGroupAccesses": [
+        {
+          "userGroup": {
+            "id": "ugabcdefghA",
+            "code": "UserGroupCodeA"
+          },
+          "access": "r-------"
+        }
+      ],
       "attributeValues": [],
       "aggregationLevels": []
     },

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_update2.json'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_update2.json	2016-03-04 04:07:55 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_update2.json	2016-03-04 06:13:25 +0000
@@ -16,7 +16,15 @@
       "categoryCombo": {
         "id": "hmqVMxvDKUD"
       },
-      "userGroupAccesses": [],
+      "userGroupAccesses": [
+        {
+          "userGroup": {
+            "id": "ugabcdefghA",
+            "code": "UserGroupCodeA"
+          },
+          "access": "r-------"
+        }
+      ],
       "attributeValues": [],
       "aggregationLevels": []
     },
@@ -56,7 +64,15 @@
       "categoryCombo": {
         "id": "hmqVMxvDKUD"
       },
-      "userGroupAccesses": [],
+      "userGroupAccesses": [
+        {
+          "userGroup": {
+            "id": "ugabcdefghA",
+            "code": "UserGroupCodeA"
+          },
+          "access": "r-------"
+        }
+      ],
       "attributeValues": [],
       "aggregationLevels": []
     },

=== modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java'
--- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2016-03-02 04:34:21 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2016-03-04 06:13:25 +0000
@@ -151,6 +151,8 @@
 
     protected static final String BASE_USER_UID = "userabcdef";
 
+    protected static final String BASE_USER_GROUP_UID = "ugabcdefgh";
+
     private static final String EXT_TEST_DIR = System.getProperty( "user.home" ) + File.separator + "dhis2_test_dir";
 
     private static Date date;
@@ -1125,6 +1127,8 @@
         UserGroup userGroup = new UserGroup();
         userGroup.setAutoFields();
 
+        userGroup.setUid( BASE_USER_GROUP_UID + uniqueCharacter );
+        userGroup.setCode( "UserGroupCode" + uniqueCharacter );
         userGroup.setName( "UserGroup" + uniqueCharacter );
         userGroup.setMembers( users );