Class CampaignCodeImportBatchHandler

  • All Implemented Interfaces:
    com.broadleafcommerce.common.dataimport.ImportBatchHandler

    @DataRouteByKey("campaign")
    public class CampaignCodeImportBatchHandler
    extends com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
    Author:
    Vitalii Voronkov (vvoronkov)
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean canHandle​(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 CampaignCodeConverter getCampaignCodeConverter()  
      protected CampaignCodeService<CampaignCode> getCampaignCodeService()  
      String getDataRouteKey()  
      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.IdResolver getIdResolver()  
      protected com.broadleafcommerce.common.dataimport.util.OperationResolver getOperationResolver()  
      com.broadleafcommerce.common.dataimport.messaging.BatchCompletion handle​(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch)  
      protected boolean isBelongsToCampaign​(String campaignId, CampaignCode existingCode)  
      protected boolean isValidEndDate​(Instant endAfterDate, CampaignCode codeToImport, CampaignCode existingCode)  
      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 as PersistenceRequests and adds persistence result to allCompletions
      protected void resolveCampaignCodeId​(com.broadleafcommerce.common.dataimport.messaging.BatchRecord record, CampaignCode campaignCode)
      Resolves and sets the id for CampaignCode.
      protected void setIdResolver​(com.broadleafcommerce.common.dataimport.util.IdResolver idResolver)  
      protected void setOperationResolver​(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
    • 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 BatchCompletionRecord will be created for it and added to erroredCompletions, 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 to erroredCompletions, and they will not appear in the converted result.

        Parameters:
        batch - the original record batch
        erroredCompletions - the list to which any errored completion records should be added
        campaignId - the id of the parent campaign, will be set on the converted campaign codes
        Returns:
        a map of the converted CampaignCode and original BatchRecord pairs grouped by code value
      • resolveCampaignCodeId

        protected void resolveCampaignCodeId​(com.broadleafcommerce.common.dataimport.messaging.BatchRecord record,
                                             CampaignCode campaignCode)
        Resolves and sets the id for CampaignCode.
        Parameters:
        record - the record represents CampaignCode from file
        campaignCode - the CampaignCode for 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 as PersistenceRequests and adds persistence result to allCompletions
        Parameters:
        batch - the original record batch
        campaignCodeRequests - a list of the campaign code persistence requests
        allCompletions - 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 id
        codesToImport - the map of CampaignCode and BatchRecord pairs grouped by code value
        errorsResults - the list of BatchCompletionRecord to add the invalid codes
        context - Request context information around sandbox and multitenant state
        Returns:
        a list of PersistenceRequests for 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)
      • 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)