Class DefaultCodeGeneratorService<P extends CodeGenerator>
- java.lang.Object
-
- com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
-
- com.broadleafcommerce.promotion.campaign.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
Constructors Constructor Description 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 Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected intcalculateRequiredCodeLength(int numberOfCodes, int charSetSize)Returns the size of the code that you must create in order to support the passed in number of Codes.Pcreate(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)PcreateWithoutPersistenceNotification(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Creates aCodeGeneratorwithout 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 CodeFormatAvailableCharHelpergetAvailableCharHelper()protected CampaignRepository<com.broadleafcommerce.data.tracking.core.Trackable>getCampaignRepository()Deprecated.since 1.4, usegetCampaignService()insteadprotected CampaignService<Campaign>getCampaignService()protected CodeGeneratorPreValidatorgetCodeGeneratorPreValidator()protected CodeGeneratorRepository<com.broadleafcommerce.data.tracking.core.Trackable>getCodeGeneratorRepository()protected intgetCodeMultiplier()Affects the "guessability" of codes when a code format has not been provided.protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManagergetValidator()voidinitializeCodeFieldsIfMissing(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)voidinitializeCodeFormat(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)protected voidinitializeCodePrefix(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Optional<P>readByCampaignIdAndVoucherCodeGenerator(String campaignId, boolean isVoucherCodeGenerator, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)Finds an activeCodeGeneratorthat is for the given campaign id and is for voucher offers.voidsetAvailableCharHelper(CodeFormatAvailableCharHelper availableCharHelper)voidsetCampaignService(CampaignService<Campaign> campaignService)voidsetCodeGeneratorPreValidator(CodeGeneratorPreValidator codeGeneratorPreValidator)PupdateQuietly(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 Detail
-
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 Detail
-
updateQuietly
public P updateQuietly(@NonNull String id, @NonNull P updateRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
Description copied from interface:CodeGeneratorServiceAn alternative toCrudEntityHelper.update(String, Object, ContextInfo, TrackableRepository)that does not callCrudEntityHelper.notify(Trackable, ContextInfo, NotificationStateRepository).- Specified by:
updateQuietlyin interfaceCodeGeneratorService<P extends CodeGenerator>- Parameters:
id- the context id of theCodeGeneratorto updateupdateRequest- theCodeGeneratorinstance 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:
findByCampaignIdin 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:CodeGeneratorServiceFinds an activeCodeGeneratorthat is for the given campaign id and is for voucher offers.- Specified by:
readByCampaignIdAndVoucherCodeGeneratorin 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:
createin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends CodeGenerator>- Overrides:
createin 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:CodeGeneratorServiceCreates aCodeGeneratorwithout the persistence notification. This is used when you want to manually generate theCampaignCodesinstead of going through theCodeGenerationPersistenceHandler.- Specified by:
createWithoutPersistenceNotificationin interfaceCodeGeneratorService<P extends CodeGenerator>- Parameters:
businessInstance- the instance ofCodeGeneratorcontext- 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
@Autowired public void setCampaignService(CampaignService<Campaign> campaignService)
-
getCampaignService
@NonNull protected CampaignService<Campaign> getCampaignService()
-
setAvailableCharHelper
@Autowired public void setAvailableCharHelper(CodeFormatAvailableCharHelper availableCharHelper)
-
getAvailableCharHelper
@NonNull protected CodeFormatAvailableCharHelper getAvailableCharHelper()
-
setCodeGeneratorPreValidator
@Autowired public void setCodeGeneratorPreValidator(CodeGeneratorPreValidator codeGeneratorPreValidator)
-
getCodeGeneratorPreValidator
@NonNull protected CodeGeneratorPreValidator getCodeGeneratorPreValidator()
-
-