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
  • Field Details

  • Constructor Details

  • Method Details

    • setUserProfile

      public void setUserProfile​(PlatformUserProfile userProfile)
      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

      public void onFilterField​(FilterJSONObject filter, Field field)
      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, see beforeParseFilters(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 definition
      field - the FieldDef this filter is based on
    • onFormConfig

      public void onFormConfig​(FormJSONObject form, java.util.List<Field> fields)
      Called after the whole form is constructed. For reports with autoExecute set to false, you should use either this or onFilterField(FilterJSONObject, Field) to set default field values.
      Parameters:
      form - The FormJSONObject containing the form metadata
      fields - 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 as onFormConfig(FormJSONObject, List). But this method is passed with filter values received from UI.
      Parameters:
      form - The FormJSONObject containing the form metadata
      fields - The list of fields that the form is composed of
      filters - The list of filter values received from UI
    • onTableColumnConfig

      public void onTableColumnConfig​(ColumnJSONObject column, Field field)
      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

      public void onReaderFieldConfig​(ReaderFieldJSONObject readerField, Field field)
      Called for each field in the record/result set. Will be called for each field in the result set
      Parameters:
      readerField -
      field -
    • onInitTableMetaData

      public void onInitTableMetaData​(TableMetaData tableMeta)
      Called as soon as the tableMetaData is available but before anything has been done with it
      Parameters:
      tableMeta -
    • onInitTableRow

      public void onInitTableRow​(TableMetaData tableMeta, TableRow tableRow)
      Called before anything is done with the table row. Subclasses and use to manipulate table data before it is serialized
      Parameters:
      tableMeta -
      tableRow -
    • onTableConfig

      public void onTableConfig​(TableJSONObject table, TableMetaData tableMeta)
      Called when the table metadata is complete
      Parameters:
      table -
      tableMeta -
    • onTableData

      public void onTableData​(org.json.JSONArray rows, Table table)
      Called when all of the table data is complete.
      Parameters:
      rows - A JSONArray of JSONObjects where each object is one record
      table -
    • onTableRow

      public void onTableRow​(org.json.JSONObject row, TableRow tableRow)
      Called when each table row is complete
      Parameters:
      row -
      tableRow -
    • onReport

      public void onReport​(ReportJSONObject report)
      Called when the entire report is complete
      Parameters:
      report -
    • onReportExecuted

      public void onReportExecuted​(Table table, javax.servlet.http.HttpServletRequest request)
      Called after report is executed
      Parameters:
      report -
    • onCellValue

      public 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)
      Parameters:
      row - The full table row
      column - The particular column this formatted value came from
      value - 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 ids
      modelLevelType - model level type of of the undelying model
      sysIds - 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 ids
      modelLevelType - model level type of of the underlying model
      sysIds - list of sys ids selected to invoke the action
      actionIds - synthetic ids to identify the uniqueness of records instead of sys ids. Empty list if report is not using ActionIdField
    • beforeWriteTable

      public void beforeWriteTable​(Table table, java.lang.String actionName, org.json.JSONArray rows)
      Called before table is passed into write flow
      Parameters:
      table - Table
      actionName - action name to be executed
      rows - 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.
      Parameters:
      table - Table
      actionName - action name to be executed
      table - Table response from the write operation (includes errors)
      rows - A JSONArray of JSONObjects where each object is one record
    • 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 executed
      table - 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 directly
      filters - user-provided filters
      ctx - caller's context
    • onExportRow

      public void onExportRow​(CsvRow row)
      Called before the CsvRow is write to stream
      Parameters:
      row - row to be exported - use the CsvRow.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

      public final BaseReportResourceListener.ReportExecutionContext 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