Class DefaultExportManager

java.lang.Object
com.broadleafcommerce.common.dataexport.service.DefaultExportManager
All Implemented Interfaces:
ExportManager

public class DefaultExportManager extends Object implements ExportManager
Author:
Samarth Dhruva (samarthd)
  • Constructor Details

    • DefaultExportManager

      public DefaultExportManager(ExportService<Export> exportService, ExportRequestValidator exportRequestValidator, List<ExportProcessor<?>> exportProcessors, List<ExportFileWriter<?>> exportFileWriters, StorageService storageService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, ExportProcessingConfigurationProperties exportProcessingConfigurationProperties, @Nullable com.broadleafcommerce.common.extension.data.DataRouteReference reference, List<com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator> contextRequestHydrators, @Nullable com.broadleafcommerce.data.tracking.core.policy.trackable.TrackablePolicyUtils trackablePolicyUtils)
  • Method Details

    • initiateExport

      public Export initiateExport(ExportRequest request, String target, @Nullable String filterString, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ExportManager
      This method accepts an export request and the context of the request to build a Export and persist it in the data store.

      Sends a ProcessExportRequest message to request that the export be processed.

      Specified by:
      initiateExport in interface ExportManager
      Parameters:
      request - a request to perform an Export.

      For each of the "exporting context" fields describing where the operation will be performed, the default implementation will first check if the field is supplied in ExportRequest, and if not, use the value from the ContextInfo.

      target - the target of the export. This is some value that can be mapped to a particular domain by the logic performing an export, rather than explicitly requiring the fully qualified classname. Used to populate Export.target.
      filterString - if ExportRequest.getFilterString() is not provided, then this will be used instead as the filter string to find the records to export. Used to populate Export.filterString.
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      the newly created Export
    • initiateExport

      public Export initiateExport(ExportRequest request, String target, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: ExportManager
      This method accepts an export request and the context of the request to build a Export and persist it in the data store.

      Sends a ProcessExportRequest message to request that the export be processed.

      Specified by:
      initiateExport in interface ExportManager
      Parameters:
      request - a request to perform an Export.

      The filter string that is used to filter the contents of the Export is also retrieved from ExportRequest.getFilterString().

      For each of the "exporting context" fields describing where the operation will be performed, the default implementation will first check if the field is supplied in ExportRequest, and if not, use the value from the ContextInfo.

      target - the target of the export. This is some value that can be mapped to a particular domain by the logic performing an export, rather than explicitly requiring the fully qualified classname. Used to populate Export.target.
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      the newly created Export
    • validateCanBeExported

      protected void validateCanBeExported(Export export)
    • validateExportingContextAccessibility

      protected void validateExportingContextAccessibility(Export export)
      Builds a ContextInfo matching the exporting context fields from export, and then evaluates whether the currently authenticated user is allowed to perform the operation in that context.

      In the event that policy validation is disabled, the TrackablePolicyUtils bean will be unavailable and thus this step will be skipped.

      Parameters:
      export - the export whose exporting context fields should be checked for accessibility
      Throws:
      com.broadleafcommerce.data.tracking.core.exception.NotVisibleException - if the exporting context is not visible by the current user
    • validateExportRequest

      protected void validateExportRequest(ExportRequest request)
      Validates the ExportRequest, throwing a ValidationException in the event that there is a validation failure.
      Parameters:
      request - the user-supplied export request
      Throws:
      com.broadleafcommerce.common.error.validation.ValidationException - in the event that there is a validation failure
    • generateExportFromRequest

      protected Export generateExportFromRequest(ExportRequest request, String target)
      Builds an Export and initializes its basic fields from the values in the ExportRequest.

      Note that context-related fields such as Export.getExportingApplicationId(), Export.getExportingCatalogId(), etc are not initialized in this method. This responsibility belongs to initializeContextFields(Export, ExportRequest, ContextInfo) .

      Parameters:
      request - the export request that was received
      target - the Export.getTarget() to set
      Returns:
      an Export object initialized from the ExportRequest
    • determineName

      protected String determineName(ExportRequest request, String target)
    • generateName

      protected String generateName(String target)
    • initializeGeneralFields

      protected void initializeGeneralFields(Export toInitialize)
    • initializeContextFields

      protected void initializeContextFields(Export target, ExportRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Initializes the context-related fields on the given Export, including the fields describing the context where the operation itself was initiated (such as Export.getApplicationId()), and "exporting context" fields describing the context where the operation will be performed (such as Export.getExportingApplicationId()).

      For each of the "exporting context" fields describing where the operation will be performed, the default implementation will first check if the field is supplied in ExportRequest, and if not, use the value from the ContextInfo.

      Parameters:
      target - the Export whose context-related fields should be initialized
      request - the ExportRequest which should be checked as a potential source for context fields
      contextInfo - context information surrounding sandboxing and multitenant state. This is the context from which the operation itself is being initiated.
    • setTotalRecordsToProcess

      protected void setTotalRecordsToProcess(Export export)
    • processExport

      public void processExport(Export export)
      Description copied from interface: ExportManager
      Performs an Export, processing the requested records and writing the file in batches while updating the status for the Export as it goes.

      Note: this method should always be called with the result of ExportService.setProcessingStatus(String) if the value is not null.

      The ExportManager will delegate processing to the first ExportProcessor for which ExportProcessor.canHandle(Export) returns true. Thus if more than one ExportProcessor can handle a request, the bean registered with the higher priority will be used.

      The ExportManager will delegate file writing to the first ExportFileWriter for which ExportFileWriter.canHandle(Export) returns true. Thus if more than one ExportFileWriter can handle a request, the bean registered with the higher priority will be used.

      Specified by:
      processExport in interface ExportManager
      Parameters:
      export - the export to perform - this should always be the result of ExportService.setProcessingStatus(String) if it is not null
    • getProcessorForExport

      protected Optional<ExportProcessor<?>> getProcessorForExport(Export export)
    • getFileWriterForExport

      protected Optional<ExportFileWriter<?>> getFileWriterForExport(Export export)
    • createTemporaryFile

      protected Optional<Path> createTemporaryFile(String exportId, String fileExtension)
    • processInBatches

      protected <P, C extends ExportFileWriteContext> void processInBatches(ExportProcessor<P> processor, ExportFileWriter<C> fileWriter, Export export, Path tempFile) throws Exception
      Throws:
      Exception
    • getOutputStream

      protected Optional<OutputStream> getOutputStream(Path path)
    • copyToStorageServiceAndFinishExport

      protected void copyToStorageServiceAndFinishExport(Path toCopy, Export toUpdate, ExportFileWriter<?> fileWriter)
    • generateStoragePath

      protected String generateStoragePath(Export export, String fileExtension)
    • setFileLocationAndFinishedStatus

      protected void setFileLocationAndFinishedStatus(String exportId, String fileLocation)
    • getExportService

      @NonNull protected ExportService<Export> getExportService()
    • getExportRequestValidator

      @NonNull protected ExportRequestValidator getExportRequestValidator()
    • getExportProcessors

      @NonNull protected List<ExportProcessor<?>> getExportProcessors()
    • getExportFileWriters

      @NonNull protected List<ExportFileWriter<?>> getExportFileWriters()
    • getStorageService

      @NonNull protected StorageService getStorageService()
    • getTypeFactory

      @NonNull protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getExportProcessingConfigurationProperties

      @NonNull protected ExportProcessingConfigurationProperties getExportProcessingConfigurationProperties()
    • getReference

      @Nullable protected com.broadleafcommerce.common.extension.data.DataRouteReference getReference()
    • getContextRequestHydrators

      protected List<com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator> getContextRequestHydrators()
    • getTrackablePolicyUtils

      @Nullable protected com.broadleafcommerce.data.tracking.core.policy.trackable.TrackablePolicyUtils getTrackablePolicyUtils()
      Used to validate that the user initiating an operation is able to access the context in which the operation will apply.

      If policy validation is disabled, this bean will be unavailable and policy validation will be skipped.

    • getSECURE_RANDOM

      @NonNull protected static Random getSECURE_RANDOM()
    • getUTC_TIMESTAMP_FORMATTER

      @NonNull protected static DateTimeFormatter getUTC_TIMESTAMP_FORMATTER()