← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22136: add update test with CODE matching

 

------------------------------------------------------------
revno: 22136
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2016-03-04 11:07:55 +0700
message:
  add update test with CODE matching
added:
  dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_update2.json
modified:
  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/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/DefaultObjectBundleService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java	2016-03-04 03:55:19 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata2/objectbundle/DefaultObjectBundleService.java	2016-03-04 04:07:55 +0000
@@ -35,7 +35,6 @@
 import org.hisp.dhis.common.CodeGenerator;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.IdentifiableObjectManager;
-import org.hisp.dhis.common.IdentifiableObjectUtils;
 import org.hisp.dhis.dxf2.metadata2.objectbundle.hooks.ObjectBundleHook;
 import org.hisp.dhis.feedback.ErrorCode;
 import org.hisp.dhis.feedback.ErrorReport;
@@ -314,7 +313,7 @@
 
             if ( log.isDebugEnabled() )
             {
-                String msg = "Created object '" + IdentifiableObjectUtils.getDisplayName( object ) + "'";
+                String msg = "Created object '" + bundle.getPreheatIdentifier().getIdentifiersWithName( object ) + "'";
                 log.debug( msg );
             }
         }
@@ -328,6 +327,7 @@
 
             IdentifiableObject persistedObject = bundle.getPreheat().get( bundle.getPreheatIdentifier(), object );
             persistedObject.mergeWith( object, bundle.getMergeMode() );
+            persistedObject.mergeSharingWith( object );
 
             objectBundleHooks.forEach( hook -> hook.preUpdate( persistedObject, bundle ) );
 
@@ -338,7 +338,7 @@
 
             if ( log.isDebugEnabled() )
             {
-                String msg = "Updated object '" + IdentifiableObjectUtils.getDisplayName( object ) + "'";
+                String msg = "Updated object '" + bundle.getPreheatIdentifier().getIdentifiersWithName( persistedObject ) + "'";
                 log.debug( msg );
             }
         }
@@ -357,7 +357,7 @@
 
             if ( log.isDebugEnabled() )
             {
-                String msg = "Deleted object '" + IdentifiableObjectUtils.getDisplayName( object ) + "'";
+                String msg = "Deleted object '" + bundle.getPreheatIdentifier().getIdentifiersWithName( object ) + "'";
                 log.debug( msg );
             }
         }

=== 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 03:55:19 +0000
+++ 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
@@ -620,7 +620,7 @@
     }
 
     @Test
