dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19293
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8346: Model change. CategoryOptionCombo -> CategoryOption goes from List to Set. There was no reason fo...
------------------------------------------------------------
revno: 8346
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-10-02 20:18:48 +0200
message:
Model change. CategoryOptionCombo -> CategoryOption goes from List to Set. There was no reason for having it as a List, and it caused a peculiar bug related to sorting.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.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/main/java/org/hisp/dhis/startup/TableAlteror.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOptionCombo.hbm.xml
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-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/service/DefaultImportObjectManager.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/DataElementCategoryCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java 2012-09-13 02:35:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java 2012-10-02 18:18:48 +0000
@@ -64,7 +64,8 @@
private List<DataElementCategory> categories = new ArrayList<DataElementCategory>();
/**
- * A set of category option combos.
+ * A set of category option combos. Use getSortedOptionCombos() to get a
+ * sorted list of category option combos.
*/
private Set<DataElementCategoryOptionCombo> optionCombos = new HashSet<DataElementCategoryOptionCombo>();
@@ -143,7 +144,7 @@
while ( generator.hasNext() )
{
DataElementCategoryOptionCombo optionCombo = new DataElementCategoryOptionCombo();
- optionCombo.setCategoryOptions( generator.getNext() );
+ optionCombo.setCategoryOptions( new HashSet<DataElementCategoryOption>( generator.getNext() ) );
optionCombo.setCategoryCombo( this );
list.add( optionCombo );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java 2012-04-20 18:31:48 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java 2012-10-02 18:18:48 +0000
@@ -69,7 +69,7 @@
* The category options.
*/
@Scanned
- private List<DataElementCategoryOption> categoryOptions = new ArrayList<DataElementCategoryOption>();
+ private Set<DataElementCategoryOption> categoryOptions = new HashSet<DataElementCategoryOption>();
// -------------------------------------------------------------------------
// Constructors
@@ -336,12 +336,12 @@
@JsonView( {DetailedView.class, ExportView.class} )
@JacksonXmlElementWrapper( localName = "categoryOptions", namespace = Dxf2Namespace.NAMESPACE )
@JacksonXmlProperty( localName = "categoryOption", namespace = Dxf2Namespace.NAMESPACE )
- public List<DataElementCategoryOption> getCategoryOptions()
+ public Set<DataElementCategoryOption> getCategoryOptions()
{
return categoryOptions;
}
- public void setCategoryOptions( List<DataElementCategoryOption> categoryOptions )
+ public void setCategoryOptions( Set<DataElementCategoryOption> categoryOptions )
{
this.categoryOptions = categoryOptions;
}
=== 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 2012-08-13 13:34:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2012-10-02 18:18:48 +0000
@@ -371,7 +371,7 @@
DataElementCategoryOptionCombo categoryOptionCombo = new DataElementCategoryOptionCombo();
categoryOptionCombo.setCategoryCombo( categoryCombo );
- categoryOptionCombo.setCategoryOptions( new ArrayList<DataElementCategoryOption>( categoryOptions ) );
+ categoryOptionCombo.setCategoryOptions( new HashSet<DataElementCategoryOption>( categoryOptions ) );
addDataElementCategoryOptionCombo( categoryOptionCombo );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2012-09-27 03:57:57 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2012-10-02 18:18:48 +0000
@@ -191,15 +191,9 @@
executeSql( "ALTER TABLE categorycombos_optioncombos DROP CONSTRAINT fk4bae70f697e49675" );
// categoryoptioncombos_categoryoptions
- // set to 0 temporarily
- int c3 = executeSql( "update categoryoptioncombos_categoryoptions SET sort_order=0 where sort_order is NULL OR sort_order=0" );
- if ( c3 > 0 )
- {
- updateSortOrder( "categoryoptioncombos_categoryoptions", "categoryoptioncomboid", "categoryoptionid" );
- }
- executeSql( "ALTER TABLE categoryoptioncombos_categoryoptions DROP CONSTRAINT categoryoptioncombos_categoryoptions_pkey" );
- executeSql( "ALTER TABLE categoryoptioncombos_categoryoptions ADD CONSTRAINT categoryoptioncombos_categoryoptions_pkey PRIMARY KEY (categoryoptioncomboid, sort_order)" );
-
+ executeSql( "alter table categoryoptioncombos_categoryoptions drop column sort_order" );
+ executeSql( "alter table categoryoptioncombos_categoryoptions add constraint categoryoptioncombos_categoryoptions_pkey primary key(categoryoptioncomboid, categoryoptionid)" );
+
// dataelementcategoryoption
executeSql( "ALTER TABLE dataelementcategoryoption DROP CONSTRAINT fk_dataelement_categoryid" );
executeSql( "ALTER TABLE dataelementcategoryoption DROP CONSTRAINT dataelementcategoryoption_shortname_key" );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOptionCombo.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOptionCombo.hbm.xml 2012-04-20 18:31:48 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOptionCombo.hbm.xml 2012-10-02 18:18:48 +0000
@@ -18,13 +18,12 @@
<property name="lastUpdated" type="timestamp" />
- <list name="categoryOptions" table="categoryoptioncombos_categoryoptions">
+ <set name="categoryOptions" table="categoryoptioncombos_categoryoptions">
<cache usage="read-write" />
<key column="categoryoptioncomboid" foreign-key="fk_categoryoptioncombos_categoryoptions_categoryoptioncomboid" />
- <list-index column="sort_order" base="1" />
<many-to-many class="org.hisp.dhis.dataelement.DataElementCategoryOption" column="categoryoptionid"
foreign-key="fk_categoryoptioncombo_categoryoptionid" />
- </list>
+ </set>
<join table="categorycombos_optioncombos">
<key column="categoryoptioncomboid" />
=== 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 2012-02-08 22:29:28 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboServiceTest.java 2012-10-02 18:18:48 +0000
@@ -31,10 +31,10 @@
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
-import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
import java.util.LinkedList;
-import java.util.List;
+import java.util.Set;
import org.hisp.dhis.DhisSpringTest;
import org.junit.Test;
@@ -112,7 +112,7 @@
{
categoryOptionComboA = new DataElementCategoryOptionCombo();
- List<DataElementCategoryOption> categoryOptions = new ArrayList<DataElementCategoryOption>();
+ Set<DataElementCategoryOption> categoryOptions = new HashSet<DataElementCategoryOption>();
categoryOptions.add( categoryOptionA );
categoryOptions.add( categoryOptionB );
@@ -150,7 +150,7 @@
{
categoryOptionComboA = new DataElementCategoryOptionCombo();
- List<DataElementCategoryOption> categoryOptions = new ArrayList<DataElementCategoryOption>();
+ Set<DataElementCategoryOption> categoryOptions = new HashSet<DataElementCategoryOption>();
categoryOptions.add( categoryOptionA );
categoryOptions.add( categoryOptionB );
=== 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 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboStoreTest.java 2012-10-02 18:18:48 +0000
@@ -31,9 +31,9 @@
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
import org.hisp.dhis.DhisSpringTest;
import org.hisp.dhis.common.GenericStore;
@@ -119,7 +119,7 @@
{
categoryOptionComboA = new DataElementCategoryOptionCombo();
- List<DataElementCategoryOption> categoryOptions = new ArrayList<DataElementCategoryOption>();
+ Set<DataElementCategoryOption> categoryOptions = new HashSet<DataElementCategoryOption>();
categoryOptions.add( categoryOptionA );
categoryOptions.add( categoryOptionB );
@@ -141,7 +141,7 @@
{
categoryOptionComboA = new DataElementCategoryOptionCombo();
- List<DataElementCategoryOption> categoryOptions = new ArrayList<DataElementCategoryOption>();
+ Set<DataElementCategoryOption> categoryOptions = new HashSet<DataElementCategoryOption>();
categoryOptions.add( categoryOptionA );
categoryOptions.add( categoryOptionB );
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/service/DefaultImportObjectManager.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/service/DefaultImportObjectManager.java 2012-06-27 07:16:03 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/service/DefaultImportObjectManager.java 2012-10-02 18:18:48 +0000
@@ -27,6 +27,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import org.amplecode.quick.BatchHandler;
import org.amplecode.quick.BatchHandlerFactory;
import org.apache.commons.logging.Log;
@@ -144,11 +149,6 @@
import org.hisp.dhis.validation.ValidationRuleService;
import org.springframework.transaction.annotation.Transactional;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
/**
* @author Lars Helge Overland
* @version $Id$
@@ -418,7 +418,7 @@
object.setCategoryCombo( categoryService.getDataElementCategoryCombo( categoryComboId ) );
- List<DataElementCategoryOption> categoryOptions = new ArrayList<DataElementCategoryOption>();
+ Set<DataElementCategoryOption> categoryOptions = new HashSet<DataElementCategoryOption>();
for ( DataElementCategoryOption categoryOption : object.getCategoryOptions() )
{