← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19888: DataValueSetService. Impl optio for requiring that the category option combo is part of the categ...

 

------------------------------------------------------------
revno: 19888
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2015-08-30 19:45:53 +0200
message:
  DataValueSetService. Impl optio for requiring that the category option combo is part of the category combo of the data element for data values during import.
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.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/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java
  dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetNonStrict.xml
  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-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java	2015-08-30 17:07:42 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ImportOptions.java	2015-08-30 17:45:53 +0000
@@ -70,6 +70,8 @@
     
     private Boolean strictPeriods;
 
+    private Boolean strictCategoryOptionCombos;
+    
     //--------------------------------------------------------------------------
     // Constructors
     //--------------------------------------------------------------------------
@@ -98,6 +100,11 @@
     {
         return strictPeriods != null;
     }
+    
+    public boolean hasStrictCategoryOptionCombos()
+    {
+        return strictCategoryOptionCombos != null;
+    }
 
     //--------------------------------------------------------------------------
     // Get methods
@@ -163,6 +170,11 @@
         return strictPeriods;
     }
 
+    public Boolean getStrictCategoryOptionCombos()
+    {
+        return strictCategoryOptionCombos;
+    }
+
     //--------------------------------------------------------------------------
     // Set methods
     //--------------------------------------------------------------------------
@@ -233,6 +245,12 @@
         return this;
     }
 
+    public ImportOptions setStrictCategoryOptionCombos( Boolean strictCategoryOptionCombos )
+    {
+        this.strictCategoryOptionCombos = strictCategoryOptionCombos;
+        return this;
+    }
+
     @Override
     public String toString()
     {
@@ -246,6 +264,7 @@
             add( "Import strategy", importStrategy ).
             add( "Skip existing check", skipExistingCheck ).
             add( "Sharing", sharing ).
-            add( "Strict periods", strictPeriods ).toString();
+            add( "Strict periods", strictPeriods ).
+            add( "Strict category option combos", strictCategoryOptionCombos ).toString();
     }
 }

=== 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-08-30 17:07:42 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2015-08-30 17:45:53 +0000
@@ -578,6 +578,8 @@
         
         boolean strictPeriods = importOptions.hasStrictPeriods() ? importOptions.getStrictPeriods() : 
             (Boolean) systemSettingManager.getSystemSetting( KEY_DATA_IMPORT_STRICT_PERIODS, false );
+        boolean strictCategoryOptionCombos = importOptions.hasStrictCategoryOptionCombos() ? importOptions.getStrictCategoryOptionCombos() :
+            (Boolean) systemSettingManager.getSystemSetting( KEY_DATA_IMPORT_STRICT_CATEGORY_OPTION_COMBOS, false );
         
         //----------------------------------------------------------------------
         // Create meta-data maps
@@ -588,6 +590,7 @@
         CachingMap<String, DataElementCategoryOptionCombo> optionComboMap = new CachingMap<>();
         CachingMap<String, Period> periodMap = new CachingMap<>();
         CachingMap<String, Set<PeriodType>> dataElementPeriodTypesMap = new CachingMap<>();
+        CachingMap<String, Set<DataElementCategoryOptionCombo>> dataElementCategoryOptionComboMap = new CachingMap<>();
         CachingMap<String, Boolean> orgUnitInHierarchyMap = new CachingMap<>();
 
         //----------------------------------------------------------------------
@@ -782,9 +785,19 @@
             // Constraints
             // -----------------------------------------------------------------
 
