Class CampaignCodeImportBatchHandler
- java.lang.Object
-
- com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
-
- com.broadleafcommerce.promotion.campaign.dataimport.CampaignCodeImportBatchHandler
-
- All Implemented Interfaces:
com.broadleafcommerce.common.dataimport.ImportBatchHandler
@DataRouteByKey("campaign") public class CampaignCodeImportBatchHandler extends com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler- Author:
- Vitalii Voronkov (vvoronkov)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCampaignCodeImportBatchHandler.ImportTypes
-
Constructor Summary
Constructors Constructor Description CampaignCodeImportBatchHandler(CampaignCodeConverter campaignCodeConverter, CampaignCodeService<CampaignCode> campaignCodeService, CampaignCodeDefaultsInitializer campaignCodeDefaultsInitializer, com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanHandle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch)protected Map<String,org.apache.commons.lang3.tuple.Pair<CampaignCode,com.broadleafcommerce.common.dataimport.messaging.BatchRecord>>convertBatchRecords(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions, String campaignId)Converts all of the batch records in the batch request to campaign codes.protected Optional<CampaignCode>convertToCode(com.broadleafcommerce.common.dataimport.messaging.BatchRecord codeRecord, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions)protected com.broadleafcommerce.common.dataimport.util.PersistenceRequest<CampaignCode>createPersistenceRequest(CampaignCode campaignCode, com.broadleafcommerce.common.dataimport.messaging.BatchRecord codeRecord, com.broadleafcommerce.data.tracking.core.type.OperationType operationType)protected CampaignCodeConvertergetCampaignCodeConverter()protected CampaignCodeService<CampaignCode>getCampaignCodeService()StringgetDataRouteKey()protected Map<String,CampaignCode>getExistingCodes(Set<String> codesToImport, String campaignId, Instant endAfterDate, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)protected com.broadleafcommerce.common.dataimport.util.IdResolvergetIdResolver()protected com.broadleafcommerce.common.dataimport.util.OperationResolvergetOperationResolver()com.broadleafcommerce.common.dataimport.messaging.BatchCompletionhandle(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch)protected booleanisBelongsToCampaign(String campaignId, CampaignCode existingCode)protected booleanisValidEndDate(Instant endAfterDate, CampaignCode codeToImport, CampaignCode existingCode)protected voidpersistPersistenceRequests(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<CampaignCode>> campaignCodeRequests, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions)Perform a persist of the parsed out domain specified asPersistenceRequests and adds persistence result toallCompletionsprotected voidresolveCampaignCodeId(com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, CampaignCode campaignCode)Resolves and sets the id forCampaignCode.protected voidsetIdResolver(com.broadleafcommerce.common.dataimport.util.IdResolver idResolver)protected voidsetOperationResolver(com.broadleafcommerce.common.dataimport.util.OperationResolver operationResolver)protected List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<CampaignCode>>validateAndBuildPersistenceRequests(String campaignId, Map<String,org.apache.commons.lang3.tuple.Pair<CampaignCode,com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> codesToImport, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> errorsResults, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)This method is used to validate that the campaign codes can be imported.-
Methods inherited from class com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
addFailedConversionCompletions, buildAndAddCompletionRecords, buildContextInfo, buildCreateContextInfo, buildNonValidationErrorCompletions, buildReadContextInfo, buildSuccessfulCompletionsForRequest, buildUpdateContextInfo, buildValidationErrorCompletions, generateAndAddCompletions, generateAndAddCompletions, generateAndAddValidationErrorCompletions, getCompletionError, getFormattedEmbeddedValidationErrorString, getFormattedValidationErrorString, getHydrator, persist, removeAndReturnFieldErrorsUnderPath
-
-
-
-
Constructor Detail
-
CampaignCodeImportBatchHandler
public CampaignCodeImportBatchHandler(CampaignCodeConverter campaignCodeConverter, CampaignCodeService<CampaignCode> campaignCodeService, CampaignCodeDefaultsInitializer campaignCodeDefaultsInitializer, com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator)
-
-
Method Detail
-
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<CampaignCode,com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> convertBatchRecords(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions, String campaignId)
Converts all of the batch records in the batch request to campaign 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 batcherroredCompletions- the list to which any errored completion records should be addedcampaignId- the id of the parent campaign, will be set on the converted campaign codes- Returns:
- a map of the converted
CampaignCodeand originalBatchRecordpairs grouped by code value
-
resolveCampaignCodeId
protected void resolveCampaignCodeId(com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, CampaignCode campaignCode)Resolves and sets the id forCampaignCode.- Parameters:
record- the record representsCampaignCodefrom filecampaignCode- theCampaignCodefor which the id should be resolved
-
persistPersistenceRequests
protected void persistPersistenceRequests(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch, List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<CampaignCode>> campaignCodeRequests, 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 batchcampaignCodeRequests- a list of the campaign code persistence requestsallCompletions- the list to which the completion records should be added
-
getDataRouteKey
public String getDataRouteKey()
-
convertToCode
protected Optional<CampaignCode> convertToCode(com.broadleafcommerce.common.dataimport.messaging.BatchRecord codeRecord, List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions)
-
validateAndBuildPersistenceRequests
protected List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<CampaignCode>> validateAndBuildPersistenceRequests(String campaignId, Map<String,org.apache.commons.lang3.tuple.Pair<CampaignCode,com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> codesToImport, 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 campaign 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:
campaignId- the campaign idcodesToImport- the map ofCampaignCodeandBatchRecordpairs 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
protected Map<String,CampaignCode> getExistingCodes(Set<String> codesToImport, String campaignId, Instant endAfterDate, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
-
createPersistenceRequest
protected com.broadleafcommerce.common.dataimport.util.PersistenceRequest<CampaignCode> createPersistenceRequest(CampaignCode campaignCode, com.broadleafcommerce.common.dataimport.messaging.BatchRecord codeRecord, com.broadleafcommerce.data.tracking.core.type.OperationType operationType)
-
isBelongsToCampaign
protected boolean isBelongsToCampaign(String campaignId, CampaignCode existingCode)
-
isValidEndDate
protected boolean isValidEndDate(Instant endAfterDate, CampaignCode codeToImport, CampaignCode existingCode)
-
getCampaignCodeConverter
protected CampaignCodeConverter getCampaignCodeConverter()
-
getCampaignCodeService
protected CampaignCodeService<CampaignCode> getCampaignCodeService()
-
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)
-
-