use of org.craftercms.core.exception.StoreException in project engine by craftercms.
the class S3ContentStoreAdapter method doFindFile.
/**
* {@inheritDoc}
*/
@Override
protected File doFindFile(Context context, String path) throws InvalidContextException, StoreException {
if (context.ignoreHiddenFiles() && isHidden(path)) {
return null;
}
S3Context s3Context = (S3Context) context;
String key = StringUtils.appendIfMissing(s3Context.getKey(), path);
logger.debug("Getting file for key {}", key);
if (StringUtils.isEmpty(FilenameUtils.getExtension(key))) {
// If it is a folder, check if there are objects with the prefix
try {
ListObjectsV2Request request = new ListObjectsV2Request().withBucketName(s3Context.getBucket()).withPrefix(key).withDelimiter(DELIMITER);
ListObjectsV2Result result = client.listObjectsV2(request);
if (!isResultEmpty(result)) {
return new S3Prefix(key);
}
} catch (AmazonS3Exception e) {
if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
logger.debug("No object found for key {}", key);
} else {
throw new StoreException("Error listing objects for key " + key, e);
}
}
} else {
// If it is a file, check if the key exist
try {
if (client.doesObjectExist(s3Context.getBucket(), key)) {
return new S3File(key);
} else {
logger.debug("No object found for key {}", key);
}
} catch (AmazonS3Exception e) {
throw new StoreException("Error checking if object for key " + key + " exists", e);
}
}
return null;
}
Aggregations