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
-
Constructor Summary
ConstructorDescriptionOfferCodeImportBatchHandler
(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 TypeMethodDescriptionboolean
canHandle
(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 String
findRelatedCampaign
(List<Campaign> campaigns, com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, String batchType, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions) protected String
findRelatedOffer
(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.IdResolver
protected OfferCodeConverter
protected OfferCodeDefaultsInitializer
protected OfferCodeService<OfferCode>
protected OfferService<Offer>
protected com.broadleafcommerce.common.dataimport.util.OperationResolver
getRelatedCampaignsForBatch
(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.BatchCompletion
handle
(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch) protected boolean
isBelongsToAnotherExistingCampaign
(String campaignId, OfferCode existingCode) protected boolean
isExistingCodeExpired
(OfferCode existingCode, Instant endAfterDate) protected boolean
isExistingCodeIrrelevantToCreation
(OfferCode codeToImport, OfferCode existingCode) protected boolean
isMatchingUniqueCampaignIds
(OfferCode codeToImport, OfferCode existingCode, com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord, List<Campaign> campaigns) protected boolean
isMatchingUniqueOfferCodeIds
(OfferCode codeToImport, OfferCode existingCode) protected boolean
isMatchingUniqueOfferIds
(OfferCode codeToImport, OfferCode existingCode, com.broadleafcommerce.common.dataimport.messaging.BatchRecord batchRecord, List<Offer> offers) protected boolean
isValidEndDate
(Instant endAfterDate, OfferCode codeToImport, OfferCode existingCode) 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 asPersistenceRequest
s and adds persistence result toallCompletions
protected void
resolveOfferCodeId
(com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, OfferCode offerCode) Resolves and sets the id forOfferCode
.protected void
resolveParentEntityId
(OfferCode offerCode, String batchType, String parentEntityId) protected void
setIdResolver
(com.broadleafcommerce.common.dataimport.util.IdResolver idResolver) protected void
setOperationResolver
(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 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) 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
BatchCompletionRecord
will 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
BatchCompletionRecord
will 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 code
and originalBatchRecord
pairs 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 theOfferCode
in 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 asPersistenceRequest
s 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 code
andBatchRecord
pairs grouped by code valueerrorsResults
- the list ofBatchCompletionRecord
to add the invalid codescontext
- Request context information around sandbox and multitenant state- Returns:
- a list of
PersistenceRequests
for 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)
-