← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4723: Made it possible to remove category options from an existing category. Category option combos for...

 

Merge authors:
  Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 4723 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-09-27 20:03:19 +0200
message:
  Made it possible to remove category options from an existing category. Category option combos for the category options will be removed if no data values exist. The delete is denied altogether if not.
added:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/RemoveDataElementCategoryOptionAction.java
modified:
  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/DataElementCategoryDeletionHandler.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboDeletionHandler.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/category.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryForm.vm


--
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/DataElementCategoryOptionCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java	2011-05-07 19:53:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java	2011-09-27 17:15:00 +0000
@@ -162,9 +162,10 @@
 
     /**
      * Tests whether two objects compare on a name basis. The default equals
-     * method becomes unusable in conjunction with persistence frameworks that
-     * put proxys on associated objects and collections, since it tests the
-     * class type which will differ between the proxy and the raw type.
+     * method becomes unusable in the case of detached objects in conjunction 
+     * with persistence frameworks that put proxys on associated objects and 
+     * collections, since it tests the class type which will differ between the 
+     * proxy and the raw type.
      * 
      * @param object the object to test for equality.
      * @return true if objects are equal, false otherwise.

=== 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-06-30 08:03:19 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryDeletionHandler.java	2011-09-27 18:03:19 +0000
@@ -35,7 +35,6 @@
 
 /**
  * @author Dang Duy Hieu
- * @version $Id$
  */
 public class DataElementCategoryDeletionHandler
     extends DeletionHandler
@@ -106,4 +105,16 @@
             }
         }
     }
