public class DSResponse extends BaseResponse
STATUS_AUTHORIZATION_FAILURE, STATUS_FAILURE, STATUS_FILE_NOT_FOUND, STATUS_FILE_REQUIRED_ERROR, STATUS_LOGIN_INCORRECT, STATUS_LOGIN_REQUIRED, STATUS_LOGIN_SUCCESS, STATUS_MAX_FILE_SIZE_EXCEEDED, STATUS_MAX_LOGIN_ATTEMPTS_EXCEEDED, STATUS_PROCESSING_SKIPPED, STATUS_REQUIRED_CRITERIA_MISSING, STATUS_SUCCESS, STATUS_TRANSACTION_FAILED, STATUS_UPDATE_WITHOUT_PK, STATUS_VALIDATION_ERROR, UPDATE_WITHOUT_PK
Constructor and Description |
---|
DSResponse() Creates an empty DSResponse. |
DSResponse(DataSource dataSource) Creates a DSResponse with the specified dataSource. |
DSResponse(DataSource dataSource, int status) Creates a DSResponse with the specified dataSource and status code. |
DSResponse(DataSource dataSource, java.lang.Object data) Creates a DSResponse with the specified dataSource and data payload |
DSResponse(DataSource dataSource, java.lang.Object data, int status) Creates a DSResponse with the specified dataSource, data payload and status code. |
DSResponse(int status) Creates a DSResponse with the specified status code. |
DSResponse(java.lang.Object data) Creates a DSResponse with the specified data payload. |
DSResponse(java.lang.Object data, int status) Creates a DSResponse with the specified data payload and status code. |
Modifier and Type | Method and Description |
---|---|
DSResponse | addError(java.lang.String fieldName, ErrorMessage errorMessage) Adds an ErrorMessage to the ErrorReport for this DSResponse. |
DSResponse | addError(java.lang.String fieldName, java.lang.String errorMessage) Adds an ErrorMessage to the ErrorReport for this DSResponse. |
DSResponse | addRelatedUpdate(DSResponse relatedUpdate) Causes client-side components to react as though the provided DSResponse had just successfully completed. |
void | clearRelatedUpdates() This can be used to clear any automatically-generated related updates |
long | getAffectedRows() For operations that modify data, this method returns the number of rows affected by the change. |
java.lang.Boolean | getBypassDataFilter() This method returns true if this DSResponse will bypass the normal data filter pipeline (i.e dropExtraFields, valueXPath evaluation, etc) and simply serialize the provided data to the client. |
java.lang.Object | getData() Returns the data object originally set by setData() |
java.util.List | getDataList() Convenience method to return the data object originally set by setData(), as a List. |
java.util.Map | getDataMap() Convenience method to return the data object originally set by setData(), as a Map. |
DataSource | getDataSource() Returns the currently set DataSource. |
java.lang.Boolean | getDropExtraFields() This method returns true if this DSResponse will automatically trim the fields in its data member to just those fields declared in the DataSource. |
long | getEndRow() Returns the endRow for this DSResponse. |
ErrorReport | getErrorReport() Returns the current ErrorReport. |
java.lang.Object | getExportObject(DSRequest dsRequest) Returns the Java object encapsulating the exported data in a format suitable for directly loading into Microsoft Excel. |
java.io.OutputStream | getExportTo() Returns the OuputStream we will use for data export. |
java.lang.Object | getFieldValue(java.lang.String fieldName) Returns the value of the field name provided in this dsResponse's data member. |
boolean | getInvalidateCache() Returns the current value of invalidateCache |
java.util.Map | getKeys() For responses produced by SQLDataSource and subclasses only, this method returns the Map of key values used in the SQL query. |
java.lang.String | getOperationType() Returns the operationType associated with this DSResponse. |
java.lang.Object | getProperty(java.lang.String key) Returns an arbitrary property of the DSResponse that has previously been set with DSResponse.setProperty(String, Object) |
java.util.Map | getRecord() Returns the DSResponse's data member in "record" format (ie, as a nested collection of Maps and Lists that can be directly translated into JSON format by the JSTranslater). |
java.util.List | getRecords() Returns the DSResponse's data member as a list of maps in "record" format (ie, each entry in the list is a nested collection of Maps and Lists that can be directly translated into JSON format by the JSTranslater). |
java.util.List | getRecords(ValidationContext vc) Returns the DSResponse's data member as a list of maps in "record" format (ie, each entry in the list is a nested collection of Maps and Lists that can be directly translated into JSON format by the JSTranslater). |
java.util.List | getRelatedUpdates() Gets list of related updates previously added to this response. |
long | getStartRow() Returns the startRow for this DSResponse. |
long | getTotalRows() Returns the totalRows for this DSResponse. |
boolean | hasNextRecord() This method is called by the framework during streaming. |
java.lang.Object | nextRecordAsObject() This method is called by the framework during streaming. |
DSResponse | setBypassDataFilter(java.lang.Boolean value) This method sets the DSResponse's behavior with regard to the normal data filter pipeline (i.e dropExtraFields, valueXPath evaluation, etc). |
DSResponse | setData(java.lang.Object data) Sets the data to satisfy the DataSource request. |
DSResponse | setDataSource(DataSource dataSource) Sets the DataSource associated with this DSResponse. |
DSResponse | setDropExtraFields(java.lang.Boolean value) This method sets the DSResponse's behavior with regard to extra fields in the data it returns. |
DSResponse | setEndRow(long endRow) If the DSRequest specified an endRow, then the DSResponse should return the actual endRow for the response. |
DSResponse | setErrorReport(ErrorReport errorReport) Sets the ErrorReport for this DSResponse |
DSResponse | setEstimatedTotalRows(java.lang.String estimatedTotalRows) For fetch requests where progressiveLoading is enabled, dsResponse.estimatedTotalRows may be set to indicate the true size of the data set. |
DSResponse | setExportObject(java.lang.Object exportObject) Set the export object on the DSResponse. |
DSResponse | setExportTo(java.io.OutputStream exportOutputStream) Sets the OuputStream we will use for data export (this means exports to CSV, XML, JSON and Excel formats; PDF exports are "content exports" and are different). |
DSResponse | setFailure(java.lang.String message) Sets the status code to BaseResponse.STATUS_FAILURE and provides an error message to be shown to the user. |
DSResponse | setInvalidateCache(boolean invalidateCache) Setting invalidateCache to true triggers the client-side ResultSet to drop its existing cache. |
DSResponse | setOperationType(java.lang.String value) Set the operationType associated with this DSResponse. |
void | setProgressiveLoading(boolean value) Mark this dsResponse as having progressiveLoading enabled. |
DSResponse | setProperty(java.lang.String key, java.lang.Object value) Set an arbitrary property of the DSResponse, so that the value will be visible to custom JavaScript code on the client-side DSResponse object. |
DSResponse | setStartRow(long startRow) If the DSRequest specified a startRow, then the DSResponse should return the actual startRow for the response. |
DSResponse | setTotalRows(long totalRows) If the DSRequest sent a paged request (see DSRequest.isPaged()) and the total number of records available to be sent to the client given the provided criteria is greater than the requested size, then you should provide the total number of rows that actually matched the provided criteria. |
getStatus, setFailure, setStatus, setSuccess, statusIsError, statusIsSuccess
public DSResponse()
public DSResponse(int status)
status
- the status code (one of the static STATUS_* codes on this class)public DSResponse(java.lang.Object data)
data
- the payload of the response - equivalent to setData()public DSResponse(java.lang.Object data, int status)
data
- the payload of the response - equivalent to setData()status
- the status code (one of the static STATUS_* codes on this class)DSResponse.setData(java.lang.Object)
, BaseResponse.setStatus(int)
public DSResponse(DataSource dataSource)
dataSource
- the DataSource associated with this DSResponseDSResponse.setDataSource(com.isomorphic.datasource.DataSource)
public DSResponse(DataSource dataSource, int status)
dataSource
- the DataSource associated with this DSResponsestatus
- the status code (one of the static STATUS_* codes on this class)DSResponse.setDataSource(com.isomorphic.datasource.DataSource)
, BaseResponse.setStatus(int)
public DSResponse(DataSource dataSource, java.lang.Object data)
dataSource
- the DataSource associated with this DSResponsedata
- the payload of the response - equivalent to setData()DSResponse.setDataSource(com.isomorphic.datasource.DataSource)
, DSResponse.setData(java.lang.Object)
, BaseResponse.setStatus(int)
public DSResponse(DataSource dataSource, java.lang.Object data, int status)
dataSource
- the DataSource associated with this DSResponsedata
- the payload of the response - equivalent to setData()status
- the status code (one of the static STATUS_* codes on this class)DSResponse.setDataSource(com.isomorphic.datasource.DataSource)
, DSResponse.setData(java.lang.Object)
, BaseResponse.setStatus(int)
public java.lang.String getOperationType()
public DSResponse setOperationType(java.lang.String value)
value
- the operationTypepublic DSResponse setProperty(java.lang.String key, java.lang.Object value)
The value
parameter will be translated to JavaScript by the JSTranslater
.
For example, if you were to call:
dsResponse.setProperty("totalRowsIsApproximate", Boolean.TRUE);JavaScript code on the client could then access "dsResponse.totalsRowsIsApproximate" from any method that receives the DSResponse, eg, DataSource.transformResponse(). In the case of SmartGWT, you will need to call getAttribute("totalsRowsIsApproximate").
This API is easily misused. setProperty
should only be used to pass metadata about the request, similar to the existing DSResponse properties like startRow/endRow
and status
. The following are bad patterns:
public java.lang.Object getProperty(java.lang.String key)
DSResponse.setProperty(String, Object)
key
- the key of the property to returnpublic java.lang.Boolean getBypassDataFilter()
DSResponse.setBypassDataFilter(java.lang.Boolean)
, DSResponse.getRecord()
public DSResponse setBypassDataFilter(java.lang.Boolean value)
DSResponse.getBypassDataFilter()
, DSResponse.setData(java.lang.Object)
public java.lang.Boolean getDropExtraFields()
DSResponse.setDropExtraFields(java.lang.Boolean)
, DSResponse.getRecord()
public DSResponse setDropExtraFields(java.lang.Boolean value)
DSResponse.getDropExtraFields()
, DSResponse.setData(java.lang.Object)
public long getAffectedRows()
public boolean getInvalidateCache()
public DSResponse setInvalidateCache(boolean invalidateCache)
invalidateCache
- new value for invalidateCachepublic DSResponse setData(java.lang.Object data)
The object passed to setData() is translated to JavaScript via the JSTranslater class. The expected return data varies by operationType and is described in terms of the JavaScript result (see below) - anything that will be translated to the appropriate JavaScript result is acceptable. Compare all the data formats you can readily retrieve against the capabilities of the JSTranslater. Common options are to pass an XML document fragment or a Collection of Java Beans.
If the operationType is DataSource.OP_FETCH, then the data is expected to be an Array of JavaScript Objects matching the criteria specified in the DSRequest.
If the operationType is DataSource.OP_UPDATE, then the data is expected to be a JavaScript Object reflecting the updated record as stored.
If the operationType is DataSource.OP_ADD, then the data is expected to be a JavaScript Object reflecting the added record as stored.
If the operationType is DataSource.OP_REMOVE, then the data is expected to be at least the primary key fields of the removed record, an as JavaScript Object. A complete record is also acceptable.
DSResponses or DSResponse data returned by DMI methods is, by default, automatically filtered to just the set of fields defined on the DataSource. You can override this default in several ways - see the DMI overview in the SmartClient Reference documentation for a full description. For backwards compatibility, non-DMI DSResponses are not filtered in this manner. If you want to enable this filtering for non-DMI responses, you can do so by setting the config parameter DSResponse.dropExtraFields
to true
in [webroot]/WEB-INF/classes/server.properties
. Note that per-DataSource overrides specified by the dropExtraFields
setting on the DataSource will still apply in this case. Note that DMI.dropExtraFields
and DSResponse.dropExtraFields
can be enabled/disabled independently of each other - that is, setting one does not side-effect the other.
Also, all data objects are automatically filtered through a DataSourceBeanFilter to resolve valueXPaths specified on the DataSource fields. Search the client-side reference for 'valueXPath' for more information on this mechanism.
setData
in class BaseResponse
data
- the dataJSTranslater.toJS(Object, java.io.Writer)
, JSONFilter
, DataSourceBeanFilter
public java.util.List getDataList()
DSResponse.getData()
, DSResponse.getDataMap()
public java.util.Map getDataMap()
DSResponse.getData()
, DSResponse.getDataList()
public java.lang.Object getData()
getData
in class BaseResponse
DSResponse.setData(Object)
public long getStartRow()
public DSResponse setStartRow(long startRow)
Note that startRow and endRow are zero-based - the first record is row zero.
startRow
- new value for startRowpublic long getEndRow()
public DSResponse setEndRow(long endRow)
Note that startRow and endRow are zero-based - the first record is row zero.
If startRow
is currently greater than endRow
, it will be reduced to a maximum of endRow
(or 0).
endRow
- new value for endRowpublic long getTotalRows()
public DSResponse setTotalRows(long totalRows)
For example, the ListGrid uses this value to display a properly sized scrollbar thumb.
DSRequest.isPaged()
public DSResponse setFailure(java.lang.String message)
BaseResponse.STATUS_FAILURE
and provides an error message to be shown to the user.public DataSource getDataSource()
public DSResponse setDataSource(DataSource dataSource)
dataSource
- the datasource to set.public java.util.List getRelatedUpdates()
DSResponse.addRelatedUpdate(DSResponse)
public DSResponse addRelatedUpdate(DSResponse relatedUpdate)
This API can be used to communicate additional changes that occur as a consequence of the current DSResponse succeeding, such as changes to other records in the same DataSource or to records from unrelated DataSources. For example, in CRM applications, Leads may be converted to Accounts. In this case the "remove" operation on the Leads DataSource might call addRelatedUpdate()
with a DSResponse representing an "add" operation on the Accounts DataSource. This would cause any client-side caches of Accounts (such as a drop-down list for picking an Account) to automatically update.
If a DSResponse is passed with the DataSource or operationType unset, they will match the current DSResponse.
This API can be called multiple times for multiple related updates. Each update is processed by the client-side method DataSource.updateCaches().
This API should NOT be used simply to complete multiple requests in a single HTTP turnaround, instead, use Queuing for this (see the client-side API isc.RPCManager.startQueue()).
relatedUpdate
- DSResponse
to add.public void clearRelatedUpdates()
public ErrorReport getErrorReport()
ErrorReport
, ErrorMessage
, DSRequest.validate()
public DSResponse setErrorReport(ErrorReport errorReport)
errorReport
- new errorReportpublic DSResponse addError(java.lang.String fieldName, ErrorMessage errorMessage)
fieldName
- the fieldName for the errorerrorMessage
- the errorMessagepublic DSResponse addError(java.lang.String fieldName, java.lang.String errorMessage)
fieldName
- the fieldName for the errorerrorMessage
- the errorMessagepublic java.util.Map getRecord()
Note: if you want to suppress valueXPath and dropExtraFields, you can call setBypassDataFilter. setDropExtraFields() will likewise be honored.
DSResponse.setBypassDataFilter(java.lang.Boolean)
, DSResponse.setDropExtraFields(java.lang.Boolean)
public java.util.List getRecords()
public java.util.List getRecords(ValidationContext vc)
vc
- Validation contextpublic java.lang.Object getFieldValue(java.lang.String fieldName)
fieldName
- The name of the field whose value to returnpublic java.io.OutputStream getExportTo()
DSResponse.setExportTo(OutputStream)
API, it will be null.public DSResponse setExportTo(java.io.OutputStream exportOutputStream)
exportOutputStream
- An OutputStream to use for the exportpublic java.lang.Object getExportObject(DSRequest dsRequest) throws java.lang.Exception
Currently, we use the Apache POI library to perform Excel exports, so the object returned by this method will be an instance of that library's Workbook interface.
Use this API with extreme caution. Most of its behavior is subject to change without notice. The types of objects returned by this API may be changed in future versions without notice if the Server Framework begins using a newer version of the various libraries used for exports (eg a newer version of Apache POI) and could change to a completely different type if the Server Framework switches to using a different library for a given type of export.
Further, the contents of the export object are likewise subject to change without notice, including, for example, the specific way that type, formatting and styling information is conveyed to Excel.
If you choose to use this API, when interacting with the generated export object, code defensively and rely on as few specifics as possible. Also, be sure to revisit and re-test this code when upgrading to new versions of the Server Framework.
dsRequest
- The DSRequest to execute to obtain the export objectjava.lang.Exception
public DSResponse setExportObject(java.lang.Object exportObject) throws java.lang.Exception
Currently, we use the Apache POI library to perform Excel exports, so the object provided to this method must be an instance of that library's Workbook interface.
Use this API with extreme caution. Most of its behavior is subject to change without notice. The types of object accepted by this API may be changed in future versions without notice if the Server Framework begins using a newer version of the various libraries used for exports (eg a newer version of Apache POI) and could change to a completely different type if the Server Framework switches to using a different library for a given type of export.
exportObject
- The export object to associate with this DSResponsejava.lang.Exception
public boolean hasNextRecord()
SQLDataSource
, the default implementation will return the correct value. Otherwise, you must override this method and cause it to return an appropriate value for the current dataset. The approach we recommend is to convert your DSResponse's data member to an StreamingResponseIterator
and then override hasNextRecord()
and DSResponse.nextRecordAsObject()
on the DSResponse to return appropriate values. For example:public DSResponse dmiMethod(DSRequest dsRequest) { List data = (List)dsRequest.execute().getData(); CustomDSResponse resp = new CustomDSResponse(); resp.setUnderlyingIterator(data.iterator()); resp.setData(new StreamingResponseIterator(resp)); return resp; } static class CustomDSResponse extends DSResponse { private Iterator underlyingIterator; public void setUnderlyingIterator(Iterator it) { underlyingIterator = it; } public CustomDSResponse(DataSource dataSource) { super(dataSource); } public boolean hasNextRecord() { return underlyingIterator.hasNext(); } public Object nextRecordAsObject() throws StreamingResponseException { return underlyingIterator.next(); } }Note, this method is only applicable when streaming a response.
DSResponse.nextRecordAsObject()
public java.lang.Object nextRecordAsObject() throws StreamingResponseException
SQLDataSource
, the default implementation will return the next available row, as you would expect. Otherwise, you must override this method and cause it to return the next row. If you do not know upfront how many rows there are in your dataset, you can also increment endRow in this method, so that the client ends up with an accurate rowcount. For example:public Object nextRecordAsObject() throws StreamingResponseException { Object obj = someUserMethodToGetTheNextRecord(); if (obj != null) { this.setEndRow(this.getEndRow() + 1); } return obj; }Note, this method is only applicable when streaming a response.
Object
StreamingResponseException
DSResponse.hasNextRecord()
public void setProgressiveLoading(boolean value)
public DSResponse setEstimatedTotalRows(java.lang.String estimatedTotalRows)
This value may be set to a String in the following format:
DSRequest.setProgressiveLoading(Boolean)
public java.util.Map getKeys()
The motivation for providing this API is to allow user-written code to provide data for cache-synchronization purposes, in rare edge cases where the framework's automatic cache-sync processing causes problems (for example, record deadlocks in complex scenarios involving queues of updates to multiple different DataSources). The intention is that you mark your operationBinding canSyncCache="false"
and then use the getKeys()
API in your own logic.