← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18342: Data value import, reading outer org unit from map

 

------------------------------------------------------------
revno: 18342
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-02-19 23:12:40 +0100
message:
  Data value import, reading outer org unit from map
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.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/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2015-02-19 16:52:45 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2015-02-19 22:12:40 +0000
@@ -592,14 +592,14 @@
 
         I18n i18n = i18nManager.getI18n();
 
+        //----------------------------------------------------------------------
+        // Get import options
+        //----------------------------------------------------------------------
+
         importOptions = importOptions != null ? importOptions : ImportOptions.getDefaultImportOptions();
 
         log.info( "Import options: " + importOptions );
 
-        //----------------------------------------------------------------------
-        // Get id scheme
-        //----------------------------------------------------------------------
-
         IdentifiableProperty dvSetIdScheme = dataValueSet.getIdSchemeProperty();
         IdentifiableProperty dvSetDataElementIdScheme = dataValueSet.getDataElementIdSchemeProperty();
         IdentifiableProperty dvSetOrgUnitIdScheme = dataValueSet.getOrgUnitIdSchemeProperty();
@@ -615,8 +615,7 @@
         boolean dryRun = dataValueSet.getDryRun() != null ? dataValueSet.getDryRun() : importOptions.isDryRun();
 
         ImportStrategy strategy = dataValueSet.getStrategy() != null ?
-            ImportStrategy.valueOf( dataValueSet.getStrategy() ) :
-            importOptions.getImportStrategy();
+            ImportStrategy.valueOf( dataValueSet.getStrategy() ) : importOptions.getImportStrategy();
 
         boolean skipExistingCheck = importOptions.isSkipExistingCheck();
 
@@ -629,26 +628,22 @@
         Map<String, DataElementCategoryOptionCombo> categoryOptionComboMap = identifiableObjectManager.getIdMap( DataElementCategoryOptionCombo.class, idScheme );
         Map<String, Period> periodMap = new HashMap<>();
 
+        //----------------------------------------------------------------------
+        // Get outer meta-data
+        //----------------------------------------------------------------------
+
         DataSet dataSet = dataValueSet.getDataSet() != null ? identifiableObjectManager.getObject( DataSet.class, idScheme, dataValueSet.getDataSet() ) : null;
+        
         Date completeDate = getDefaultDate( dataValueSet.getCompleteDate() );
 
         Period outerPeriod = PeriodType.getPeriodFromIsoString( trimToNull( dataValueSet.getPeriod() ) );
 
-        OrganisationUnit outerOrgUnit = null;
+        OrganisationUnit outerOrgUnit = dataValueSet.getOrgUnit() != null ? orgUnitMap.get( dataValueSet.getOrgUnit() ) : null;
 
         DataElementCategoryOptionCombo fallbackCategoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
 
-        if ( orgUnitIdScheme.equals( IdentifiableProperty.UUID ) )
-        {
-            outerOrgUnit = dataValueSet.getOrgUnit() == null ? null : organisationUnitService.getOrganisationUnitByUuid( dataValueSet.getOrgUnit() );
-        }
-        else
-        {
-            outerOrgUnit = dataValueSet.getOrgUnit() != null ? identifiableObjectManager.getObject( OrganisationUnit.class, orgUnitIdScheme, dataValueSet.getOrgUnit() ) : null;
-        }
-
-        DataElementCategoryOptionCombo outerAttrOptionCombo = dataValueSet.getAttributeOptionCombo() != null ?
-            identifiableObjectManager.getObject( DataElementCategoryOptionCombo.class, idScheme, trimToNull( dataValueSet.getAttributeOptionCombo() ) ) : null;
+        DataElementCategoryOptionCombo outerAttrOptionCombo = 
+            dataValueSet.getAttributeOptionCombo() != null ? categoryOptionComboMap.get( dataValueSet.getAttributeOptionCombo() ) : null;
 
         // ---------------------------------------------------------------------
         // Validation

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java	2015-02-19 16:52:45 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java	2015-02-19 22:12:40 +0000
@@ -196,6 +196,7 @@
         assertNotNull( summary );
         assertNotNull( summary.getDataValueCount() );
         assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
+        assertEquals( 0, summary.getConflicts().size() );
         
         Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
         
@@ -225,6 +226,7 @@
         assertNotNull( summary );
         assertNotNull( summary.getDataValueCount() );
         assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
+        assertEquals( 0, summary.getConflicts().size() );
 
         Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
         
@@ -252,6 +254,7 @@
         ImportSummary summary = dataValueSetService.saveDataValueSet( in );
 
         assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
+        assertEquals( 0, summary.getConflicts().size() );
         
         assertImportDataValues( summary );
     }
@@ -266,6 +269,7 @@
         ImportSummary summary = dataValueSetService.saveDataValueSet( in, options );
 
         assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
+        assertEquals( 0, summary.getConflicts().size() );
         
         assertImportDataValues( summary );
     }
@@ -279,6 +283,7 @@
         ImportSummary summary = dataValueSetService.saveDataValueSetCsv( in, null, null );
 
         assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
+        assertEquals( 0, summary.getConflicts().size() );
         
         assertImportDataValues( summary );
     }
@@ -294,6 +299,7 @@
         ImportSummary summary = dataValueSetService.saveDataValueSet( in, options );
 
         assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
+        assertEquals( 0, summary.getConflicts().size() );
         
         Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
         
@@ -312,6 +318,7 @@
         ImportSummary summary = dataValueSetService.saveDataValueSet( in, options );
 
         assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
+        assertEquals( 0, summary.getConflicts().size() );
         
         Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
         
@@ -326,6 +333,7 @@
         ImportSummary summary = dataValueSetService.saveDataValueSet( new ClassPathResource( "datavalueset/dataValueSetC.xml" ).getInputStream() );
 
         assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
+        assertEquals( 0, summary.getConflicts().size() );
         
         Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
         
@@ -342,6 +350,7 @@
         ImportSummary summary = dataValueSetService.saveDataValueSet( in );
 
         assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
+        assertEquals( 0, summary.getConflicts().size() );
         
         Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
         
@@ -359,6 +368,7 @@
         in = new ClassPathResource( "datavalueset/dataValueSetF.xml" ).getInputStream();
         
         ImportSummary summary = dataValueSetService.saveDataValueSet( in );
+        assertEquals( 0, summary.getConflicts().size() );
 
         Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();