← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6680: GIS: performance improvement

 

------------------------------------------------------------
revno: 6680
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-04-22 21:36:58 +0200
message:
  GIS: performance improvement
removed:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitWithValidPointCoordinateFilter.java
added:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitWithValidCoordinatesFilter.java
modified:
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataElementsByDataElementGroupAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFacilitiesAction.java
  dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonWithValuesAction.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
=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitWithValidCoordinatesFilter.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitWithValidCoordinatesFilter.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitWithValidCoordinatesFilter.java	2012-04-22 19:36:58 +0000
@@ -0,0 +1,45 @@
+package org.hisp.dhis.system.filter;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.ValidationUtils;
+
+import static org.hisp.dhis.organisationunit.OrganisationUnit.*;
+
+public class OrganisationUnitWithValidCoordinatesFilter
+    implements Filter<OrganisationUnit>
+{
+    @Override
+    public boolean retain( OrganisationUnit object )
+    {
+        return object != null && object.getFeatureType() != null && object.hasCoordinates() &&
+            ( object.getFeatureType().equals( FEATURETYPE_POINT ) ? ValidationUtils.coordinateIsValid( object.getCoordinates() ) : true );
+    }
+}

=== removed file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitWithValidPointCoordinateFilter.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitWithValidPointCoordinateFilter.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/filter/OrganisationUnitWithValidPointCoordinateFilter.java	1970-01-01 00:00:00 +0000
@@ -1,51 +0,0 @@
-package org.hisp.dhis.system.filter;
-
-/*
- * Copyright (c) 2004-2012, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- *   this list of conditions and the following disclaimer in the documentation
- *   and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- *   be used to endorse or promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.system.util.Filter;
-import org.hisp.dhis.system.util.ValidationUtils;
-
-/**
- * @author Jan Henrik Overland
- */
-public class OrganisationUnitWithValidPointCoordinateFilter
-    implements Filter<OrganisationUnit>
-{
-    @Override
-    public boolean retain( OrganisationUnit object )
-    {
-        if ( object != null && object.hasCoordinates() )
-        {
-            return object.getFeatureType().equals( OrganisationUnit.FEATURETYPE_POINT ) ?
-                ValidationUtils.coordinateIsValid( object.getCoordinates() ) : true;
-        }
-        
-        return false;
-    }
-}

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.java	2012-04-18 13:51:28 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.java	2012-04-22 19:36:58 +0000
@@ -188,7 +188,7 @@
      * @param response the HttpServletResponse.
      * @return true if the eTag values are equals, false otherwise.
      */
-    public static void clearIfNotModified( HttpServletRequest request, HttpServletResponse response, Collection<? extends IdentifiableObject> objects )
+    public static boolean clearIfNotModified( HttpServletRequest request, HttpServletResponse response, Collection<? extends IdentifiableObject> objects )
     {
         String tag = QUOTE + IdentifiableObjectUtils.getLastUpdatedTag( objects ) + QUOTE;
         
@@ -201,7 +201,11 @@
             response.setStatus( HttpServletResponse.SC_NOT_MODIFIED );
             
             objects.clear();
+            
+            return true;
         }
+        
+        return false;
     }
 
     /**

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataElementsByDataElementGroupAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataElementsByDataElementGroupAction.java	2012-01-20 10:38:11 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetDataElementsByDataElementGroupAction.java	2012-04-22 19:36:58 +0000
@@ -40,7 +40,6 @@
 
 /**
  * @author Jan Henrik Overland
- * @version $Id$
  */
 public class GetDataElementsByDataElementGroupAction
     implements Action

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonAction.java	2012-04-20 09:52:17 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonAction.java	2012-04-22 19:36:58 +0000
@@ -27,22 +27,21 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.util.ContextUtils.clearIfNotModified;
+
 import java.util.ArrayList;
 import java.util.Collection;
 
 import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.system.filter.OrganisationUnitWithCoordinatesFilter;
-import org.hisp.dhis.system.filter.OrganisationUnitWithValidPointCoordinateFilter;
+import org.hisp.dhis.system.filter.OrganisationUnitWithValidCoordinatesFilter;
 import org.hisp.dhis.system.util.FilterUtils;
-import org.hisp.dhis.util.ContextUtils;
 
 import com.opensymphony.xwork2.Action;
 
 /**
  * @author Jan Henrik Overland
- * @version $Id$
  */
 public class GetGeoJsonAction
     implements Action
@@ -80,7 +79,7 @@
     // Output
     // -------------------------------------------------------------------------
 
