Interface ProductCharacteristicService<P extends ProductCharacteristic>

All Superinterfaces:
com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>
All Known Implementing Classes:
DefaultProductCharacteristicService

public interface ProductCharacteristicService<P extends ProductCharacteristic> extends com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>
Service for managing ProductCharacteristics. This is typically only called from the ProductService for managing product characteristics as part of product CRUD operations.
Since:
Catalog Service 2.3.0, Release Train 2.3.0
  • 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.
    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(Collection<String> productContextIds, boolean deduplicateByFieldName, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads all product characteristics for given productContextIds.
    readAllByProductContextIdIn(Collection<String> productContextIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Reads all product characteristics for given productContextIds.

    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
  • Method Details

    • readAllByProductContextIdAndCatalogContextId

      List<P> readAllByProductContextIdAndCatalogContextId(@NonNull @NonNull String productContextId, @Nullable String catalogContextId, @Nullable 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
      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

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

      List<P> readAllByProductContextIdIn(Collection<String> productContextIds, boolean deduplicateByFieldName, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)

      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 deduplicateProductCharacteristicsByFieldName(List) for an explanation of the edge cases this is handling.

      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

      List<P> deduplicateProductCharacteristicsByFieldName(List<P> input)

      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.

      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
    • readAllByProductContextIdAndInheritanceLine

      List<P> readAllByProductContextIdAndInheritanceLine(Collection<String> contextIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      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.
      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

      long countNonProductionRecordsByProductIdsInTenant(@NonNull @NonNull Collection<String> productIds, @Nullable 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.
      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