Class DefaultExportManager
- All Implemented Interfaces:
ExportManager
- Author:
- Samarth Dhruva (samarthd)
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultExportManager(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 voidcopyToStorageServiceAndFinishExport(Path toCopy, Export toUpdate, ExportFileWriter<?> fileWriter) createTemporaryFile(String exportId, String fileExtension) protected StringdetermineName(ExportRequest request, String target) protected ExportgenerateExportFromRequest(ExportRequest request, String target) Builds anExportand initializes its basic fields from the values in theExportRequest.protected StringgenerateName(String target) protected StringgenerateStoragePath(Export export, String fileExtension) protected List<com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator>protected List<ExportFileWriter<?>>protected ExportProcessingConfigurationPropertiesprotected List<ExportProcessor<?>>protected ExportRequestValidatorprotected 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.DataRouteReferenceprotected static Randomprotected StorageServiceprotected com.broadleafcommerce.data.tracking.core.policy.trackable.TrackablePolicyUtilsUsed 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.TypeFactoryprotected static DateTimeFormatterprotected voidinitializeContextFields(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 voidinitializeGeneralFields(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 aExportand 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 aExportand persist it in the data store.voidprocessExport(Export export) protected <P,C extends ExportFileWriteContext>
voidprocessInBatches(ExportProcessor<P> processor, ExportFileWriter<C> fileWriter, Export export, Path tempFile) protected voidsetFileLocationAndFinishedStatus(String exportId, String fileLocation) protected voidsetTotalRecordsToProcess(Export export) protected voidvalidateCanBeExported(Export export) protected voidBuilds aContextInfomatching the exporting context fields fromexport, and then evaluates whether the currently authenticated user is allowed to perform the operation in that context.protected voidvalidateExportRequest(ExportRequest request) Validates theExportRequest, throwing aValidationExceptionin 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:ExportManagerThis method accepts an export request and the context of the request to build aExportand persist it in the data store.Sends a
ProcessExportRequestmessage to request that the export be processed.- Specified by:
initiateExportin 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:ExportManagerThis method accepts an export request and the context of the request to build aExportand persist it in the data store.Sends a
ProcessExportRequestmessage to request that the export be processed.- Specified by:
initiateExportin 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 aContextInfomatching 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
TrackablePolicyUtilsbean 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 aValidationExceptionin 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 anExportand 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
Exportobject 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- theExportwhose context-related fields should be initializedrequest- theExportRequestwhich 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:ExportManagerPerforms anExport, processing the requested records and writing the file in batches while updating the status for theExportas it goes.Note: this method should always be called with the result of
ExportService.setProcessingStatus(String)if the value is not null.The
ExportManagerwill delegate processing to the firstExportProcessorfor whichExportProcessor.canHandle(Export)returns true. Thus if more than oneExportProcessorcan handle a request, the bean registered with the higher priority will be used.The
ExportManagerwill delegate file writing to the firstExportFileWriterfor whichExportFileWriter.canHandle(Export)returns true. Thus if more than oneExportFileWritercan handle a request, the bean registered with the higher priority will be used.- Specified by:
processExportin 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
-