Search in sources :

Example 1 with DELIMITER

use of org.craftercms.engine.store.s3.S3ContentStoreAdapter.DELIMITER in project engine by craftercms.

the class S3SiteListResolver method getSiteListFromBucketKeys.

protected Collection<String> getSiteListFromBucketKeys(String bucketName, String rootPrefix) {
    List<String> siteNames = new ArrayList<>();
    AmazonS3 client = clientBuilder.getClient();
    ListObjectsV2Request request = new ListObjectsV2Request().withBucketName(bucketName).withPrefix(rootPrefix).withDelimiter(DELIMITER);
    ListObjectsV2Result result = client.listObjectsV2(request);
    if (CollectionUtils.isNotEmpty(result.getCommonPrefixes())) {
        result.getCommonPrefixes().stream().map(prefix -> StringUtils.stripEnd(StringUtils.removeStart(prefix, rootPrefix), DELIMITER)).forEach(siteNames::add);
    }
    return siteNames;
}
Also used : SiteListResolver(org.craftercms.engine.service.context.SiteListResolver) Collection(java.util.Collection) Bucket(com.amazonaws.services.s3.model.Bucket) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) DELIMITER(org.craftercms.engine.store.s3.S3ContentStoreAdapter.DELIMITER) ListObjectsV2Result(com.amazonaws.services.s3.model.ListObjectsV2Result) ArrayList(java.util.ArrayList) ListObjectsV2Request(com.amazonaws.services.s3.model.ListObjectsV2Request) List(java.util.List) Matcher(java.util.regex.Matcher) SiteContextFactory(org.craftercms.engine.service.context.SiteContextFactory) AmazonS3(com.amazonaws.services.s3.AmazonS3) Required(org.springframework.beans.factory.annotation.Required) Pattern(java.util.regex.Pattern) S3ClientBuilder(org.craftercms.engine.store.s3.util.S3ClientBuilder) AmazonS3URI(com.amazonaws.services.s3.AmazonS3URI) AmazonS3(com.amazonaws.services.s3.AmazonS3) ListObjectsV2Request(com.amazonaws.services.s3.model.ListObjectsV2Request) ListObjectsV2Result(com.amazonaws.services.s3.model.ListObjectsV2Result) ArrayList(java.util.ArrayList)

Aggregations

AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 AmazonS3URI (com.amazonaws.services.s3.AmazonS3URI)1 Bucket (com.amazonaws.services.s3.model.Bucket)1 ListObjectsV2Request (com.amazonaws.services.s3.model.ListObjectsV2Request)1 ListObjectsV2Result (com.amazonaws.services.s3.model.ListObjectsV2Result)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 CollectionUtils (org.apache.commons.collections4.CollectionUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 SiteContextFactory (org.craftercms.engine.service.context.SiteContextFactory)1 SiteListResolver (org.craftercms.engine.service.context.SiteListResolver)1 DELIMITER (org.craftercms.engine.store.s3.S3ContentStoreAdapter.DELIMITER)1 S3ClientBuilder (org.craftercms.engine.store.s3.util.S3ClientBuilder)1 Required (org.springframework.beans.factory.annotation.Required)1