← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1792: Update service layer of OrgnisationUnit pruning function.

 

------------------------------------------------------------
revno: 1792
committer: Quang <Quang@Quang-PC>
branch nick: trunk
timestamp: Wed 2010-04-21 10:59:02 +0700
message:
  Update service layer of OrgnisationUnit pruning function.
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/resources/META-INF/dhis/beans.xml


--
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-04-13 11:04:48 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataprune/DefaultDataPruneService.java	2010-04-21 03:59:02 +0000
@@ -27,19 +27,15 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.List;
 import java.util.Set;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.hisp.dhis.dataset.CompleteDataSetRegistrationService;
 import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.hierarchy.HierarchyViolationException;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.springframework.transaction.annotation.Transactional;
 
-import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList;
-
 /**
  * @author Quang Nguyen
  * @version Apr 6, 2010 5:48:15 PM
@@ -61,13 +57,6 @@
         this.organisationUnitService = organisationUnitService;
     }
 
-    private CompleteDataSetRegistrationService completeDataSetRegistrationService;
-
-    public void setCompleteDataSetRegistrationService( CompleteDataSetRegistrationService completeDataSetRegistrationService )
-    {
-        this.completeDataSetRegistrationService = completeDataSetRegistrationService;
-    }
-    
     private DataValueService dataValueService;
 
     public void setDataValueService( DataValueService dataValueService )
@@ -82,37 +71,21 @@
     @Transactional
     public void pruneOrganisationUnit( OrganisationUnit organisationUnit )
     {
-        if(organisationUnit.getParent() != null) {
-            deleteSiblings(organisationUnit);
-
-            deleteParents(organisationUnit);
+        if ( organisationUnit.getParent() != null )
+        {
+            organisationUnit.setParent( null );
+            organisationUnitService.updateOrganisationUnit( organisationUnit );
         }
-    }
-
-    private void deleteParents( OrganisationUnit organisationUnit )
-    {
-        /*
-         * Not implemented yet.
-         */
-    }
-
-    @SuppressWarnings( "unchecked" )
-    private void deleteSiblings( OrganisationUnit organisationUnit )
-    {
-        List<OrganisationUnit> copiedSiblingList = new CopyOnWriteArrayList(organisationUnit.getParent().getChildren());
         
-        for ( OrganisationUnit sibling : copiedSiblingList )
+        for(OrganisationUnit eachRoot : organisationUnitService.getRootOrganisationUnits())
         {
-            if ( !sibling.equals( organisationUnit ) )
-            //if ( sibling.getId() == 988 )
-            {   
-                System.out.println("delete sibling: " + sibling.getName());
-                deleteABranch( sibling );
+            if(!eachRoot.equals( organisationUnit ))
+            {
+                deleteABranch( eachRoot );
             }
         }
-
     }
-
+    
     private void deleteABranch(OrganisationUnit organisationUnit) {
         if(!organisationUnit.getChildren().isEmpty()) {
             Set<OrganisationUnit> tmp = organisationUnit.getChildren();
@@ -123,6 +96,16 @@
                 deleteABranch( (OrganisationUnit)eachChild );
             }
         }
-      //removeOrganisationUnitAndBelonging( organisationUnit );
+        
+        dataValueService.deleteDataValuesBySource( organisationUnit );
+        
+        try
+        {
+            organisationUnitService.deleteOrganisationUnit( organisationUnit );
+        }
+        catch ( HierarchyViolationException e )
+        {
+            e.printStackTrace();
+        }
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml	2010-04-13 11:04:48 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/META-INF/dhis/beans.xml	2010-04-21 03:59:02 +0000
@@ -126,8 +126,6 @@
     class="org.hisp.dhis.dataprune.DefaultDataPruneService">
     <property name="organisationUnitService"
       ref="org.hisp.dhis.organisationunit.OrganisationUnitService"/>
-	<property name="completeDataSetRegistrationService"
-      ref="org.hisp.dhis.dataset.CompleteDataSetRegistrationService"/>
 	<property name="dataValueService"
       ref="org.hisp.dhis.datavalue.DataValueService"/>
   </bean>