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 Summary
Constructors Constructor Description DefaultExportManager(ExportService<Export> exportService, ExportRequestValidator exportRequestValidator, List<ExportProcessor<?>> exportProcessors, List<ExportFileWriter<?>> exportFileWriters, StorageService storageService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, ExportProcessingConfigurationProperties exportProcessingConfigurationProperties, com.broadleafcommerce.common.extension.data.DataRouteReference reference, List<com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator> contextRequestHydrators, com.broadleafcommerce.data.tracking.core.policy.trackable.TrackablePolicyUtils trackablePolicyUtils)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
copyToStorageServiceAndFinishExport(Path toCopy, Export toUpdate, ExportFileWriter<?> fileWriter)
protected Optional<Path>
createTemporaryFile(String exportId, String fileExtension)
protected String
determineName(ExportRequest request, String target)
protected Export
generateExportFromRequest(ExportRequest request, String target)
Builds anExport
and initializes its basic fields from the values in theExportRequest
.protected String
generateName(String target)
protected String
generateStoragePath(Export export, String fileExtension)
protected List<com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator>
getContextRequestHydrators()
protected List<ExportFileWriter<?>>
getExportFileWriters()
protected ExportProcessingConfigurationProperties
getExportProcessingConfigurationProperties()
protected List<ExportProcessor<?>>
getExportProcessors()
protected ExportRequestValidator
getExportRequestValidator()
protected ExportService<Export>
getExportService()
protected Optional<ExportFileWriter<?>>
getFileWriterForExport(Export export)
protected Optional<OutputStream>
getOutputStream(Path path)
protected Optional<ExportProcessor<?>>
getProcessorForExport(Export export)
protected com.broadleafcommerce.common.extension.data.DataRouteReference
getReference()
protected static Random
getSECURE_RANDOM()
protected StorageService
getStorageService()
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.protected com.broadleafcommerce.common.extension.TypeFactory
getTypeFactory()
protected static DateTimeFormatter
getUTC_TIMESTAMP_FORMATTER()
protected void
initializeContextFields(Export target, ExportRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Initializes the context-related fields on the givenExport
, including the fields describing the context where the operation itself was initiated (such asExport.getApplicationId()
), and "exporting context" fields describing the context where the operation will be performed (such asExport.getExportingApplicationId()
).protected void
initializeGeneralFields(Export toInitialize)
Export
initiateExport(ExportRequest request, String target, String filterString, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
This method accepts an export request and the context of the request to build aExport
and persist it in the data store.void
processExport(Export export)
protected <P,C extends ExportFileWriteContext>
voidprocessInBatches(ExportProcessor<P> processor, ExportFileWriter<C> fileWriter, Export export, Path tempFile)
protected void
setFileLocationAndFinishedStatus(String exportId, String fileLocation)
protected void
setTotalRecordsToProcess(Export export)
protected void
validateCanBeExported(Export export)
protected void
validateExportingContextAccessibility(Export export)
Builds aContextInfo
matching the exporting context fields fromexport
, and then evaluates whether the currently authenticated user is allowed to perform the operation in that context.protected void
validateExportRequest(ExportRequest request)
Validates theExportRequest
, throwing aValidationException
in the event that there is a validation failure.
-
-
-
Constructor Detail
-
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 Detail
-
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 aExport
and persist it in the data store.Sends a
ProcessExportRequest
message to request that the export be processed.- Specified by:
initiateExport
in interfaceExportManager
- Parameters:
request
- a request to perform anExport
.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 theContextInfo
.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 populateExport.target
.filterString
- the filter string that should be used to find the records to export. Used to populateExport.filterString
.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 aContextInfo
matching the exporting context fields fromexport
, 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 theExportRequest
, throwing aValidationException
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 anExport
and initializes its basic fields from the values in theExportRequest
.Note that context-related fields such as
Export.getExportingApplicationId()
,Export.getExportingCatalogId()
, etc are not initialized in this method. This responsibility belongs toinitializeContextFields(Export, ExportRequest, ContextInfo)
.- Parameters:
request
- the export request that was receivedtarget
- theExport.getTarget()
to set- Returns:
- an
Export
object initialized from theExportRequest
-
determineName
protected String determineName(ExportRequest request, 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 givenExport
, including the fields describing the context where the operation itself was initiated (such asExport.getApplicationId()
), and "exporting context" fields describing the context where the operation will be performed (such asExport.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 theContextInfo
.- Parameters:
target
- theExport
whose context-related fields should be initializedrequest
- theExportRequest
which should be checked as a potential source for context fieldscontextInfo
- 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 anExport
, processing the requested records and writing the file in batches while updating the status for theExport
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 firstExportProcessor
for whichExportProcessor.canHandle(Export)
returns true. Thus if more than oneExportProcessor
can handle a request, the bean registered with the higher priority will be used.The
ExportManager
will delegate file writing to the firstExportFileWriter
for whichExportFileWriter.canHandle(Export)
returns true. Thus if more than oneExportFileWriter
can handle a request, the bean registered with the higher priority will be used.- Specified by:
processExport
in interfaceExportManager
- Parameters:
export
- the export to perform - this should always be the result ofExportService.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)
-
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()
-
-