dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21070
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9877: Made the assocation between category and category option many-to-many. No db change.
------------------------------------------------------------
revno: 9877
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-02-22 13:26:37 +0100
message:
Made the assocation between category and category option many-to-many. No db change.
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/DataElementCategoryOption.java
dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryComboTest.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/DataElementCategoryOptionComboDeletionHandler.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/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOption.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryComboServiceTest.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/AddDataElementCategoryOptionAction.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 2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategory.java 2013-02-22 12:26:37 +0000
@@ -101,17 +101,20 @@
public void addDataElementCategoryOption( DataElementCategoryOption dataElementCategoryOption )
{
categoryOptions.add( dataElementCategoryOption );
- dataElementCategoryOption.setCategory( this );
+ dataElementCategoryOption.getCategories().add( this );
}
+ public void removeDataElementCategoryOption( DataElementCategoryOption dataElementCategoryOption )
+ {
+ categoryOptions.remove( dataElementCategoryOption );
+ dataElementCategoryOption.getCategories().remove( this );
+ }
+
public void removeAllCategoryOptions()
{
- for ( DataElementCategoryOption dataElementCategoryOption : categoryOptions )
+ for ( DataElementCategoryOption categoryOption : categoryOptions )
{
- if ( dataElementCategoryOption.getCategory() == this )
- {
- dataElementCategoryOption.setCategory( null );
- }
+ categoryOption.getCategories().remove( this );
}
categoryOptions.clear();
=== 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 2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java 2013-02-22 12:26:37 +0000
@@ -59,7 +59,7 @@
public static final String DEFAULT_NAME = "default";
- private DataElementCategory category;
+ private Set<DataElementCategory> categories = new HashSet<DataElementCategory>();
private Concept concept;
@@ -157,14 +157,14 @@
@JsonSerialize( as = BaseIdentifiableObject.class )
@JsonView( {DetailedView.class} )
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
- public DataElementCategory getCategory()
+ public Set<DataElementCategory> getCategories()
{
- return category;
+ return categories;
}
- public void setCategory( DataElementCategory category )
+ public void setCategories( Set<DataElementCategory> categories )
{
- this.category = category;
+ this.categories = categories;
}
@JsonProperty
=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryComboTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryComboTest.java 2013-01-14 16:10:34 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryComboTest.java 2013-02-22 12:26:37 +0000
@@ -78,12 +78,12 @@
categoryC.getCategoryOptions().add( categoryOptionE );
categoryC.getCategoryOptions().add( categoryOptionF );
- categoryOptionA.setCategory( categoryA );
- categoryOptionB.setCategory( categoryA );
- categoryOptionC.setCategory( categoryB );
- categoryOptionD.setCategory( categoryB );
- categoryOptionE.setCategory( categoryC );
- categoryOptionF.setCategory( categoryC );
+ categoryOptionA.getCategories().add( categoryA );
+ categoryOptionB.getCategories().add( categoryA );
+ categoryOptionC.getCategories().add( categoryB );
+ categoryOptionD.getCategories().add( categoryB );
+ categoryOptionE.getCategories().add( categoryC );
+ categoryOptionF.getCategories().add( categoryC );
categoryCombo = new DataElementCategoryCombo( "CategoryCombo" );
=== 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 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryDeletionHandler.java 2013-02-22 12:26:37 +0000
@@ -27,6 +27,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.Set;
+
import org.hisp.dhis.concept.Concept;
import org.hisp.dhis.concept.ConceptService;
import org.hisp.dhis.dataelement.DataElementCategory;
@@ -109,11 +111,11 @@
@Override
public void deleteDataElementCategoryOption( DataElementCategoryOption categoryOption )
{
- DataElementCategory category = categoryOption.getCategory();
+ Set<DataElementCategory> categories = categoryOption.getCategories();
- if ( category != null )
+ for ( DataElementCategory category : categories )
{
- category.getCategoryOptions().remove( categoryOption );
+ category.removeDataElementCategoryOption( categoryOption );
categoryService.updateDataElementCategory( category );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboDeletionHandler.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboDeletionHandler.java 2013-02-22 12:26:37 +0000
@@ -87,9 +87,9 @@
final String sql =
"select count(*) from datavalue dv " +
"where dv.categoryoptioncomboid in ( " +
- "select cc.categoryoptioncomboid from categoryoptioncombos_categoryoptions cc, categories_categoryoptions co " +
- "where cc.categoryoptionid = co.categoryoptionid " +
- "and co.categoryid=" + category.getId() + " );";
+ "select cc.categoryoptioncomboid from categoryoptioncombos_categoryoptions cc " +
+ "join categories_categoryoptions co on cc.categoryoptionid=co.categoryoptionid " +
+ "where co.categoryid=" + category.getId() + " );";
return jdbcTemplate.queryForInt( sql ) == 0 ? null : ERROR;
}
=== 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 2013-02-22 08:14:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2013-02-22 12:26:37 +0000
@@ -377,25 +377,15 @@
// ---------------------------------------------------------------------
DataElementCategory category = new DataElementCategory( DataElementCategory.DEFAULT_NAME );
-
- List<DataElementCategoryOption> categoryOptions = new ArrayList<DataElementCategoryOption>();
- categoryOptions.add( categoryOption );
- category.setCategoryOptions( categoryOptions );
- categoryOption.setCategory( category );
-
+ category.addDataElementCategoryOption( categoryOption );
addDataElementCategory( category );
// ---------------------------------------------------------------------
// DataElementCategoryCombo
// ---------------------------------------------------------------------
- DataElementCategoryCombo categoryCombo = new DataElementCategoryCombo(
- DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME );
-
- List<DataElementCategory> categories = new ArrayList<DataElementCategory>();
- categories.add( category );
- categoryCombo.setCategories( categories );
-
+ DataElementCategoryCombo categoryCombo = new DataElementCategoryCombo( DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME );
+ categoryCombo.addDataElementCategory( category );
addDataElementCategoryCombo( categoryCombo );
// ---------------------------------------------------------------------
@@ -405,7 +395,7 @@
DataElementCategoryOptionCombo categoryOptionCombo = new DataElementCategoryOptionCombo();
categoryOptionCombo.setCategoryCombo( categoryCombo );
- categoryOptionCombo.setCategoryOptions( new HashSet<DataElementCategoryOption>( categoryOptions ) );
+ categoryOptionCombo.addDataElementCategoryOption( categoryOption );
addDataElementCategoryOptionCombo( categoryOptionCombo );
=== 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 2013-02-07 10:25:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOption.hbm.xml 2013-02-22 12:26:37 +0000
@@ -27,10 +27,11 @@
foreign-key="fk_categoryoption_categoryoptioncomboid" />
</set>
- <join table="categories_categoryoptions" inverse="true">
+ <set name="categories" table="categories_categoryoptions" inverse="true">
+ <cache usage="read-write" />
<key column="categoryoptionid" />
- <many-to-one column="categoryid" name="category" />
- </join>
+ <many-to-many class="org.hisp.dhis.dataelement.DataElementCategory" column="categoryid" />
+ </set>
</class>
</hibernate-mapping>
=== 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 2012-11-20 17:04:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryComboServiceTest.java 2013-02-22 12:26:37 +0000
@@ -96,19 +96,12 @@
categoryB = new DataElementCategory( "CategoryB" );
categoryC = new DataElementCategory( "CategoryC" );
- categoryA.getCategoryOptions().add( categoryOptionA );
- categoryA.getCategoryOptions().add( categoryOptionB );
- categoryB.getCategoryOptions().add( categoryOptionC );
- categoryB.getCategoryOptions().add( categoryOptionD );
- categoryC.getCategoryOptions().add( categoryOptionE );
- categoryC.getCategoryOptions().add( categoryOptionF );
-
- categoryOptionA.setCategory( categoryA );
- categoryOptionB.setCategory( categoryA );
- categoryOptionC.setCategory( categoryB );
- categoryOptionD.setCategory( categoryB );
- categoryOptionE.setCategory( categoryC );
- categoryOptionF.setCategory( categoryC );
+ categoryA.addDataElementCategoryOption( categoryOptionA );
+ categoryA.addDataElementCategoryOption( categoryOptionB );
+ categoryB.addDataElementCategoryOption( categoryOptionC );
+ categoryB.addDataElementCategoryOption( categoryOptionD );
+ categoryC.addDataElementCategoryOption( categoryOptionE );
+ categoryC.addDataElementCategoryOption( categoryOptionF );
categoryService.addDataElementCategory( categoryA );
categoryService.addDataElementCategory( categoryB );
@@ -217,8 +210,7 @@
assertEquals( 8, categoryComboA.getOptionCombos().size() );
assertOptionCombos( categoryComboA.getOptionCombos() );
- categoryC.getCategoryOptions().add( categoryOptionG );
- categoryOptionG.setCategory( categoryC );
+ categoryC.addDataElementCategoryOption( categoryOptionG );
categoryService.updateDataElementCategory( categoryC );
categoryService.updateOptionCombos( categoryComboA );
@@ -264,8 +256,7 @@
assertEquals( 8, categoryComboA.getOptionCombos().size() );
assertOptionCombos( categoryComboA.getOptionCombos() );
- categoryC.getCategoryOptions().add( categoryOptionG );
- categoryOptionG.setCategory( categoryC );
+ categoryC.addDataElementCategoryOption( categoryOptionG );
categoryService.updateDataElementCategory( categoryC );
categoryService.updateOptionCombos( categoryC );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/AddDataElementCategoryOptionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/AddDataElementCategoryOptionAction.java 2013-02-22 14:58:47 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/AddDataElementCategoryOptionAction.java 2013-02-22 12:26:37 +0000
@@ -28,7 +28,6 @@
*/
import org.hisp.dhis.concept.ConceptService;
-import org.hisp.dhis.dataelement.DataElementCategory;
import org.hisp.dhis.dataelement.DataElementCategoryOption;
import org.hisp.dhis.dataelement.DataElementCategoryService;
@@ -62,13 +61,6 @@
// Input
// -------------------------------------------------------------------------
- private Integer categoryId;
-
- public void setCategoryId( Integer categoryId )
- {
- this.categoryId = categoryId;
- }
-
private String name;
public void setName( String name )
@@ -107,24 +99,11 @@
public String execute()
{
-
dataElementCategoryOption = new DataElementCategoryOption( name );
dataElementCategoryOption.setCode( code );
dataElementCategoryOption.setConcept( conceptService.getConcept( conceptId ) );
- if ( categoryId != null )
- {
- DataElementCategory category = dataElementCategoryService.getDataElementCategory( categoryId );
- dataElementCategoryOption.setCategory( category );
- category.getCategoryOptions().add( dataElementCategoryOption );
- dataElementCategoryService.addDataElementCategoryOption( dataElementCategoryOption );
- dataElementCategoryService.updateDataElementCategory( category );
- dataElementCategoryService.updateOptionCombos( category );
- }
- else
- {
- dataElementCategoryService.addDataElementCategoryOption( dataElementCategoryOption );
- }
+ dataElementCategoryService.addDataElementCategoryOption( dataElementCategoryOption );
return SUCCESS;
}