Class PriceDataImportBatchHandler

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

    @DataRouteByKey("pricing")
    public class PriceDataImportBatchHandler
    extends com.broadleafcommerce.common.dataimport.AbstractImportBatchHandler
    Author:
    Vitalii Voronkov (vvoronkov)
    • Constructor Detail

      • PriceDataImportBatchHandler

        public PriceDataImportBatchHandler​(PriceDataConverter priceDataConverter,
                                           PriceDataService<PriceData> priceDataService,
                                           PriceListService<PriceList> priceListService,
                                           com.broadleafcommerce.common.extension.TypeFactory pricingFactory,
                                           com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator hydrator)
    • Method Detail

      • 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<PriceData,​com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> convertBatchRecords​(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch,
                                                                                                                                                                           List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> erroredCompletions,
                                                                                                                                                                           String priceListId)
        Converts all of the batch records in the batch request to price data.

        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 price data, 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
        priceListId - the id of the parent price list
        Returns:
        a map of the converted PriceData and original BatchRecord pairs grouped by target key value
      • persistPersistenceRequests

        protected void persistPersistenceRequests​(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch,
                                                  List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<PriceData>> priceDataRequests,
                                                  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
        priceDataRequests - a list of the price data persistence requests
        allCompletions - the list to which the completion records should be added
      • getDataRouteKey

        public String getDataRouteKey()
      • getTargetKey

        protected String getTargetKey​(com.broadleafcommerce.pricing.client.domain.PriceableTargetRef target)
      • getTargetKey

        protected String getTargetKey​(String targetType,
                                      String targetId,
                                      @Nullable
                                      String targetVendorRef)
      • convertToPriceData

        protected Optional<PriceData> convertToPriceData​(com.broadleafcommerce.common.dataimport.messaging.BatchRecord priceDataRecord,
                                                         List<com.broadleafcommerce.common.dataimport.messaging.BatchCompletionRecord> allCompletions)
      • buildPersistenceRequests

        protected List<com.broadleafcommerce.common.dataimport.util.PersistenceRequest<PriceData>> buildPersistenceRequests​(String priceListId,
                                                                                                                            Map<String,​org.apache.commons.lang3.tuple.Pair<PriceData,​com.broadleafcommerce.common.dataimport.messaging.BatchRecord>> requestedPriceDataByTargetKey,
                                                                                                                            @Nullable
                                                                                                                            com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
        Builds the list of PersistenceRequest for the PriceData.

        This method will query the data-store for existing price data to determine whether each item should be an update or a create.

        Parameters:
        priceListId - the id of the parent price list
        requestedPriceDataByTargetKey - the map of PriceData and BatchRecord pairs grouped by price data target key
        context - request context information around sandbox and multitenant state
        Returns:
        the list of PersistenceRequest for the PriceData
      • buildPersistenceRequest

        protected com.broadleafcommerce.common.dataimport.util.PersistenceRequest<PriceData> buildPersistenceRequest​(String requestedPriceDataTargetKey,
                                                                                                                     org.apache.commons.lang3.tuple.Pair<PriceData,​com.broadleafcommerce.common.dataimport.messaging.BatchRecord> requestedPriceDataAndBatchRecord,
                                                                                                                     Map<String,​PriceData> existingPriceDataByTargetKey)
        Determines id, operation type and builds the PersistenceRequest for the PriceData.
        Parameters:
        requestedPriceDataTargetKey - the target key of the requested price data
        requestedPriceDataAndBatchRecord - the pair of requested PriceData and BatchRecord
        existingPriceDataByTargetKey - a map of PriceData that already exist in the data store, with the target key as the map key
        Returns:
        the PersistenceRequest for the PriceData
      • getExistingPriceDataByTargetKey

        protected Map<String,​PriceData> getExistingPriceDataByTargetKey​(List<com.broadleafcommerce.pricing.client.domain.PriceableTargetRef> priceableTargetRefs,
                                                                              String priceListId,
                                                                              @Nullable
                                                                              com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      • canHandle

        public boolean canHandle​(com.broadleafcommerce.common.dataimport.messaging.BatchRequest batch)
      • getIMPORT_TYPES

        protected static String[] getIMPORT_TYPES()
      • getTARGET_TYPE

        protected static String getTARGET_TYPE()
      • getTARGET_ID

        protected static String getTARGET_ID()
      • getPRICE_DATA_IMPORTED_ERROR

        protected static String getPRICE_DATA_IMPORTED_ERROR()
      • getPricingFactory

        public com.broadleafcommerce.common.extension.TypeFactory getPricingFactory()
      • 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)