Class DefaultCodeGeneratorService<P extends CodeGenerator>
java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.promotion.offer.service.DefaultCodeGeneratorService<P>
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>
,CodeGeneratorService<P>
public class DefaultCodeGeneratorService<P extends CodeGenerator>
extends com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
implements CodeGeneratorService<P>
- Author:
- Chad Harchar (charchar)
-
Constructor Summary
ConstructorDescriptionDefaultCodeGeneratorService
(CodeGeneratorRepository<com.broadleafcommerce.data.tracking.core.Trackable> codeGeneratorRepository, CampaignRepository<com.broadleafcommerce.data.tracking.core.Trackable> campaignRepository, com.broadleafcommerce.data.tracking.core.service.CrudEntityHelper helper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager entityValidatorManager) -
Method Summary
Modifier and TypeMethodDescriptionprotected int
calculateRequiredCodeLength
(int numberOfCodes, int charSetSize) Returns the size of the code that you must create in order to support the passed in number of Codes.createWithoutPersistenceNotification
(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Creates aCodeGenerator
without the persistence notification.org.springframework.data.domain.Page<P>
findByCampaignId
(String campaignId, org.springframework.data.domain.Pageable page, Class<P> payloadType, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected CodeFormatAvailableCharHelper
protected CampaignRepository<com.broadleafcommerce.data.tracking.core.Trackable>
Deprecated.protected CampaignService<Campaign>
protected CodeGeneratorPreValidator
protected CodeGeneratorRepository<com.broadleafcommerce.data.tracking.core.Trackable>
protected int
Affects the "guessability" of codes when a code format has not been provided.protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager
void
initializeCodeFieldsIfMissing
(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) void
initializeCodeFormat
(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected void
initializeCodePrefix
(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) readByCampaignIdAndVoucherCodeGenerator
(String campaignId, boolean isVoucherCodeGenerator, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Finds an activeCodeGenerator
that is for the given campaign id and is for voucher offers.void
setAvailableCharHelper
(CodeFormatAvailableCharHelper availableCharHelper) void
setCampaignService
(CampaignService<Campaign> campaignService) void
setCodeGeneratorPreValidator
(CodeGeneratorPreValidator codeGeneratorPreValidator) updateQuietly
(String id, P updateRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) An alternative toCrudEntityHelper.update(String, Object, ContextInfo, TrackableRepository)
that does not callCrudEntityHelper.notify(Trackable, ContextInfo, NotificationStateRepository)
.Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService
convertFromPersistentDomain, convertToPersistentDomain, createAll, createAllAllowingPartialSuccess, delete, getHelper, getRepository, 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
createAll, createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readAllByContextId, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccess, updateSort
-
Constructor Details
-
DefaultCodeGeneratorService
public DefaultCodeGeneratorService(CodeGeneratorRepository<com.broadleafcommerce.data.tracking.core.Trackable> codeGeneratorRepository, CampaignRepository<com.broadleafcommerce.data.tracking.core.Trackable> campaignRepository, com.broadleafcommerce.data.tracking.core.service.CrudEntityHelper helper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager entityValidatorManager)
-
-
Method Details
-
updateQuietly
public P updateQuietly(@NonNull String id, @NonNull P updateRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:CodeGeneratorService
An alternative toCrudEntityHelper.update(String, Object, ContextInfo, TrackableRepository)
that does not callCrudEntityHelper.notify(Trackable, ContextInfo, NotificationStateRepository)
.- Specified by:
updateQuietly
in interfaceCodeGeneratorService<P extends CodeGenerator>
- Parameters:
id
- the context id of theCodeGenerator
to updateupdateRequest
- theCodeGenerator
instance containing the new values to patch onto the existing instancecontext
- context surrounding sandboxing and multitenant state- Returns:
- the fully updated instance
-
findByCampaignId
@NonNull public org.springframework.data.domain.Page<P> findByCampaignId(@NonNull String campaignId, org.springframework.data.domain.Pageable page, @NonNull Class<P> payloadType, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
findByCampaignId
in interfaceCodeGeneratorService<P extends CodeGenerator>
-
readByCampaignIdAndVoucherCodeGenerator
@NonNull public Optional<P> readByCampaignIdAndVoucherCodeGenerator(String campaignId, boolean isVoucherCodeGenerator, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:CodeGeneratorService
Finds an activeCodeGenerator
that is for the given campaign id and is for voucher offers.- Specified by:
readByCampaignIdAndVoucherCodeGenerator
in interfaceCodeGeneratorService<P extends CodeGenerator>
- Parameters:
campaignId
- the campaign id that the code generator is forisVoucherCodeGenerator
- whether this code generator is for voucher offerscontext
- context information surrounding sandboxing and multi tenant state- Returns:
- an active code generator that is for the given campaign id and is for voucher offers
-
create
public P create(P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
create
in interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends CodeGenerator>
- Overrides:
create
in classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends CodeGenerator>
-
createWithoutPersistenceNotification
@SuppressNotification("PERSISTENCE") public P createWithoutPersistenceNotification(P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:CodeGeneratorService
Creates aCodeGenerator
without the persistence notification. This is used when you want to manually generate theCampaignCodes
instead of going through theCodeGenerationPersistenceHandler
.- Specified by:
createWithoutPersistenceNotification
in interfaceCodeGeneratorService<P extends CodeGenerator>
- Parameters:
businessInstance
- the instance ofCodeGenerator
context
- context surrounding sandboxing and multitenant state- Returns:
- the created instance of
CodeGenerator
-
initializeCodeFieldsIfMissing
public void initializeCodeFieldsIfMissing(P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) -
initializeCodePrefix
protected void initializeCodePrefix(P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) -
initializeCodeFormat
public void initializeCodeFormat(P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) -
calculateRequiredCodeLength
protected int calculateRequiredCodeLength(int numberOfCodes, int charSetSize) Returns the size of the code that you must create in order to support the passed in number of Codes.- Parameters:
numberOfCodes
-- Returns:
-
getCodeMultiplier
protected int getCodeMultiplier()Affects the "guessability" of codes when a code format has not been provided. For example, if 100 codes are being generated, the default will insure that the codes are generated at least from a pool of 100000 possible codes.- Returns:
-
getCodeGeneratorRepository
@NonNull protected CodeGeneratorRepository<com.broadleafcommerce.data.tracking.core.Trackable> getCodeGeneratorRepository() -
getCampaignRepository
@Deprecated @NonNull protected CampaignRepository<com.broadleafcommerce.data.tracking.core.Trackable> getCampaignRepository()Deprecated.since 1.4, usegetCampaignService()
instead -
getValidator
@NonNull protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator() -
setCampaignService
-
getCampaignService
-
setAvailableCharHelper
-
getAvailableCharHelper
-
setCodeGeneratorPreValidator
@Autowired public void setCodeGeneratorPreValidator(CodeGeneratorPreValidator codeGeneratorPreValidator) -
getCodeGeneratorPreValidator
-
getCampaignService()
instead