Class DefaultProductCharacteristicService<P extends ProductCharacteristic>

java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
com.broadleafcommerce.catalog.service.product.characteristic.DefaultProductCharacteristicService<P>
All Implemented Interfaces:
ProductCharacteristicService<P>, com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>

public class DefaultProductCharacteristicService<P extends ProductCharacteristic> extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P> implements ProductCharacteristicService<P>
Default implementation of ProductCharacteristicService.
Since:
Catalog Service 2.3.0, Release Train 2.3.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultProductCharacteristicService(ProductCharacteristicRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    countNonProductionRecordsByProductIdsInTenant(@NonNull Collection<String> productIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    Returns the count of non-production records that match the given productContextIds and the given tenant context.
    Resolves a scenario where the query for product characteristics of a product/products actually produced multiple results for the same ProductCharacteristic.getFieldName() on the same product.
    protected Long
     
    protected com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node>
     
    protected ProductCharacteristicRepository<com.broadleafcommerce.data.tracking.core.Trackable>
     
    protected com.broadleafcommerce.common.extension.TypeFactory
     
    readAllByProductContextIdAndCatalogContextId(@NonNull String productContextId, String catalogContextId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads all product characteristics for a given productContextId, restricting results to only the items directly resident in the provided catalogContextId
    readAllByProductContextIdAndInheritanceLine(Collection<String> contextIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds all product characteristics by product context id for a given catalog inheritance line.
    readAllByProductContextIdIn(@NonNull Collection<String> productContextIds, boolean deduplicateByFieldName, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads all product characteristics for given productContextIds.
    readAllByProductContextIdIn(@NonNull Collection<String> productContextIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads all product characteristics for given productContextIds.

    Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService

    getRsqlHelper, readAll, readAll, readAll, readAll

    Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService

    convertFromPersistentDomain, convertToPersistentDomain, create, createAll, createAllAllowingPartialSuccess, delete, getHelper, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, setSortPositionStrategy, update, updateAll, updateAllAllowingPartialSuccess, updateSort

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService

    create, createAll, createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readAllByContextId, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccess, updateSort

    Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService

    readAll, readAll, readAll, readAll
  • Constructor Details

    • DefaultProductCharacteristicService

      public DefaultProductCharacteristicService(ProductCharacteristicRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
  • Method Details

    • readAllByProductContextIdAndCatalogContextId

      public List<P> readAllByProductContextIdAndCatalogContextId(@NonNull @NonNull String productContextId, @Nullable String catalogContextId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ProductCharacteristicService
      Reads all product characteristics for a given productContextId, restricting results to only the items directly resident in the provided catalogContextId
      Specified by:
      readAllByProductContextIdAndCatalogContextId in interface ProductCharacteristicService<P extends ProductCharacteristic>
      Parameters:
      productContextId - the product context ID to find characteristics for
      catalogContextId - the catalog context ID to restrict the results to
      contextInfo - Request context information around sandbox and multitenant state
      Returns:
      a list of characteristics associated with the product in the specified catalog
    • readAllByProductContextIdIn

      public List<P> readAllByProductContextIdIn(@NonNull @NonNull Collection<String> productContextIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ProductCharacteristicService
      Reads all product characteristics for given productContextIds. This is the same as ProductCharacteristicService.readAllByProductContextIdIn(Collection, boolean, ContextInfo) with deduplicateByFieldName set to 'true'.
      Specified by:
      readAllByProductContextIdIn in interface ProductCharacteristicService<P extends ProductCharacteristic>
      Parameters:
      productContextIds - The product context ids
      contextInfo - Request context information around sandbox and multitenant state
      Returns:
      All product characteristics for given productContextIds.
    • readAllByProductContextIdIn

      public List<P> readAllByProductContextIdIn(@NonNull @NonNull Collection<String> productContextIds, boolean deduplicateByFieldName, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ProductCharacteristicService

      Reads all product characteristics for given productContextIds.

      The deduplicateByFieldName parameter, when set to true, resolves a scenario where the query for product characteristics of a product/products actually produced multiple results for the same ProductCharacteristic.getFieldName() on the same product. See the Javadocs of ProductCharacteristicService.deduplicateProductCharacteristicsByFieldName(List) for an explanation of the edge cases this is handling.

      Specified by:
      readAllByProductContextIdIn in interface ProductCharacteristicService<P extends ProductCharacteristic>
      Parameters:
      productContextIds - The product context ids
      deduplicateByFieldName - whether to deduplicate results for the same product by field name
      contextInfo - Request context information around sandbox and multitenant state
      Returns:
      All product characteristics for given productContextIds.
    • deduplicateProductCharacteristicsByFieldName

      public List<P> deduplicateProductCharacteristicsByFieldName(List<P> input)
      Description copied from interface: ProductCharacteristicService

      Resolves a scenario where the query for product characteristics of a product/products actually produced multiple results for the same ProductCharacteristic.getFieldName() on the same product.

      In most cases, this scenario should not arise. We're expecting the results to have gone through our standard catalog narrowing process to filter down ProductCharacteristics to just 1 instance per ProductCharacteristic context ID. This should ensure only the most derived catalog representation is in play for each ProductCharacteristic context ID, and in most cases for every ProductCharacteristic.getFieldName() on a product, the ProductCharacteristic.getId() will be unique.

      With that being said, consider a scenario where we started out with a product in TopTenantCatalog that didn't have any actual persisted ProductCharacteristic records and simply relied on the inherited defaults from its parent business type to be hydrated at read time. If, after that, an API caller went into ChildTenantCatalog (or application catalog) and specified a different value for any of those characteristics, that change would be interpreted as a new ProductCharacteristic creation in that catalog. It would not technically be considered an override from a DataTracking perspective, because there was no base ProductCharacteristic record in the parent catalog to override. It's a net new insert, and as a result will have a net new context ID. Then, imagine later, someone goes and modifies the value of the characteristic with the same fieldName at the top catalog level. There too, it would be seen as a new ProductCharacteristic creation and have its own new context ID. If you then come back to the child catalog context and read the persisted ProductCharacteristic records, narrowing won't help us because it only narrows by context ID. The results will end up including both the different ProductCharacteristic records for the same field name.

      As a result, we must manually filter out duplicate field names and use this hook point to find the 'most derived' characteristic - usually just by finding the item with the deepest catalog level.

      Specified by:
      deduplicateProductCharacteristicsByFieldName in interface ProductCharacteristicService<P extends ProductCharacteristic>
      Parameters:
      input - a list of product characteristics, potentially for multiple different products. Generally speaking this input should already only be a list of 'most derived' entities narrowed by context ID. We are only expecting to handle duplicates based on ProductCharacteristic.getProductId() + ProductCharacteristic.getFieldName()
      Returns:
      a new list with duplicate field name results for the same product filtered out
    • getCatalogLevel

      @Nullable protected Long getCatalogLevel(P pc)
    • readAllByProductContextIdAndInheritanceLine

      public List<P> readAllByProductContextIdAndInheritanceLine(Collection<String> contextIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ProductCharacteristicService
      Finds all product characteristics by product context id for a given catalog inheritance line. For more details on the filtration semantics and what can be expected in the result, please see the Javadocs of CustomizedProductCharacteristicRepository.findAllByProductContextIdAndInheritanceLine(Collection, ContextInfo), which backs this method.
      Specified by:
      readAllByProductContextIdAndInheritanceLine in interface ProductCharacteristicService<P extends ProductCharacteristic>
      Parameters:
      contextIds - the product context ids to find
      contextInfo - the information surrounding sandboxing and multitenant state, used to determine the catalog inheritance line
      Returns:
      All product characteristics by product context id for a given catalog inheritance line
    • countNonProductionRecordsByProductIdsInTenant

      public long countNonProductionRecordsByProductIdsInTenant(@NonNull @NonNull Collection<String> productIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: ProductCharacteristicService
      Returns the count of non-production records that match the given productContextIds and the given tenant context.
      Specified by:
      countNonProductionRecordsByProductIdsInTenant in interface ProductCharacteristicService<P extends ProductCharacteristic>
      Parameters:
      productIds - IDs of parent Products to match against
      context - Request context information around sandbox and multitenant state
      Returns:
      the count of non-production records that match the given productContextIds and the given tenant context
    • getRepository

      protected ProductCharacteristicRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()
      Overrides:
      getRepository in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends ProductCharacteristic>
    • getParser

      protected com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> getParser()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()