Class DefaultCampaignCodeService<P extends CampaignCode>

  • All Implemented Interfaces:
    com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>, CampaignCodeService<P>

    public class DefaultCampaignCodeService<P extends CampaignCode>
    extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
    implements CampaignCodeService<P>
    Author:
    Chad Harchar (charchar)
    • Constructor Detail

      • DefaultCampaignCodeService

        public DefaultCampaignCodeService​(CampaignCodeRepository<com.broadleafcommerce.data.tracking.core.Trackable> campaignCodeRepository,
                                          CampaignRepository<com.broadleafcommerce.data.tracking.core.Trackable> campaignRepository,
                                          com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper,
                                          com.broadleafcommerce.common.extension.TypeFactory campaignFactory)
    • Method Detail

      • findByCampaignId

        @NonNull
        public org.springframework.data.domain.Page<P> findByCampaignId​(@NonNull
                                                                        String campaignId,
                                                                        @Nullable
                                                                        cz.jirutka.rsql.parser.ast.Node filters,
                                                                        @Nullable
                                                                        org.springframework.data.domain.Pageable page,
                                                                        @NonNull
                                                                        Class<P> payloadType,
                                                                        @Nullable
                                                                        com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Specified by:
        findByCampaignId in interface CampaignCodeService<P extends CampaignCode>
      • readAllByCode

        @NonNull
        public List<P> readAllByCode​(@NonNull
                                     String code,
                                     @Nullable
                                     com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from interface: CampaignCodeService
        Finds all of the CampaignCodes by code.
        Specified by:
        readAllByCode in interface CampaignCodeService<P extends CampaignCode>
        Parameters:
        code - Code to match
        context - Additional sandbox and multitenant state data
        Returns:
        all of the @link CampaignCode CampaignCodes} by code
      • create

        public P create​(P businessInstance,
                        com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Specified by:
        create in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends CampaignCode>
        Overrides:
        create in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends CampaignCode>
      • update

        public P update​(String id,
                        P businessInstance,
                        com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Specified by:
        update in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends CampaignCode>
        Overrides:
        update in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends CampaignCode>
      • replace

        public P replace​(String id,
                         P businessInstance,
                         com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Specified by:
        replace in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends CampaignCode>
        Overrides:
        replace in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends CampaignCode>
      • saveAll

        public List<com.broadleafcommerce.data.tracking.core.Trackable> saveAll​(List<P> businessInstances,
                                                                                com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Specified by:
        saveAll in interface CampaignCodeService<P extends CampaignCode>
      • readAllByCampaignId

        public Stream<P> readAllByCampaignId​(String campaignId,
                                             @Nullable
                                             cz.jirutka.rsql.parser.ast.Node filters,
                                             @Nullable
                                             com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from interface: CampaignCodeService
        Reads the campaign codes for the specified campaign id matching the given filters.
        Specified by:
        readAllByCampaignId in interface CampaignCodeService<P extends CampaignCode>
        Parameters:
        campaignId - the campaign id
        filters - additional filters to apply in the query
        context - Request context information around sandbox and multitenant state
        Returns:
        the campaign codes for the specified campaign id matching the given filters
      • findExistingByCodesIncludeExpiredForCampaignId

        public List<P> findExistingByCodesIncludeExpiredForCampaignId​(Set<String> codes,
                                                                      String campaignId,
                                                                      Instant endAfterDate,
                                                                      @Nullable
                                                                      com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Description copied from interface: CampaignCodeService
        Search all non-expired campaign codes or expired but belonging to the specified campaignId. This is useful to validate that the campaign codes can be added or updated. NOTE: This method is used during import of CampaignCode and because different DBs has a different limitation on how many entries can be in "in" statement please make sure that the property "broadleaf.dataimport.processor.batch-size" not exited this limitation.
        Specified by:
        findExistingByCodesIncludeExpiredForCampaignId in interface CampaignCodeService<P extends CampaignCode>
        Parameters:
        codes - The set of codes to match
        campaignId - the campaign id
        endAfterDate - Date after which code should be active
        context - Request context information around sandbox and multitenant state
        Returns:
        all CampaignCodes by CampaignCode.getCode() that are also active or belonging to the specified campaignId
        See Also:
        CampaignCodeImportBatchHandler
      • rejectDuplicateCode

        protected org.springframework.validation.Errors rejectDuplicateCode​(P duplicate)
      • populateCodeGeneratorDetailsToCode

        protected void populateCodeGeneratorDetailsToCode​(CodeGenerator codeGenerator,
                                                          P campaignCode)
      • saveAllNonDuplicates

        protected void saveAllNonDuplicates​(String codeGeneratorId,
                                            List<P> campaignCodeList,
                                            Class<P> payloadType,
                                            com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      • findDuplicateCodes

        protected List<P> findDuplicateCodes​(String codeGeneratorId,
                                             List<P> campaignCodeList,
                                             Class<P> payloadType,
                                             com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      • buildCampaignCodeStringList

        protected List<String> buildCampaignCodeStringList​(List<P> offerCodeList)
      • removeDuplicatesFromList

        protected void removeDuplicatesFromList​(List<P> campaignCodeList,
                                                List<P> duplicateCampaignCodes)
        Iterate through the codes we are about to save. If the code is in the duplicateCampaignCodes list then remove it.
        Parameters:
        campaignCodeList -
        duplicateCampaignCodes -
      • getCampaignCodeRepository

        @NonNull
        protected CampaignCodeRepository<com.broadleafcommerce.data.tracking.core.Trackable> getCampaignCodeRepository()
      • getCampaignRepository

        @NonNull
        protected CampaignRepository<com.broadleafcommerce.data.tracking.core.Trackable> getCampaignRepository()
      • getCampaignFactory

        @NonNull
        protected com.broadleafcommerce.common.extension.TypeFactory getCampaignFactory()