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 Details

    • s3ConfigurationService

      protected S3ConfigurationService s3ConfigurationService
    • blFileService

      protected org.broadleafcommerce.common.file.service.BroadleafFileService blFileService
    • configClientMap

      protected Map<S3Configuration,com.amazonaws.services.s3.AmazonS3> configClientMap
    • concurrentFileOutputStream

      protected org.broadleafcommerce.common.io.ConcurrentFileOutputStream concurrentFileOutputStream
    • BUCKET_PREFIX

      protected static String BUCKET_PREFIX
    • SITE_PREFIX

      protected static String SITE_PREFIX
    • MULTITENANT_SITE_CLASSNAME

      protected static String MULTITENANT_SITE_CLASSNAME
    • MULTITENANTSITE_GETPARENTID_METHODNAME

      protected static String MULTITENANTSITE_GETPARENTID_METHODNAME
  • Constructor Details

    • S3FileServiceProvider

      public S3FileServiceProvider()
  • Method Details

    • getResource

      public File getResource(String name)
      Entry point to retrieve resources from this module.
      Specified by:
      getResource in interface org.broadleafcommerce.common.file.service.FileServiceProvider
    • getBucketName

      protected String getBucketName(String name, String defaultBucketName)
      Returns the bucket name or the default one.
      Parameters:
      name -
      defaultBucketName -
      Returns:
    • getResourceName

      protected String getResourceName(S3Configuration s3config, String bucketName, String rawName)
      Retrieves the resourceName from its rawname.
      Parameters:
      s3config -
      bucketName -
      rawName -
      Returns:
    • ensureFileCreation

      protected void ensureFileCreation(File returnFile, String name) throws RuntimeException
      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:
      addOrUpdateResources in interface org.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:
      addOrUpdateResourcesForPaths in interface org.broadleafcommerce.common.file.service.FileServiceProvider
    • addOrUpdateResourcesInternal

      protected List<String> addOrUpdateResourcesInternal(S3Configuration s3config, com.amazonaws.services.s3.AmazonS3 s3, org.broadleafcommerce.common.file.domain.FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea)
    • removeResource

      public boolean removeResource(String name)
      Specified by:
      removeResource in interface org.broadleafcommerce.common.file.service.FileServiceProvider
    • buildResourceName

      protected String buildResourceName(String name)
      hook for overriding name used for resource in S3
      Parameters:
      name -
      Returns:
    • getSiteSpecificResourceName

      protected String getSiteSpecificResourceName(String resourceName)
    • getSiteDirectory

      protected String getSiteDirectory(org.broadleafcommerce.common.site.domain.Site site)
    • getSiteDirectory

      protected String getSiteDirectory(Long id)
    • getAmazonS3Client

      protected com.amazonaws.services.s3.AmazonS3 getAmazonS3Client(S3Configuration s3config)
    • getAmazonS3ClientFromConfiguration

      protected com.amazonaws.services.s3.AmazonS3 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 com.amazonaws.auth.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:
      getResource in interface org.broadleafcommerce.common.file.service.FileServiceProvider
    • buildResourceParentName

      protected String buildResourceParentName(String name)
      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

      protected Class<?> getMultiTenantClass() throws ClassNotFoundException, LinkageError
      Get MultiTenantSite Class by Reflection
      Returns:
      Throws:
      Throwable
      ClassNotFoundException
      LinkageError
    • getMultiTenantGetParentSiteIdMethod

      protected Method getMultiTenantGetParentSiteIdMethod() throws NoSuchMethodException, SecurityException, ClassNotFoundException, LinkageError
      Gets getParentId method by reflection
      Returns:
      Throws:
      NoSuchMethodException
      SecurityException
      ClassNotFoundException
      LinkageError
    • invokeMultiTenantGetParentSiteIdMethod

      protected Long invokeMultiTenantGetParentSiteIdMethod(Object site)
      Reflection getParentSiteId Invocation
      Parameters:
      site -
      Returns:
    • getMultiTenantSiteSpecificResourceNameParent

      protected String getMultiTenantSiteSpecificResourceNameParent(String resourceName)
      Get the parent from a MultiTentantSite. The MultiTenantSite environment is detected by reflection.
      Parameters:
      resourceName -
      Returns: