Class DefaultFlexibleCMSItemSearchService
- java.lang.Object
-
- de.hybris.platform.cms2.cmsitems.service.impl.DefaultFlexibleCMSItemSearchService
-
- All Implemented Interfaces:
CMSItemSearchService
public class DefaultFlexibleCMSItemSearchService extends java.lang.Object implements CMSItemSearchService
The DefaultFlexibleCMSItemSearchService is aCMSItemSearchService
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
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CATALOG_VERSION_QUERY_PARAM
static java.lang.String
EXCLUDED_TYPES_QUERY_PARAM
static java.lang.String
ITEM_SEARCH_PARAM_CHECK
static java.lang.String
ITEM_SEARCH_PARAM_CHECK_NULL
static java.lang.String
MASK_CHECK
static java.lang.String
MASK_QUERY_PARAM
static java.lang.String
ORDER_BY
static java.lang.String
QUERY
static java.lang.String
TYPECODES_QUERY_PARAM
-
Constructor Summary
Constructors Constructor Description DefaultFlexibleCMSItemSearchService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 builderprotected void
appendSort(java.lang.String sortNameAndDirection, java.lang.StringBuilder queryBuilder, java.lang.String typeCode)
Append theORDER BY
clause to the query builderprotected 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.protected java.util.function.Predicate<Sort>
attributeExistsForType(java.lang.String typeCode)
protected java.lang.String
buildSortStatement(java.lang.String typeCode, Sort sort)
Create theString
representation of the sort parameter and direction by formatting the sort parameter by applying the syntax required by the Flexible Search query.SearchResult<CMSItemModel>
findCMSItems(CMSItemSearchData cmsItemSearchData, PageableData pageableData)
Paged Search for CMSItemsprotected java.util.List<ComposedTypeModel>
getAllSubTypes(ComposedTypeModel composedType)
Get the list of all the sub types given a composedType.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.protected CatalogVersionService
getCatalogVersionService()
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>>
getCmsItemSearchTypeBlacklistMap()
protected SortStatementFormatter
getDefaultSortStatementFormatter()
protected java.lang.String
getFirstCommonAncestorTypeCode(java.util.List<ComposedTypeModel> composedTypes)
Get the first common ancestor typeCode given a list of composed types.protected java.lang.String
getFirstCommonElement(java.util.List<java.util.List<java.lang.String>> collections)
Get the first common element given multiple collections.protected FlexibleSearchAttributeValueConverter
getFlexibleSearchAttributeValueConverter()
protected FlexibleSearchService
getFlexibleSearchService()
protected java.util.List<java.lang.String>
getInheritedTypeCodes(java.util.List<ComposedTypeModel> composedTypes)
Get all the inherited typeCodes given a list of composed types.protected PermissionCRUDService
getPermissionCRUDService()
protected SearchHelper
getSearchHelper()
protected java.util.List<SortStatementFormatter>
getSortStatementFormatters()
protected java.util.List<java.lang.String>
getTypeCodesFromSearchData(CMSItemSearchData cmsItemSearchData)
Get the list of typeCodes given the cmsItemSearchData.protected TypeService
getTypeService()
protected java.util.List<ComposedTypeModel>
getValidComposedTypes(CMSItemSearchData cmsItemSearchData)
Get the list of all valid composed types given cmsItemSearchDataprotected java.util.List<ComposedTypeModel>
getValidComposedTypes(java.util.List<java.lang.String> typeCodes)
Get the list of all valid composed types given a list of typeCodesboolean
hasCommonAncestorForTypeCodes(java.util.List<java.lang.String> typeCodes)
Validate if there is a common ancestor typeCode given a list of typeCodesprotected 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.void
setCatalogVersionService(CatalogVersionService catalogVersionService)
void
setCmsItemSearchTypeBlacklistMap(java.util.Map<java.lang.String,java.util.List<java.lang.String>> cmsItemSearchTypeBlacklistMap)
void
setDefaultSortStatementFormatter(SortStatementFormatter defaultSortStatementFormatter)
void
setFlexibleSearchAttributeValueConverter(FlexibleSearchAttributeValueConverter flexibleSearchAttributeValueConverter)
void
setFlexibleSearchService(FlexibleSearchService flexibleSearchService)
void
setPermissionCRUDService(PermissionCRUDService permissionCRUDService)
void
setSearchHelper(SearchHelper searchHelper)
void
setSortStatementFormatters(java.util.List<SortStatementFormatter> sortStatementFormatters)
void
setTypeService(TypeService typeService)
protected java.util.function.Predicate<java.lang.String>
typeCodeExists()
protected void
validateCommonAncestorTypeCode(java.util.List<java.lang.String> typeCodes)
protected void
validateSearchData(CMSItemSearchData cmsItemSearchData, PageableData pageableData)
Validate the cms item search data and pageable data
-
-
-
Field Detail
-
QUERY
public static final java.lang.String QUERY
- See Also:
- Constant Field Values
-
TYPECODES_QUERY_PARAM
public static final java.lang.String TYPECODES_QUERY_PARAM
- See Also:
- Constant Field Values
-
CATALOG_VERSION_QUERY_PARAM
public static final java.lang.String CATALOG_VERSION_QUERY_PARAM
- See Also:
- Constant Field Values
-
MASK_CHECK
public static final java.lang.String MASK_CHECK
- See Also:
- Constant Field Values
-
MASK_QUERY_PARAM
public static final java.lang.String MASK_QUERY_PARAM
- See Also:
- Constant Field Values
-
ITEM_SEARCH_PARAM_CHECK
public static final java.lang.String ITEM_SEARCH_PARAM_CHECK
- See Also:
- Constant Field Values
-
ITEM_SEARCH_PARAM_CHECK_NULL
public static final java.lang.String ITEM_SEARCH_PARAM_CHECK_NULL
- See Also:
- Constant Field Values
-
EXCLUDED_TYPES_QUERY_PARAM
public static final java.lang.String EXCLUDED_TYPES_QUERY_PARAM
- See Also:
- Constant Field Values
-
ORDER_BY
public static final java.lang.String ORDER_BY
- See Also:
- Constant Field Values
-
-
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 interfaceCMSItemSearchService
- Parameters:
cmsItemSearchData
- All the required and optional search params, excluding pagingpageableData
- 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 interfaceCMSItemSearchService
- 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
ofString
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
ofComposedTypeModel
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. UseCMSItemModel
_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 definedqueryBuilder
- the query builder for the query statementqueryParameters
- 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 paramsqueryBuilder
- the query builder for the query statementqueryParameters
- map of key-value pairs of query parameter fields and Object valuestypeCode
- the typeCode
-
appendSort
protected void appendSort(java.lang.String sortNameAndDirection, java.lang.StringBuilder queryBuilder, java.lang.String typeCode)
Append theORDER BY
clause to the query builder- Parameters:
sortNameAndDirection
- string containing the field name to be sorted and the sort orderqueryBuilder
- the query builder for the query statementtypeCode
- 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 theString
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 customSortStatementFormatter
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 retrievedsort
- theSort
object containing the parameter to be sorted and the sort direction- Returns:
- the
String
representation of the formatted sort parameter and direction
-
getCatalogVersionService
protected CatalogVersionService getCatalogVersionService()
-
setCatalogVersionService
public void setCatalogVersionService(CatalogVersionService catalogVersionService)
-
getFlexibleSearchService
protected FlexibleSearchService getFlexibleSearchService()
-
setFlexibleSearchService
public void setFlexibleSearchService(FlexibleSearchService flexibleSearchService)
-
getFlexibleSearchAttributeValueConverter
protected FlexibleSearchAttributeValueConverter getFlexibleSearchAttributeValueConverter()
-
setFlexibleSearchAttributeValueConverter
public void setFlexibleSearchAttributeValueConverter(FlexibleSearchAttributeValueConverter flexibleSearchAttributeValueConverter)
-
getTypeService
protected TypeService getTypeService()
-
setTypeService
public void setTypeService(TypeService typeService)
-
getSortStatementFormatters
protected java.util.List<SortStatementFormatter> getSortStatementFormatters()
-
setSortStatementFormatters
public void setSortStatementFormatters(java.util.List<SortStatementFormatter> sortStatementFormatters)
-
getDefaultSortStatementFormatter
protected SortStatementFormatter getDefaultSortStatementFormatter()
-
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)
-
getPermissionCRUDService
protected PermissionCRUDService getPermissionCRUDService()
-
setPermissionCRUDService
public void setPermissionCRUDService(PermissionCRUDService permissionCRUDService)
-
-