← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21685: add mapping fra categories.combos <=> combos.categories, wip

 

------------------------------------------------------------
revno: 21685
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2016-01-11 13:09:26 +0700
message:
  add mapping fra categories.combos <=> combos.categories, wip
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategory.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryDeletionHandler.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryComboServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboStoreTest.java
  dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/AddDataElementCategoryAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/UpdateDataElementCategoryAction.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-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategory.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategory.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategory.java	2016-01-11 06:09:26 +0000
@@ -35,7 +35,6 @@
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 import com.google.common.collect.Lists;
-
 import org.hisp.dhis.common.BaseDimensionalItemObject;
 import org.hisp.dhis.common.BaseDimensionalObject;
 import org.hisp.dhis.common.BaseIdentifiableObject;
@@ -51,7 +50,9 @@
 import org.hisp.dhis.common.view.ExportView;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 /**
  * A Category is a dimension of a data element. DataElements can have sets of
@@ -72,6 +73,8 @@
     @Scanned
     private List<DataElementCategoryOption> categoryOptions = new ArrayList<>();
 
+    private Set<DataElementCategoryCombo> categoryCombos = new HashSet<>();
+
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -96,13 +99,13 @@
     // Logic
     // -------------------------------------------------------------------------
 
-    public void addDataElementCategoryOption( DataElementCategoryOption dataElementCategoryOption )
+    public void addCategoryOption( DataElementCategoryOption dataElementCategoryOption )
     {
         categoryOptions.add( dataElementCategoryOption );
         dataElementCategoryOption.getCategories().add( this );
     }
 
-    public void removeDataElementCategoryOption( DataElementCategoryOption dataElementCategoryOption )
+    public void removeCategoryOption( DataElementCategoryOption dataElementCategoryOption )
     {
         categoryOptions.remove( dataElementCategoryOption );
         dataElementCategoryOption.getCategories().remove( this );
@@ -118,6 +121,28 @@
         categoryOptions.clear();
     }
 
+    public void addCategoryCombo( DataElementCategoryCombo categoryCombo )
+    {
+        categoryCombos.add( categoryCombo );
+        categoryCombo.getCategories().add( this );
+    }
+
+    public void removeCategoryCombo( DataElementCategoryCombo categoryCombo )
+    {
+        categoryCombos.remove( categoryCombo );
+        categoryCombo.getCategories().remove( this );
+    }
+
+    public void removeAllCategoryCombos()
+    {
+        for ( DataElementCategoryCombo categoryCombo : categoryCombos )
+        {
+            categoryCombo.getCategories().remove( this );
+        }
+
+        categoryCombos.clear();
+    }
+
     public DataElementCategoryOption getCategoryOption( DataElementCategoryOptionCombo categoryOptionCombo )
     {
         for ( DataElementCategoryOption categoryOption : categoryOptions )
@@ -212,6 +237,21 @@
         this.categoryOptions = categoryOptions;
     }
 
+    @JsonProperty
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+    @JsonView( { DetailedView.class, ExportView.class } )
+    @JacksonXmlElementWrapper( localName = "categoryCombos", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "categoryCombo", namespace = DxfNamespaces.DXF_2_0 )
+    public Set<DataElementCategoryCombo> getCategoryCombos()
+    {
+        return categoryCombos;
+    }
+
+    public void setCategoryCombos( Set<DataElementCategoryCombo> categoryCombos )
+    {
+        this.categoryCombos = categoryCombos;
+    }
+
     @Override
     public void mergeWith( IdentifiableObject other, MergeStrategy strategy )
     {
@@ -231,11 +271,10 @@
             }
 
             removeAllCategoryOptions();
+            removeAllCategoryCombos();
 
-            for ( DataElementCategoryOption dataElementCategoryOption : category.getCategoryOptions() )
-            {
-                addDataElementCategoryOption( dataElementCategoryOption );
-            }
+            category.getCategoryOptions().forEach( this::addCategoryOption );
+            category.getCategoryCombos().forEach( this::addCategoryCombo );
         }
     }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java	2016-01-06 12:12:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java	2016-01-11 06:09:26 +0000
@@ -240,18 +240,25 @@
     // Logic
     // -------------------------------------------------------------------------
 
-    public void addDataElementCategory( DataElementCategory dataElementCategory )
-    {
-        categories.add( dataElementCategory );
-    }
-
-    public void removeDataElementCategory( DataElementCategory dataElementCategory )
-    {
-        categories.remove( dataElementCategory );
-    }
-
-    public void removeAllDataElementCategories()
-    {
+    public void addDataElementCategory( DataElementCategory category )
+    {
+        categories.add( category );
+        category.getCategoryCombos().add( this );
+    }
+
+    public void removeDataElementCategory( DataElementCategory category )
+    {
+        categories.remove( category );
+        category.getCategoryCombos().remove( this );
+    }
+
+    public void removeAllCategories()
+    {
+        for ( DataElementCategory category : categories )
+        {
+            category.getCategoryCombos().remove( this );
+        }
+
         categories.clear();
     }
 
@@ -335,12 +342,8 @@
                 dataDimensionType = categoryCombo.getDataDimensionType() == null ? dataDimensionType : categoryCombo.getDataDimensionType();
             }
 
-            removeAllDataElementCategories();
-
-            for ( DataElementCategory dataElementCategory : categoryCombo.getCategories() )
-            {
-                addDataElementCategory( dataElementCategory );
-            }
+            removeAllCategories();
+            categoryCombo.getCategories().forEach( this::addDataElementCategory );
         }
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryDeletionHandler.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryDeletionHandler.java	2016-01-11 06:09:26 +0000
@@ -60,7 +60,7 @@
 
         for ( DataElementCategory category : categories )
         {
-            category.removeDataElementCategoryOption( categoryOption );
+            category.removeCategoryOption( categoryOption );
             idObjectManager.updateNoAcl( category );
         }
     }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java	2016-01-11 06:09:26 +0000
@@ -620,7 +620,7 @@
         // ---------------------------------------------------------------------
 
         DataElementCategory category = new DataElementCategory( DataElementCategory.DEFAULT_NAME );
-        category.addDataElementCategoryOption( categoryOption );
+        category.addCategoryOption( categoryOption );
         addDataElementCategory( category );
 
         // ---------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryComboServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryComboServiceTest.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryComboServiceTest.java	2016-01-11 06:09:26 +0000
@@ -98,12 +98,12 @@
         categoryB = new DataElementCategory( "CategoryB" );
         categoryC = new DataElementCategory( "CategoryC" );
         
-        categoryA.addDataElementCategoryOption( categoryOptionA );
-        categoryA.addDataElementCategoryOption( categoryOptionB );
-        categoryB.addDataElementCategoryOption( categoryOptionC );
-        categoryB.addDataElementCategoryOption( categoryOptionD );
-        categoryC.addDataElementCategoryOption( categoryOptionE );
-        categoryC.addDataElementCategoryOption( categoryOptionF );
+        categoryA.addCategoryOption( categoryOptionA );
+        categoryA.addCategoryOption( categoryOptionB );
+        categoryB.addCategoryOption( categoryOptionC );
+        categoryB.addCategoryOption( categoryOptionD );
+        categoryC.addCategoryOption( categoryOptionE );
+        categoryC.addCategoryOption( categoryOptionF );
         
         categoryService.addDataElementCategory( categoryA );
         categoryService.addDataElementCategory( categoryB );
@@ -212,7 +212,7 @@
         assertEquals( 8, categoryComboA.getOptionCombos().size() );
         assertOptionCombos( categoryComboA.getOptionCombos() );
         
-        categoryC.addDataElementCategoryOption( categoryOptionG );
+        categoryC.addCategoryOption( categoryOptionG );
         categoryService.updateDataElementCategory( categoryC );
         
         categoryService.updateOptionCombos( categoryComboA );
@@ -258,7 +258,7 @@
         assertEquals( 8, categoryComboA.getOptionCombos().size() );
         assertOptionCombos( categoryComboA.getOptionCombos() );
         
-        categoryC.addDataElementCategoryOption( categoryOptionG );
+        categoryC.addCategoryOption( categoryOptionG );
         categoryService.updateDataElementCategory( categoryC );
         
         categoryService.updateOptionCombos( categoryC );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboServiceTest.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboServiceTest.java	2016-01-11 06:09:26 +0000
@@ -88,10 +88,10 @@
         categoryA = new DataElementCategory( "Gender" );
         categoryB = new DataElementCategory( "Agegroup" );
         
-        categoryA.addDataElementCategoryOption( categoryOptionA );
-        categoryA.addDataElementCategoryOption( categoryOptionB );        
-        categoryB.addDataElementCategoryOption( categoryOptionC );
-        categoryB.addDataElementCategoryOption( categoryOptionD );
+        categoryA.addCategoryOption( categoryOptionA );
+        categoryA.addCategoryOption( categoryOptionB );
+        categoryB.addCategoryOption( categoryOptionC );
+        categoryB.addCategoryOption( categoryOptionD );
         
         categoryService.addDataElementCategory( categoryA );
         categoryService.addDataElementCategory( categoryB );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboStoreTest.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboStoreTest.java	2016-01-11 06:09:26 +0000
@@ -90,10 +90,10 @@
         categoryA = new DataElementCategory( "Gender" );
         categoryB = new DataElementCategory( "Agegroup" );
         
-        categoryA.addDataElementCategoryOption( categoryOptionA );
-        categoryA.addDataElementCategoryOption( categoryOptionB );        
-        categoryB.addDataElementCategoryOption( categoryOptionC );
-        categoryB.addDataElementCategoryOption( categoryOptionD );
+        categoryA.addCategoryOption( categoryOptionA );
+        categoryA.addCategoryOption( categoryOptionB );
+        categoryB.addCategoryOption( categoryOptionC );
+        categoryB.addCategoryOption( categoryOptionD );
         
         categoryService.addDataElementCategory( categoryA );
         categoryService.addDataElementCategory( categoryB );

=== 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	2016-01-08 22:18:47 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2016-01-11 06:09:26 +0000
@@ -533,7 +533,7 @@
 
         for ( DataElementCategoryOption categoryOption : categoryOptions )
         {
-            dataElementCategory.addDataElementCategoryOption( categoryOption );
+            dataElementCategory.addCategoryOption( categoryOption );
         }
 
         return dataElementCategory;

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/AddDataElementCategoryAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/AddDataElementCategoryAction.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/AddDataElementCategoryAction.java	2016-01-11 06:09:26 +0000
@@ -109,7 +109,7 @@
 
         for ( String id : coSelected )
         {
-            dataElementCategory.addDataElementCategoryOption( dataElementCategoryService.getDataElementCategoryOption( id ) );
+            dataElementCategory.addCategoryOption( dataElementCategoryService.getDataElementCategoryOption( id ) );
         }
 
         dataElementCategoryService.addDataElementCategory( dataElementCategory );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/UpdateDataElementCategoryAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/UpdateDataElementCategoryAction.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/UpdateDataElementCategoryAction.java	2016-01-11 06:09:26 +0000
@@ -110,7 +110,7 @@
         
         for ( String id : coSelected )
         {
-            dataElementCategory.addDataElementCategoryOption( dataElementCategoryService.getDataElementCategoryOption( id ) );
+            dataElementCategory.addCategoryOption( dataElementCategoryService.getDataElementCategoryOption( id ) );
         }
 
         dataElementCategoryService.updateDataElementCategory( dataElementCategory );