dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #17980
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7387: Case entry, single event, added server validation caching when loading option sets without querie...
------------------------------------------------------------
revno: 7387
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-06-25 20:40:49 +0200
message:
Case entry, single event, added server validation caching when loading option sets without queries for improved performance
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.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-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2012-04-22 18:21:40 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectUtils.java 2012-06-25 18:40:49 +0000
@@ -100,7 +100,7 @@
}
/**
- * Generates a tag reflecting when the date of when the most recently updated
+ * Generates a tag reflecting the date of when the most recently updated
* IdentifiableObject in the given collection was modified.
*
* @param objects the collection of IdentifiableObjects.
@@ -123,4 +123,15 @@
return latest != null && objects != null ? objects.size() + SEPARATOR + LONG_DATE_FORMAT.format( latest ) : null;
}
+
+ /**
+ * Generates a tag reflecting the date of when the object was last updated.
+ *
+ * @param object the identifiable object.
+ * @return a string tag.
+ */
+ public static String getLastUpdatedTag( IdentifiableObject object )
+ {
+ return object != null ? LONG_DATE_FORMAT.format( object.getLastUpdated() ) : null;
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java 2012-06-25 17:44:04 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/GetOptionsByDataElementAction.java 2012-06-25 18:40:49 +0000
@@ -29,9 +29,13 @@
import java.util.List;
+import org.apache.commons.lang.StringUtils;
+import org.apache.struts2.ServletActionContext;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.option.OptionService;
+import org.hisp.dhis.option.OptionSet;
+import org.hisp.dhis.util.ContextUtils;
import com.opensymphony.xwork2.Action;
@@ -98,10 +102,24 @@
public String execute()
{
+ query = StringUtils.trimToNull( query );
+
DataElement dataElement = dataElementService.getDataElement( id );
- options = optionService.getOptions( dataElement.getOptionSet(), query, MAX_OPTIONS_DISPLAYED );
-
+ OptionSet optionSet = dataElement.getOptionSet();
+
+ // ---------------------------------------------------------------------
+ // If the query is null and the option set has not changed since last
+ // request we can tell the client to use its cached response (304)
+ // ---------------------------------------------------------------------
+
+ boolean isNotModified = ( query == null && ContextUtils.isNotModified( ServletActionContext.getRequest(), ServletActionContext.getResponse(), optionSet ) );
+
+ if ( !isNotModified )
+ {
+ options = optionService.getOptions( optionSet, query, MAX_OPTIONS_DISPLAYED );
+ }
+
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-04-22 19:36:58 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/util/ContextUtils.java 2012-06-25 18:40:49 +0000
@@ -209,6 +209,36 @@
}
/**
+ * Returns true if the given object 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.
+ * 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 boolean isNotModified( HttpServletRequest request, HttpServletResponse response, IdentifiableObject object )
+ {
+ String tag = IdentifiableObjectUtils.getLastUpdatedTag( object );
+
+ response.setHeader( HEADER_ETAG, tag );
+
+ String inputTag = request.getHeader( HEADER_IF_NONE_MATCH );
+
+ if ( object != null && inputTag != null && tag != null && inputTag.equals( tag ) )
+ {
+ response.setStatus( HttpServletResponse.SC_NOT_MODIFIED );
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
* Creates a ZipOutputStream based on the HttpServletResponse and puts a
* new ZipEntry with the given filename to it.
*