← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2073: Delete OrgUnitLevel when pruning OrgUnit (https://bugs.launchpad.net/dhis2/+bug/625478).

 

------------------------------------------------------------
revno: 2073
committer: Quang <Quang@Quang-PC>
branch nick: trunk
timestamp: Mon 2010-09-06 21:54:16 +0700
message:
  Delete OrgUnitLevel when pruning OrgUnit (https://bugs.launchpad.net/dhis2/+bug/625478).
modified:
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/DefaultDataPruneService.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/jdbc/JdbcDataPruneStore.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-administration/src/main/java/org/hisp/dhis/dataprune/DefaultDataPruneService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/DefaultDataPruneService.java	2010-07-04 04:39:44 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/DefaultDataPruneService.java	2010-09-06 14:54:16 +0000
@@ -31,6 +31,7 @@
 import java.util.List;
 import java.util.Set;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
@@ -64,6 +65,8 @@
     @Transactional
     public void pruneOrganisationUnit( OrganisationUnit organisationUnit )
     {
+        deleteLevels( organisationUnit );
+
         if ( organisationUnit.getParent() != null )
         {
             organisationUnit.setParent( null );
@@ -75,6 +78,25 @@
         dataPruneStore.deleteMultiOrganisationUnit( deletedOrgUnits );
     }
 
+    private void deleteLevels( OrganisationUnit organisationUnit )
+    {
+        if ( organisationUnit.getParent() != null )
+        {
+            OrganisationUnitLevel level = organisationUnitService
+                .getOrganisationUnitLevelByLevel( organisationUnitService.getLevelOfOrganisationUnit( organisationUnit
+                    .getParent() ) );
+
+            if ( level != null )
+            {
+                organisationUnitService.deleteOrganisationUnitLevel( level );
+            }
+        }
+        if ( organisationUnit.getParent().getParent() != null )
+        {
+            deleteLevels( organisationUnit.getParent() );
+        }
+    }
+    
     private List<OrganisationUnit> pruneOrganisationUnitLocal( OrganisationUnit organisationUnit )
     {
         List<OrganisationUnit> deleteOrgUnits = new ArrayList<OrganisationUnit>();

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/jdbc/JdbcDataPruneStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/jdbc/JdbcDataPruneStore.java	2010-08-19 21:37:22 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/jdbc/JdbcDataPruneStore.java	2010-09-06 14:54:16 +0000
@@ -123,6 +123,12 @@
         sql = "delete from datavalue where sourceid in (" + orgUnitIds + ");";
         jdbcTemplate.execute( sql );
 
+        sql = "delete from mapfile where organisationunitid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+        
+        sql = "delete from feature where organisationunitid in (" + orgUnitIds + ");";
+        jdbcTemplate.execute( sql );
+
         sql = "update organisationunit set parentid=null where organisationunitid in (" + orgUnitIds + ");";
         jdbcTemplate.execute( sql );