Class DefaultImportManager
- All Implemented Interfaces:
ImportManager
- Author:
- Phillip Verheyden (phillipuniverse)
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultImportManager(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.ContextInfobuildImportingContextInfo(Import metadata, com.broadleafcommerce.data.tracking.core.type.OperationType operationType) Convenience method to construct the 'importing'ContextInfobased on theImportmetadata.protected ImportProcessingContext<FileReaderContext>createProcessingContext(Import metadata, ImportSpecification importSpecification, FileReader<FileReaderContext> reader, long dataLinesToSkip) protected ImportcreateSandbox(String importId, String importingSandboxId) protected ImportValidationContext<FileReaderContext>createValidationContext(ImportRequest request, ImportSpecification importSpecification, FileReader<FileReaderContext> fileReader, org.springframework.core.io.InputStreamSource inputStreamSource) protected StringdetermineImportingSandboxId(ImportRequest request) IfImportRequest.productionImportis true or ifImportRequest.importingSandboxIdis blank, this will returnnull.protected StringdetermineName(ImportRequest request) protected booleandoesRequireSandboxCreation(Import metadata) protected ImportProcessorfindProcessor(Import metadata) protected FileReader<FileReaderContext>findReader(String fileType) protected ImportValidatorfindValidator(ImportRequest request) protected ImportgenerateImportFromRequest(ImportRequest request) Builds anImportand initializes its basic fields from the values in theImportRequest.protected StringgenerateName(ImportRequest request) protected StringgenerateStoragePath(ImportRequest request) protected List<com.broadleafcommerce.data.tracking.core.web.ContextRequestHydrator>protected ImportService<Import>protected ImportSpecificationServiceprotected List<ImportProcessor>protected List<FileReader<? extends FileReaderContext>>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 and mutate the context in which the operation will apply.protected com.broadleafcommerce.common.extension.TypeFactoryprotected static DateTimeFormatterprotected List<ImportValidator>protected voidinitializeContextFields(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 voidinitializeImportingCatalogId(Import target, ImportRequest request, ImportSpecification spec, com.broadleafcommerce.data.tracking.core.context.ContextInfo requestingContextInfo) InitializesImport.getImportingCatalogId().protected voidinitializeImportingSandboxFields(Import target, ImportRequest request, ImportSpecification spec, com.broadleafcommerce.data.tracking.core.context.ContextInfo requestingContextInfo) Initializes sandbox-related fields on the importing context.protected voidinitializeParentEntityId(ImportRequest request, Import newImport) InitializesImport.getParentEntityId()fromImportRequest.getParentEntityId().protected voidinitializeSandboxNameToCreate(Import newImport, ImportRequest request) Sets theImport.importingSandboxNameToCreateto 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 ImportmarkErrored(String importId, String errorMessage) protected ImportmarkProcessing(String importId) protected voidnotifyOfDeleteSandboxRequest(String importId) voidprocessImport(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.voidsetImportSpecificationService(ImportSpecificationService importSpecificationService) protected ImportsetTotalItems(String importId, long totalItems) protected ImportValidationResponseprotected voidvalidateCanPerformImport(Import metadata, ImportSpecification spec, com.broadleafcommerce.data.tracking.core.context.ContextInfo requestingContextInfo) protected voidvalidateImportingContextAccessibility(Import metadata, ImportSpecification spec, com.broadleafcommerce.data.tracking.core.context.ContextInfo requestingContextInfo) Builds aContextInfomatching the importing context fields frommetadata, and then evaluates whether the currently authenticated user is allowed to perform the operation in that context.protected voidvalidateImportingContextReadableAndMutable(com.broadleafcommerce.data.tracking.core.context.ContextInfo importingContextInfo) protected voidvalidateImportingVendorAccessibility(Import metadata, ImportSpecification spec, com.broadleafcommerce.data.tracking.core.context.ContextInfo requestingContextInfo, com.broadleafcommerce.data.tracking.core.context.ContextInfo importingContextInfo) protected ImportValidationResponsevalidateRequest(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:ImportManagerValidates, 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
ImportValidatorfor validation.- Specified by:
initiateImportin 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 anImportand 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
Importobject 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- theImportwhose context-related fields should be initializedrequest- theImportRequestwhich 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 aContextInfomatching 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
TrackablePolicyUtilsbean 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:ImportManagerConvenience method to construct the 'importing'ContextInfobased on theImportmetadata.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:
buildImportingContextInfoin 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
ImportValidatorbefore 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.productionImportis true or ifImportRequest.importingSandboxIdis blank, this will returnnull.Otherwise, this will return
ImportRequest.importingSandboxId.Note that in the case that
ImportRequest.productionImportis false andImportRequest.importingSandboxIdis 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,
nullotherwise
-
determineName
-
generateName
-
initializeSandboxNameToCreate
Sets theImport.importingSandboxNameToCreateto 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.namehas already been finalized/generated and set.request- the import request
-
doesRequireSandboxCreation
-
generateStoragePath
-
processImport
Description copied from interface:ImportManagerBegins 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:
processImportin 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)