← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13214: only allow deletion of an orgUnit if it has no children (DeletionHandler)

 

------------------------------------------------------------
revno: 13214
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-12-12 17:34:34 +0100
message:
  only allow deletion of an orgUnit if it has no children (DeletionHandler)
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitDeletionHandler.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.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/organisationunit/OrganisationUnitDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitDeletionHandler.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitDeletionHandler.java	2013-12-12 16:34:34 +0000
@@ -28,12 +28,12 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.Iterator;
-
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.system.deletion.DeletionHandler;
 import org.hisp.dhis.user.User;
 
+import java.util.Iterator;
+
 /**
  * @author Lars Helge Overland
  */
@@ -65,28 +65,28 @@
     public void deleteDataSet( DataSet dataSet )
     {
         Iterator<OrganisationUnit> iterator = dataSet.getSources().iterator();
-        
+
         while ( iterator.hasNext() )
         {
             OrganisationUnit unit = iterator.next();
-            
+
             unit.getDataSets().remove( unit );
-            
+
             organisationUnitService.updateOrganisationUnit( unit );
-        }        
+        }
     }
 
     @Override
     public void deleteUser( User user )
     {
         Iterator<OrganisationUnit> iterator = user.getOrganisationUnits().iterator();
-        
+
         while ( iterator.hasNext() )
         {
             OrganisationUnit unit = iterator.next();
-            
+
             unit.getUsers().remove( user );
-            
+
             organisationUnitService.updateOrganisationUnit( unit );
         }
     }
@@ -95,14 +95,20 @@
     public void deleteOrganisationUnitGroup( OrganisationUnitGroup group )
     {
         Iterator<OrganisationUnit> iterator = group.getMembers().iterator();
-        
+
         while ( iterator.hasNext() )
         {
             OrganisationUnit unit = iterator.next();
-            
+
             unit.getGroups().remove( unit );
-            
+
             organisationUnitService.updateOrganisationUnit( unit );
-        }            
+        }
+    }
+
+    @Override
+    public String allowDeleteOrganisationUnit( OrganisationUnit unit )
+    {
+        return unit.getChildren().isEmpty() ? null : ERROR;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java	2013-12-12 13:27:33 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/DefaultObjectBridge.java	2013-12-12 16:34:34 +0000
@@ -36,6 +36,7 @@
 import org.hisp.dhis.dxf2.timer.Timer;
 import org.hisp.dhis.period.PeriodStore;
 import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.system.deletion.DeletionManager;
 import org.hisp.dhis.user.User;
 import org.hisp.dhis.user.UserCredentials;
 import org.hisp.dhis.user.UserService;
@@ -70,6 +71,9 @@
     @Autowired
     private UserService userService;
 
+    @Autowired
+    private DeletionManager deletionManager;
+
     //-------------------------------------------------------------------------------------------------------
     // Internal and Semi-Public maps
     //-------------------------------------------------------------------------------------------------------
@@ -307,6 +311,7 @@
         {
             if ( writeEnabled )
             {
+                deletionManager.execute( object );
                 manager.delete( (IdentifiableObject) object );
             }
 

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2013-12-12 14:44:41 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java	2013-12-12 16:34:34 +0000
@@ -38,6 +38,7 @@
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.common.SharingUtils;
+import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.dataelement.DataElementOperandService;
 import org.hisp.dhis.dataentryform.DataEntryForm;
@@ -425,16 +426,27 @@
 
         log.debug( "Trying to delete object => " + ImportUtils.getDisplayName( persistedObject ) + " (" + persistedObject.getClass().getSimpleName() + ")" );
 
+        /*
         persistedObject.setUser( null );
         NonIdentifiableObjects nonIdentifiableObjects = new NonIdentifiableObjects();
         nonIdentifiableObjects.delete( persistedObject );
 
         Map<Field, Object> fields = detachFields( persistedObject );
         Map<Field, Collection<Object>> collectionFields = detachCollectionFields( persistedObject );
+        */
 
         sessionFactory.getCurrentSession().flush();
 
-        objectBridge.deleteObject( persistedObject );
+        try
+        {
+            objectBridge.deleteObject( persistedObject );
+        }
+        catch ( Exception ex )
+        {
+            summaryType.getImportConflicts().add(
+                new ImportConflict( ImportUtils.getDisplayName( persistedObject ), ex.getMessage() ) );
+            return false;
+        }
 
         sessionFactory.getCurrentSession().flush();
 
@@ -844,6 +856,11 @@
             conflict = reportMoreThanOneConflict( object );
         }
 
+        if ( !OrganisationUnit.class.isAssignableFrom( object.getClass() ) )
+        {
+            conflict = new ImportConflict( "NoOrg", "no no no" );
+        }
+
         if ( conflict != null )
         {
             summaryType.getImportConflicts().add( conflict );