Class DefaultExportManager
- All Implemented Interfaces:
ExportManager
- Author:
- Samarth Dhruva (samarthd)
-
Constructor Summary
ConstructorDescriptionDefaultExportManager
(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
Modifier and TypeMethodDescriptionprotected void
copyToStorageServiceAndFinishExport
(Path toCopy, Export toUpdate, ExportFileWriter<?> fileWriter) 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>
protected List<ExportFileWriter<?>>
protected ExportProcessingConfigurationProperties
protected List<ExportProcessor<?>>
protected ExportRequestValidator
protected ExportService<Export>
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
protected static Random
protected StorageService
protected com.broadleafcommerce.data.tracking.core.policy.trackable.TrackablePolicyUtils
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
protected static DateTimeFormatter
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) initiateExport
(ExportRequest request, String target, 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.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
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 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 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
- ifExportRequest.getFilterString()
is not provided, then this will be used instead as the filter string to find the records to export. Used to populateExport.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 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
.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 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
.contextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- the newly created
Export
-
validateCanBeExported
-
validateExportingContextAccessibility
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
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
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
-
generateName
-
initializeGeneralFields
-
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
-
processExport
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
-
getFileWriterForExport
-
createTemporaryFile
-
processInBatches
protected <P,C extends ExportFileWriteContext> void processInBatches(ExportProcessor<P> processor, ExportFileWriter<C> fileWriter, Export export, Path tempFile) throws Exception - Throws:
Exception
-
getOutputStream
-
copyToStorageServiceAndFinishExport
protected void copyToStorageServiceAndFinishExport(Path toCopy, Export toUpdate, ExportFileWriter<?> fileWriter) -
generateStoragePath
-
setFileLocationAndFinishedStatus
-
getExportService
-
getExportRequestValidator
-
getExportProcessors
-
getExportFileWriters
-
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
-
getUTC_TIMESTAMP_FORMATTER
-