-    public void testUpdateDataElements() throws IOException
+    public void testUpdateDataElementsUID() throws IOException
     {
         defaultSetup();
 
@@ -653,6 +653,73 @@
         assertEquals( "DEB", dataElementB.getName() );
         assertEquals( "DEC", dataElementC.getName() );
         assertEquals( "DED", dataElementD.getName() );
+
+        assertEquals( "DECA", dataElementA.getCode() );
+        assertEquals( "DECB", dataElementB.getCode() );
+        assertEquals( "DECC", dataElementC.getCode() );
+        assertEquals( "DECD", dataElementD.getCode() );
+
+        assertEquals( "DESA", dataElementA.getShortName() );
+        assertEquals( "DESB", dataElementB.getShortName() );
+        assertEquals( "DESC", dataElementC.getShortName() );
+        assertEquals( "DESD", dataElementD.getShortName() );
+
+        assertEquals( "DEDA", dataElementA.getDescription() );
+        assertEquals( "DEDB", dataElementB.getDescription() );
+        assertEquals( "DEDC", dataElementC.getDescription() );
+        assertEquals( "DEDD", dataElementD.getDescription() );
+    }
+
+    @Test
+    public void testUpdateDataElementsCODE() throws IOException
+    {
+        defaultSetup();
+
+        Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(
+            new ClassPathResource( "dxf2/de_update2.json" ).getInputStream(), RenderFormat.JSON );
+
+        ObjectBundleParams params = new ObjectBundleParams();
+        params.setObjectBundleMode( ObjectBundleMode.COMMIT );
+        params.setPreheatIdentifier( PreheatIdentifier.CODE );
+        params.setImportMode( ImportStrategy.UPDATE );
+        params.setObjects( metadata );
+
+        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" );
+        DataElement dataElementD = dataElementMap.get( "deabcdefghD" );
+
+        assertNotNull( dataElementA );
+        assertNotNull( dataElementB );
+        assertNotNull( dataElementC );
+        assertNotNull( dataElementD );
+
+        assertEquals( "DEA", dataElementA.getName() );
+        assertEquals( "DEB", dataElementB.getName() );
+        assertEquals( "DEC", dataElementC.getName() );
+        assertEquals( "DED", dataElementD.getName() );
+
+        assertEquals( "DataElementCodeA", dataElementA.getCode() );
+        assertEquals( "DataElementCodeB", dataElementB.getCode() );
+        assertEquals( "DataElementCodeC", dataElementC.getCode() );
+        assertEquals( "DataElementCodeD", dataElementD.getCode() );
+
+        assertEquals( "DESA", dataElementA.getShortName() );
+        assertEquals( "DESB", dataElementB.getShortName() );
+        assertEquals( "DESC", dataElementC.getShortName() );
+        assertEquals( "DESD", dataElementD.getShortName() );
+
+        assertEquals( "DEDA", dataElementA.getDescription() );
+        assertEquals( "DEDB", dataElementB.getDescription() );
+        assertEquals( "DEDC", dataElementC.getDescription() );
+        assertEquals( "DEDD", dataElementD.getDescription() );
     }
 
     private void defaultSetup()

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_update2.json	2016-03-04 04:07:55 +0000
@@ -0,0 +1,84 @@
+{
+  "dataElements": [
+    {
+      "code": "DataElementCodeA",
+      "created": "2016-03-04T03:37:12.714+0000",
+      "lastUpdated": "2016-03-04T03:37:12.733+0000",
+      "name": "DEA",
+      "id": "deabcdefghA",
+      "shortName": "DESA",
+      "aggregationType": "SUM",
+      "domainType": "AGGREGATE",
+      "publicAccess": "--------",
+      "description": "DEDA",
+      "zeroIsSignificant": false,
+      "valueType": "INTEGER",
+      "categoryCombo": {
+        "id": "hmqVMxvDKUD"
+      },
+      "userGroupAccesses": [],
+      "attributeValues": [],
+      "aggregationLevels": []
+    },
+    {
+      "code": "DataElementCodeB",
+      "created": "2016-03-04T03:37:12.720+0000",
+      "lastUpdated": "2016-03-04T03:37:12.741+0000",
+      "name": "DEB",
+      "id": "deabcdefghB",
+      "shortName": "DESB",
+      "aggregationType": "SUM",
+      "domainType": "AGGREGATE",
+      "publicAccess": "--------",
+      "description": "DEDB",
+      "zeroIsSignificant": false,
+      "valueType": "INTEGER",
+      "categoryCombo": {
+        "id": "hmqVMxvDKUD"
+      },
+      "userGroupAccesses": [],
+      "attributeValues": [],
+      "aggregationLevels": []
+    },
+    {
+      "code": "DataElementCodeC",
+      "created": "2016-03-04T03:37:12.725+0000",
+      "lastUpdated": "2016-03-04T03:37:12.743+0000",
+      "name": "DEC",
+      "id": "deabcdefghC",
+      "shortName": "DESC",
+      "aggregationType": "SUM",
+      "domainType": "AGGREGATE",
+      "publicAccess": "--------",
+      "description": "DEDC",
+      "zeroIsSignificant": false,
+      "valueType": "INTEGER",
+      "categoryCombo": {
+        "id": "hmqVMxvDKUD"
+      },
+      "userGroupAccesses": [],
+      "attributeValues": [],
+      "aggregationLevels": []
+    },
+    {
+      "code": "DataElementCodeD",
+      "created": "2016-03-04T03:37:12.729+0000",
+      "lastUpdated": "2016-03-04T03:37:12.745+0000",
+      "name": "DED",
+      "id": "deabcdefghD",
+      "shortName": "DESD",
+      "aggregationType": "SUM",
+      "domainType": "AGGREGATE",
+      "publicAccess": "--------",
+      "description": "DEDD",
+      "zeroIsSignificant": false,
+      "valueType": "INTEGER",
+      "categoryCombo": {
+        "id": "hmqVMxvDKUD"
+      },
+      "userGroupAccesses": [],
+      "attributeValues": [],
+      "aggregationLevels": []
+    }
+  ]
+}
\ No newline at end of file