← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3457: Simplified ouwt

 

------------------------------------------------------------
revno: 3457
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2011-04-24 10:56:40 +0200
message:
  Simplified ouwt
modified:
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/AddSelectedOrganisationUnitAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/CollapseSubtreeAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/ExpandSubtreeAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetExpandedTreeAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/RemoveSelectedOrganisationUnitAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/SetSelectedOrganisationUnitAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/manager/DefaultOrganisationUnitSelectionManager.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-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/AddSelectedOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/AddSelectedOrganisationUnitAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/AddSelectedOrganisationUnitAction.java	2011-04-24 08:56:40 +0000
@@ -29,8 +29,6 @@
 
 import java.util.Collection;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
@@ -44,8 +42,6 @@
 public class AddSelectedOrganisationUnitAction
     implements Action
 {
-    private static final Log LOG = LogFactory.getLog( AddSelectedOrganisationUnitAction.class );
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -89,25 +85,16 @@
     public String execute()
         throws Exception
     {
-        try
-        {
-            OrganisationUnit unit = organisationUnitService.getOrganisationUnit( id );
-
-            if ( unit == null )
-            {
-                throw new RuntimeException( "OrganisationUnit with id " + id + " doesn't exist" );
-            }
-
-            selectedUnits = selectionManager.getSelectedOrganisationUnits();
-            selectedUnits.add( unit );
-            selectionManager.setSelectedOrganisationUnits( selectedUnits );
-        }
-        catch ( Exception e )
-        {
-            LOG.error( e.getMessage(), e );
-
-            throw e;
-        }
+        OrganisationUnit unit = organisationUnitService.getOrganisationUnit( id );
+
+        if ( unit == null )
+        {
+            throw new RuntimeException( "OrganisationUnit with id " + id + " doesn't exist" );
+        }
+
+        selectedUnits = selectionManager.getSelectedOrganisationUnits();
+        selectedUnits.add( unit );
+        selectionManager.setSelectedOrganisationUnits( selectedUnits );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/CollapseSubtreeAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/CollapseSubtreeAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/CollapseSubtreeAction.java	2011-04-24 08:56:40 +0000
@@ -29,8 +29,6 @@
 
 import java.util.Collection;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.ouwt.manager.TreeStateManager;
@@ -44,8 +42,6 @@
 public class CollapseSubtreeAction
     implements Action
 {
-    private static final Log LOG = LogFactory.getLog( CollapseSubtreeAction.class );
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -93,18 +89,9 @@
     public String execute()
         throws Exception
     {
-        try
-        {
-            OrganisationUnit parentUnit = organisationUnitService.getOrganisationUnit( parentId );
-
-            collapsedUnits = treeStateManager.setSubtreeCollapsed( parentUnit );
-        }
-        catch ( Exception e )
-        {
-            LOG.error( e.getMessage(), e );
-
-            throw e;
-        }
+        OrganisationUnit parentUnit = organisationUnitService.getOrganisationUnit( parentId );
+
+        collapsedUnits = treeStateManager.setSubtreeCollapsed( parentUnit );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/ExpandSubtreeAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/ExpandSubtreeAction.java	2011-02-15 13:45:11 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/ExpandSubtreeAction.java	2011-04-24 08:56:40 +0000
@@ -28,16 +28,12 @@
  */
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
 import org.hisp.dhis.ouwt.manager.TreeStateManager;
 
 import com.opensymphony.xwork2.Action;
@@ -49,8 +45,6 @@
 public class ExpandSubtreeAction
     implements Action
 {
-    private static final Log LOG = LogFactory.getLog( ExpandSubtreeAction.class );
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -105,25 +99,16 @@
     public String execute()
         throws Exception
     {
-        try
-        {
-            OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentId );
-
-            if ( parent == null )
-            {
-                throw new RuntimeException( "OrganisationUnit with id " + parentId + " doesn't exist" );
-            }
-
-            treeStateManager.setSubtreeExpanded( parent );
-
-            addParentWithChildren( parent );
-        }
-        catch ( Exception e )
-        {
-            LOG.error( e.getMessage(), e );
-
-            throw e;
-        }
+        OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentId );
+
+        if ( parent == null )
+        {
+            throw new RuntimeException( "OrganisationUnit with id " + parentId + " doesn't exist" );
+        }
+
+        treeStateManager.setSubtreeExpanded( parent );
+
+        addParentWithChildren( parent );
 
         return SUCCESS;
     }
@@ -131,7 +116,7 @@
     private void addParentWithChildren( OrganisationUnit parent )
         throws Exception
     {
-        List<OrganisationUnit> children = getChildren( parent );
+        List<OrganisationUnit> children = parent.getSortedChildren();
 
         parents.add( parent );
 
@@ -139,23 +124,10 @@
 
         for ( OrganisationUnit child : children )
         {
-            boolean hasChildren = child.getChildren().size() > 0; // Dirty loading
-
-            LOG.debug( "OrganisationUnit " + child.getId() + " has children = " + hasChildren );
-
             if ( treeStateManager.isSubtreeExpanded( child ) )
             {
                 addParentWithChildren( child );
             }
         }
     }
-
-    private final List<OrganisationUnit> getChildren( OrganisationUnit parent )
-    {
-        List<OrganisationUnit> children = new ArrayList<OrganisationUnit>( parent.getChildren() );
-
-        Collections.sort( children, new OrganisationUnitNameComparator() );
-
-        return children;
-    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetExpandedTreeAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetExpandedTreeAction.java	2011-02-15 13:45:11 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetExpandedTreeAction.java	2011-04-24 08:56:40 +0000
@@ -34,8 +34,6 @@
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
@@ -50,8 +48,6 @@
 public class GetExpandedTreeAction
     implements Action
 {
-    private static final Log LOG = LogFactory.getLog( GetExpandedTreeAction.class );
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -123,10 +119,6 @@
 
         for ( OrganisationUnit root : roots )
         {
-            boolean hasChildren = root.getChildren().size() > 0; // Dirty loading
-
-            LOG.debug( "OrganisationUnit " + root.getId() + " has children = " + hasChildren );
-
             if ( treeStateManager.isSubtreeExpanded( root ) )
             {
                 addParentWithChildren( root );
@@ -145,7 +137,7 @@
     private void addParentWithChildren( OrganisationUnit parent )
         throws Exception
     {
-        List<OrganisationUnit> children = getChildren( parent );
+        List<OrganisationUnit> children = parent.getSortedChildren();
 
         parents.add( parent );
 
@@ -153,23 +145,10 @@
 
         for ( OrganisationUnit child : children )
         {
-            boolean hasChildren = child.getChildren().size() > 0; // Dirty loading
-
-            LOG.debug( "OrganisationUnit " + child.getId() + " has children = " + hasChildren );
-
             if ( treeStateManager.isSubtreeExpanded( child ) )
             {
                 addParentWithChildren( child );
             }
         }
     }
-
-    private final List<OrganisationUnit> getChildren( OrganisationUnit parent )
-    {
-        List<OrganisationUnit> children = new ArrayList<OrganisationUnit>( parent.getChildren() );
-
-        Collections.sort( children, new OrganisationUnitNameComparator() );
-
-        return children;
-    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/RemoveSelectedOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/RemoveSelectedOrganisationUnitAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/RemoveSelectedOrganisationUnitAction.java	2011-04-24 08:56:40 +0000
@@ -29,8 +29,6 @@
 
 import java.util.Collection;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
@@ -44,8 +42,6 @@
 public class RemoveSelectedOrganisationUnitAction
     implements Action
 {
-    private static final Log LOG = LogFactory.getLog( RemoveSelectedOrganisationUnitAction.class );
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -89,25 +85,16 @@
     public String execute()
         throws Exception
     {
-        try
-        {
-            OrganisationUnit unit = organisationUnitService.getOrganisationUnit( id );
-
-            if ( unit == null )
-            {
-                throw new RuntimeException( "OrganisationUnit with id " + id + " doesn't exist" );
-            }
-
-            selectedUnits = selectionManager.getSelectedOrganisationUnits();
-            selectedUnits.remove( unit );
-            selectionManager.setSelectedOrganisationUnits( selectedUnits );
-        }
-        catch ( Exception e )
-        {
-            LOG.error( e.getMessage(), e );
-
-            throw e;
-        }
+        OrganisationUnit unit = organisationUnitService.getOrganisationUnit( id );
+
+        if ( unit == null )
+        {
+            throw new RuntimeException( "OrganisationUnit with id " + id + " doesn't exist" );
+        }
+
+        selectedUnits = selectionManager.getSelectedOrganisationUnits();
+        selectedUnits.remove( unit );
+        selectionManager.setSelectedOrganisationUnits( selectedUnits );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/SetSelectedOrganisationUnitAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/SetSelectedOrganisationUnitAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/SetSelectedOrganisationUnitAction.java	2011-04-24 08:56:40 +0000
@@ -30,8 +30,6 @@
 import java.util.Collection;
 import java.util.HashSet;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
@@ -45,8 +43,6 @@
 public class SetSelectedOrganisationUnitAction
     implements Action
 {
-    private static final Log LOG = LogFactory.getLog( SetSelectedOrganisationUnitAction.class );
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -90,26 +86,17 @@
     public String execute()
         throws Exception
     {
-        try
-        {
-            OrganisationUnit unit = organisationUnitService.getOrganisationUnit( id );
-
-            if ( unit == null )
-            {
-                throw new RuntimeException( "OrganisationUnit with id " + id + " doesn't exist" );
-            }
-
-            selectedUnits = new HashSet<OrganisationUnit>( 1 );
-            selectedUnits.add( unit );
-
-            selectionManager.setSelectedOrganisationUnits( selectedUnits );
-        }
-        catch ( Exception e )
-        {
-            LOG.error( e.getMessage(), e );
-
-            throw e;
-        }
+        OrganisationUnit unit = organisationUnitService.getOrganisationUnit( id );
+
+        if ( unit == null )
+        {
+            throw new RuntimeException( "OrganisationUnit with id " + id + " doesn't exist" );
+        }
+
+        selectedUnits = new HashSet<OrganisationUnit>( 1 );
+        selectedUnits.add( unit );
+
+        selectionManager.setSelectedOrganisationUnits( selectedUnits );
 
         return SUCCESS;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/manager/DefaultOrganisationUnitSelectionManager.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/manager/DefaultOrganisationUnitSelectionManager.java	2011-02-22 23:17:50 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/manager/DefaultOrganisationUnitSelectionManager.java	2011-04-24 08:56:40 +0000
@@ -72,10 +72,7 @@
             throw new IllegalArgumentException( "Root OrganisationUnit cannot be null" );
         }
 
-        Collection<OrganisationUnit> rootUnits = new HashSet<OrganisationUnit>();
-        rootUnits.addAll( organisationUnits );
-
-        saveToSession( SESSION_KEY_ROOT_ORG_UNITS, rootUnits );
+        saveToSession( SESSION_KEY_ROOT_ORG_UNITS, new HashSet<OrganisationUnit>( organisationUnits ) );
 
         clearSelectedOrganisationUnits();
     }