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 Summary
ConstructorsConstructorDescriptionDefaultOptionGenerationService(ProductService<P> productService, OptionTemplateValidator optionTemplateValidator, OptionTemplateGroupValidator optionTemplateGroupValidator, OptionTemplateService<OptionTemplate> optionTemplateService, OptionTemplateGroupService<OptionTemplateGroup> optionTemplateGroupService, com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> translationEntityService, OptionTemplateGroupHydrationService optionTemplateGroupHydrationService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, String optionTemplateRepositoryDomain) -
Method Summary
Modifier and TypeMethodDescriptioncopyOptionsFromTemplates(@NonNull Product product, @NonNull List<OptionTemplate> templates) Deprecated, for removal: This API element is subject to removal in a future version.copyOptionsFromTemplatesToProduct(@NonNull Product product, @NonNull List<OptionTemplate> templates) protected com.broadleafcommerce.translation.domain.TranslationcopyTemplateTranslation(@NonNull com.broadleafcommerce.translation.domain.Translation translation, Product product, String optionId) Copies the givenTranslationfrom anOptionTemplateand updates its entity fields to point to the given product.protected com.broadleafcommerce.translation.domain.TranslationcopyTemplateTranslation(@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 ofcopyTemplateTranslation(Translation, Product, String).protected voidcopyTranslationsFromTemplates(Product product, @NonNull Map<String, String> copiedOptionIdByTemplateId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Copies theTranslationsof theOptionTemplateswhose IDs are supplied onto theProductfor itsProductOptions.protected voidcopyTranslationsFromTemplates(String productId, @NonNull Map<String, Integer> templateIdToCopiedOptionIndex, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Deprecated, for removal: This API element is subject to removal in a future version.since 1.7.2, in favor ofcopyTranslationsFromTemplates(Product, Map, ContextInfo)protected PgenerateOptionFromTemplate(@NonNull String productId, @NonNull OptionTemplate optionTemplate, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) generateOptions(@NonNull OptionGenerationRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Generates theProduct.getOptions()based on theOptionGenerationRequest.protected PgenerateOptionsFromTemplateGroup(@NonNull String productId, @NonNull OptionTemplateGroup optionTemplateGroup, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Generates new entries for therequested product'soptionsbased on the providedOptionTemplateGroup.protected OptionTemplateGroupHydrationServiceprotected OptionTemplateGroupService<OptionTemplateGroup>protected OptionTemplateGroupValidatorprotected Stringprotected OptionTemplateService<OptionTemplate>protected OptionTemplateValidatorprotected ProductService<P>protected com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation>protected com.broadleafcommerce.common.extension.TypeFactoryprotected booleanshouldCopyTranslation(@NonNull com.broadleafcommerce.translation.domain.Translation translation) Determines whether anOptionTemplate'sTranslationis for the template's option, and, thus, should be copied onto theProduct'scopy of theProductOption.protected StringtransformEntityFieldToProductEquivalent(String templateEntityField, int optionIndex) Deprecated, for removal: This API element is subject to removal in a future version.since 1.7.2, in favor oftransformEntityFieldToProductEquivalent(String, String)protected StringtransformEntityFieldToProductEquivalent(String templateEntityField, String optionId) Transforms the givenTranslation.getEntityField()from anOptionTemplate's Option'sTranslationinto a value that is appropriate for aProduct's copy of the option.
-
Constructor Details
-
DefaultOptionGenerationService
public DefaultOptionGenerationService(ProductService<P> productService, OptionTemplateValidator optionTemplateValidator, OptionTemplateGroupValidator optionTemplateGroupValidator, OptionTemplateService<OptionTemplate> optionTemplateService, OptionTemplateGroupService<OptionTemplateGroup> optionTemplateGroupService, com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> translationEntityService, OptionTemplateGroupHydrationService optionTemplateGroupHydrationService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, String optionTemplateRepositoryDomain)
-
-
Method Details
-
generateOptions
public P generateOptions(@NonNull @NonNull OptionGenerationRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:OptionGenerationServiceGenerates theProduct.getOptions()based on theOptionGenerationRequest.- Specified by:
generateOptionsin interfaceOptionGenerationService<P extends Product>- Parameters:
request-OptionGenerationRequestwith theOptionTemplateOptionTemplateGroupto 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) - Parameters:
productId- id of theProducton which to apply theOptionTemplateoptionTemplate- theOptionTemplatewhich is being applied to the productcontext- context information surrounding sandboxing and multitenant state- Returns:
- The updated product.
-
generateOptionsFromTemplateGroup
protected P generateOptionsFromTemplateGroup(@NonNull @NonNull String productId, @NonNull @NonNull OptionTemplateGroup optionTemplateGroup, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Generates new entries for therequested product'soptionsbased on the providedOptionTemplateGroup.- Parameters:
productId- productId of theProducton which to apply theOptionTemplateGroupoptionTemplateGroup- theOptionTemplateGroupwhich is being applied to the productcontext- context information surrounding sandboxing and multitenant state- Returns:
- The updated product.
-
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 ofcopyOptionsFromTemplatesToProduct(Product, List). The option ids should be used instead of the index.AddsProductOptionsfromthe given OptionTemplatesto thethe give Product's option collection. Then, returns aMapof 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 appropriateentityFieldvalues.- Parameters:
product- Product onto which to copy the options from the templatestemplates- Templates whose options to copy- Returns:
- a
Mapof 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) AddsProductOptionsfromthe given OptionTemplatesto thethe give Product's option collection. Then, returns aMapof 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 appropriateentityFieldvalues.- Parameters:
product- Product onto which to copy the options from the templatestemplates- Templates whose options to copy- Returns:
- a
Mapof 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.since 1.7.2, in favor ofcopyTranslationsFromTemplates(Product, Map, ContextInfo) -
copyTranslationsFromTemplates
protected void copyTranslationsFromTemplates(Product product, @NonNull @NonNull Map<String, String> copiedOptionIdByTemplateId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Copies theTranslationsof theOptionTemplateswhose IDs are supplied onto theProductfor itsProductOptions. This will usePathUtil.getValueForPath(Object, String)to change theentityField valuesof the copied translations to what is appropriate for theProduct.- Parameters:
product- the product onto which translations should be copiedcopiedOptionIdByTemplateId- AMapof the IDs of the templates by the id of the newly added option inProduct.getOptions().context- context information surrounding sandboxing and multitenant state
-
shouldCopyTranslation
protected boolean shouldCopyTranslation(@NonNull @NonNull com.broadleafcommerce.translation.domain.Translation translation) Determines whether anOptionTemplate'sTranslationis for the template's option, and, thus, should be copied onto theProduct'scopy of theProductOption.- Parameters:
translation- TheTranslationin question.- Returns:
- Whether the
Translationshould 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 ofcopyTemplateTranslation(Translation, Product, String). Option id should be used instead of index.Copies the givenTranslationfrom anOptionTemplateand updates its entity fields to point to the given product.- Parameters:
translation-Translationto be copiedproductId- ID of theProductonto which a template's option was copiedoptionIndex- Index of the copiedProductOptionin the given product'sProduct.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 givenTranslationfrom anOptionTemplateand updates its entity fields to point to the given product.- Parameters:
translation-Translationto be copiedproductId- ID of theProductonto which a template's option was copiedoptionId- ID of the copiedProductOptionin the given product'sProduct.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.since 1.7.2, in favor oftransformEntityFieldToProductEquivalent(String, String)Transforms the givenTranslation.getEntityField()from anOptionTemplate's Option'sTranslationinto a value that is appropriate for aProduct's copy of the option.- Parameters:
templateEntityField-Translation.getEntityField()from anOptionTemplate's Option'sTranslationoptionIndex- Index of the copiedProductOptioninProduct.getOptions()- Returns:
- The appropriate
Translation.getEntityField()for aProduct's copy of the option.
-
transformEntityFieldToProductEquivalent
protected String transformEntityFieldToProductEquivalent(String templateEntityField, String optionId) Transforms the givenTranslation.getEntityField()from anOptionTemplate's Option'sTranslationinto a value that is appropriate for aProduct's copy of the option.- Parameters:
templateEntityField-Translation.getEntityField()from anOptionTemplate's Option'sTranslationoptionId- ID of the copiedProductOptioninProduct.getOptions()- Returns:
- The appropriate
Translation.getEntityField()for aProduct's copy of the option.
-
getProductService
-
getOptionTemplateValidator
-
getOptionTemplateGroupValidator
-
getOptionTemplateService
-
getOptionTemplateGroupService
-
getTranslationEntityService
protected com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation> getTranslationEntityService() -
getOptionTemplateGroupHydrationService
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getOptionTemplateRepositoryDomain
-
copyOptionsFromTemplatesToProduct(Product, List).