← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 873: Changed the category - categoryoption assocication from unidirectional n-m to bidirectional 1-n. ...

 

------------------------------------------------------------
revno: 873
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Fri 2009-10-16 14:26:29 +0200
message:
  Changed the category - categoryoption assocication from unidirectional n-m to bidirectional 1-n. Fixed test errors in importexport module related to the new sorting of categories. Fixed compilation errors in the ReportExcel api.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelCategory.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelNormal.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelOganiztionGroupListing.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelPeriodColumnListing.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategory.hbm.xml
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryCombo.hbm.xml
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOption.hbm.xml
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryCategoryOptionAssociationConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryComboCategoryAssociationConverter.java
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/CategoryCategoryOptionAssociationBatchHandler.java
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/CategoryComboCategoryAssociationBatchHandler.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/DataElementCategoryOption.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java	2009-10-05 16:07:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java	2009-10-16 12:26:29 +0000
@@ -27,8 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.Serializable;
-
 import org.hisp.dhis.common.IdentifiableObject;
 
 /**
@@ -37,10 +35,10 @@
  */
 public class DataElementCategoryOption
     extends IdentifiableObject
-    implements Serializable
 {
     public static final String DEFAULT_NAME = "default";
     
+    private DataElementCategory category;
     
     // -------------------------------------------------------------------------
     // Constructors
@@ -106,4 +104,18 @@
     {
         return "[" + name + "]";
     }
+
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+
+    public DataElementCategory getCategory()
+    {
+        return category;
+    }
+
+    public void setCategory( DataElementCategory category )
+    {
+        this.category = category;
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelCategory.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelCategory.java	2009-09-18 04:47:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelCategory.java	2009-10-16 12:26:29 +0000
@@ -27,10 +27,6 @@
 package org.hisp.dhis.reportexcel;
 
 import java.util.List;
-import java.util.Set;
-
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.user.UserAuthorityGroup;
 
 /**
  * @author Tran Thanh Tri
@@ -50,14 +46,6 @@
         super();        
     }
 
-    public ReportExcelCategory( String name, String excelTemplateFile, int periodRow, int periodColumn, int organisationRow,
-        int organisationColumn, Set<ReportExcelItem> reportItems, Set<OrganisationUnit> organisationAssocitions,
-        Set<UserAuthorityGroup> userRoles, String group )
-    {
-        super( name, excelTemplateFile, periodRow, periodColumn, organisationRow, organisationColumn, reportItems,
-            organisationAssocitions, userRoles, group );        
-    }
-
     // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelNormal.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelNormal.java	2009-09-15 13:18:11 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelNormal.java	2009-10-16 12:26:29 +0000
@@ -1,9 +1,5 @@
 package org.hisp.dhis.reportexcel;
 
-import java.util.Set;
-
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.user.UserAuthorityGroup;
 
 public class ReportExcelNormal
     extends ReportExcel
@@ -16,15 +12,7 @@
     {
         super();
     }
-
-    public ReportExcelNormal( String name, String excelTemplateFile, int periodRow, int periodColumn, int organisationRow,
-        int organisationColumn, Set<ReportExcelItem> reportItems, Set<OrganisationUnit> organisationAssocitions,
-        Set<UserAuthorityGroup> userRoles, String group )
-    {
-        super( name, excelTemplateFile, periodRow, periodColumn, organisationRow, organisationColumn, reportItems,
-            organisationAssocitions, userRoles, group );
-    }
-
+    
     @Override
     public String getReportType()
     {       

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelOganiztionGroupListing.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelOganiztionGroupListing.java	2009-09-15 13:18:11 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelOganiztionGroupListing.java	2009-10-16 12:26:29 +0000
@@ -52,14 +52,6 @@
         super();       
     }
 
-    public ReportExcelOganiztionGroupListing( String name, String excelTemplateFile, int periodRow, int periodColumn,
-        int organisationRow, int organisationColumn, Set<ReportExcelItem> reportItems,
-        Set<OrganisationUnit> organisationAssocitions, Set<UserAuthorityGroup> userRoles, String group )
-    {
-        super( name, excelTemplateFile, periodRow, periodColumn, organisationRow, organisationColumn, reportItems,
-            organisationAssocitions, userRoles, group );        
-    }
-
     // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelPeriodColumnListing.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelPeriodColumnListing.java	2009-09-15 13:18:11 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportExcelPeriodColumnListing.java	2009-10-16 12:26:29 +0000
@@ -26,10 +26,6 @@
  */
 package org.hisp.dhis.reportexcel;
 
-import java.util.Set;
-
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.user.UserAuthorityGroup;
 
 /**
  * @author Tran Thanh Tri
@@ -47,14 +43,6 @@
         super();
     }
 
-    public ReportExcelPeriodColumnListing( String name, String excelTemplateFile, int periodRow, int periodColumn,
-        int organisationRow, int organisationColumn, Set<ReportExcelItem> reportItems,
-        Set<OrganisationUnit> organisationAssocitions, Set<UserAuthorityGroup> userRoles, String group )
-    {
-        super( name, excelTemplateFile, periodRow, periodColumn, organisationRow, organisationColumn, reportItems,
-            organisationAssocitions, userRoles, group );
-    }
-
     @Override
     public String getReportType()
     {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategory.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategory.hbm.xml	2009-10-13 20:08:57 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategory.hbm.xml	2009-10-16 12:26:29 +0000
@@ -22,7 +22,7 @@
       <key column="categoryid"/>
       <list-index column="sort_order"/>
       <many-to-many class="org.hisp.dhis.dataelement.DataElementCategoryOption" 
-        column="categoryoptionid" foreign-key="fk_category_categoryoptionid"/>
+        column="categoryoptionid" foreign-key="fk_category_categoryoptionid" unique="true"/>
     </list>    
         
   </class>

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryCombo.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryCombo.hbm.xml	2009-10-15 18:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryCombo.hbm.xml	2009-10-16 12:26:29 +0000
@@ -24,7 +24,7 @@
     <set name="optionCombos" table="categorycombos_optioncombos" inverse="true" cascade="all">
       <key column="categorycomboid"/>
       <many-to-many class="org.hisp.dhis.dataelement.DataElementCategoryOptionCombo"
-        column="categoryoptioncomboid" unique="true"/>
+        column="categoryoptioncomboid" foreign-key="fk_categorycombo_categoryoptioncomboid" unique="true"/>
     </set>    
     
     </class>

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOption.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOption.hbm.xml	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOption.hbm.xml	2009-10-16 12:26:29 +0000
@@ -11,12 +11,17 @@
     </id>
         	
     <property name="name">
-      <column name="name" not-null="true" unique="true" length="160"/>
+      <column name="name" not-null="true" length="160"/>
     </property>
     
-    <property name="shortName" unique="true" length="40"/>
+    <property name="shortName" length="40"/>
     
     <property name="uuid" length="40"/>
+    
+    <join table="categories_categoryoptions" inverse="true">
+      <key column="categoryoptionid"/>
+      <many-to-one column="categoryid" name="category"/>
+    </join>
     
   </class>
 </hibernate-mapping>

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryCategoryOptionAssociationConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryCategoryOptionAssociationConverter.java	2009-08-12 21:06:37 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryCategoryOptionAssociationConverter.java	2009-10-16 12:26:29 +0000
@@ -58,6 +58,7 @@
     
     private static final String FIELD_CATEGORY = "category";
     private static final String FIELD_CATEGORY_OPTION = "categoryOption";
+    private static final String FIELD_SORT_ORDER = "sortOrder";
 
     // -------------------------------------------------------------------------
     // Properties
@@ -120,7 +121,9 @@
             for ( DataElementCategory category : categories )
             {
                 if ( category.getCategoryOptions() != null )
-                {                    
+                {
+                    int sortOrder = 0;
+                	
                     for ( DataElementCategoryOption categoryOption : category.getCategoryOptions() )
                     {
                         if ( categoryOptions.contains( categoryOption ) )
@@ -129,6 +132,7 @@
                             
                             writer.writeElement( FIELD_CATEGORY, String.valueOf( category.getId() ) );
                             writer.writeElement( FIELD_CATEGORY_OPTION, String.valueOf( categoryOption.getId() ) );
+                            writer.writeElement( FIELD_SORT_ORDER, String.valueOf( sortOrder++ ) );
                             
                             writer.closeElement();
                         }
@@ -142,14 +146,18 @@
     
     public void read( XMLReader reader, ImportParams params )
     {
+        int sortOrder = 1;
+        
         while ( reader.moveToStartElement( ELEMENT_NAME, COLLECTION_NAME ) )
         {
             final Map<String, String> values = reader.readElements( ELEMENT_NAME );
             
-            final GroupMemberAssociation association = new GroupMemberAssociation( AssociationType.SET );
+            final GroupMemberAssociation association = new GroupMemberAssociation( AssociationType.LIST );
             
             association.setGroupId( categoryMapping.get( Integer.parseInt( values.get( FIELD_CATEGORY ) ) ) );
             association.setMemberId( categoryOptionMapping.get( Integer.parseInt( values.get( FIELD_CATEGORY_OPTION ) ) ) );
+            association.setSortOrder( sortOrder++ ); //TODO Fix
+            //association.setSortOrder( values.containsKey( FIELD_SORT_ORDER ) ? categoryMapping.get( Integer.parseInt( values.get( FIELD_SORT_ORDER ) ) ) : 0 );
             
             read( association, GroupMemberType.CATEGORY_CATEGORYOPTION, params );
         }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryComboCategoryAssociationConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryComboCategoryAssociationConverter.java	2009-08-12 21:06:37 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryComboCategoryAssociationConverter.java	2009-10-16 12:26:29 +0000
@@ -58,6 +58,7 @@
     
     private static final String FIELD_CATEGORY_COMBO = "categoryCombo";
     private static final String FIELD_CATEGORY = "category";
+    private static final String FIELD_SORT_ORDER = "sortOrder";
 
     // -------------------------------------------------------------------------
     // Properties
@@ -122,6 +123,8 @@
             {
                 if ( categoryCombo.getCategories() != null )
                 {
+                    int sortOrder = 0;
+                    
                     for ( DataElementCategory category : categoryCombo.getCategories() )
                     {
                         if ( categories.contains( category ) )
@@ -130,6 +133,7 @@
                             
                             writer.writeElement( FIELD_CATEGORY_COMBO, String.valueOf( categoryCombo.getId() ) );
                             writer.writeElement( FIELD_CATEGORY, String.valueOf( category.getId() ) );
+                            writer.writeElement( FIELD_SORT_ORDER, String.valueOf( sortOrder++ ) );
                             
                             writer.closeElement();
                         }
@@ -143,6 +147,8 @@
 
     public void read( XMLReader reader, ImportParams params )
     {
+        int sortOrder = 1;
+        
         while ( reader.moveToStartElement( ELEMENT_NAME, COLLECTION_NAME ) )
         {
             final Map<String, String> values = reader.readElements( ELEMENT_NAME );
@@ -151,6 +157,8 @@
             
             association.setGroupId( categoryComboMapping.get( Integer.parseInt( values.get( FIELD_CATEGORY_COMBO ) ) ) );            
             association.setMemberId( categoryMapping.get( Integer.parseInt( values.get( FIELD_CATEGORY ) ) ) );
+            association.setSortOrder( sortOrder++ ); //TODO Fix
+            //association.setSortOrder( values.containsKey( FIELD_SORT_ORDER ) ? categoryMapping.get( Integer.parseInt( values.get( FIELD_SORT_ORDER ) ) ) : 0 );
             
             read( association, GroupMemberType.CATEGORYCOMBO_CATEGORY, params );
         }

=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/CategoryCategoryOptionAssociationBatchHandler.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/CategoryCategoryOptionAssociationBatchHandler.java	2009-08-12 21:06:37 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/CategoryCategoryOptionAssociationBatchHandler.java	2009-10-16 12:26:29 +0000
@@ -72,11 +72,13 @@
     {
         statementBuilder.setColumn( "categoryid" );
         statementBuilder.setColumn( "categoryoptionid" );
+        statementBuilder.setColumn( "sort_order" );
     }
     
     protected void setValues( GroupMemberAssociation association )
     {        
         statementBuilder.setValue( association.getGroupId() );
         statementBuilder.setValue( association.getMemberId() );
+        statementBuilder.setValue( association.getSortOrder() );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/CategoryComboCategoryAssociationBatchHandler.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/CategoryComboCategoryAssociationBatchHandler.java	2009-08-12 21:06:37 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/CategoryComboCategoryAssociationBatchHandler.java	2009-10-16 12:26:29 +0000
@@ -72,11 +72,13 @@
     {
         statementBuilder.setColumn( "categorycomboid" );
         statementBuilder.setColumn( "categoryid" );
+        statementBuilder.setColumn( "sort_order" );
     }
     
     protected void setValues( GroupMemberAssociation association )
     {        
         statementBuilder.setValue( association.getGroupId() );
         statementBuilder.setValue( association.getMemberId() );
+        statementBuilder.setValue( association.getSortOrder() );
     }
 }


Follow ups