← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20104: Using getOrganisationUnitsByQuery in mergeWithCurrentUserOrganisationUnits

 

------------------------------------------------------------
revno: 20104
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2015-09-13 15:48:45 +0200
message:
  Using getOrganisationUnitsByQuery in mergeWithCurrentUserOrganisationUnits
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/DefineDataSetAssociationsAction.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/dataset/DefaultDataSetService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java	2015-09-10 16:35:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java	2015-09-13 13:48:45 +0000
@@ -48,6 +48,7 @@
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.i18n.I18nService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitQueryParams;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
@@ -421,19 +422,17 @@
     @Override
     public void mergeWithCurrentUserOrganisationUnits( DataSet dataSet, Collection<OrganisationUnit> mergeOrganisationUnits )
     {
-        Set<OrganisationUnit> organisationUnits = new HashSet<>( dataSet.getSources() );
-
-        Set<OrganisationUnit> userOrganisationUnits = new HashSet<>();
-
-        for ( OrganisationUnit organisationUnit : currentUserService.getCurrentUser().getOrganisationUnits() )
-        {
-            userOrganisationUnits.addAll( organisationUnitService.getOrganisationUnitWithChildren( organisationUnit.getUid() ) );
-        }
-
-        organisationUnits.removeAll( userOrganisationUnits );
-        organisationUnits.addAll( mergeOrganisationUnits );
-
-        dataSet.updateOrganisationUnits( organisationUnits );
+        Set<OrganisationUnit> dataSetOrgUnits = new HashSet<>( dataSet.getSources() );
+        
+        OrganisationUnitQueryParams params = new OrganisationUnitQueryParams();
+        params.setParents( currentUserService.getCurrentUser().getOrganisationUnits() );
+
+        List<OrganisationUnit> userOrganisationUnits = organisationUnitService.getOrganisationUnitsByQuery( params );
+
+        dataSetOrgUnits.removeAll( userOrganisationUnits );
+        dataSetOrgUnits.addAll( mergeOrganisationUnits );
+
+        dataSet.updateOrganisationUnits( dataSetOrgUnits );
 
         updateDataSet( dataSet );
     }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.java	2015-09-11 17:54:48 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/manager/DefaultSelectionTreeManager.java	2015-09-13 13:48:45 +0000
@@ -47,8 +47,8 @@
 {
     private static final String SESSION_KEY_SELECTED_ORG_UNITS = "dhis-oust-selected-org-units";
     private static final String SESSION_KEY_ROOT_ORG_UNITS = "dhis-oust-root-org-units";
-
-    private static final double PERCENTAGE_OF_MULTIPLE_RELOADING_ORG_UNITS = 0.1;
+    
+    private static final int LIMIT_SELECT_ALL_ORG_UNITS = 200;
 
     // -------------------------------------------------------------------------
     // Dependencies
@@ -246,11 +246,9 @@
     {
         Set<OrganisationUnit> reloadedUnits = new HashSet<>();
 
-        int noTotal = organisationUnitService.getNumberOfOrganisationUnits();
-
         int noSelected = units.size();
 
-        if ( (double) noSelected / noTotal > PERCENTAGE_OF_MULTIPLE_RELOADING_ORG_UNITS ) // Select all at once
+        if ( noSelected > LIMIT_SELECT_ALL_ORG_UNITS ) // Select all at once
         {
             Collection<OrganisationUnit> allOrgUnits = organisationUnitService.getAllOrganisationUnits();
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/DefineDataSetAssociationsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/DefineDataSetAssociationsAction.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/DefineDataSetAssociationsAction.java	2015-09-13 13:48:45 +0000
@@ -28,8 +28,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.Collection;
+
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
 
 import com.opensymphony.xwork2.Action;
@@ -78,7 +81,10 @@
         throws Exception
     {
         DataSet dataSet = dataSetService.getDataSet( dataSetId );
-        dataSetService.mergeWithCurrentUserOrganisationUnits( dataSet, selectionTreeManager.getReloadedSelectedOrganisationUnits() );
+
+        Collection<OrganisationUnit> units = selectionTreeManager.getReloadedSelectedOrganisationUnits();
+
+        dataSetService.mergeWithCurrentUserOrganisationUnits( dataSet, units );
 
         return SUCCESS;
     }