Class DefaultImportManager
- All Implemented Interfaces:
ImportManager
- Author:
- Phillip Verheyden (phillipuniverse)
-
Constructor Summary
ConstructorDescriptionDefaultImportManager
(com.broadleafcommerce.common.extension.TypeFactory typeFactory, StorageService storage, ImportService<Import> importService, List<ImportProcessor> processors, List<ImportValidator> validators, List<FileReader<? extends FileReaderContext>> readers, 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 TypeMethodDescriptioncom.broadleafcommerce.data.tracking.core.context.ContextInfo
buildImportingContextInfo
(Import metadata, com.broadleafcommerce.data.tracking.core.type.OperationType operationType) Convenience method to construct the 'importing'ContextInfo
based on theImport
metadata.protected ImportProcessingContext<FileReaderContext>
createProcessingContext
(Import metadata, ImportSpecification importSpecification, FileReader<FileReaderContext> reader, long dataLinesToSkip) protected Import
createSandbox
(String importId, String importingSandboxId) protected ImportValidationContext<FileReaderContext>
createValidationContext
(ImportRequest request, ImportSpecification importSpecification, FileReader<FileReaderContext> fileReader, org.springframework.core.io.InputStreamSource inputStreamSource) protected String
determineImportingSandboxId
(ImportRequest request) IfImportRequest.productionImport
is true or ifImportRequest.importingSandboxId
is blank, this will returnnull
.protected String
determineName
(ImportRequest request) protected boolean
doesRequireSandboxCreation
(Import metadata) protected ImportProcessor
findProcessor
(Import metadata) protected FileReader<FileReaderContext>
findReader
(String fileType) protected ImportValidator
findValidator
(ImportRequest request) protected Import
generateImportFromRequest
(ImportRequest request) Builds anImport
and initializes its basic fields from the values in theImportRequest
.protected String
generateName
(ImportRequest request) protected String
generateStoragePath
(ImportRequest request) protected List<com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator>
protected ImportService<Import>
protected ImportSpecificationService
protected List<ImportProcessor>
protected List<FileReader<? extends FileReaderContext>>
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 and mutate the context in which the operation will apply.protected com.broadleafcommerce.common.extension.TypeFactory
protected static DateTimeFormatter
protected List<ImportValidator>
protected void
initializeContextFields
(Import target, ImportRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Initializes the context-related fields on the givenImport
, including the fields describing the context where the operation itself was initiated (such asImport.getApplicationId()
), and "importing context" fields describing the context where the operation will be performed (such asImport.getImportingApplicationId()
).protected void
initializeImportingCatalogId
(Import target, ImportRequest request, ImportSpecification spec, com.broadleafcommerce.data.tracking.core.context.ContextInfo requestingContextInfo) InitializesImport.getImportingCatalogId()
.protected void
initializeImportingSandboxFields
(Import target, ImportRequest request, ImportSpecification spec, com.broadleafcommerce.data.tracking.core.context.ContextInfo requestingContextInfo) Initializes sandbox-related fields on the importing context.protected void
initializeParentEntityId
(ImportRequest request, Import newImport) InitializesImport.getParentEntityId()
fromImportRequest.getParentEntityId()
.protected void
initializeSandboxNameToCreate
(Import newImport, ImportRequest request) Sets theImport.importingSandboxNameToCreate
to the requested value if provided, else sets it to the name of the import.initiateImport
(ImportRequest request, org.springframework.core.io.InputStreamSource inputStreamSource, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates, prepares, and requests an import to be executed from the given request, but does not actually execute the import.protected Import
markErrored
(String importId, String errorMessage) protected Import
markProcessing
(String importId) protected void
notifyOfDeleteSandboxRequest
(String importId) void
processImport
(String importId) Begins processing the import by reading the uploaded file and parsing out the items within it.resolveParentEntityId
(ImportRequest request, Import newImport) Deprecated, for removal: This API element is subject to removal in a future version.void
setImportSpecificationService
(ImportSpecificationService importSpecificationService) protected Import
setTotalItems
(String importId, long totalItems) protected ImportValidationResponse
protected void
validateCanPerformImport
(Import metadata, ImportSpecification spec, com.broadleafcommerce.data.tracking.core.context.ContextInfo requestingContextInfo) protected void
validateImportingContextAccessibility
(Import metadata, ImportSpecification spec, com.broadleafcommerce.data.tracking.core.context.ContextInfo requestingContextInfo) Builds aContextInfo
matching the importing context fields frommetadata
, and then evaluates whether the currently authenticated user is allowed to perform the operation in that context.protected void
validateImportingContextReadableAndMutable
(com.broadleafcommerce.data.tracking.core.context.ContextInfo importingContextInfo) protected void
validateImportingVendorAccessibility
(Import metadata, ImportSpecification spec, com.broadleafcommerce.data.tracking.core.context.ContextInfo requestingContextInfo, com.broadleafcommerce.data.tracking.core.context.ContextInfo importingContextInfo) protected ImportValidationResponse
validateRequest
(ImportRequest request, org.springframework.core.io.InputStreamSource inputStreamSource, ImportSpecification spec)
-
Constructor Details
-
DefaultImportManager
public DefaultImportManager(com.broadleafcommerce.common.extension.TypeFactory typeFactory, StorageService storage, ImportService<Import> importService, List<ImportProcessor> processors, List<ImportValidator> validators, List<FileReader<? extends FileReaderContext>> readers, @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
-
initiateImport
public Import initiateImport(ImportRequest request, org.springframework.core.io.InputStreamSource inputStreamSource, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:ImportManager
Validates, prepares, and requests an import to be executed from the given request, but does not actually execute the import. The output of this is that the import is scheduled and returned back to the caller.
Emits a
ProcessImportRequest
.Delegates to
ImportValidator
for validation.- Specified by:
initiateImport
in interfaceImportManager
- Parameters:
request
- metadata around where the import will go.For each of the "importing context" fields describing where the operation will be performed, the default implementation will first check if the field is supplied in
ImportRequest
, and if not, use the value from theContextInfo
.inputStreamSource
- an input stream source for the data that should be used to importcontextInfo
- context information surrounding sandboxing and multitenant state. This is the context from which the operation itself is being initiated.- Returns:
- the newly created Import if valid
-
generateImportFromRequest
Builds anImport
and initializes its basic fields from the values in theImportRequest
.Note that context-related fields such as
Import.getImportingApplicationId()
,Import.getImportingCatalogId()
, etc are not initialized in this method. This responsibility belongs toinitializeContextFields(Import, ImportRequest, ContextInfo)
,initializeImportingCatalogId(Import, ImportRequest, ImportSpecification, ContextInfo)
, andinitializeImportingSandboxFields(Import, ImportRequest, ImportSpecification, ContextInfo)
.- Parameters:
request
- the import request that was received- Returns:
- an
Import
object initialized from theImportRequest
-
initializeContextFields
protected void initializeContextFields(Import target, ImportRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Initializes the context-related fields on the givenImport
, including the fields describing the context where the operation itself was initiated (such asImport.getApplicationId()
), and "importing context" fields describing the context where the operation will be performed (such asImport.getImportingApplicationId()
).For each of the "importing context" fields describing where the operation will be performed, the default implementation will first check if the field is supplied in
ImportRequest
, and if not, use the value from theContextInfo
.Importing catalog ID initialization requires access to the specification, and is done in
initializeImportingCatalogId(Import, ImportRequest, ImportSpecification, ContextInfo)
.Importing sandbox ID initialization requires access to the specification, and is done in
initializeImportingSandboxFields(Import, ImportRequest, ImportSpecification, ContextInfo)
.- Parameters:
target
- theImport
whose context-related fields should be initializedrequest
- theImportRequest
which should be checked as a potential source for context fieldscontextInfo
- the context info used in the request to start the import. Not necessarily the same as the context the import's data will go into.
-
initializeImportingCatalogId
protected void initializeImportingCatalogId(Import target, ImportRequest request, ImportSpecification spec, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo requestingContextInfo) InitializesImport.getImportingCatalogId()
.Separated from
initializeContextFields(Import, ImportRequest, ContextInfo)
since this requires having the specification available. Fetching the specification itself requires the importing context (with just app/tenant information) to be available. Thus, the other fields are initialized first, and importing catalog ID is initialized here, in a later step.- Parameters:
target
- the import on which to initializeImport.getImportingCatalogId()
request
- the original import requestspec
- the specification for the importrequestingContextInfo
- the requesting context info from which the import was initiated (not the ultimate importing context info)
-
initializeImportingSandboxFields
protected void initializeImportingSandboxFields(Import target, ImportRequest request, ImportSpecification spec, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo requestingContextInfo) Initializes sandbox-related fields on the importing context.Separated from
initializeContextFields(Import, ImportRequest, ContextInfo)
since this requires having the specification available. Fetching the specification itself requires the importing context (with just app/tenant information) to be available. Thus, the other fields are initialized first, and importing sandbox information is initialized here, in a later step.- Parameters:
target
- the import on which to initialize importing sandbox related fieldsrequest
- the original import requestspec
- the specification for the importrequestingContextInfo
- the requesting context info from which the import was initiated (not the ultimate importing context info)
-
validateCanPerformImport
protected void validateCanPerformImport(Import metadata, ImportSpecification spec, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo requestingContextInfo) -
validateImportingContextAccessibility
protected void validateImportingContextAccessibility(Import metadata, ImportSpecification spec, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo requestingContextInfo) Builds aContextInfo
matching the importing context fields frommetadata
, 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:
metadata
- the import whose importing context fields should be checked for accessibilityspec
- the import specification to use for this importrequestingContextInfo
- the context info used in the request to start the import. Not necessarily the same as the context the import's data will go into.- Throws:
com.broadleafcommerce.data.tracking.core.exception.NotVisibleException
- if the importing context is not visible by the current usercom.broadleafcommerce.data.tracking.core.exception.NotMutableException
- if the importing context is not mutable by the current user
-
validateImportingContextReadableAndMutable
protected void validateImportingContextReadableAndMutable(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo importingContextInfo) -
validateImportingVendorAccessibility
protected void validateImportingVendorAccessibility(Import metadata, ImportSpecification spec, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo requestingContextInfo, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo importingContextInfo) -
buildImportingContextInfo
public com.broadleafcommerce.data.tracking.core.context.ContextInfo buildImportingContextInfo(Import metadata, com.broadleafcommerce.data.tracking.core.type.OperationType operationType) Description copied from interface:ImportManager
Convenience method to construct the 'importing'ContextInfo
based on theImport
metadata.This represents the context that the import will actually be performed in, rather than the context the import itself was requested from.
Note that this method should not perform any security or access validation on the resulting context info and is merely used to construct the instance itself.
- Specified by:
buildImportingContextInfo
in interfaceImportManager
- Parameters:
metadata
- the import instance itself from which context fields will be sourcedoperationType
- the operation type to set on the context info- Returns:
- the importing context info for the given import
-
initializeParentEntityId
InitializesImport.getParentEntityId()
fromImportRequest.getParentEntityId()
.The value itself should already be validated via
ImportValidator
before invoking this method.- Parameters:
request
- the request to initialize the field fromnewImport
- the destination instance to set the field on
-
resolveParentEntityId
@Deprecated(since="1.8.2", forRemoval=true) protected Optional<String> resolveParentEntityId(ImportRequest request, Import newImport) Deprecated, for removal: This API element is subject to removal in a future version.If the imported entity has parent entity, we need to resolve it's id. In case of grid level import - parent entity id will be included in the requestImportRequest.parentEntityId
. In case of global import - parent entity id should be extracted from the import file.- Parameters:
request
- the import requestnewImport
- initiated import- Returns:
- parent entity id or null if not exists for the entity
-
validateRequest
protected ImportValidationResponse validateRequest(ImportRequest request, org.springframework.core.io.InputStreamSource inputStreamSource, ImportSpecification spec) -
userHasRequiredAuthorities
-
findValidator
-
determineImportingSandboxId
IfImportRequest.productionImport
is true or ifImportRequest.importingSandboxId
is blank, this will returnnull
.Otherwise, this will return
ImportRequest.importingSandboxId
.Note that in the case that
ImportRequest.productionImport
is false andImportRequest.importingSandboxId
is blank, this means a new sandbox needs to be created for this import. The generation of this new sandbox ID is not done at this stage. Instead, it's done inprocessImport(String)
. At this point, we will just guarantee it is null.- Parameters:
request
- the import request- Returns:
- the requested sandbox ID if it is not blank and this is a non-production import,
null
otherwise
-
determineName
-
generateName
-
initializeSandboxNameToCreate
Sets theImport.importingSandboxNameToCreate
to the requested value if provided, else sets it to the name of the import.- Parameters:
newImport
- the import whose field needs to be initialized. This should be the import after itsImport.name
has already been finalized/generated and set.request
- the import request
-
doesRequireSandboxCreation
-
generateStoragePath
-
processImport
Description copied from interface:ImportManager
Begins processing the import by reading the uploaded file and parsing out the items within it.If a new sandbox needs to be created for the import, emits a
CreateSandboxRequest
.- Specified by:
processImport
in interfaceImportManager
- Parameters:
importId
- an import managed by the persistent store. The import passed here should have its status asImportStatus.REQUESTED
-
markProcessing
-
markErrored
-
notifyOfDeleteSandboxRequest
-
createSandbox
-
setTotalItems
-
findProcessor
-
findReader
-
createProcessingContext
protected ImportProcessingContext<FileReaderContext> createProcessingContext(Import metadata, ImportSpecification importSpecification, FileReader<FileReaderContext> reader, long dataLinesToSkip) throws IOException - Throws:
IOException
-
createValidationContext
protected ImportValidationContext<FileReaderContext> createValidationContext(ImportRequest request, ImportSpecification importSpecification, FileReader<FileReaderContext> fileReader, org.springframework.core.io.InputStreamSource inputStreamSource) throws IOException - Throws:
IOException
-
getTypeFactory
@NonNull protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getStorage
-
getImportService
-
getProcessors
-
getValidators
-
getReaders
-
setImportSpecificationService
@Autowired public void setImportSpecificationService(@NonNull ImportSpecificationService importSpecificationService) -
getImportSpecificationService
-
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 and mutate 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
-
initializeParentEntityId(ImportRequest, Import)