← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14083: Made CategoryOption-CategoryOptionGroup association bi-directional. Added deletion handler.

 

------------------------------------------------------------
revno: 14083
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-02-20 19:26:56 +0100
message:
  Made CategoryOption-CategoryOptionGroup association bi-directional. Added deletion handler.
added:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupDeletionHandler.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroup.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupSetDeletionHandler.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.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-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.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/CategoryOptionGroup.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroup.java	2014-02-14 13:54:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroup.java	2014-02-20 18:26:56 +0000
@@ -71,6 +71,22 @@
     }
 
     // -------------------------------------------------------------------------
+    // Logic
+    // -------------------------------------------------------------------------
+
+    public void addCategoryOption( DataElementCategoryOption categoryOption )
+    {
+        members.add( categoryOption );
+        categoryOption.getGroups().add( this );
+    }
+
+    public void removeCategoryOption( DataElementCategoryOption categoryOption )
+    {
+        members.remove( categoryOption );
+        categoryOption.getGroups().remove( this );
+    }
+
+    // -------------------------------------------------------------------------
     // Getters and setters
     // -------------------------------------------------------------------------
 
@@ -103,20 +119,6 @@
         this.groupSet = groupSet;
     }
 
-    // -------------------------------------------------------------------------
-    // Logic
-    // -------------------------------------------------------------------------
-
-    public void addCategoryOption( DataElementCategoryOption categoryOption )
-    {
-        members.add( categoryOption );
-    }
-
-    public void removeCategoryOption( DataElementCategoryOption categoryOption )
-    {
-        members.remove( categoryOption );
-    }
-
     @Override
     public void mergeWith( IdentifiableObject other )
     {

=== 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	2014-02-12 16:09:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java	2014-02-20 18:26:56 +0000
@@ -64,6 +64,8 @@
     @Scanned
     private Set<DataElementCategoryOptionCombo> categoryOptionCombos = new HashSet<DataElementCategoryOptionCombo>();
 
+    private Set<CategoryOptionGroup> groups = new HashSet<CategoryOptionGroup>();
+    
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -154,4 +156,14 @@
     {
         this.categoryOptionCombos = categoryOptionCombos;
     }
+
+    public Set<CategoryOptionGroup> getGroups()
+    {
+        return groups;
+    }
+
+    public void setGroups( Set<CategoryOptionGroup> groups )
+    {
+        this.groups = groups;
+    }
 }

=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupDeletionHandler.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupDeletionHandler.java	2014-02-20 18:26:56 +0000
@@ -0,0 +1,66 @@
+package org.hisp.dhis.dataelement;
+
+/*
+ * Copyright (c) 2004-2013, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.system.deletion.DeletionHandler;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class CategoryOptionGroupDeletionHandler
+    extends DeletionHandler
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    @Autowired
+    private DataElementCategoryService categoryService;
+
+    // -------------------------------------------------------------------------
+    // DeletionHandler implementation
+    // -------------------------------------------------------------------------
+
+    @Override
+    public String getClassName()
+    {
+        return CategoryOptionGroup.class.getName();
+    }
+    
+    @Override
+    public void deleteDataElementCategoryOption( DataElementCategoryOption categoryOption )
+    {
+        for ( CategoryOptionGroup group : categoryOption.getGroups() )
+        {
+            group.getMembers().remove( categoryOption );
+            categoryService.updateCategoryOptionGroup( group );
+        }
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupSetDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupSetDeletionHandler.java	2014-02-13 15:03:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/CategoryOptionGroupSetDeletionHandler.java	2014-02-20 18:26:56 +0000
@@ -32,9 +32,6 @@
 
 /**
  * @author Chau Thu Tran
- * 
- * @version $ CategoryOptionGroupSetDeletionHandler.java Feb 13, 2014 7:53:06 PM
- *          $
  */
 public class CategoryOptionGroupSetDeletionHandler
     extends DeletionHandler

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2014-02-16 13:49:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2014-02-20 18:26:56 +0000
@@ -1140,8 +1140,9 @@
 
   <bean id="org.hisp.dhis.sms.SMSCodesDeletionHandler" class="org.hisp.dhis.sms.SMSCodesDeletionHandler" />
 
-  <bean id="org.hisp.dhis.dataelement.CategoryOptionGroupSetDeletionHandler" class="org.hisp.dhis.dataelement.CategoryOptionGroupSetDeletionHandler">
-  </bean>
+  <bean id="org.hisp.dhis.dataelement.CategoryOptionGroupDeletionHandler" class="org.hisp.dhis.dataelement.CategoryOptionGroupDeletionHandler"/>
+
+  <bean id="org.hisp.dhis.dataelement.CategoryOptionGroupSetDeletionHandler" class="org.hisp.dhis.dataelement.CategoryOptionGroupSetDeletionHandler"/>
   
   <!-- DeletionManager -->
 
@@ -1178,6 +1179,7 @@
           <ref local="org.hisp.dhis.user.UserSettingDeletionHandler" />
           <ref local="org.hisp.dhis.dataelement.DataElementCategoryDeletionHandler" />
           <ref local="org.hisp.dhis.dataelement.DataElementGroupSetDeletionHandler" />
+          <ref local="org.hisp.dhis.dataelement.CategoryOptionGroupDeletionHandler" />
           <ref local="org.hisp.dhis.dataelement.CategoryOptionGroupSetDeletionHandler" />
           <ref local="org.hisp.dhis.configuration.ConfigurationDeletionHandler" />
           <ref local="org.hisp.dhis.message.MessageConversationDeletionHandler" />

=== 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	2014-02-14 12:15:54 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOption.hbm.xml	2014-02-20 18:26:56 +0000
@@ -30,6 +30,12 @@
       <many-to-many class="org.hisp.dhis.dataelement.DataElementCategory" column="categoryid" />
     </set>
 
+    <set name="groups" table="categoryoptiongroupmembers" inverse="true">
+      <cache usage="read-write" />
+      <key column="categoryoptionid" />
+      <many-to-many class="org.hisp.dhis.dataelement.CategoryOptionGroup" column="dataelementgroupid" />
+    </set>
+
     <!-- Access properties -->
     <many-to-one name="user" class="org.hisp.dhis.user.User" column="userid" foreign-key="fk_dataelementcategoryoption_userid" />
 

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java	2013-12-19 08:23:37 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java	2014-02-20 18:26:56 +0000
@@ -95,7 +95,6 @@
         dataValueSet.setPeriod( period != null ? period.getIsoDate() : null );
         dataValueSet.setOrgUnit( orgUnit != null ? orgUnit.getUid() : null );
 
-
         while ( rowSet.next() )
         {
             DataValue dataValue = dataValueSet.getDataValueInstance();