-            if ( strictPeriods && !dataElementPeriodTypesMap.get( dataValue.getDataElement(), () -> dataElement.getPeriodTypes() ).contains( period.getPeriodType() ) )
-            {
-                summary.getConflicts().add( new ImportConflict( dataValue.getPeriod(), "Period type of period: " + dataValue.getPeriod() + " not valid for data element: " + dataValue.getDataElement() ) );
+            if ( strictPeriods && !dataElementPeriodTypesMap.get( dataValue.getDataElement(), 
+                () -> dataElement.getPeriodTypes() ).contains( period.getPeriodType() ) )
+            {
+                summary.getConflicts().add( new ImportConflict( dataValue.getPeriod(), 
+                    "Period type of period: " + dataValue.getPeriod() + " not valid for data element: " + dataValue.getDataElement() ) );
+                continue;
+            }
+            
+            if ( strictCategoryOptionCombos && !dataElementCategoryOptionComboMap.get( dataValue.getDataElement(),
+                () -> dataElement.getCategoryCombo().getOptionCombos() ).contains( categoryOptionCombo ) )
+            {
+                summary.getConflicts().add( new ImportConflict( dataValue.getCategoryOptionCombo(), 
+                    "Category option combo: " + dataValue.getCategoryOptionCombo() + " must be part of category combo of data element: " + dataValue.getDataElement() ) );
                 continue;
             }
             

=== 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-08-30 17:07:42 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java	2015-08-30 17:45:53 +0000
@@ -103,6 +103,7 @@
     private DataElementCategoryOption categoryOptionA;
     private DataElementCategoryOption categoryOptionB;
     private DataElementCategory categoryA;
+    private DataElementCategoryCombo categoryComboDef;
     private DataElementCategoryCombo categoryComboA;
     private DataElementCategoryOptionCombo ocA;
     private DataElementCategoryOptionCombo ocB;
@@ -137,14 +138,15 @@
         categoryOptionB = createCategoryOption( 'B' );
         categoryA = createDataElementCategory( 'A', categoryOptionA, categoryOptionB );
         categoryComboA = createCategoryCombo( 'A', categoryA );
+        categoryComboDef = categoryService.getDefaultDataElementCategoryCombo();
         ocDef = categoryService.getDefaultDataElementCategoryOptionCombo();
         
         ocA = createCategoryOptionCombo( categoryComboA, categoryOptionA );
         ocB = createCategoryOptionCombo( categoryComboA, categoryOptionB );
-        deA = createDataElement( 'A' );
-        deB = createDataElement( 'B' );
-        deC = createDataElement( 'C' );
-        deD = createDataElement( 'D' );
+        deA = createDataElement( 'A', categoryComboDef );
+        deB = createDataElement( 'B', categoryComboDef );
+        deC = createDataElement( 'C', categoryComboDef );
+        deD = createDataElement( 'D', categoryComboDef );
         dsA = createDataSet( 'A', new MonthlyPeriodType() );
         ouA = createOrganisationUnit( 'A' );
         ouB = createOrganisationUnit( 'B' );
@@ -496,6 +498,24 @@
         assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
     }
 
+    @Test
+    public void testImportDataValuesWithNonStrictCategoryOptionCombos()
+        throws Exception
+    {
+        in = new ClassPathResource( "datavalueset/dataValueSetNonStrict.xml" ).getInputStream();
+
+        ImportOptions options = new ImportOptions().setStrictCategoryOptionCombos( true );
+
+        ImportSummary summary = dataValueSetService.saveDataValueSet( in, options );
+
+        assertEquals( summary.getConflicts().toString(), 1, summary.getConflicts().size() );
+        assertEquals( 2, summary.getImportCount().getImported() );
+        assertEquals( 0, summary.getImportCount().getUpdated() );
+        assertEquals( 0, summary.getImportCount().getDeleted() );
+        assertEquals( 1, summary.getImportCount().getIgnored() );
+        assertEquals( ImportStatus.SUCCESS, summary.getStatus() );
+    }
+
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetNonStrict.xml'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetNonStrict.xml	2015-08-30 17:07:42 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/resources/datavalueset/dataValueSetNonStrict.xml	2015-08-30 17:45:53 +0000
@@ -1,5 +1,5 @@
 <dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0"; dataSet="pBOMPrpg1QX" orgUnit="DiszpKrYNg8">
-    <dataValue dataElement="f7n9E0hX8qk" period="201201" value="10001" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+    <dataValue dataElement="f7n9E0hX8qk" period="201201" value="10001" categoryOptionCombo="kjuiHgy67hg" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
     <dataValue dataElement="Ix2HsbDMLea" period="2012Q2" value="10002" storedBy="john" timestamp="2012-01-02" comment="comment" followup="false"/>
     <dataValue dataElement="eY5ehpbEsB7" period="2012" value="10003" storedBy="john" timestamp="2012-01-03" comment="comment" followup="false"/>
 </dataValueSet>
\ No newline at end of file

=== 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	2015-08-22 15:04:37 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2015-08-30 17:45:53 +0000
@@ -491,11 +491,11 @@
         categoryOptionCombo.setAutoFields();
 
         categoryOptionCombo.setCategoryCombo( categoryCombo );
+        categoryCombo.getOptionCombos().add( categoryOptionCombo );
 
         for ( DataElementCategoryOption categoryOption : categoryOptions )
         {
             categoryOptionCombo.getCategoryOptions().add( categoryOption );
-
             categoryOption.getCategoryOptionCombos().add( categoryOptionCombo );
         }