Class TableResponseGenerator



  • public class TableResponseGenerator
    extends java.lang.Object
    Singleton class that generates a TableResponse given a TableRequest, functions to retrieve counters and elements, and an array of the fields used as columns.
    • Method Detail

      • instance

        public static TableResponseGenerator instance​()
        Retrieves the instance of this class.
        Returns:
        the instance
      • generateResponse

        public <E> TableResponse generateResponse​(TableRequest tableRequest,
                                                  java.util.function.LongSupplier totalCountSupplier,
                                                  TotalFilteredFunction totalFilteredFunction,
                                                  PaginatedSearchFunction<E> paginatedSearchFunction,
                                                  java.lang.String... fields)
        Generates a TableResponse given a TableRequest, functions to retrieve counters and elements, and an array of the fields used as columns.
        Type Parameters:
        E - the element used in the table. Must implement bean-style getters for the fields
        Parameters:
        tableRequest - the TableRequest received from the view
        totalCountSupplier - a Supplier that retrieves the total count of entries in the table
        totalFilteredFunction - a Function that returns the count of entries matching the given query string.

        The query string is always non-null, trimmed and in lowercase.

        An empty query string should result in the same value returned by totalCountSupplier

        paginatedSearchFunction - a Function that returns the requested interval of (filtered) elements, sorted by the given field, in ascending/descending order. The query string is always trimmed and in lowercase. An empty query string should return the interval of all elements
        fields - an array of field names of the element used in the table, in the same order of the columns
        Returns:
        the TableResponse instance, which should be returned to the view as a JSON response object