Class DefaultPaginatedFlexibleSearchService

    • Constructor Detail

      • DefaultPaginatedFlexibleSearchService

        public DefaultPaginatedFlexibleSearchService()
    • Method Detail

      • validatePaginatedFlexibleSearchParameter

        protected void validatePaginatedFlexibleSearchParameter​(PaginatedFlexibleSearchParameter parameter)
        Validates if the given PaginatedFlexibleSearchParameter contains valid parameters.
        Parameters:
        parameter - the PaginatedFlexibleSearchParameter
        Throws:
        java.lang.IllegalArgumentException - if parameter contains invalid data
      • populateSearchQuery

        protected FlexibleSearchQuery populateSearchQuery​(SearchPageData searchPageData,
                                                          FlexibleSearchQuery searchQuery,
                                                          java.util.Map<java.lang.String,​java.lang.String> sortCodeToQueryAlias,
                                                          boolean nextElementAdded)
        Populates a FlexibleSearchQuery based on given searchQuery by appending "ORDER BY" clause if given searchPageData has list of SortData.
        Parameters:
        searchPageData - the searchPageData contains requested pagination and sorting information
        searchQuery - the searchQuery
        sortCodeToQueryAlias - the sortCodeToQueryAlias contains mapping between sort code and query alias which will be used to dynamically generate "ORDER BY" clause.
        nextElementAdded -
        Returns:
        the FlexibleSearchQuery with requested sorts applied
      • filterSearchPageDataSorts

        protected java.util.List<SortData> filterSearchPageDataSorts​(SearchPageData searchPageData,
                                                                     java.util.Map<java.lang.String,​java.lang.String> sortCodeToQueryAlias)
        Returns a list of SortData where each of it exists from given sortCodeToQueryAlias map. The intention of method is to filter out the undefined sort code from given SearchPageData.getSorts() based on given sortCodeToQueryAlias map, so that once buildSortsAppliedQuery(String, SearchPageData, Map) is called, sortDataParsingStrategy is guaranteed to return the mapped query alias for each sort code.

        It also converts sortData's code to lower case to meet the expectation of SortDataParsingStrategy

        Parameters:
        searchPageData - the searchPageData contains list of SortData which will be used as requested sort list
        sortCodeToQueryAlias - the sortCodeToQueryAlias contains mapping between sort code and query alias which will be used to generate "ORDER BY" clause dynamically based on requested sort codes
        Returns:
        the list of SortData where each of them found from given sortCodeToQueryAlias
        See Also:
        SortDataParsingStrategy
      • buildSortsAppliedQuery

        protected java.lang.String buildSortsAppliedQuery​(java.lang.String query,
                                                          SearchPageData searchPageData,
                                                          java.util.Map<java.lang.String,​java.lang.String> sortCodeToQueryAlias)
        Builds a requested sorts applied query based on given query by appending list of SortData passed from given searchPageData. It uses SortDataParsingStrategy to properly generate "ORDER BY {queryAlias:sortCode} asc|desc" search query dynamically based on the requested sorts. If the list of SortData from given searchPageData is empty, the given query will be returned without any modification.
        Parameters:
        query - the query
        searchPageData - the searchPageData contains requested pagination and sorting information
        sortCodeToQueryAlias - the sortCodeToQueryAlias contains mapping between sort code and query alias which will be used to generate "ORDER BY" clause dynamically based on requested sort codes
        Returns:
        a requested sorts applied query
      • createPagedSearchResult

        protected <T> SearchPageData<T> createPagedSearchResult​(SearchResult<T> searchResult,
                                                                SearchPageData searchPageData,
                                                                DefaultPaginatedFlexibleSearchService.SearchResultInfo searchResultInfo)
        Returns an instance of {link SearchPageData} with given SearchResult. It also contains updated pagination and applied sorts information
        Type Parameters:
        T - the type of item returned from the search
        Parameters:
        searchResult - the searchResult
        searchPageData - the searchPageData containing pagination and sorting information
        searchResultInfo - the search result info needed to properly calculate slicing (hasNext, hasPrevious values)
        Returns:
        an instance of SearchPageData with searchResult, pagination and sorting information
      • createPagination

        protected <T> PaginationData createPagination​(SearchPageData searchPageDataInput,
                                                      DefaultPaginatedFlexibleSearchService.SearchResultInfo searchResultInfo)
        Creates PaginationData based on searchPageDataInput.pagination and calculates the numberOfPages based on the totalNumberOfResults.
        Type Parameters:
        T - the type of item returned from the search
        Parameters:
        searchPageDataInput - the searchPageDataInput contains pagination and sorting information
        searchResultInfo - the search result info needed to properly calculate slicing (hasNext, hasPrevious values)
        Returns:
        PaginationData based on input paginationData and calculated numberOfPages of the given searchResult
      • setFlexibleSearchService

        public void setFlexibleSearchService​(FlexibleSearchService flexibleSearchService)
      • setSortDataParsingStrategy

        public void setSortDataParsingStrategy​(SortDataParsingStrategy sortDataParsingStrategy)
      • setAbstractQueryHelper

        public void setAbstractQueryHelper​(AbstractQueryHelper abstractQueryHelper)