Class OfferCodeImportBatchHandler
java.lang.Object
com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
com.broadleafcommerce.promotion.offer.dataimport.OfferCodeImportBatchHandler
- All Implemented Interfaces:
com.broadleafcommerce.common.dataimport.ImportBatchHandler
@DataRouteByKey("offer")
public class OfferCodeImportBatchHandler
extends com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
- Author:
- Vitalii Voronkov (vvoronkov)
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionOfferCodeImportBatchHandler(OfferCodeConverter offerCodeConverter, OfferCodeService<OfferCode> offerCodeService, com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator, OfferCodeDefaultsInitializer offerCodeDefaultsInitializer, OfferService<Offer> offerService, CampaignService<Campaign> campaignService) -
Method Summary
Modifier and TypeMethodDescriptionbooleancanHandle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) protected Map<String,org.apache.commons.lang3.tuple.Pair<OfferCode, com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> convertBatchRecords(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<Offer> offers, List<Campaign> campaigns, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions, String parentEntityId) Converts all of the batch records in the batch request to offer codes.convertBatchRecordToOfferCode(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, List<Offer> offers, List<Campaign> campaigns, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions, String parentEntityId) Converts the batch record into an offer code, orOptional.empty()if conversion failed.convertToCode(com.broadleafcommerce.common.dataimport.messaging.BatchRecord codeRecord, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions) protected com.broadleafcommerce.common.dataimport.util.PersistenceRequest<OfferCode>createPersistenceRequest(OfferCode offerCode, com.broadleafcommerce.common.dataimport.messaging.BatchRecord codeRecord, com.broadleafcommerce.data.tracking.core.type.OperationType operationType) protected StringfindRelatedCampaign(List<Campaign> campaigns, com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, String batchType, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions) protected StringfindRelatedOffer(List<Offer> offers, com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, String batchType, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions) protected CampaignService<Campaign>getExistingCodes(Set<String> codesToImport, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected com.broadleafcommerce.common.dataimport.util.IdResolverprotected OfferCodeConverterprotected OfferCodeDefaultsInitializerprotected OfferCodeService<OfferCode>protected OfferService<Offer>protected com.broadleafcommerce.common.dataimport.util.OperationResolvergetRelatedCampaignsForBatch(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, String parentEntityId) Queries for the related campaigns of the batch records by id or external id.getRelatedOffersForBatch(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, String parentEntityId) Queries for the related offers of the batch records by id or external id.com.broadleafcommerce.common.dataimport.messaging.BatchCompletionhandle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) protected booleanisBelongsToAnotherExistingCampaign(String campaignId, OfferCode existingCode) protected booleanisExistingCodeExpired(OfferCode existingCode, Instant endAfterDate) protected booleanisExistingCodeIrrelevantToCreation(OfferCode codeToImport, OfferCode existingCode) protected booleanisMatchingUniqueCampaignIds(OfferCode codeToImport, OfferCode existingCode, com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord, List<Campaign> campaigns) protected booleanisMatchingUniqueOfferCodeIds(OfferCode codeToImport, OfferCode existingCode) protected booleanisMatchingUniqueOfferIds(OfferCode codeToImport, OfferCode existingCode, com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord, List<Offer> offers) protected booleanisValidEndDate(Instant endAfterDate, OfferCode codeToImport, OfferCode existingCode) protected voidpersistPersistenceRequests(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<OfferCode>> offerCodeRequests, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions) Perform a persist of the parsed out domain specified asPersistenceRequests and adds persistence result toallCompletionsprotected voidresolveOfferCodeId(com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, OfferCode offerCode) Resolves and sets the id forOfferCode.protected voidresolveParentEntityId(OfferCode offerCode, String batchType, String parentEntityId) protected voidsetIdResolver(com.broadleafcommerce.common.dataimport.util.IdResolver idResolver) protected voidsetOperationResolver(com.broadleafcommerce.common.dataimport.util.OperationResolver operationResolver) validateAndBuildPersistenceRequests(Map<String, org.apache.commons.lang3.tuple.Pair<OfferCode, com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> codesToImport, List<Offer> offers, List<Campaign> campaigns, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> errorsResults, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) This method is used to validate that the offer codes can be imported.protected booleanvalidOfferCodeUpdateRequest(OfferCode codeToImport, OfferCode existingCode, com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord, List<Offer> offers, List<Campaign> campaigns, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> errorsResults) Methods inherited from class com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
addFailedConversionCompletions, buildAndAddCompletionRecords, buildContextInfo, buildCreateContextInfo, buildNonValidationErrorCompletions, buildReadContextInfo, buildSuccessfulCompletionsForRequest, buildUpdateContextInfo, buildValidationErrorCompletions, failRecordAndDependentsEarly, finalizeContextForBatch, generateAndAddCompletions, generateAndAddCompletions, generateAndAddValidationErrorCompletions, getBatchContextHelper, getCompletionError, getFormattedEmbeddedValidationErrorString, getFormattedValidationErrorString, getHydrator, getImportContextConfigurationProperties, getImportContextProperties, initializeContextForBatch, persist, persist, removeAndReturnFieldErrorsUnderPath, setBatchContextHelper, setImportContextConfigurationProperties
-
Constructor Details
-
OfferCodeImportBatchHandler
public OfferCodeImportBatchHandler(OfferCodeConverter offerCodeConverter, OfferCodeService<OfferCode> offerCodeService, com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator, OfferCodeDefaultsInitializer offerCodeDefaultsInitializer, OfferService<Offer> offerService, CampaignService<Campaign> campaignService)
-
-
Method Details
-
canHandle
public boolean canHandle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) -
handle
public com.broadleafcommerce.common.dataimport.messaging.BatchCompletion handle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) -
convertBatchRecords
protected Map<String,org.apache.commons.lang3.tuple.Pair<OfferCode, convertBatchRecordscom.broadleafcommerce.common.dataimport.messaging.BatchRecord>> (com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<Offer> offers, List<Campaign> campaigns, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions, @Nullable String parentEntityId) Converts all of the batch records in the batch request to offer codes.If conversion fails for a record, a
BatchCompletionRecordwill be created for it and added toerroredCompletions, and it will not appear in the converted result.If multiple batch records are attempting to import the same code, all but the first will be considered errored. A
BatchCompletionRecordwill be created for the duplicates and added toerroredCompletions, and they will not appear in the converted result.- Parameters:
batch- the original record batchoffers- the list of offers that are associated (typically as the parent entity) with the offer code recordscampaigns- the list of campaigns that are associated (typically as the parent entity) with the offer code recordserroredCompletions- the list to which any errored completion records should be addedparentEntityId- the id of the parent entity, will be set on the converted offer codes- Returns:
- a map of the converted
offer codeand originalBatchRecordpairs grouped by code value
-
convertBatchRecordToOfferCode
protected Optional<OfferCode> convertBatchRecordToOfferCode(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, List<Offer> offers, List<Campaign> campaigns, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions, @Nullable String parentEntityId) Converts the batch record into an offer code, orOptional.empty()if conversion failed.- Parameters:
batch- the original record batchrecord- the record which represents theOfferCodein the import fileoffers- the list of offers that are associated (typically as the parent entity) with the offer code recordscampaigns- the list of campaigns that are associated (typically as the parent entity) with the offer code recordserroredCompletions- the list to which any errored completion records should be addedparentEntityId- the id of the parent entity, will be set on the converted offer codes- Returns:
- the
OfferCode, orOptional.empty()if conversion failed.
-
getRelatedOffersForBatch
protected List<Offer> getRelatedOffersForBatch(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, @Nullable String parentEntityId) Queries for the related offers of the batch records by id or external id.- Parameters:
batch- the original record batchparentEntityId- the id of the parent entity- Returns:
- a list of offers queried by id or external id
-
getRelatedCampaignsForBatch
protected List<Campaign> getRelatedCampaignsForBatch(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, @Nullable String parentEntityId) Queries for the related campaigns of the batch records by id or external id.- Parameters:
batch- the original record batchparentEntityId- the id of the parent entity- Returns:
- a list of campaigns queried by id or external id
-
resolveParentEntityId
-
resolveOfferCodeId
protected void resolveOfferCodeId(com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, OfferCode offerCode) Resolves and sets the id forOfferCode. -
findRelatedOffer
-
findRelatedCampaign
-
persistPersistenceRequests
protected void persistPersistenceRequests(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<OfferCode>> offerCodeRequests, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions) Perform a persist of the parsed out domain specified asPersistenceRequests and adds persistence result toallCompletions- Parameters:
batch- the original record batchofferCodeRequests- a list of the offer code persistence requestsallCompletions- the list to which the completion records should be added
-
getDataRouteKey
-
convertToCode
-
validateAndBuildPersistenceRequests
protected List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<OfferCode>> validateAndBuildPersistenceRequests(Map<String, org.apache.commons.lang3.tuple.Pair<OfferCode, com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> codesToImport, List<Offer> offers, List<Campaign> campaigns, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> errorsResults, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) This method is used to validate that the offer codes can be imported. It adds the valid result to validResults and invalid to errorsResults.It checks the next cases:
- Active codes must be unique within a tenant. (if multiple tenants are present, then they can use the same codes).
- "Expired Codes" are not considered when considering uniqueness. Future dated codes ARE that are not yet active are considered in the uniqueness check.
- If a code is imported to a campaign and that code already exists within the campaign, the existing code will be updated.
- If a code is imported to a campaign and that code already exists within another campaign but is expired, the code will be added to this campaign.
- If updating the expiration date of an expired code, the date will be updated if valid.
- Parameters:
codesToImport- the map ofoffer codeandBatchRecordpairs grouped by code valueerrorsResults- the list ofBatchCompletionRecordto add the invalid codescontext- Request context information around sandbox and multitenant state- Returns:
- a list of
PersistenceRequestsfor codes that passed validation
-
getExistingCodes
-
createPersistenceRequest
-
validOfferCodeUpdateRequest
protected boolean validOfferCodeUpdateRequest(OfferCode codeToImport, OfferCode existingCode, com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord, List<Offer> offers, List<Campaign> campaigns, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> errorsResults) -
isMatchingUniqueOfferIds
-
isMatchingUniqueCampaignIds
-
isMatchingUniqueOfferCodeIds
-
isExistingCodeIrrelevantToCreation
-
isBelongsToAnotherExistingCampaign
-
isExistingCodeExpired
-
isValidEndDate
-
getOfferCodeConverter
-
getOfferCodeDefaultsInitializer
-
getOfferCodeService
-
getOfferService
-
getCampaignService
-
getIdResolver
protected com.broadleafcommerce.common.dataimport.util.IdResolver getIdResolver() -
setIdResolver
protected void setIdResolver(com.broadleafcommerce.common.dataimport.util.IdResolver idResolver) -
getOperationResolver
protected com.broadleafcommerce.common.dataimport.util.OperationResolver getOperationResolver() -
setOperationResolver
protected void setOperationResolver(com.broadleafcommerce.common.dataimport.util.OperationResolver operationResolver)
-