Class DefaultOptionGenerationService<P extends Product>

java.lang.Object
com.broadleafcommerce.catalog.service.product.DefaultOptionGenerationService<P>
All Implemented Interfaces:
OptionGenerationService<P>

public class DefaultOptionGenerationService<P extends Product> extends Object implements OptionGenerationService<P>
Author:
Nathan Moore (nathandmoore)
  • Constructor Details

  • Method Details

    • generateOptions

      public P generateOptions(@NonNull @NonNull OptionGenerationRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: OptionGenerationService
      Generates the Product.getOptions() based on the OptionGenerationRequest.
      Specified by:
      generateOptions in interface OptionGenerationService<P extends Product>
      Parameters:
      request - OptionGenerationRequest with the OptionTemplate OptionTemplateGroup to be used for generating a product's options.
      context - context information surrounding sandboxing and multitenant state
      Returns:
      The product with newly generated options.
    • generateOptionFromTemplate

      protected P generateOptionFromTemplate(@NonNull @NonNull String productId, @NonNull @NonNull OptionTemplate optionTemplate, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Generates a new entry for the requested product's options based on the provided OptionTemplate.
      Parameters:
      productId - id of the Product on which to apply the OptionTemplate
      optionTemplate - the OptionTemplate which is being applied to the product
      context - context information surrounding sandboxing and multitenant state
      Returns:
      The updated product.
    • referenceOptionFromTemplate

      protected P referenceOptionFromTemplate(@NonNull @NonNull String productId, @NonNull @NonNull String optionTemplateId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Populates the requested product's options' with the provided option template ID.
      Parameters:
      productId - productId of the Product referencing the OptionTemplate
      optionTemplateId - the OptionTemplate.getId() which is being referenced by the product options
      context - context information surrounding sandboxing and multitenant state
      Returns:
      The updated product.
      See Also:
    • generateOptionsFromTemplateGroup

      protected P generateOptionsFromTemplateGroup(@NonNull @NonNull String productId, @NonNull @NonNull OptionTemplateGroup optionTemplateGroup, @NonNull @NonNull List<String> productOptionTypesToExclude, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Generates new entries for the requested product's options based on the provided OptionTemplateGroup.Also accepts a list of Product Option types that will be excluded from product option generation.
      Parameters:
      productId - productId of the Product on which to apply the OptionTemplateGroup
      optionTemplateGroup - the OptionTemplateGroup which is being applied to the product
      productOptionTypesToExclude - the list of Product Option types that will be excluded from product option generation
      context - context information surrounding sandboxing and multitenant state
      Returns:
      The updated product.
    • referenceOptionsFromTemplateGroup

      protected P referenceOptionsFromTemplateGroup(@NonNull @NonNull String productId, @NonNull @NonNull OptionTemplateGroup optionTemplateGroup, @NonNull @NonNull List<String> productOptionTypesToExclude, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Populates the requested product's options' with each of the option template IDs of the provided OptionTemplateGroup. Also accepts a list of Product Option types that will be excluded from product option generation.
      Parameters:
      productId - productId of the Product referencing the OptionTemplateGroup
      optionTemplateGroup - the OptionTemplateGroup whose templates' IDs are being referenced by the product options
      productOptionTypesToExclude - the list of Product Option types that will be excluded from product option generation
      context - context information surrounding sandboxing and multitenant state
      Returns:
      The updated product.
      See Also:
    • copyOptionsFromTemplates

      @Deprecated(since="1.7.2", forRemoval=true) protected Map<String,Integer> copyOptionsFromTemplates(@NonNull @NonNull Product product, @NonNull @NonNull List<OptionTemplate> templates)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 1.7.2, in favor of copyOptionsFromTemplatesToProduct(Product, List). The option ids should be used instead of the index.
      Adds ProductOptions from the given OptionTemplates to the the give Product's option collection. Then, returns a Map of the IDs of the copied templates to the index of the newly added option in the Product's option collection so that translations may also be copied with appropriate entityField values.
      Parameters:
      product - Product onto which to copy the options from the templates
      templates - Templates whose options to copy
      Returns:
      a Map of the IDs of the copied templates to the index of the newly added option in the Product's option collection.
    • copyOptionsFromTemplatesToProduct

      protected Map<String,String> copyOptionsFromTemplatesToProduct(@NonNull @NonNull Product product, @NonNull @NonNull List<OptionTemplate> templates)
      Adds ProductOptions from the given OptionTemplates to the the give Product's option collection. Then, returns a Map of the IDs of the copied templates to the IDs of the newly added option in the Product's option collection so that translations may also be copied with appropriate entityField values.
      Parameters:
      product - Product onto which to copy the options from the templates
      templates - Templates whose options to copy
      Returns:
      a Map of the IDs of the copied templates to the IDs of the newly added option in the Product's option collection.
    • copyTranslationsFromTemplates

      @Deprecated(since="1.7.2", forRemoval=true) protected void copyTranslationsFromTemplates(String productId, @NonNull @NonNull Map<String,Integer> templateIdToCopiedOptionIndex, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • copyTranslationsFromTemplates

      protected void copyTranslationsFromTemplates(Product product, @NonNull @NonNull Map<String,String> copiedOptionIdByTemplateId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Copies the Translations of the OptionTemplates whose IDs are supplied onto the Product for its ProductOptions. This will use PathUtil.getValueForPath(Object, String) to change the entityField values of the copied translations to what is appropriate for the Product.
      Parameters:
      product - the product onto which translations should be copied
      copiedOptionIdByTemplateId - A Map of the IDs of the templates by the id of the newly added option in Product.getOptions().
      context - context information surrounding sandboxing and multitenant state
    • shouldCopyTranslation

      protected boolean shouldCopyTranslation(@NonNull @NonNull com.broadleafcommerce.translation.domain.Translation translation)
      Determines whether an OptionTemplate's Translation is for the template's option, and, thus, should be copied onto the Product's copy of the ProductOption.
      Parameters:
      translation - The Translation in question.
      Returns:
      Whether the Translation should be copied.
    • copyTemplateTranslation

      @Deprecated(since="1.7.2", forRemoval=true) protected com.broadleafcommerce.translation.domain.Translation copyTemplateTranslation(@NonNull @NonNull com.broadleafcommerce.translation.domain.Translation translation, String productId, int optionIndex)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 1.7.2, in favor of copyTemplateTranslation(Translation, Product, String). Option id should be used instead of index.
      Copies the given Translation from an OptionTemplate and updates its entity fields to point to the given product.
      Parameters:
      translation - Translation to be copied
      productId - ID of the Product onto which a template's option was copied
      optionIndex - Index of the copied ProductOption in the given product's Product.getOptions()
      Returns:
      The new Translation.
    • copyTemplateTranslation

      protected com.broadleafcommerce.translation.domain.Translation copyTemplateTranslation(@NonNull @NonNull com.broadleafcommerce.translation.domain.Translation translation, Product product, String optionId)
      Copies the given Translation from an OptionTemplate and updates its entity fields to point to the given product.
      Parameters:
      translation - Translation to be copied
      product - the Product onto which a template's option was copied
      optionId - ID of the copied ProductOption in the given product's Product.getOptions()
      Returns:
      The new Translation.
    • transformEntityFieldToProductEquivalent

      @Deprecated(since="1.7.2", forRemoval=true) protected String transformEntityFieldToProductEquivalent(String templateEntityField, int optionIndex)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Transforms the given Translation.getEntityField() from an OptionTemplate's Option's Translation into a value that is appropriate for a Product's copy of the option.
      Parameters:
      templateEntityField - Translation.getEntityField() from an OptionTemplate's Option's Translation
      optionIndex - Index of the copied ProductOption in Product.getOptions()
      Returns:
      The appropriate Translation.getEntityField() for a Product's copy of the option.
    • transformEntityFieldToProductEquivalent

      protected String transformEntityFieldToProductEquivalent(String templateEntityField, String optionId)
      Transforms the given Translation.getEntityField() from an OptionTemplate's Option's Translation into a value that is appropriate for a Product's copy of the option.
      Parameters:
      templateEntityField - Translation.getEntityField() from an OptionTemplate's Option's Translation
      optionId - ID of the copied ProductOption in Product.getOptions()
      Returns:
      The appropriate Translation.getEntityField() for a Product's copy of the option.
    • getProductService

      protected ProductService<P> getProductService()
    • getOptionTemplateValidator

      protected OptionTemplateValidator getOptionTemplateValidator()
    • getOptionTemplateGroupValidator

      protected OptionTemplateGroupValidator getOptionTemplateGroupValidator()
    • getOptionTemplateService

      protected OptionTemplateService<OptionTemplate> getOptionTemplateService()
    • getOptionTemplateGroupService

      protected OptionTemplateGroupService<OptionTemplateGroup> getOptionTemplateGroupService()
    • getTranslationEntityService

      protected com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> getTranslationEntityService()
    • getOptionTemplateGroupHydrationService

      protected OptionTemplateGroupHydrationService getOptionTemplateGroupHydrationService()
    • getTypeFactory

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

      protected String getOptionTemplateRepositoryDomain()