← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19794: Cat option combo deletion handler, taking attribute option combo for complete dataset registratio...

 

------------------------------------------------------------
revno: 19794
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-08-19 10:31:28 -0400
message:
  Cat option combo deletion handler, taking attribute option combo for complete dataset registrations into account
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboDeletionHandler.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	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboDeletionHandler.java	2015-08-19 14:31:28 +0000
@@ -73,7 +73,7 @@
     @Override
     public String allowDeleteDataElementCategoryOption( DataElementCategoryOption categoryOption )
     {
-        final String sql =
+        final String dvSql =
             "select count(*) from datavalue dv " +
             "where dv.categoryoptioncomboid in ( " +
                 "select cc.categoryoptioncomboid from categoryoptioncombos_categoryoptions cc " +
@@ -82,13 +82,29 @@
                 "select cc.categoryoptioncomboid from categoryoptioncombos_categoryoptions cc " +
                 "where cc.categoryoptionid = " + categoryOption.getId() + " );";
         
-        return jdbcTemplate.queryForObject( sql, Integer.class ) == 0 ? null : ERROR;
+        if ( jdbcTemplate.queryForObject( dvSql, Integer.class ) > 0 )
+        {
+            return ERROR;
+        }
+        
+        final String crSql = 
+            "select count(*) from completedatasetregistration cdr " +
+            "where cdr.attributeoptioncomboid in ( " +
+                "select cc.categoryoptioncomboid from categoryoptioncombos_categoryoptions cc " +
+                "where cc.categoryoptionid = " + categoryOption.getId() + " );";
+        
+        if ( jdbcTemplate.queryForObject( crSql, Integer.class ) > 0 )
+        {
+            return ERROR;
+        }
+        
+        return null;
     }
     
     @Override
     public String allowDeleteDataElementCategoryCombo( DataElementCategoryCombo categoryCombo )
     {
-        final String sql =
+        final String dvSql =
             "select count(*) from datavalue dv " +
             "where dv.categoryoptioncomboid in ( " +
                 "select co.categoryoptioncomboid from categorycombos_optioncombos co " +
@@ -97,7 +113,23 @@
                 "select co.categoryoptioncomboid from categorycombos_optioncombos co " +
                 "where co.categorycomboid=" + categoryCombo.getId() + " );";
         
-        return jdbcTemplate.queryForObject( sql, Integer.class ) == 0 ? null : ERROR;
+        if ( jdbcTemplate.queryForObject( dvSql, Integer.class ) > 0 )
+        {
+            return ERROR;
+        }
+        
+        final String crSql =
+            "select count(*) from completedatasetregistration cdr " +
+            "where cdr.attributeoptioncomboid in ( " +
+                "select co.categoryoptioncomboid from categorycombos_optioncombos co " +
+                "where co.categorycomboid=" + categoryCombo.getId() + " );";
+        
+        if ( jdbcTemplate.queryForObject( crSql, Integer.class ) > 0 )
+        {
+            return ERROR;
+        }
+        
+        return null;
     }
     
     @Override