org.ibisph.mvc.model
Class QueryModule

java.lang.Object
  extended by org.ibisph.mvc.model.QueryModule

public class QueryModule
extends java.lang.Object

Handles Query System's module requests. This controller first needs to get/build/process the xincludes for the module XML. The document is then set into the session for further requests and the document is returned for the view operation.

Author:
Garth Braithwaite, STG

Field Summary
protected  java.lang.String columnGroupByParameterName
           
protected  org.dom4j.Document document
           
protected  java.io.File file
           
protected  java.lang.String otherGroupByParameterName
           
protected  java.util.Map<java.lang.String,java.lang.String> parametersMap
           
protected  java.lang.String rowGroupByParameterName
           
 
Constructor Summary
QueryModule(org.dom4j.Document document, java.lang.String configurationPath, java.lang.String configurationName, long serialNumber)
          Constructor that sets the XML document.
 
Method Summary
protected  void addQueryURLParameter(java.lang.String name, java.lang.String value, java.lang.String urlCharacterEncoding, java.lang.String controlParameterPrefix, java.lang.StringBuffer queryURLParameters)
          Helper that localizes encoding the PARAMETER elements.
protected  void addQueryURLParameters(java.lang.String urlCharacterEncoding, java.lang.String rootRelativeParametersXpath, java.lang.String controlParameterPrefix, java.lang.StringBuffer queryURLParameters)
          Helper that localizes looping the PARAMETER elements.
 void deleteQueryResult()
           
 void deleteRequestError()
          Deletes any existing REQUEST/ERROR element.
 java.lang.String getBaseQueryApplicationURL()
          Simple access to the CONFIGURATION/BASE_QUERY_APPLICATION_URL element.
 java.lang.String getConfigurationPath()
          Simple access to the REQUEST/CONFIGURATION_PATH element.
 org.dom4j.Document getDocument()
          Basic getter used to access the query module XML document.
 java.io.File getFile()
          Gets the query module's XML file (base/core file in the case of xinclude).
 java.lang.String getGraphicName()
           
 java.lang.String getQueryURLParameters(java.lang.String urlCharacterEncoding, java.lang.String controlParameterPrefix)
          Localizes appending of encoded NAME and VALUE elements to StringBuffer.
 java.lang.String getRequestStartedDateTimeStamp()
          Gets the formatted date time stamp string for when the request was started.
protected  java.lang.String getResultGroupByDimensionName(java.util.HashSet resultDimensionNames, java.lang.String dimensionElementNameToMatch)
          Helper that sets the actual dimension name element into the document based on the dimensionElementNameToMatch string passed in.
 boolean hasQueryResponse()
          Performs a simple existence test of the REQUEST/IBISQ_QUERY_RESULT element or the the REQUEST/ERROR element.
 void setCompleteQueryURL(java.lang.String url)
          Sets the URL used to query the data.
 void setFile(java.io.File queryModuleFile)
          Sets the module's XML file.
 void setGraphicName(java.lang.String graphicName)
           
 void setHiddenInputParameters(javax.servlet.http.HttpServletRequest request)
          Sets any PARAMETER elements which have a HIDDEN_INPUT_FLAG which has a name that matches a request's parameter name.
 void setMeasureName(java.lang.String measureName)
           
 void setQueryResult(java.lang.String queryResult)
          Parses the query result string and puts into the query module XML document object.
 void setRequestError(java.lang.String title, java.lang.String description)
           
 void setRequestError(java.lang.String title, java.lang.String description, java.lang.String response)
          Creates a new REQUEST/ERROR element and adds the appropriate elements and sets those elements with the supplied values.
 void setRequestFinishedDateTimeStamp(java.lang.String formattedDateTimeStamp)
          Sets the formatted date time stamp string which the view can show on the result page.
 void setRequestStartedDateTimeStamp(java.lang.String formattedDateTimeStamp)
          Sets the formatted date time stamp string for when the request was started.
 void setRequestSubmittedDateTimeStamp(java.lang.String formattedDateTimeStamp)
          Sets the formatted date time stamp string which the view can show on the result page.
 void setResultGroupByDimensionNames()
          Parses the query result string and puts into the query module XML document object.
 void setSelectedControls(javax.servlet.http.HttpServletRequest request)
          Sets the request selected groupby dim names, graphic, and measure elements.
 void setSelectedDimensions(javax.servlet.http.HttpServletRequest request)
          Main worker method that loads the request parameters into the approp Query Module XML document SELECTED_DIMENSION element structure.
