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
ConstructorDescriptionDefaultOptionGenerationService
(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.Translation
copyTemplateTranslation
(@NonNull com.broadleafcommerce.translation.domain.Translation translation, Product product, String optionId) Copies the givenTranslation
from anOptionTemplate
and updates its entity fields to point to the given product.protected com.broadleafcommerce.translation.domain.Translation
copyTemplateTranslation
(@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 void
copyTranslationsFromTemplates
(Product product, @NonNull Map<String, String> copiedOptionIdByTemplateId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Copies theTranslations
of theOptionTemplates
whose IDs are supplied onto theProduct
for itsProductOptions
.protected void
copyTranslationsFromTemplates
(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 P
generateOptionFromTemplate
(@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 P
generateOptionsFromTemplateGroup
(@NonNull String productId, @NonNull OptionTemplateGroup optionTemplateGroup, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Generates new entries for therequested product's
options
based on the providedOptionTemplateGroup
.protected OptionTemplateGroupHydrationService
protected OptionTemplateGroupService<OptionTemplateGroup>
protected OptionTemplateGroupValidator
protected String
protected OptionTemplateService<OptionTemplate>
protected OptionTemplateValidator
protected ProductService<P>
protected com.broadleafcommerce.translation.service.TranslationEntityService<com.broadleafcommerce.translation.domain.Translation>
protected com.broadleafcommerce.common.extension.TypeFactory
protected P
referenceOptionFromTemplate
(@NonNull String productId, @NonNull String optionTemplateId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected P
referenceOptionsFromTemplateGroup
(@NonNull String productId, @NonNull OptionTemplateGroup optionTemplateGroup, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Populates therequested product's
options'
with each of theoption template IDs
of the providedOptionTemplateGroup
.protected boolean
shouldCopyTranslation
(@NonNull com.broadleafcommerce.translation.domain.Translation translation) Determines whether anOptionTemplate's
Translation
is for the template's option, and, thus, should be copied onto theProduct's
copy of theProductOption
.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)
protected String
transformEntityFieldToProductEquivalent
(String templateEntityField, String optionId) Transforms the givenTranslation.getEntityField()
from anOptionTemplate's Option's
Translation
into 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:OptionGenerationService
Generates theProduct.getOptions()
based on theOptionGenerationRequest
.- Specified by:
generateOptions
in interfaceOptionGenerationService<P extends Product>
- Parameters:
request
-OptionGenerationRequest
with theOptionTemplate
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) - Parameters:
productId
- id of theProduct
on which to apply theOptionTemplate
optionTemplate
- theOptionTemplate
which is being applied to the productcontext
- 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) - Parameters:
productId
- productId of theProduct
referencing theOptionTemplate
optionTemplateId
- theOptionTemplate.getId()
which is being referenced by the product optionscontext
- 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, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Generates new entries for therequested product's
options
based on the providedOptionTemplateGroup
.- Parameters:
productId
- productId of theProduct
on which to apply theOptionTemplateGroup
optionTemplateGroup
- theOptionTemplateGroup
which is being applied to the productcontext
- context information surrounding sandboxing and multitenant state- Returns:
- The updated product.
-
referenceOptionsFromTemplateGroup
protected P referenceOptionsFromTemplateGroup(@NonNull @NonNull String productId, @NonNull @NonNull OptionTemplateGroup optionTemplateGroup, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Populates therequested product's
options'
with each of theoption template IDs
of the providedOptionTemplateGroup
.- Parameters:
productId
- productId of theProduct
referencing theOptionTemplateGroup
optionTemplateGroup
- theOptionTemplateGroup
whose templates' IDs are being referenced by the product optionscontext
- 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 ofcopyOptionsFromTemplatesToProduct(Product, List)
. The option ids should be used instead of the index.AddsProductOptions
fromthe given OptionTemplates
to thethe give Product's option collection
. Then, returns aMap
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 appropriateentityField
values.- Parameters:
product
- Product onto which to copy the options from the templatestemplates
- 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) AddsProductOptions
fromthe given OptionTemplates
to thethe give Product's option collection
. Then, returns aMap
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 appropriateentityField
values.- Parameters:
product
- Product onto which to copy the options from the templatestemplates
- 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.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 theTranslations
of theOptionTemplates
whose IDs are supplied onto theProduct
for itsProductOptions
. This will usePathUtil.getValueForPath(Object, String)
to change theentityField values
of the copied translations to what is appropriate for theProduct
.- Parameters:
product
- the product onto which translations should be copiedcopiedOptionIdByTemplateId
- AMap
of 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's
Translation
is for the template's option, and, thus, should be copied onto theProduct's
copy of theProductOption
.- Parameters:
translation
- TheTranslation
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 ofcopyTemplateTranslation(Translation, Product, String)
. Option id should be used instead of index.Copies the givenTranslation
from anOptionTemplate
and updates its entity fields to point to the given product.- Parameters:
translation
-Translation
to be copiedproductId
- ID of theProduct
onto which a template's option was copiedoptionIndex
- Index of the copiedProductOption
in 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 givenTranslation
from anOptionTemplate
and updates its entity fields to point to the given product.- Parameters:
translation
-Translation
to be copiedproduct
- theProduct
onto which a template's option was copiedoptionId
- ID of the copiedProductOption
in 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's
Translation
into a value that is appropriate for aProduct's copy of the option
.- Parameters:
templateEntityField
-Translation.getEntityField()
from anOptionTemplate's Option's
Translation
optionIndex
- Index of the copiedProductOption
inProduct.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's
Translation
into a value that is appropriate for aProduct's copy of the option
.- Parameters:
templateEntityField
-Translation.getEntityField()
from anOptionTemplate's Option's
Translation
optionId
- ID of the copiedProductOption
inProduct.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)
.