dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #06179
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1928: Add deletion handler to CatCombo, show the error response when cannot delete CatCombo.
Merge authors:
Quang <Quang@Quang-PC>
------------------------------------------------------------
revno: 1928 [merge]
committer: Quang <Quang@Quang-PC>
branch nick: trunk
timestamp: Sat 2010-05-29 23:09:22 +0700
message:
Add deletion handler to CatCombo, show the error response when cannot delete CatCombo.
modified:
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/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/categorycombo/RemoveDataElementCategoryComboAction.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-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 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboDeletionHandler.java 2010-05-27 13:31:39 +0000
@@ -28,6 +28,7 @@
*/
import org.hisp.dhis.system.deletion.DeletionHandler;
+import org.springframework.jdbc.core.JdbcTemplate;
/**
* @author Lars Helge Overland
@@ -47,6 +48,13 @@
this.categoryService = categoryService;
}
+ private JdbcTemplate jdbcTemplate;
+
+ public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+ {
+ this.jdbcTemplate = jdbcTemplate;
+ }
+
// -------------------------------------------------------------------------
// DeletionHandler implementation
// -------------------------------------------------------------------------
@@ -73,10 +81,22 @@
}
@Override
+ public boolean allowDeleteDataElementCategoryCombo( DataElementCategoryCombo categoryCombo )
+ {
+ for(DataElementCategoryOptionCombo eachOptionCombo : categoryCombo.getOptionCombos())
+ {
+ String sql = "SELECT COUNT(*) FROM datavalue where categoryoptioncomboid=" + eachOptionCombo.getId();
+
+ if( jdbcTemplate.queryForInt( sql ) > 0) return false;
+ }
+
+ return true;
+ }
+
+ @Override
public void deleteDataElementCategoryCombo( DataElementCategoryCombo categoryCombo )
{
- for ( DataElementCategoryOptionCombo categoryOptionCombo :
- categoryService.getAllDataElementCategoryOptionCombos() )
+ for ( DataElementCategoryOptionCombo categoryOptionCombo : categoryService.getAllDataElementCategoryOptionCombos() )
{
if ( categoryOptionCombo.getCategoryCombo().equals( categoryCombo ) )
{
=== 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 2010-05-26 15:58:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml 2010-05-27 13:31:39 +0000
@@ -793,6 +793,7 @@
<bean id="org.hisp.dhis.dataelement.DataElementCategoryOptionComboDeletionHandler"
class="org.hisp.dhis.dataelement.DataElementCategoryOptionComboDeletionHandler">
+ <property name="jdbcTemplate" ref="jdbcTemplate"/>
<property name="categoryService"
ref="org.hisp.dhis.dataelement.DataElementCategoryService"/>
</bean>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/categorycombo/RemoveDataElementCategoryComboAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/categorycombo/RemoveDataElementCategoryComboAction.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/categorycombo/RemoveDataElementCategoryComboAction.java 2010-05-29 16:09:22 +0000
@@ -27,8 +27,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.common.DeleteNotAllowedException;
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.i18n.I18n;
import com.opensymphony.xwork2.Action;
@@ -49,6 +51,13 @@
{
this.dataElementCategoryService = dataElementCategoryService;
}
+
+ private I18n i18n;
+
+ public void setI18n( I18n i18n )
+ {
+ this.i18n = i18n;
+ }
// -------------------------------------------------------------------------
// Input
@@ -62,19 +71,42 @@
}
// -------------------------------------------------------------------------
+ // Output
+ // -------------------------------------------------------------------------
+
+ private String message;
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+ // -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
public String execute()
{
- DataElementCategoryCombo categoryCombo = dataElementCategoryService.getDataElementCategoryCombo( id );
-
- DataElementCategoryCombo defaultCategoryCombo = dataElementCategoryService.getDataElementCategoryComboByName( DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME );
-
- if ( !categoryCombo.equals( defaultCategoryCombo ) )
- {
- dataElementCategoryService.deleteDataElementCategoryCombo( categoryCombo );
- }
+ DataElementCategoryCombo categoryCombo = dataElementCategoryService.getDataElementCategoryCombo( id );
+
+ DataElementCategoryCombo defaultCategoryCombo = dataElementCategoryService.getDataElementCategoryComboByName( DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME );
+
+ if ( !categoryCombo.equals( defaultCategoryCombo ) )
+ {
+ try
+ {
+ dataElementCategoryService.deleteDataElementCategoryCombo( categoryCombo );
+ }
+ catch ( DeleteNotAllowedException ex )
+ {
+ if ( ex.getErrorCode().equals( DeleteNotAllowedException.ERROR_ASSOCIATED_BY_OTHER_OBJECTS ) )
+ {
+ message = i18n.getString( "object_not_deleted_associated_by_objects" ) + " " + ex.getClassName();
+ return ERROR;
+ }
+ }
+
+ }
return SUCCESS;
}