protected  void setSelectedGroupByDimensionName(javax.servlet.http.HttpServletRequest request, java.lang.String groupByParameterName, java.lang.String groupByElementName)
          Helper that localizes getting the GroupByDimensionName type request parameters and setting the associated REQUEST/GROUP_BY element.
protected  void setSelectedGroupByDimensionNames(javax.servlet.http.HttpServletRequest request)
          Helper that sets the REQUEST/SELECTED_GROUP_BY elements.
protected  void updateHiddenInputParameters(java.lang.String rootRelativeParametersXpath, javax.servlet.http.HttpServletRequest request)
          Helper that localizes setting PARAMETER HIDDEN_INPUT_FLAG elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rowGroupByParameterName

protected java.lang.String rowGroupByParameterName

columnGroupByParameterName

protected java.lang.String columnGroupByParameterName

otherGroupByParameterName

protected java.lang.String otherGroupByParameterName

document

protected org.dom4j.Document document

file

protected java.io.File file

parametersMap

protected java.util.Map<java.lang.String,java.lang.String> parametersMap
Constructor Detail

QueryModule

public QueryModule(org.dom4j.Document document,
                   java.lang.String configurationPath,
                   java.lang.String configurationName,
                   long serialNumber)
Constructor that sets the XML document.

Parameters:
document - Core XML Document which contains the Query Module XML elements.
configurationPath - Path of the module configuration (module path, core filename, configuration name sans extension like ".html". This value is used by the XSLT as the basis for the result and builder URLs.
configurationName - Name of the selected configuration.
serialNumber - unique value that is not required but may be useful for debugging system problems as this value is simply the count of loaded modules.
Method Detail

getDocument

public org.dom4j.Document getDocument()
Basic getter used to access the query module XML document.

Returns:
query module XML document.

getFile

public java.io.File getFile()
Gets the query module's XML file (base/core file in the case of xinclude).

Returns:
Query Module XML file.

getConfigurationPath

public java.lang.String getConfigurationPath()
Simple access to the REQUEST/CONFIGURATION_PATH element.

Returns:
value of the /QUERY_MODULE/REQUEST/CONFIGURATION_PATH element.

getBaseQueryApplicationURL

public java.lang.String getBaseQueryApplicationURL()
Simple access to the CONFIGURATION/BASE_QUERY_APPLICATION_URL element.

Returns:
value of the selected configuration's BASE_QUERY_APPLICATION_URL element.

getGraphicName

public java.lang.String getGraphicName()

hasQueryResponse

public boolean hasQueryResponse()
Performs a simple existence test of the REQUEST/IBISQ_QUERY_RESULT element or the the REQUEST/ERROR element. This is used as a flag that says that the query request was made (doesn't matter if successful or not).

Returns:
true if REQUEST/IBISQ_QUERY_RESULT or REQUEST/ERROR, else false.

setFile

public void setFile(java.io.File queryModuleFile)
Sets the module's XML file. This functionality is simply used to gain access to the last date modified and possibly path information etc. This value should be the base/main query module file if using in an xinclude type environment.

Parameters:
queryModuleFile - base Query Module XML file.

setMeasureName

public void setMeasureName(java.lang.String measureName)

setGraphicName

public void setGraphicName(java.lang.String graphicName)

setSelectedDimensions

public void setSelectedDimensions(javax.servlet.http.HttpServletRequest request)
                           throws java.lang.Exception
Main worker method that loads the request parameters into the approp Query Module XML document SELECTED_DIMENSION element structure. First of all existing SELECTED_DIMENSION elements are deleted. Then all SECTIONs are looped. For each section all DIMENSION_NAME, SELECTIONS/NAME, and SELECTION/NAME elements are retrieved and looped on. If the name matches a request parameter name and the name exists as a DIMENSION/NAME then a new SELECTED_DIMENSIONS is added along with the approp SELECTED_DIMENSION.

Parameters:
request - contains the submitted parameters to be added.
Throws:
java.lang.Exception

setHiddenInputParameters

public void setHiddenInputParameters(javax.servlet.http.HttpServletRequest request)
Sets any PARAMETER elements which have a HIDDEN_INPUT_FLAG which has a name that matches a request's parameter name. The hidden input flag is used to control putting a parameter value on the builder form for javascript to adjust on the fly as needed. This method sets those values to what was submitted from the builder page. Even if the assoc value is null, a HIDDEN type parameter will still be created so that the next time in the builder page that a HIDDEN input element will be present.

Parameters:
request - contains the submitted parameter values.

updateHiddenInputParameters

protected void updateHiddenInputParameters(java.lang.String rootRelativeParametersXpath,
                                           javax.servlet.http.HttpServletRequest request)
Helper that localizes setting PARAMETER HIDDEN_INPUT_FLAG elements.

Parameters:
rootRelativeParametersXpath - xpath statement for the PARAMTERS element to process.
request - contains the submitted parameter values.

setSelectedControls

public void setSelectedControls(javax.servlet.http.HttpServletRequest request)
Sets the request selected groupby dim names, graphic, and measure elements.

Parameters:
request - optional HTTP request. If not supplied then gets default values from the CONFIGURATION and root elements.

setSelectedGroupByDimensionNames

protected void setSelectedGroupByDimensionNames(javax.servlet.http.HttpServletRequest request)
Helper that sets the REQUEST/SELECTED_GROUP_BY elements.

Parameters:
request - optional HTTP request. If not supplied then gets default values from the CONFIGURATION and root elements.

setSelectedGroupByDimensionName

protected void setSelectedGroupByDimensionName(javax.servlet.http.HttpServletRequest request,
                                               java.lang.String groupByParameterName,
                                               java.lang.String groupByElementName)
Helper that localizes getting the GroupByDimensionName type request parameters and setting the associated REQUEST/GROUP_BY element. This first tries to get the parameter from the HTTP request. If not found then searches the CONFIGURATION/PARAMETER elements. If still not found then searches the root PARAMETER elements. If something found then sets the REQUEST/GROUP_BY element based on the supplied groupByElementName.

Parameters:
request - optional HTTP request to get submitted parameter values from.
groupByParameterName - HTTP request parameter name and PARAMETER/NAME value to be used to search for.
groupByElementName - Element name used to store the found groupby value.

getQueryURLParameters

public java.lang.String getQueryURLParameters(java.lang.String urlCharacterEncoding,
                                              java.lang.String controlParameterPrefix)
Localizes appending of encoded NAME and VALUE elements to StringBuffer. First the core module PARAMETERs are added. Then the configuration PARAMETER ones and finally the SELECTED_DIMENSIONs.

Parameters:
urlCharacterEncoding - encoding to use for the query url parameters. If null, then no encoding is performed.
controlParameterPrefix - Prefix that defines which parameters are to NOT be included.

addQueryURLParameters

protected void addQueryURLParameters(java.lang.String urlCharacterEncoding,
                                     java.lang.String rootRelativeParametersXpath,
                                     java.lang.String controlParameterPrefix,
                                     java.lang.StringBuffer queryURLParameters)
Helper that localizes looping the PARAMETER elements.

Parameters:
urlCharacterEncoding - encoding to use for the query url parameters. If null, then no encoding is performed.
rootRelativeParametersXpath - xpath statement for the PARAMTERS element to process.
queryURLParameters - StringBuffer to append the paramters to.
controlParameterPrefix - Prefix that defines which parameters are to NOT be included.

addQueryURLParameter

protected void addQueryURLParameter(java.lang.String name,
                                    java.lang.String value,
                                    java.lang.String urlCharacterEncoding,
                                    java.lang.String controlParameterPrefix,
                                    java.lang.StringBuffer queryURLParameters)
Helper that localizes encoding the PARAMETER elements. All control type parameters are not added (identified by the controlParameterPrefix property) nor are null/blank value parameters.

Parameters:
name - parameter name.
value - parameter value.
urlCharacterEncoding - encoding to use for the query url parameters. If null, then no encoding is performed.
controlParameterPrefix - Prefix that defines which parameters are to NOT be included.
queryURLParameters - StringBuffer to append the paramters to.

setCompleteQueryURL

public void setCompleteQueryURL(java.lang.String url)
Sets the URL used to query the data. This is made availabe on the results page when the query module XML is shown.

Parameters:
url - complete, optionally encoded, URL that contains all parameters.

getRequestStartedDateTimeStamp

public java.lang.String getRequestStartedDateTimeStamp()
Gets the formatted date time stamp string for when the request was started. This serves as a flag to the result controller code to know if the result controller needs to be cycled through again thus giving the XSLT a chance to display the "please wait" message to the user while the controller then builds and submits the request and parses the result.


setRequestStartedDateTimeStamp

public void setRequestStartedDateTimeStamp(java.lang.String formattedDateTimeStamp)
Sets the formatted date time stamp string for when the request was started. This value can also be used to help debug problems.

Parameters:
formattedDateTimeStamp - Date time stamp when the request was started.

setRequestSubmittedDateTimeStamp

public void setRequestSubmittedDateTimeStamp(java.lang.String formattedDateTimeStamp)
Sets the formatted date time stamp string which the view can show on the result page.

Parameters:
formattedDateTimeStamp - Date time stamp when the query was submitted to the backend query app.

setRequestFinishedDateTimeStamp

public void setRequestFinishedDateTimeStamp(java.lang.String formattedDateTimeStamp)
Sets the formatted date time stamp string which the view can show on the result page.

Parameters:
formattedDateTimeStamp - Date time stamp when the query result was received from the backend query app.

setRequestError

public void setRequestError(java.lang.String title,
                            java.lang.String description,
                            java.lang.String response)
Creates a new REQUEST/ERROR element and adds the appropriate elements and sets those elements with the supplied values.

Parameters:
title - Short description of the problem.
description - Long detailed description of the error. May include the exception message etc.
response - result text/XML streamed back. Typically set by the controller when invalid XML is returned from query request.

setRequestError

public void setRequestError(java.lang.String title,
                            java.lang.String description)

deleteRequestError

public void deleteRequestError()
Deletes any existing REQUEST/ERROR element. This is used by the controller to clear the error so that the XSLT does not display the error page based on a prior ERROR condition.


setQueryResult

public void setQueryResult(java.lang.String queryResult)
                    throws org.dom4j.DocumentException
Parses the query result string and puts into the query module XML document object.

Parameters:
queryResult - String of XML to be added to the query result document.
Throws:
org.dom4j.DocumentException - according to XML being parsed.

deleteQueryResult

public void deleteQueryResult()

setResultGroupByDimensionNames

public void setResultGroupByDimensionNames()
                                    throws java.lang.Exception
Parses the query result string and puts into the query module XML document object.

Throws:
java.lang.Exception

getResultGroupByDimensionName

protected java.lang.String getResultGroupByDimensionName(java.util.HashSet resultDimensionNames,
                                                         java.lang.String dimensionElementNameToMatch)
                                                  throws java.lang.Exception
Helper that sets the actual dimension name element into the document based on the dimensionElementNameToMatch string passed in.

Parameters:
resultDimensionNames - actual query result dimensions.
dimensionElementNameToMatch - dimension element name to be added to the parent xpath and looked up.
Throws:
java.lang.Exception - if a dimension element name is found and nothing matches.