+
+    @Override
+    public void deleteDataElementCategoryOption( DataElementCategoryOption categoryOption )
+    {
+        DataElementCategory category = categoryOption.getCategory();
+        
+        if ( category != null )
+        {
+            category.getCategoryOptions().remove( 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-08-05 14:06:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboDeletionHandler.java	2011-09-27 18:03:19 +0000
@@ -107,6 +107,19 @@
     }
     
     @Override
+    public void deleteDataElementCategoryOption( DataElementCategoryOption categoryOption )
+    {
+        Iterator<DataElementCategoryOptionCombo> iterator = categoryOption.getCategoryOptionCombos().iterator();
+
+        while ( iterator.hasNext() )
+        {
+            DataElementCategoryOptionCombo optionCombo = iterator.next();
+            iterator.remove();
+            categoryService.deleteDataElementCategoryOptionCombo( optionCombo );
+        }
+    }
+    
+    @Override
     public void deleteDataElementCategoryCombo( DataElementCategoryCombo categoryCombo )
     {
         Iterator<DataElementCategoryOptionCombo> iterator = categoryCombo.getOptionCombos().iterator();

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/RemoveDataElementCategoryOptionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/RemoveDataElementCategoryOptionAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/category/RemoveDataElementCategoryOptionAction.java	2011-09-27 18:03:19 +0000
@@ -0,0 +1,96 @@
+package org.hisp.dhis.dd.action.category;
+
+/*
+ * Copyright (c) 2004-2010, 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.common.DeleteNotAllowedException;
+import org.hisp.dhis.dataelement.DataElementCategoryOption;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class RemoveDataElementCategoryOptionAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private DataElementCategoryService dataElementCategoryService;
+
+    public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService )
+    {
+        this.dataElementCategoryService = dataElementCategoryService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private Integer id;
+
+    public void setId( Integer id )
+    {
+        this.id = id;
+    }
+
+    // -------------------------------------------------------------------------
+    // Output
+    // -------------------------------------------------------------------------
+
+    private String message;
+
+    public String getMessage()
+    {
+        return message;
+    }
+    
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+    {
+        DataElementCategoryOption categoryOption = dataElementCategoryService.getDataElementCategoryOption( id );
+        
+        try
+        {
+            dataElementCategoryService.deleteDataElementCategoryOption( categoryOption );
+            
+            return SUCCESS;
+        }
+        catch ( DeleteNotAllowedException ex )
+        {
+            message = ex.getMessage();
+            
+            return ERROR;
+        }
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/META-INF/dhis/beans.xml	2011-09-27 15:52:56 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/META-INF/dhis/beans.xml	2011-09-27 18:03:19 +0000
@@ -600,6 +600,8 @@
     </property>
   </bean>
 
+  <!-- CategoryOption -->
+
   <bean id="org.hisp.dhis.dd.action.category.AddDataElementCategoryOptionAction" class="org.hisp.dhis.dd.action.category.AddDataElementCategoryOptionAction"
     scope="prototype">
     <property name="dataElementCategoryService">
@@ -614,6 +616,13 @@
     </property>
   </bean>
 
+  <bean id="org.hisp.dhis.dd.action.category.RemoveDataElementCategoryOptionAction" class="org.hisp.dhis.dd.action.category.RemoveDataElementCategoryOptionAction"
+    scope="prototype">
+    <property name="dataElementCategoryService">
+      <ref bean="org.hisp.dhis.dataelement.DataElementCategoryService" />
+    </property>
+  </bean>
+
   <!-- CategoryCombo -->
 
   <bean id="org.hisp.dhis.dd.action.categorycombo.GetDataElementCategoryListAction" class="org.hisp.dhis.dd.action.categorycombo.GetDataElementCategoryListAction"

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml	2011-09-27 17:05:48 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/struts.xml	2011-09-27 18:03:19 +0000
@@ -620,6 +620,8 @@
       <param name="requiredAuthorities">F_DATAELEMENT_DELETE</param>
     </action>
 
+    <!-- CategoryOption -->
+
     <action name="addDataElementCategoryOption" class="org.hisp.dhis.dd.action.category.AddDataElementCategoryOptionAction">
       <result name="success" type="velocity-json">
         /dhis-web-commons/ajax/jsonCategoryOption.vm
@@ -634,6 +636,13 @@
       <param name="requiredAuthorities">F_DATAELEMENT_UPDATE</param>
     </action>
 
+    <action name="removeDataElementCategoryOption" class="org.hisp.dhis.dd.action.category.RemoveDataElementCategoryOptionAction">
+      <result name="success" type="velocity-json">
+        /dhis-web-commons/ajax/jsonResponseSuccess.vm
+      </result>
+      <param name="requiredAuthorities">F_DATAELEMENT_DELETE</param>
+    </action>
+
     <!-- CategoryCombo -->
 
     <action name="showAddDataElementCategoryComboForm" class="org.hisp.dhis.dd.action.categorycombo.GetDataElementCategoryListAction">

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/category.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/category.js	2011-09-27 17:05:48 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/javascript/category.js	2011-09-27 18:03:19 +0000
@@ -62,10 +62,21 @@
 	}	
 }
 
+function removeCategoryOption()
+{
+	var id = $( '#categoryOptions :selected' ).val();
+	var name = $( '#categoryOptions :selected' ).text();
+	
+	if ( id != null )
+	{	
+		removeItem( id, name, i18n_confirm_delete, 'removeDataElementCategoryOption.action' );
+	}
+}
+
 function updateCategoryOption()
 {
 	var name = $( '#categoryOptionName' ).val();
-	var id = $( '#categoryOptions :selected' ).val;
+	var id = $( '#categoryOptions :selected' ).val();
 	
 	if ( name.length == 0 )
 	{
@@ -93,8 +104,8 @@
 
 function getSelectedCategoryOption()
 {
-	var selected = $( '#categoryOptions :selected' ).text();
-	$( '#categoryOptionName' ).val( selected );
+	var name = $( '#categoryOptions :selected' ).text();
+	$( '#categoryOptionName' ).val( name );
 }
 
 function updateCategoryOptionName()

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryForm.vm	2011-09-27 16:31:45 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/multidimensional/updateDataElementCategoryForm.vm	2011-09-27 18:03:19 +0000
@@ -8,6 +8,7 @@
 		checkValueIsExist( "name", "validateDataElementCategory.action", {id: $dataElementCategory.id});		
 	});
 
+    var i18n_confirm_delete = '$encoder.jsEscape( $i18n.getString( "confirm_delete_data_element_category_option" ) , "'")';
     var i18n_specify_category_option_name = '$encoder.jsEscape( $i18n.getString( "specify_category_option_name" ) , "'")';
     var i18n_category_option_name_already_exists = '$encoder.jsEscape( $i18n.getString( "category_option_name_already_exists" ) , "'")';
 	var i18n_option_rename_successfully = '$encoder.jsEscape( $i18n.getString( "option_rename_successfully" ) , "'")';
@@ -76,6 +77,7 @@
 			<td style="width:30px; text-align:center">
 				<a href="javascript:moveUpSelectedOption( 'categoryOptions' )"><img src="../images/move_up.png"/></a><br/><br/>
 				<a href="javascript:moveDownSelectedOption( 'categoryOptions' )"><img src="../images/move_down.png"/></a><br/><br/>
+				<a href="javascript:removeCategoryOption()"><img src="../images/delete.png"/></a>
 			</td>
 		  </tr>
 		</table>