dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #16657
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6385: Impl a solution for ETag based validation caching for collections of objects. ETag is based on th...
------------------------------------------------------------
revno: 6385
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-03-26 20:11:26 +0200
message:
Impl a solution for ETag based validation caching for collections of objects. ETag is based on the number of objects in the collection and the last-updated date of the most recent object. Improves performance especially for available/selected lists.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Pager.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementGroupSets.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitLevel.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.utils.js
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.js
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetAttributesAction.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetDataElementsAction.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetDataSetsAction.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetIndicatorsAction.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetUsersAction.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetValidationRulesAction.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js
dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js
dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataCompleteness.js
--
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-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2012-01-28 16:24:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2012-03-26 18:11:26 +0000
@@ -27,8 +27,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
@@ -39,6 +41,8 @@
public class IdentifiableObjectUtils
{
private static final String SEPARATOR_JOIN = ", ";
+ private static final String SEPARATOR = "-";
+ private static final SimpleDateFormat LONG_DATE_FORMAT = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss" );
/**
* Joins the names of the IdentifiableObjects in the given list and separates
@@ -67,6 +71,14 @@
return null;
}
+ /**
+ * Filters the given list of IdentifiableObjects based on the given key.
+ *
+ * @param identifiableObjects the list of IdentifiableObjects.
+ * @param key the key.
+ * @param ignoreCase indicates whether to ignore case when filtering.
+ * @return a filtered list of IdentifiableObjects.
+ */
public static <T extends IdentifiableObject> List<T> filterNameByKey( List<T> identifiableObjects, String key,
boolean ignoreCase )
{
@@ -91,4 +103,29 @@
return objects;
}
+
+ /**
+ * Generates a tag reflecting when the date of when the most recently updated
+ * IdentifiableObject in the given collection was modified.
+ *
+ * @param objects the collection of IdentifiableObjects.
+ * @return a string tag.
+ */
+ public static <T extends IdentifiableObject> String getLastUpdatedTag( Collection<T> objects )
+ {
+ Date latest = null;
+
+ if ( objects != null )
+ {
+ for ( IdentifiableObject object : objects )
+ {
+ if ( object != null && object.getLastUpdated() != null && ( latest == null || object.getLastUpdated().after( latest ) ) )
+ {
+ latest = object.getLastUpdated();
+ }
+ }
+ }
+
+ return latest != null && objects != null ? objects.size() + SEPARATOR + LONG_DATE_FORMAT.format( latest ) : null;
+ }
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Pager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Pager.java 2012-03-16 10:07:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Pager.java 2012-03-26 18:11:26 +0000
@@ -27,9 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
/**
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2012-03-20 15:05:16 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2012-03-26 18:11:26 +0000
@@ -33,7 +33,6 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.apache.commons.lang.StringEscapeUtils;
import org.hisp.dhis.attribute.AttributeValue;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.BaseNameableObject;
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java 2012-03-20 15:05:16 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java 2012-03-26 18:11:26 +0000
@@ -34,7 +34,6 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.apache.commons.lang.StringEscapeUtils;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.BaseNameableObject;
import org.hisp.dhis.common.Dxf2Namespace;
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementGroupSets.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementGroupSets.java 2012-03-16 10:07:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementGroupSets.java 2012-03-26 18:11:26 +0000
@@ -34,9 +34,6 @@
import org.hisp.dhis.common.BaseCollection;
import org.hisp.dhis.common.Dxf2Namespace;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java 2012-03-20 15:05:16 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java 2012-03-26 18:11:26 +0000
@@ -27,19 +27,19 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.Dxf2Namespace;
+import org.hisp.dhis.common.view.DetailedView;
+
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.apache.commons.lang.StringEscapeUtils;
-import org.hisp.dhis.common.BaseIdentifiableObject;
-import org.hisp.dhis.common.Dxf2Namespace;
-import org.hisp.dhis.common.view.DetailedView;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
/**
* This object can act both as a hydrated persisted object and as a wrapper
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitLevel.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitLevel.java 2012-03-19 14:58:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitLevel.java 2012-03-26 18:11:26 +0000
@@ -27,18 +27,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonView;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.Dxf2Namespace;
import org.hisp.dhis.common.view.DetailedView;
import org.hisp.dhis.common.view.ExportView;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
/**
* @author Lars Helge Overland
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2012-03-19 22:10:02 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/User.java 2012-03-26 18:11:26 +0000
@@ -27,7 +27,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.utils.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.utils.js 2011-05-23 17:44:10 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/jQuery/jquery.utils.js 2012-03-26 18:11:26 +0000
@@ -6,5 +6,11 @@
postUTF8: function( url, data, success ) {
$.ajax( { url:url, data:data, success:success, type:'post', contentType:'application/x-www-form-urlencoded;charset=utf-8' } );
+ },
+
+ loadNoCache: function( elementId, url, data ) {
+ $.ajax( { url:url, data:data, type:'get', dataType:'html', success:function( data ) {
+ $( '#' + elementId ).html( data );
+ } } );
}
} );
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.js 2012-03-04 13:26:24 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/main.js 2012-03-26 18:11:26 +0000
@@ -7,13 +7,6 @@
function pageInit()
{
- // jQuery ajax setup
-
- $.ajaxSetup(
- {
- cache: false
- } );
-
// Zebra stripes in lists
$( "table.listTable tbody tr:odd" ).addClass( "listAlternateRow" );
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetAttributesAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetAttributesAction.java 2012-01-25 17:11:43 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetAttributesAction.java 2012-03-26 18:11:26 +0000
@@ -31,9 +31,11 @@
import java.util.Collections;
import java.util.List;
+import org.apache.struts2.ServletActionContext;
import org.hisp.dhis.attribute.Attribute;
import org.hisp.dhis.attribute.AttributeService;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
+import org.hisp.dhis.util.ContextUtils;
import com.opensymphony.xwork2.Action;
@@ -73,7 +75,9 @@
public String execute()
{
attributes = new ArrayList<Attribute>( attributeService.getAllAttributes() );
-
+
+ ContextUtils.clearIfNotModified( ServletActionContext.getRequest(), ServletActionContext.getResponse(), attributes );
+
Collections.sort( attributes, IdentifiableObjectNameComparator.INSTANCE );
return SUCCESS;
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetDataElementsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetDataElementsAction.java 2012-01-28 16:24:59 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetDataElementsAction.java 2012-03-26 18:11:26 +0000
@@ -31,6 +31,7 @@
import java.util.Collections;
import java.util.List;
+import org.apache.struts2.ServletActionContext;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
@@ -44,6 +45,7 @@
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.system.filter.AggregatableDataElementFilter;
import org.hisp.dhis.system.util.FilterUtils;
+import org.hisp.dhis.util.ContextUtils;
import org.hisp.dhis.common.IdentifiableObjectUtils;
/**
@@ -198,11 +200,8 @@
else
{
dataElements = new ArrayList<DataElement>( dataElementService.getAllDataElements() );
- }
-
- if ( dataElements == null )
- {
- dataElements = new ArrayList<DataElement>();
+
+ ContextUtils.clearIfNotModified( ServletActionContext.getRequest(), ServletActionContext.getResponse(), dataElements );
}
if ( key != null )
@@ -210,7 +209,7 @@
dataElements = IdentifiableObjectUtils.filterNameByKey( dataElements, key, true );
}
- Collections.sort( dataElements, new IdentifiableObjectNameComparator() );
+ Collections.sort( dataElements, IdentifiableObjectNameComparator.INSTANCE );
if ( aggregate )
{
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetDataSetsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetDataSetsAction.java 2012-01-25 17:11:43 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetDataSetsAction.java 2012-03-26 18:11:26 +0000
@@ -33,6 +33,7 @@
import java.util.List;
import java.util.Set;
+import org.apache.struts2.ServletActionContext;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
@@ -41,6 +42,7 @@
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.UserAuthorityGroup;
import org.hisp.dhis.user.UserService;
+import org.hisp.dhis.util.ContextUtils;
/**
* @author Lars Helge Overland
@@ -116,11 +118,7 @@
public String execute()
throws Exception
{
- if ( id == null && name == null )
- {
- dataSets = new ArrayList<DataSet>( dataSetService.getAllDataSets() );
- }
- else if ( id != null )
+ if ( id != null )
{
dataSets = new ArrayList<DataSet>(
dataSetService.getDataSetsByPeriodType( periodService.getPeriodType( id ) ) );
@@ -130,18 +128,24 @@
dataSets = new ArrayList<DataSet>( dataSetService.getDataSetsByPeriodType( periodService
.getPeriodTypeByName( name ) ) );
}
+ else
+ {
+ dataSets = new ArrayList<DataSet>( dataSetService.getAllDataSets() );
+
+ ContextUtils.clearIfNotModified( ServletActionContext.getRequest(), ServletActionContext.getResponse(), dataSets );
+ }
if ( !currentUserService.currentUserIsSuper() )
{
- Set<DataSet> ds = new HashSet<DataSet>();
+ Set<DataSet> accessibleDataSets = new HashSet<DataSet>();
for ( UserAuthorityGroup u : userService.getUserCredentials( currentUserService.getCurrentUser() )
.getUserAuthorityGroups() )
{
- ds.addAll( u.getDataSets() );
+ accessibleDataSets.addAll( u.getDataSets() );
}
- dataSets.retainAll( ds );
+ dataSets.retainAll( accessibleDataSets );
}
Collections.sort( dataSets, IdentifiableObjectNameComparator.INSTANCE );
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetIndicatorsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetIndicatorsAction.java 2012-01-28 16:24:59 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetIndicatorsAction.java 2012-03-26 18:11:26 +0000
@@ -31,6 +31,7 @@
import java.util.Collections;
import java.util.List;
+import org.apache.struts2.ServletActionContext;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
@@ -38,6 +39,7 @@
import org.hisp.dhis.indicator.IndicatorGroup;
import org.hisp.dhis.indicator.IndicatorService;
import org.hisp.dhis.paging.ActionPagingSupport;
+import org.hisp.dhis.util.ContextUtils;
import org.hisp.dhis.common.IdentifiableObjectUtils;
/**
@@ -126,11 +128,8 @@
else
{
indicators = new ArrayList<Indicator>( indicatorService.getAllIndicators() );
- }
-
- if ( indicators == null )
- {
- indicators = new ArrayList<Indicator>();
+
+ ContextUtils.clearIfNotModified( ServletActionContext.getRequest(), ServletActionContext.getResponse(), indicators );
}
if ( key != null )
@@ -138,7 +137,7 @@
indicators = IdentifiableObjectUtils.filterNameByKey( indicators, key, true );
}
- Collections.sort( indicators, new IdentifiableObjectNameComparator() );
+ Collections.sort( indicators, IdentifiableObjectNameComparator.INSTANCE );
if ( usePaging )
{
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetUsersAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetUsersAction.java 2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetUsersAction.java 2012-03-26 18:11:26 +0000
@@ -32,10 +32,12 @@
import java.util.List;
import java.util.ListIterator;
+import org.apache.struts2.ServletActionContext;
import org.hisp.dhis.paging.ActionPagingSupport;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserService;
import org.hisp.dhis.user.comparator.UserComparator;
+import org.hisp.dhis.util.ContextUtils;
/**
* @author mortenoh
@@ -82,6 +84,8 @@
{
users = new ArrayList<User>( userService.getAllUsers() );
+ ContextUtils.clearIfNotModified( ServletActionContext.getRequest(), ServletActionContext.getResponse(), users );
+
if ( key != null )
{
filterByKey( key, true );
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetValidationRulesAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetValidationRulesAction.java 2012-01-25 17:11:43 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetValidationRulesAction.java 2012-03-26 18:11:26 +0000
@@ -31,7 +31,9 @@
import java.util.Collections;
import java.util.List;
+import org.apache.struts2.ServletActionContext;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
+import org.hisp.dhis.util.ContextUtils;
import org.hisp.dhis.validation.ValidationRule;
import org.hisp.dhis.validation.ValidationRuleService;
@@ -73,6 +75,8 @@
{
validationRules = new ArrayList<ValidationRule>( validationRuleService.getAllValidationRules() );
+ ContextUtils.clearIfNotModified( ServletActionContext.getRequest(), ServletActionContext.getResponse(), validationRules );
+
Collections.sort( validationRules, IdentifiableObjectNameComparator.INSTANCE );
return SUCCESS;
=== 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-03-10 10:01:52 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.java 2012-03-26 18:11:26 +0000
@@ -29,6 +29,7 @@
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
@@ -37,6 +38,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.IdentifiableObjectUtils;
import org.hisp.dhis.system.util.DateUtils;
/**
@@ -59,10 +62,13 @@
public static final String CONTENT_TYPE_JAVASCRIPT = "application/javascript";
public static final String HEADER_USER_AGENT = "User-Agent";
+ public static final String HEADER_IF_NONE_MATCH = "If-None-Match";
+ public static final String HEADER_ETAG = "ETag";
private static final String SEPARATOR = "/";
private static final String PORT_SEPARATOR = ":";
private static final String PROTOCOL = "http://";
+ private static final String QUOTE = "\"";
private static final Map<String, String> CONTENT_TYPE_MAP = new HashMap<String, String>()
{ {
@@ -166,4 +172,33 @@
writer.println( message );
writer.flush();
}
+
+ /**
+ * Clears the given collection if it is not modified according to the HTTP
+ * cache validation. This method looks up the ETag sent in the request from
+ * the "If-None-Match" header value, generates an ETag based on the given
+ * collection of IdentifiableObjects and compares them for equality. If this
+ * evaluates to true, it will set status code 304 Not Modified on the response
+ * and remove all elements from the given list. It will also set the ETag header
+ * on the response in any case.
+ *
+ * @param request the HttpServletRequest.
+ * @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 )
+ {
+ String tag = QUOTE + IdentifiableObjectUtils.getLastUpdatedTag( objects ) + QUOTE;
+
+ response.setHeader( HEADER_ETAG, tag );
+
+ String inputTag = request.getHeader( HEADER_IF_NONE_MATCH );
+
+ if ( objects != null && inputTag != null && tag != null && inputTag.equals( tag ) )
+ {
+ response.setStatus( HttpServletResponse.SC_NOT_MODIFIED );
+
+ objects.clear();
+ }
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js 2012-02-17 06:58:48 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/entry.js 2012-03-26 18:11:26 +0000
@@ -254,7 +254,6 @@
url: 'saveValue.action',
data: dataValue,
dataType: 'json',
- cache: false,
success: handleSuccess,
error: handleError
} );
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2012-03-12 09:31:46 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2012-03-26 18:11:26 +0000
@@ -70,7 +70,8 @@
$( document ).ready( function()
{
$.ajaxSetup( {
- type: 'POST'
+ type: 'POST',
+ cache: false
} );
selection.setListenerFunction( organisationUnitSelected );
@@ -144,7 +145,6 @@
$.ajax( {
url: 'getMetaData.action',
- cache: false,
dataType: 'json',
success: function( json )
{
@@ -202,7 +202,6 @@
url: 'registerCompleteDataSet.action',
data: value,
dataType: 'json',
- cache: false,
success: function( data, textStatus, jqXHR )
{
if ( data.status == 2 )
@@ -255,7 +254,6 @@
url: 'saveValue.action',
data: value,
dataType: 'json',
- cache: false,
success: function( data, textStatus, jqXHR )
{
if ( data.c == 2 ) {
@@ -676,7 +674,6 @@
dataSetId : dataSetId,
organisationUnitId : currentOrganisationUnitId
},
- cache: false,
dataType: 'json',
success: function( json )
{
@@ -859,7 +856,6 @@
$.ajax( { url: 'getValidationViolations.action',
data: params,
- cache: false,
dataType: 'json',
success: function( data )
{
@@ -883,7 +879,6 @@
$.ajax( {
url: 'registerCompleteDataSet.action',
data: params,
- cache: false,
dataType: 'json',
success: function(data)
{
@@ -921,7 +916,6 @@
$.ajax( {
url: 'undoCompleteDataSet.action',
data: params,
- cache: false,
dataType: 'json',
success: function(data)
{
@@ -1316,7 +1310,6 @@
},
dataSetId: dataSetId,
formVersion: formVersion,
- cache: false,
dataType: 'text',
success: function( data, textStatus, jqXHR )
{
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js 2011-08-22 08:08:11 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/history.js 2012-03-26 18:11:26 +0000
@@ -36,7 +36,6 @@
commentValue: commentValue
},
dataType: 'json',
- cache: false,
success: handleResponse,
error: handleError
} );
@@ -87,8 +86,7 @@
$( '#maxLimit' ).css( 'background-color', COLOR_WHITE );
refreshChart()
- },
- cache: false
+ }
} );
}
@@ -152,7 +150,6 @@
maxLimit: maxValue
},
dataType: 'json',
- cache: false,
success: function() {
$( '#minLimit' ).css( 'background-color', COLOR_GREEN );
$( '#maxLimit' ).css( 'background-color', COLOR_GREEN );
@@ -188,7 +185,6 @@
periodId: periodId,
organisationUnitId: currentOrganisationUnitId
},
- cache: false,
dataType: 'json',
success: function( json )
{
=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataCompleteness.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataCompleteness.js 2012-03-18 22:44:02 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataCompleteness.js 2012-03-26 18:11:26 +0000
@@ -21,7 +21,7 @@
showLoader();
var url = "getDataCompleteness.action" + "?periodId=" + periodId + "&criteria=" + criteria + "&dataSetId="
- + dataSetId + "&type=html";
+ + dataSetId + "&type=html&r=" + getRandomNumber();
$( "#contentDiv" ).load( url, function()
{