Class S3FileServiceProvider
java.lang.Object
org.broadleafcommerce.vendor.amazon.s3.S3FileServiceProvider
- All Implemented Interfaces:
org.broadleafcommerce.common.file.service.FileServiceProvider
@Service("blS3FileServiceProvider")
public class S3FileServiceProvider
extends Object
implements org.broadleafcommerce.common.file.service.FileServiceProvider
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.broadleafcommerce.common.file.service.BroadleafFileServiceprotected static Stringprotected org.broadleafcommerce.common.io.ConcurrentFileOutputStreamprotected Map<S3Configuration,software.amazon.awssdk.services.s3.S3Client> protected static Stringprotected static Stringprotected S3ConfigurationServiceprotected static String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOrUpdateResources(org.broadleafcommerce.common.file.domain.FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea) addOrUpdateResourcesForPaths(org.broadleafcommerce.common.file.domain.FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea) Writes the resource to S3.addOrUpdateResourcesInternal(S3Configuration s3config, software.amazon.awssdk.services.s3.S3Client s3, org.broadleafcommerce.common.file.domain.FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea) protected StringbuildResourceName(String name) hook for overriding name used for resource in S3protected StringBuilds the resourceName for it's parent.protected voidensureFileCreation(File returnFile, String name) Ensures the file creationprotected software.amazon.awssdk.services.s3.S3ClientgetAmazonS3Client(S3Configuration s3config) protected software.amazon.awssdk.services.s3.S3ClientCreates an instance of the S3 Client based on the 'use instance profile' property.protected software.amazon.awssdk.auth.credentials.AwsCredentialsgetAWSCredentials(S3Configuration s3configParam) protected StringgetBucketName(String name, String defaultBucketName) Returns the bucket name or the default one.protected Class<?>Get MultiTenantSite Class by Reflectionprotected MethodGets getParentId method by reflectionprotected StringgetMultiTenantSiteSpecificResourceNameParent(String resourceName) Get the parent from a MultiTentantSite.getResource(String name) Entry point to retrieve resources from this module.getResource(String name, org.broadleafcommerce.common.file.service.type.FileApplicationType fileApplicationType) Handles the resource gathering, starts as regular retrieval, if it fails (and the conditions allow it) it will try to retrieve the image from the parent sitegetResource(String rawName, org.broadleafcommerce.common.file.service.type.FileApplicationType fileApplicationType, boolean isParent) Handles the logic for resource retrieval it accepts if is a child resource or parent, only differs in in tha name generation.protected StringgetResourceName(S3Configuration s3config, String bucketName, String rawName) Retrieves the resourceName from its rawname.protected StringgetSiteDirectory(Long id) protected StringgetSiteDirectory(org.broadleafcommerce.common.site.domain.Site site) protected StringgetSiteSpecificResourceName(String resourceName) protected LongReflection getParentSiteId Invocationprotected booleanCheck if the module is call with MultiTenant modulebooleanremoveResource(String name) voidsetBroadleafFileService(org.broadleafcommerce.common.file.service.BroadleafFileService bfs) voidsetConcurrentFileOutputStream(org.broadleafcommerce.common.io.ConcurrentFileOutputStream concurrentFileOutputStream)
-
Field Details
-
s3ConfigurationService
-
blFileService
protected org.broadleafcommerce.common.file.service.BroadleafFileService blFileService -
configClientMap
-
concurrentFileOutputStream
protected org.broadleafcommerce.common.io.ConcurrentFileOutputStream concurrentFileOutputStream -
BUCKET_PREFIX
-
SITE_PREFIX
-
MULTITENANT_SITE_CLASSNAME
-
MULTITENANTSITE_GETPARENTID_METHODNAME
-
-
Constructor Details
-
S3FileServiceProvider
public S3FileServiceProvider()
-
-
Method Details
-
getResource
Entry point to retrieve resources from this module.- Specified by:
getResourcein interfaceorg.broadleafcommerce.common.file.service.FileServiceProvider
-
getBucketName
Returns the bucket name or the default one.- Parameters:
name-defaultBucketName-- Returns:
-
getResourceName
Retrieves the resourceName from its rawname.- Parameters:
s3config-bucketName-rawName-- Returns:
-
ensureFileCreation
Ensures the file creation- Parameters:
returnFile-name-- Throws:
RuntimeException
-
getResource
public File getResource(String rawName, org.broadleafcommerce.common.file.service.type.FileApplicationType fileApplicationType, boolean isParent) Handles the logic for resource retrieval it accepts if is a child resource or parent, only differs in in tha name generation.- Parameters:
rawName-fileApplicationType-isParent-- Returns:
-
addOrUpdateResources
public void addOrUpdateResources(org.broadleafcommerce.common.file.domain.FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea) - Specified by:
addOrUpdateResourcesin interfaceorg.broadleafcommerce.common.file.service.FileServiceProvider
-
addOrUpdateResourcesForPaths
public List<String> addOrUpdateResourcesForPaths(org.broadleafcommerce.common.file.domain.FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea) Writes the resource to S3. If the bucket returns as "NoSuchBucket" then will attempt to create the bucket and try again.- Specified by:
addOrUpdateResourcesForPathsin interfaceorg.broadleafcommerce.common.file.service.FileServiceProvider
-
addOrUpdateResourcesInternal
protected List<String> addOrUpdateResourcesInternal(S3Configuration s3config, software.amazon.awssdk.services.s3.S3Client s3, org.broadleafcommerce.common.file.domain.FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea) -
removeResource
- Specified by:
removeResourcein interfaceorg.broadleafcommerce.common.file.service.FileServiceProvider
-
buildResourceName
hook for overriding name used for resource in S3- Parameters:
name-- Returns:
-
getSiteSpecificResourceName
-
getSiteDirectory
-
getSiteDirectory
-
getAmazonS3Client
-
getAmazonS3ClientFromConfiguration
protected software.amazon.awssdk.services.s3.S3Client getAmazonS3ClientFromConfiguration(S3Configuration s3config) Creates an instance of the S3 Client based on the 'use instance profile' property. If it exists, it retrieves credentials from the IAM role (valid only on EC2 instances). Otherwise, a secret key and access key ID must be provided.- Parameters:
s3config- Configuration object- Returns:
- an authenticated AmazonS3Client
-
getAWSCredentials
protected software.amazon.awssdk.auth.credentials.AwsCredentials getAWSCredentials(S3Configuration s3configParam) -
setBroadleafFileService
public void setBroadleafFileService(org.broadleafcommerce.common.file.service.BroadleafFileService bfs) -
setConcurrentFileOutputStream
public void setConcurrentFileOutputStream(org.broadleafcommerce.common.io.ConcurrentFileOutputStream concurrentFileOutputStream) -
getResource
public File getResource(String name, org.broadleafcommerce.common.file.service.type.FileApplicationType fileApplicationType) Handles the resource gathering, starts as regular retrieval, if it fails (and the conditions allow it) it will try to retrieve the image from the parent site- Specified by:
getResourcein interfaceorg.broadleafcommerce.common.file.service.FileServiceProvider
-
buildResourceParentName
Builds the resourceName for it's parent.- Parameters:
name-- Returns:
-
isMultiTenantEnvironment
protected boolean isMultiTenantEnvironment()Check if the module is call with MultiTenant module- Returns:
-
getMultiTenantClass
Get MultiTenantSite Class by Reflection- Returns:
- Throws:
ThrowableClassNotFoundExceptionLinkageError
-
getMultiTenantGetParentSiteIdMethod
protected Method getMultiTenantGetParentSiteIdMethod() throws NoSuchMethodException, SecurityException, ClassNotFoundException, LinkageErrorGets getParentId method by reflection- Returns:
- Throws:
NoSuchMethodExceptionSecurityExceptionClassNotFoundExceptionLinkageError
-
invokeMultiTenantGetParentSiteIdMethod
Reflection getParentSiteId Invocation- Parameters:
site-- Returns:
-
getMultiTenantSiteSpecificResourceNameParent
Get the parent from a MultiTentantSite. The MultiTenantSite environment is detected by reflection.- Parameters:
resourceName-- Returns:
-