Class DefaultFlexibleCMSItemSearchService

  • All Implemented Interfaces:
    CMSItemSearchService

    public class DefaultFlexibleCMSItemSearchService
    extends java.lang.Object
    implements CMSItemSearchService
    The DefaultFlexibleCMSItemSearchService is a CMSItemSearchService implementation that performs partial matching of the mask param on both UID and NAME fields, and exact matching on typeCode(s) and additional parameter fields
    • Constructor Detail

      • DefaultFlexibleCMSItemSearchService

        public DefaultFlexibleCMSItemSearchService()
    • Method Detail

      • findCMSItems

        public SearchResult<CMSItemModel> findCMSItems​(CMSItemSearchData cmsItemSearchData,
                                                       PageableData pageableData)
        Paged Search for CMSItems CMSItem search params:
        • mask (optional) value does the search on uid and name.
        • typeCode or typeCodes values are optional, if used only one of them must be provided. The default typeCode value if not provided is CMSItemModel._TYPECODE.
        • itemSearchParams (optional) is a map of key-value pairs of query parameter fields and Object values. The key-value pair is ignored if the key doesn't belong to any provided typeCode(s). You can use null as value.
        • sort (optional) value is the requested ordering for the search results. The ordering is ignored for any column that doesn't belong to the provided typeCode(s).
        Specified by:
        findCMSItems in interface CMSItemSearchService
        Parameters:
        cmsItemSearchData - All the required and optional search params, excluding paging
        pageableData - Paging search params
        Returns:
        The search results and paging information
      • hasCommonAncestorForTypeCodes

        public boolean hasCommonAncestorForTypeCodes​(java.util.List<java.lang.String> typeCodes)
        Description copied from interface: CMSItemSearchService
        Validate if there is a common ancestor typeCode given a list of typeCodes
        Specified by:
        hasCommonAncestorForTypeCodes in interface CMSItemSearchService
        Parameters:
        typeCodes - the list of typeCodes
        Returns:
        true, if a common ancestor for the given typeCodes exist.
      • validateCommonAncestorTypeCode

        protected void validateCommonAncestorTypeCode​(java.util.List<java.lang.String> typeCodes)
      • validateSearchData

        protected void validateSearchData​(CMSItemSearchData cmsItemSearchData,
                                          PageableData pageableData)
        Validate the cms item search data and pageable data
        Parameters:
        cmsItemSearchData -
        pageableData -
        Throws:
        java.lang.IllegalArgumentException - if both typeCode and typeCodes are used.
      • prepareQueryBuilder

        protected java.lang.StringBuilder prepareQueryBuilder​(java.util.List<ComposedTypeModel> composedTypes,
                                                              java.lang.String typeCode,
                                                              java.util.Map<java.lang.String,​java.lang.Object> queryParameters)
        Prepare the query builder to set the parent query typeCode, the inherited typeCodes and the excluded typeCodes.
        Parameters:
        composedTypes -
        typeCode -
        queryParameters -
        Returns:
        the query builder
      • getValidComposedTypes

        protected java.util.List<ComposedTypeModel> getValidComposedTypes​(CMSItemSearchData cmsItemSearchData)
        Get the list of all valid composed types given cmsItemSearchData
        Parameters:
        cmsItemSearchData -
        Returns:
        the list of valid composed types
      • getValidComposedTypes

        protected java.util.List<ComposedTypeModel> getValidComposedTypes​(java.util.List<java.lang.String> typeCodes)
        Get the list of all valid composed types given a list of typeCodes
        Parameters:
        typeCodes -
        Returns:
        the list of valid composed types
      • typeCodeExists

        protected java.util.function.Predicate<java.lang.String> typeCodeExists()
      • getFirstCommonAncestorTypeCode

        protected java.lang.String getFirstCommonAncestorTypeCode​(java.util.List<ComposedTypeModel> composedTypes)
        Get the first common ancestor typeCode given a list of composed types. This is collecting all the super types of each composed type in the list and returns the top-level common super type.
        Parameters:
        composedTypes - the list of composed types
        Returns:
        the String representation of the first common ancestor typeCode
      • getAllSuperTypeCodes

        protected java.util.List<java.lang.String> getAllSuperTypeCodes​(ComposedTypeModel composedType)
        Get the list of all the super typeCodes given a composedType, including the composedType typeCode.
        Parameters:
        composedType -
        Returns:
        the List of String representation of all the super typeCodes given a composedType, including the composedType typeCode.
      • getInheritedTypeCodes

        protected java.util.List<java.lang.String> getInheritedTypeCodes​(java.util.List<ComposedTypeModel> composedTypes)
        Get all the inherited typeCodes given a list of composed types.
        Parameters:
        composedTypes - the list of composed types
        Returns:
        the list of the inherited typeCodes given a list of composed types
      • getAllSubTypes

        protected java.util.List<ComposedTypeModel> getAllSubTypes​(ComposedTypeModel composedType)
        Get the list of all the sub types given a composedType. The given composedType is included in the list if it's not abstract.
        Parameters:
        composedType -
        Returns:
        the List of ComposedTypeModel representation of all the sub types given a composedType,
      • getFirstCommonElement

        protected java.lang.String getFirstCommonElement​(java.util.List<java.util.List<java.lang.String>> collections)
        Get the first common element given multiple collections. Assumption is that each collection is already ordered.
        Parameters:
        collections - the collections to iterate over
        Returns:
        the String representation of the first common element from amongst all the given Collections.
      • getTypeCodesFromSearchData

        protected java.util.List<java.lang.String> getTypeCodesFromSearchData​(CMSItemSearchData cmsItemSearchData)
        Get the list of typeCodes given the cmsItemSearchData. Use CMSItemModel _TYPECODE by default if typeCode(s) is blank.
        Parameters:
        cmsItemSearchData -
        Returns:
        the list of typeCodes
      • appendTypeExclusions

        protected void appendTypeExclusions​(java.util.List<ComposedTypeModel> composedTypes,
                                            java.lang.StringBuilder queryBuilder,
                                            java.util.Map<java.lang.String,​java.lang.Object> queryParameters)
        Append the type codes to be excluded from the query to the query builder.
        A type code is added to the exclusion list when:
        • the type is blacklisted
        • the user does not have READ permission for the type
        Parameters:
        composedTypes - the composedTypes which may have a list of blacklisted types defined
        queryBuilder - the query builder for the query statement
        queryParameters - map of key-value pairs of query parameter fields and Object values
      • appendSearchParams

        protected void appendSearchParams​(java.util.Map<java.lang.String,​java.lang.String> itemSearchParams,
                                          java.lang.StringBuilder queryBuilder,
                                          java.util.Map<java.lang.String,​java.lang.Object> queryParameters,
                                          java.lang.String typeCode)
        Append the item search data to the query builder
        Parameters:
        itemSearchParams - the item search params
        queryBuilder - the query builder for the query statement
        queryParameters - map of key-value pairs of query parameter fields and Object values
        typeCode - the typeCode
      • appendSort

        protected void appendSort​(java.lang.String sortNameAndDirection,
                                  java.lang.StringBuilder queryBuilder,
                                  java.lang.String typeCode)
        Append the ORDER BY clause to the query builder
        Parameters:
        sortNameAndDirection - string containing the field name to be sorted and the sort order
        queryBuilder - the query builder for the query statement
        typeCode - the typeCode
      • attributeExistsForType

        protected java.util.function.Predicate<Sort> attributeExistsForType​(java.lang.String typeCode)
      • buildSortStatement

        protected java.lang.String buildSortStatement​(java.lang.String typeCode,
                                                      Sort sort)
        Create the String representation of the sort parameter and direction by formatting the sort parameter by applying the syntax required by the Flexible Search query. This uses a custom SortStatementFormatter to format the sort parameter value if applicable, otherwise the default formatter is used instead.
        Parameters:
        typeCode - the typeCode value of the cms items to be retrieved
        sort - the Sort object containing the parameter to be sorted and the sort direction
        Returns:
        the String representation of the formatted sort parameter and direction
      • setCatalogVersionService

        public void setCatalogVersionService​(CatalogVersionService catalogVersionService)
      • setFlexibleSearchService

        public void setFlexibleSearchService​(FlexibleSearchService flexibleSearchService)
      • getTypeService

        protected TypeService getTypeService()
      • setTypeService

        public void setTypeService​(TypeService typeService)
      • setSortStatementFormatters

        public void setSortStatementFormatters​(java.util.List<SortStatementFormatter> sortStatementFormatters)
      • setDefaultSortStatementFormatter

        public void setDefaultSortStatementFormatter​(SortStatementFormatter defaultSortStatementFormatter)
      • getCmsItemSearchTypeBlacklistMap

        protected java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getCmsItemSearchTypeBlacklistMap()
      • setCmsItemSearchTypeBlacklistMap

        public void setCmsItemSearchTypeBlacklistMap​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> cmsItemSearchTypeBlacklistMap)
      • getSearchHelper

        protected SearchHelper getSearchHelper()
      • setSearchHelper

        public void setSearchHelper​(SearchHelper searchHelper)
      • setPermissionCRUDService

        public void setPermissionCRUDService​(PermissionCRUDService permissionCRUDService)