Class BaseReportResourceListener
java.lang.Object
com.onenetwork.platform.integ.rest.report.BaseReportResourceListener
public class BaseReportResourceListener
extends java.lang.Object
A class which defines event handlers that will be called at different stages
of the construction of report metadata. Subclasses are free to override only
the methods they need.
In general:
- Each method will be called as the very last step in the construction of that piece of the report. For example, the onFilterField method will be called after the ReportResource has added all of the standard metadata but before the filter field is added to the form.
- Events for higher level components are fired after lower level components. IE: after all of the filter fields are constructed, the onFormConfig will be fired
- Each event will not necessarily fire on each request to the report resource. For example, if the client already has the form, then the form-related events will not fire. The only event that will fire every time is onReport and the ReportJSONObject it is passed will not have all of the pieces of the report: only the pieces that were constructed during this report request
- The FieldDef passed the listener could be an instance of UiFieldDef or ReportFieldDef
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BaseReportResourceListener.ReportExecutionContext
-
Field Summary
Fields Modifier and Type Field Description protected int
pageSize
protected PlatformUserContext
platformContext
protected int
startOffset
protected PlatformUserProfile
userProfile
-
Constructor Summary
Constructors Constructor Description BaseReportResourceListener()
-
Method Summary
Modifier and Type Method Description org.json.JSONObject
beforeParseFilters(org.json.JSONObject filters)
Called just before JSON filters are converted into objects to be passed to the read API.void
beforeSaveFavorite(org.json.JSONObject reportCfg)
Called just before the config from the client is processed and saved as a favorite.void
beforeWriteTable(Table table, java.lang.String actionName, org.json.JSONArray rows)
Called before table is passed into write flowBaseReportResourceListener.ReportExecutionContext
getReportExecutionContext()
boolean
isFirstExecution()
void
onActionList(java.util.List<java.lang.String> actionList, java.lang.String modelLevelType, java.util.List<java.lang.Long> sysIds)
Called when the action list is created.void
onActionList(java.util.List<java.lang.String> actionList, java.lang.String modelLevelType, java.util.List<java.lang.Long> sysIds, java.util.List<java.lang.String> actionIds)
Called when the action list is created.void
onAutocompleteExecuted(Table table, org.json.JSONObject filters, PlatformUserContext ctx)
Called after report is executed in the context of an autocomplete (e.g.java.lang.String
onCellValue(TableRow row, Field column, java.lang.String value)
Used only for reports where the markup is rendered by the server.
Called with the default formatted value for the given column and returns the new formatted value (or the original if no changes)void
onExportRow(CsvRow row)
Called before theCsvRow
is write to streamvoid
onFilterField(FilterJSONObject filter, Field field)
Called when building the metadata for each filter field.void
onFormConfig(FormJSONObject form, java.util.List<Field> fields)
Called after the whole form is constructed.void
onFormConfig(FormJSONObject form, java.util.List<Field> fields, org.json.JSONObject filters)
Same asonFormConfig(FormJSONObject, List)
.void
onInitTableMetaData(TableMetaData tableMeta)
Called as soon as the tableMetaData is available but before anything has been done with itvoid
onInitTableRow(TableMetaData tableMeta, TableRow tableRow)
Called before anything is done with the table row.void
onReaderFieldConfig(ReaderFieldJSONObject readerField, Field field)
Called for each field in the record/result set.void
onReport(ReportJSONObject report)
Called when the entire report is completevoid
onReportExecuted(Table table, javax.servlet.http.HttpServletRequest request)
Called after report is executedvoid
onTableColumnConfig(ColumnJSONObject column, Field field)
Called for each column in the table.void
onTableConfig(TableJSONObject table, TableMetaData tableMeta)
Called when the table metadata is completevoid
onTableData(org.json.JSONArray rows, Table table)
Called when all of the table data is complete.void
onTableRow(org.json.JSONObject row, TableRow tableRow)
Called when each table row is completevoid
onWriteTableExecuted(Table inputTable, java.lang.String actionName, Table responseTable)
Called after a table write is completed.void
onWriteTableResponse(Table inputTable, java.lang.String actionName, Table responseTable, ReportJSONObject response)
Called after a table write is completed, just before responding.void
setFirstExecution(boolean isFirstExecution)
void
setPagingInfo(int startOffset, int pageSize)
Deprecated.Not intended for client use.void
setReportExecutionContext(BaseReportResourceListener.ReportExecutionContext executionContext)
Deprecated.Not intended for client use.void
setUserProfile(PlatformUserProfile userProfile)
Deprecated.Not intended for client use.
-
Field Details
-
userProfile
-
platformContext
-
startOffset
protected int startOffset -
pageSize
protected int pageSize
-
-
Constructor Details
-
BaseReportResourceListener
public BaseReportResourceListener()
-
-
Method Details
-
setUserProfile
Deprecated.Not intended for client use.This method is called by the report framework to initialize it with the user profile for the current query.- Parameters:
userProfile
-
-
setPagingInfo
public void setPagingInfo(int startOffset, int pageSize)Deprecated.Not intended for client use.This method is called by the report framework to initialize it with the paging info for the current report query.- Parameters:
startOffset
-pageSize
-
-
onFilterField
Called when building the metadata for each filter field. This allows you to make changes such as making fields required or optional, making fields hidden or visible, changing the autocomplete/picker options for model link fields, etc. Please note that this does not give you access to filter field values. To change or prepopulate filter values for reports with autoExecute set to true, seebeforeParseFilters(JSONObject)
. If autoExecute is false, however, you should use this method to prepopulate default filter values. For example, the following code will make the OwningOrg filter hidden:if (field.getId().getName().equals("OwningOrg")) { filter.setXtype("hidden"); }
- Parameters:
filter
- the json object representing the filter field definitionfield
- the FieldDef this filter is based on
-
onFormConfig
Called after the whole form is constructed. For reports with autoExecute set to false, you should use either this oronFilterField(FilterJSONObject, Field)
to set default field values.- Parameters:
form
- The FormJSONObject containing the form metadatafields
- The list of fields that the form is composed of
-
onFormConfig
public void onFormConfig(FormJSONObject form, java.util.List<Field> fields, org.json.JSONObject filters)Same asonFormConfig(FormJSONObject, List)
. But this method is passed with filter values received from UI.- Parameters:
form
- The FormJSONObject containing the form metadatafields
- The list of fields that the form is composed offilters
- The list of filter values received from UI
-
onTableColumnConfig
Called for each column in the table. May not be called for each column in the result set since some of the columns could be hidden- Parameters:
column
-field
-
-
onReaderFieldConfig
Called for each field in the record/result set. Will be called for each field in the result set- Parameters:
readerField
-field
-
-
onInitTableMetaData
Called as soon as the tableMetaData is available but before anything has been done with it- Parameters:
tableMeta
-
-
onInitTableRow
Called before anything is done with the table row. Subclasses and use to manipulate table data before it is serialized- Parameters:
tableMeta
-tableRow
-
-
onTableConfig
Called when the table metadata is complete- Parameters:
table
-tableMeta
-
-
onTableData
Called when all of the table data is complete.- Parameters:
rows
- A JSONArray of JSONObjects where each object is one recordtable
-
-
onTableRow
Called when each table row is complete- Parameters:
row
-tableRow
-
-
onReport
Called when the entire report is complete- Parameters:
report
-
-
onReportExecuted
Called after report is executed- Parameters:
report
-
-
onCellValue
Used only for reports where the markup is rendered by the server.
Called with the default formatted value for the given column and returns the new formatted value (or the original if no changes)- Parameters:
row
- The full table rowcolumn
- The particular column this formatted value came fromvalue
- The formatted value- Returns:
- the new formatted value
-
beforeParseFilters
public org.json.JSONObject beforeParseFilters(org.json.JSONObject filters)Called just before JSON filters are converted into objects to be passed to the read API. Gives the client an opportunity to add, remove or mutate filters.For example, the following code will set the value of the OwningOrg filter to the user's org id:
filters.put("OwningOrg", this.platformContext.getRoleOrganizationId());
It is also possible to perform server-side validation of the existing filters at this point. If any filter value is invalid, you should throw a
RuntimeException
where the message is a serialized JSONArray or JSONObject. Example:JSONArray errors = new JSONArray(); if(filters.optString("Field1").contains("-")) { errors.put(new JSONObject().put("id", "Field1").put("msg", "Field1 cannot have dashes")); } if(filters.optString("Field2").contains("!")) { errors.put(new JSONObject().put("id", "Field2").put("msg", "Field2 cannot have exclamation marks")); } if(errors.length() > 0) { throw new RuntimeException(errors.toString()); } return filters;
- Parameters:
filters
- filters received from client. may be null- Returns:
- filters to be used during parse - client may mutate the given object and return that directly, or may return a new JSONObject
-
beforeSaveFavorite
public void beforeSaveFavorite(org.json.JSONObject reportCfg)Called just before the config from the client is processed and saved as a favorite.- Parameters:
reportCfg
-
-
onActionList
public void onActionList(java.util.List<java.lang.String> actionList, java.lang.String modelLevelType, java.util.List<java.lang.Long> sysIds)Called when the action list is created. From here, you can add/remove/change actions. The list passed here will contain the all of the actions which are 1) available to the user and 2) applicable to all of the models represented by the list of sysIds.- Parameters:
actionList
- list of actions to be eligible for the selected sys idsmodelLevelType
- model level type of of the undelying modelsysIds
- list of sys ids selected to invoke the action
-
onActionList
public void onActionList(java.util.List<java.lang.String> actionList, java.lang.String modelLevelType, java.util.List<java.lang.Long> sysIds, java.util.List<java.lang.String> actionIds)Called when the action list is created. From here, you can add/remove/change actions. The list passed here will contain the all of the actions which are 1) available to the user and 2) applicable to all of the models represented by the list of sysIds and actionIds(if report has ActionId specified).- Parameters:
actionList
- list of actions to be eligible for the selected sys idsmodelLevelType
- model level type of of the underlying modelsysIds
- list of sys ids selected to invoke the actionactionIds
- synthetic ids to identify the uniqueness of records instead of sys ids. Empty list if report is not using ActionIdField
-
beforeWriteTable
Called before table is passed into write flow- Parameters:
table
-Table
actionName
- action name to be executedrows
- A JSONArray of JSONObjects where each object is one record
-
onWriteTableExecuted
public void onWriteTableExecuted(Table inputTable, java.lang.String actionName, Table responseTable)Called after a table write is completed. -
onWriteTableResponse
public void onWriteTableResponse(Table inputTable, java.lang.String actionName, Table responseTable, ReportJSONObject response)Called after a table write is completed, just before responding. This means the ReportJSONObject contains a "data" element in case there are any erroneous records.- Parameters:
table
-Table
actionName
- action name to be executedtable
-Table
response from the write operation (includes errors)response
- ReportJSONObject containing a "data" element in the case there are any erroneous records. WARNING: this value may be null if an exception was thrown during table processing.rows
- A JSONArray of JSONObjects where each object is one record
-
onAutocompleteExecuted
public void onAutocompleteExecuted(Table table, org.json.JSONObject filters, PlatformUserContext ctx)Called after report is executed in the context of an autocomplete (e.g. in a model picker or other autocomplete field)- Parameters:
table
-Table
table generated by the originalr report execution - you can modify this directlyfilters
- user-provided filtersctx
- caller's context
-
onExportRow
Called before theCsvRow
is write to stream- Parameters:
row
- row to be exported - use theCsvRow.set(String, String)
method to change values on this row
-
setReportExecutionContext
public final void setReportExecutionContext(BaseReportResourceListener.ReportExecutionContext executionContext)Deprecated.Not intended for client use.set the report execution context -
getReportExecutionContext
- Returns:
- the execution context in which the report is being executed, i.e. UI or SCHEDULED_REPORT (Report Subscription)
-
isFirstExecution
public boolean isFirstExecution()- Returns:
- true if this report is being executed for 1st time. For subsequent refresh of the report or next page, return false
-
setFirstExecution
public void setFirstExecution(boolean isFirstExecution)- Parameters:
isFirstExecution
- the isFirstExecution to set
-