dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43671
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22135: implemented basic support for updates in dxf2 importer
------------------------------------------------------------
revno: 22135
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2016-03-04 10:55:19 +0700
message:
implemented basic support for updates in dxf2 importer
added:
dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_update1.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-03 10:04:35 +0000
+++ 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
@@ -322,7 +322,26 @@
private void handleUpdates( List<IdentifiableObject> objects, ObjectBundle bundle )
{
-
+ for ( IdentifiableObject object : objects )
+ {
+ if ( Preheat.isDefault( object ) ) continue;
+
+ IdentifiableObject persistedObject = bundle.getPreheat().get( bundle.getPreheatIdentifier(), object );
+ persistedObject.mergeWith( object, bundle.getMergeMode() );
+
+ objectBundleHooks.forEach( hook -> hook.preUpdate( persistedObject, bundle ) );
+
+ preheatService.connectReferences( persistedObject, bundle.getPreheat(), bundle.getPreheatIdentifier() );
+ manager.update( persistedObject, bundle.getUser() );
+
+ objectBundleHooks.forEach( hook -> hook.postUpdate( persistedObject, bundle ) );
+
+ if ( log.isDebugEnabled() )
+ {
+ String msg = "Updated object '" + IdentifiableObjectUtils.getDisplayName( object ) + "'";
+ log.debug( msg );
+ }
+ }
}
private void handleDeletes( List<IdentifiableObject> objects, ObjectBundle bundle )
=== 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:27:18 +0000
+++ 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
@@ -30,6 +30,7 @@
import org.hisp.dhis.DhisSpringTest;
import org.hisp.dhis.attribute.Attribute;
+import org.hisp.dhis.common.IdScheme;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.MergeMode;
@@ -37,9 +38,11 @@
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.dataelement.DataElementGroup;
import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dxf2.metadata2.MetadataExportService;
import org.hisp.dhis.feedback.ErrorCode;
import org.hisp.dhis.feedback.ErrorReport;
import org.hisp.dhis.importexport.ImportStrategy;
+import org.hisp.dhis.node.NodeService;
import org.hisp.dhis.option.Option;
import org.hisp.dhis.option.OptionSet;
import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -75,6 +78,12 @@
private IdentifiableObjectManager manager;
@Autowired
+ private MetadataExportService metadataExportService;
+
+ @Autowired
+ private NodeService nodeService;
+
+ @Autowired
private RenderService _renderService;
@Override
@@ -610,6 +619,42 @@
assertEquals( 1, dataElements.get( 1 ).getUserGroupAccesses().size() );
}
+ @Test
+ public void testUpdateDataElements() throws IOException
+ {
+ defaultSetup();
+
+ Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(
+ new ClassPathResource( "dxf2/de_update1.json" ).getInputStream(), RenderFormat.JSON );
+
+ ObjectBundleParams params = new ObjectBundleParams();
+ params.setObjectBundleMode( ObjectBundleMode.COMMIT );
+ 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() );
+ }
+
private void defaultSetup()
{
DataElement de1 = createDataElement( 'A' );
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/dxf2/de_update1.json 2016-03-04 03:55:19 +0000
@@ -0,0 +1,84 @@
+{
+ "dataElements": [
+ {
+ "code": "DECA",
+ "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": "DECB",
+ "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": "DECC",
+ "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": "DECD",
+ "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