-    private Collection<OrganisationUnit> object;
+    private Collection<OrganisationUnit> object = new ArrayList<OrganisationUnit>();
 
     public Collection<OrganisationUnit> getObject()
     {
@@ -98,33 +97,31 @@
 
         level = level == null ? organisationUnitService.getLevelOfOrganisationUnit( parent.getId() ) : level;
 
-        Collection<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel( level,
-            parent );
-
-        FilterUtils.filter( organisationUnits, new OrganisationUnitWithCoordinatesFilter() );
-
-        FilterUtils.filter( organisationUnits, new OrganisationUnitWithValidPointCoordinateFilter() );
-
-        object = new ArrayList<OrganisationUnit>();
-
-        for ( OrganisationUnit unit : organisationUnits )
-        {
-            if ( !unit.getFeatureType().equals( OrganisationUnit.FEATURETYPE_POINT ) )
-            {
-                object.add( unit );
-            }
-        }
-
-        for ( OrganisationUnit unit : organisationUnits )
-        {
-            if ( unit.getFeatureType().equals( OrganisationUnit.FEATURETYPE_POINT ) )
-            {
-                object.add( unit );
-            }
-        }
-
-        ContextUtils.clearIfNotModified( ServletActionContext.getRequest(), ServletActionContext.getResponse(), object );
+        Collection<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel( level, parent );
+
+        FilterUtils.filter( organisationUnits, new OrganisationUnitWithValidCoordinatesFilter() );
+
+        boolean modified = !clearIfNotModified( ServletActionContext.getRequest(), ServletActionContext.getResponse(), organisationUnits );
         
+        if ( modified )
+        {        
+            for ( OrganisationUnit unit : organisationUnits )
+            {
+                if ( !unit.getFeatureType().equals( OrganisationUnit.FEATURETYPE_POINT ) )
+                {
+                    object.add( unit );
+                }
+            }
+    
+            for ( OrganisationUnit unit : organisationUnits )
+            {
+                if ( unit.getFeatureType().equals( OrganisationUnit.FEATURETYPE_POINT ) )
+                {
+                    object.add( unit );
+                }
+            }
+        }
+
         return SUCCESS;
     }
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFacilitiesAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFacilitiesAction.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonFacilitiesAction.java	2012-04-22 19:36:58 +0000
@@ -34,8 +34,7 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.system.filter.OrganisationUnitWithCoordinatesFilter;
-import org.hisp.dhis.system.filter.OrganisationUnitWithValidPointCoordinateFilter;
+import org.hisp.dhis.system.filter.OrganisationUnitWithValidCoordinatesFilter;
 import org.hisp.dhis.system.util.FilterUtils;
 
 import com.opensymphony.xwork2.Action;
@@ -114,11 +113,9 @@
 
         Collection<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel( level,
             parent );
-        
-        FilterUtils.filter( organisationUnits, new OrganisationUnitWithCoordinatesFilter() );
-
-        FilterUtils.filter( organisationUnits, new OrganisationUnitWithValidPointCoordinateFilter() );
-        
+
+        FilterUtils.filter( organisationUnits, new OrganisationUnitWithValidCoordinatesFilter() );
+
         groupSets = organisationUnitGroupService.getAllOrganisationUnitGroupSets();
         
         object = new ArrayList<OrganisationUnit>();

=== modified file 'dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonWithValuesAction.java'
--- dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonWithValuesAction.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-mapping/src/main/java/org/hisp/dhis/mapping/action/GetGeoJsonWithValuesAction.java	2012-04-22 19:36:58 +0000
@@ -34,8 +34,7 @@
 import org.hisp.dhis.mapping.MappingService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.system.filter.OrganisationUnitWithCoordinatesFilter;
-import org.hisp.dhis.system.filter.OrganisationUnitWithValidPointCoordinateFilter;
+import org.hisp.dhis.system.filter.OrganisationUnitWithValidCoordinatesFilter;
 import org.hisp.dhis.system.util.FilterUtils;
 
 import com.opensymphony.xwork2.Action;
@@ -129,9 +128,7 @@
         Collection<OrganisationUnit> organisationUnits = organisationUnitService.getOrganisationUnitsAtLevel( level,
             parent );
 
-        FilterUtils.filter( organisationUnits, new OrganisationUnitWithCoordinatesFilter() );
-
-        FilterUtils.filter( organisationUnits, new OrganisationUnitWithValidPointCoordinateFilter() );
+        FilterUtils.filter( organisationUnits, new OrganisationUnitWithValidCoordinatesFilter() );
 
         object = new ArrayList<OrganisationUnit>();