← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16973: Data value set import, id scheme in xml fix

 

------------------------------------------------------------
revno: 16973
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-10-07 00:28:17 +0200
message:
  Data value set import, id scheme in xml fix
added:
  dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetACode.xml
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java
  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/StreamingDataValueSet.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingJsonDataValueSet.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java
  resources/sql/div.sql
  resources/sql/integritychecks.sql


--
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/DataValueSet.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java	2014-10-03 11:44:35 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java	2014-10-06 22:28:17 +0000
@@ -52,6 +52,20 @@
 @JacksonXmlRootElement(localName = "dataValueSet", namespace = DxfNamespaces.DXF_2_0)
 public class DataValueSet
 {
+    protected static final String FIELD_IDSCHEME = "idScheme";
+    protected static final String FIELD_DATAELEMENTIDSCHEME = "dataElementIdScheme";
+    protected static final String FIELD_ORGUNITIDSCHEME = "orgUnitIdScheme";
+    protected static final String FIELD_DRYRUN = "dryRun";
+    protected static final String FIELD_IMPORTSTRATEGY = "importStrategy";
+
+    protected static final String FIELD_DATAVALUESET = "dataValueSet";
+    protected static final String FIELD_DATAVALUE = "dataValue";
+    protected static final String FIELD_DATASET = "dataSet";
+    protected static final String FIELD_COMPLETEDATE = "completeDate";
+    protected static final String FIELD_PERIOD = "period";
+    protected static final String FIELD_ORGUNIT = "orgUnit";
+    protected static final String FIELD_ATTRIBUTE_OPTION_COMBO = "attributeOptionCombo";
+
     //--------------------------------------------------------------------------
     // Options
     //--------------------------------------------------------------------------
@@ -280,20 +294,25 @@
 
     public IdentifiableProperty getIdSchemeProperty()
     {
-        return idScheme != null ? IdentifiableProperty.valueOf( idScheme.toUpperCase() ) : null;
+        String scheme = getIdScheme();
+        return scheme != null ? IdentifiableProperty.valueOf( scheme.toUpperCase() ) : null;
     }
     
     public IdentifiableProperty getDataElementIdSchemeProperty()
     {
-        String scheme = defaultIfEmpty( idScheme, dataElementIdScheme );
+        String scheme = getIdScheme();
+        String dataElementScheme = getDataElementIdScheme();
         
+        scheme = defaultIfEmpty( scheme, dataElementScheme );        
         return scheme != null ? IdentifiableProperty.valueOf( scheme.toUpperCase() ) : null;
     }
 
     public IdentifiableProperty getOrgUnitIdSchemeProperty()
     {
-        String scheme = defaultIfEmpty( idScheme, orgUnitIdScheme );
+        String scheme = getIdScheme();
+        String orgUnitScheme = getOrgUnitIdScheme();
         
+        scheme = defaultIfEmpty( scheme, orgUnitScheme );        
         return scheme != null ? IdentifiableProperty.valueOf( scheme.toUpperCase() ) : null;
     }
 

=== 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	2014-10-03 11:44:35 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2014-10-06 22:28:17 +0000
@@ -508,15 +508,15 @@
 
         importOptions = importOptions != null ? importOptions : ImportOptions.getDefaultImportOptions();
 
+        IdentifiableProperty idScheme = dataValueSet.getIdSchemeProperty() != null ?
+            dataValueSet.getIdSchemeProperty() : importOptions.getIdScheme();
+                    
         IdentifiableProperty dataElementIdScheme = dataValueSet.getDataElementIdSchemeProperty() != null ?
             dataValueSet.getDataElementIdSchemeProperty() : importOptions.getDataElementIdScheme();
-            
+                
         IdentifiableProperty orgUnitIdScheme = dataValueSet.getOrgUnitIdSchemeProperty() != null ?
             dataValueSet.getOrgUnitIdSchemeProperty() : importOptions.getOrgUnitIdScheme();
             
-        IdentifiableProperty idScheme = dataValueSet.getIdSchemeProperty() != null ?
-            dataValueSet.getIdSchemeProperty() : importOptions.getIdScheme();
-        
         log.info( "Data element scheme: " + dataElementIdScheme + ", org unit scheme: " + orgUnitIdScheme + ", scheme: " + idScheme );
             
         boolean dryRun = dataValueSet.getDryRun() != null ? dataValueSet.getDryRun() : importOptions.isDryRun();

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingDataValueSet.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingDataValueSet.java	2014-07-22 16:44:27 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingDataValueSet.java	2014-10-06 22:28:17 +0000
@@ -40,19 +40,6 @@
     private static final String NS = "http://dhis2.org/schema/dxf/2.0";;
     private static final String TRUE = "true";
 
-    private static final String FIELD_DATAELEMENTIDSCHEME = "dataElementIdScheme";
-    private static final String FIELD_ORGUNITIDSCHEME = "orgUnitIdScheme";
-    private static final String FIELD_DRYRUN = "dryRun";
-    private static final String FIELD_IMPORTSTRATEGY = "importStrategy";
-
-    private static final String FIELD_DATAVALUESET = "dataValueSet";
-    private static final String FIELD_DATAVALUE = "dataValue";
-    private static final String FIELD_DATASET = "dataSet";
-    private static final String FIELD_COMPLETEDATE = "completeDate";
-    private static final String FIELD_PERIOD = "period";
-    private static final String FIELD_ORGUNIT = "orgUnit";
-    private static final String FIELD_ATTRIBUTE_OPTION_COMBO = "attributeOptionCombo";
-
     private XMLWriter writer;
 
     private XMLReader reader;
@@ -81,6 +68,12 @@
     //--------------------------------------------------------------------------
 
     @Override
+    public String getIdScheme()
+    {
+        return idScheme = idScheme == null ? reader.getAttributeValue( FIELD_IDSCHEME ) : idScheme;
+    }
+    
+    @Override
     public String getDataElementIdScheme()
     {
         return dataElementIdScheme = dataElementIdScheme == null ? reader.getAttributeValue( FIELD_DATAELEMENTIDSCHEME ) : dataElementIdScheme;
@@ -95,7 +88,7 @@
     @Override
     public Boolean getDryRun()
     {
-        return dryRun = dryRun == null ? (TRUE.equals( reader.getAttributeValue( FIELD_DRYRUN ) ) ? Boolean.TRUE : null) : dryRun;
+        return dryRun = dryRun == null ? ( TRUE.equals( reader.getAttributeValue( FIELD_DRYRUN ) ) ? Boolean.TRUE : null ) : dryRun;
     }
 
     @Override
@@ -151,6 +144,12 @@
     //--------------------------------------------------------------------------
 
     @Override
+    public void setIdScheme( String idScheme )
+    {
+        writer.writeAttribute( FIELD_IDSCHEME, idScheme );
+    }
+    
+    @Override
     public void setDataElementIdScheme( String dataElementIdScheme )
     {
         writer.writeAttribute( FIELD_DATAELEMENTIDSCHEME, dataElementIdScheme );

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingJsonDataValueSet.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingJsonDataValueSet.java	2014-07-22 16:44:27 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingJsonDataValueSet.java	2014-10-06 22:28:17 +0000
@@ -62,41 +62,43 @@
     @Override
     public void setDataElementIdScheme( String dataElementIdScheme )
     {
+        writeObjectField( FIELD_DATAELEMENTIDSCHEME, dataElementIdScheme );
     }
 
     @Override
     public void setOrgUnitIdScheme( String orgUnitIdScheme )
     {
+        writeObjectField( FIELD_ORGUNITIDSCHEME, orgUnitIdScheme );
     }
 
     @Override
     public void setDataSet( String dataSet )
     {
-        writeObjectField( "dataSet", dataSet );
+        writeObjectField( FIELD_DATASET, dataSet );
     }
 
     @Override
     public void setCompleteDate( String completeDate )
     {
-        writeObjectField( "completeDate", completeDate );
+        writeObjectField( FIELD_COMPLETEDATE, completeDate );
     }
 
     @Override
     public void setPeriod( String period )
     {
-        writeObjectField( "period", period );
+        writeObjectField( FIELD_PERIOD, period );
     }
 
     @Override
     public void setOrgUnit( String orgUnit )
     {
-        writeObjectField( "orgUnit", orgUnit );
+        writeObjectField( FIELD_ORGUNIT, orgUnit );
     }
 
     @Override
     public void setAttributeOptionCombo( String attributeOptionCombo )
     {
-        writeObjectField( "attributeOptionCombo", attributeOptionCombo );
+        writeObjectField( FIELD_ATTRIBUTE_OPTION_COMBO, attributeOptionCombo );
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java	2014-10-03 11:44:35 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/ImportOptions.java	2014-10-06 22:28:17 +0000
@@ -40,6 +40,9 @@
  */
 public class ImportOptions
 {
+    private static final ImportOptions DEFAULT_OPTIONS = new ImportOptions( 
+        IdentifiableProperty.UID, IdentifiableProperty.UID, false, true, ImportStrategy.NEW_AND_UPDATES, false );
+
     private IdentifiableProperty idScheme;
     
     private IdentifiableProperty dataElementIdScheme = IdentifiableProperty.UID;
@@ -56,12 +59,9 @@
 
     private boolean skipExistingCheck;
 
-    private static final ImportOptions DEFAULT_OPTIONS = new ImportOptions( IdentifiableProperty.UID, IdentifiableProperty.UID, false, true, ImportStrategy.NEW_AND_UPDATES, false );
-
-    public static ImportOptions getDefaultImportOptions()
-    {
-        return DEFAULT_OPTIONS;
-    }
+    //--------------------------------------------------------------------------
+    // Constructors
+    //--------------------------------------------------------------------------
 
     public ImportOptions()
     {
@@ -72,7 +72,8 @@
         this.importStrategy = importStrategy;
     }
 
-    public ImportOptions( IdentifiableProperty dataElementIdScheme, IdentifiableProperty orgUnitIdScheme, boolean dryRun, boolean preheatCache, ImportStrategy importStrategy, boolean skipExistingCheck )
+    public ImportOptions( IdentifiableProperty dataElementIdScheme, IdentifiableProperty orgUnitIdScheme, 
+        boolean dryRun, boolean preheatCache, ImportStrategy importStrategy, boolean skipExistingCheck )
     {
         this.dataElementIdScheme = dataElementIdScheme;
         this.orgUnitIdScheme = orgUnitIdScheme;
@@ -83,6 +84,15 @@
     }
 
     //--------------------------------------------------------------------------
+    // Logic
+    //--------------------------------------------------------------------------
+
+    public static ImportOptions getDefaultImportOptions()
+    {
+        return DEFAULT_OPTIONS;
+    }
+
+    //--------------------------------------------------------------------------
     // Get methods
     //--------------------------------------------------------------------------
 

=== 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	2014-10-03 11:44:35 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java	2014-10-06 22:28:17 +0000
@@ -175,7 +175,7 @@
         periodService.addPeriod( peA );
         periodService.addPeriod( peB );        
     }
-    
+
     @Test
     public void testImportDataValueSetXml()
         throws Exception
@@ -201,7 +201,33 @@
         assertEquals( ouA, registration.getSource() );
         assertEquals( getDate( 2012, 1, 9 ), registration.getDate() );
     }
-    
+
+    @Test
+    public void testImportDataValuesXmlWithCodeA()
+        throws Exception
+    {
+        ImportSummary summary = dataValueSetService.saveDataValueSet( new ClassPathResource( "datavalueset/dataValueSetACode.xml" ).getInputStream() );
+        
+        assertNotNull( summary );
+        assertNotNull( summary.getDataValueCount() );
+        
+        Collection<DataValue> dataValues = dataValueService.getAllDataValues();
+        
+        assertNotNull( dataValues );
+        assertEquals( 3, dataValues.size() );
+        assertTrue( dataValues.contains( new DataValue( deA, peA, ouA, ocDef, ocDef ) ) );
+        assertTrue( dataValues.contains( new DataValue( deB, peA, ouA, ocDef, ocDef ) ) );
+        assertTrue( dataValues.contains( new DataValue( deC, peA, ouA, ocDef, ocDef ) ) );
+        
+        CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration( dsA, peA, ouA, ocDef );
+        
+        assertNotNull( registration );
+        assertEquals( dsA, registration.getDataSet() );
+        assertEquals( peA, registration.getPeriod() );
+        assertEquals( ouA, registration.getSource() );
+        assertEquals( getDate( 2012, 1, 9 ), registration.getDate() );
+    }
+
     @Test
     public void testImportDataValuesXml()
         throws Exception
@@ -210,9 +236,9 @@
         
         assertImportDataValues( summary );
     }
-    
+
     @Test
-    public void testImportDataValuesXmlWithCode()
+    public void testImportDataValuesXmlWithCodeB()
         throws Exception
     {
         ImportOptions options = new ImportOptions( CODE, CODE, false, true, NEW_AND_UPDATES, false );

=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetACode.xml'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetACode.xml	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetACode.xml	2014-10-06 22:28:17 +0000
@@ -0,0 +1,5 @@
+<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0"; idScheme="code" dataSet="DS_A" completeDate="2012-01-09" period="201201" orgUnit="OU_A">
+    <dataValue dataElement="DE_A" value="10001" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+    <dataValue dataElement="DE_B" value="10002" storedBy="john" timestamp="2012-01-02" comment="comment" followup="false"/>
+    <dataValue dataElement="DE_C" value="10003" storedBy="john" timestamp="2012-01-03" comment="comment" followup="false"/>
+</dataValueSet>
\ No newline at end of file

=== modified file 'resources/sql/div.sql'
--- resources/sql/div.sql	2014-10-06 18:10:46 +0000
+++ resources/sql/div.sql	2014-10-06 22:28:17 +0000
@@ -165,7 +165,7 @@
 
 -- Display overview of category option combo
 
-select coc.categoryoptioncomboid as coc_id, coc.uid as coc_uid, co.categoryoptionid as co_id, co.name as co_name, cc.categorycomboid as cc_id, cc.name as cc_name
+select coc.categoryoptioncomboid as coc_id, coc.uid as coc_uid, co.categoryoptionid as co_id, co.name as co_name, ca.categoryid as ca_id, ca.name as ca_name, cc.categorycomboid as cc_id, cc.name as cc_name
 from categoryoptioncombo coc 
 inner join categoryoptioncombos_categoryoptions coo on coc.categoryoptioncomboid=coo.categoryoptioncomboid
 inner join dataelementcategoryoption co on coo.categoryoptionid=co.categoryoptionid

=== modified file 'resources/sql/integritychecks.sql'
--- resources/sql/integritychecks.sql	2014-10-05 14:09:41 +0000
+++ resources/sql/integritychecks.sql	2014-10-06 22:28:17 +0000
@@ -137,6 +137,10 @@
 
 select categoryid, categoryoptionid, count(*) from categories_categoryoptions group by categoryid, categoryoptionid having count(*) > 1;
 
+-- Get categories with more than one membership for a category combination
+
+select categorycomboid, categoryid, count(*) from categorycombos_categories group by categorycomboid, categoryid having count(*) > 1;
+
 -- Get category options with count of memberships in categories
 
 select cc.categoryoptionid, co.name, (