use of com.amazonaws.services.s3.model.Filter in project boot by workoss.
the class AbstractS3Client method getBucket.
@Override
public StorageBucketInfo getBucket() {
AmazonS3 amazonS3 = getClient("", "getBucket");
try {
ListBucketsRequest listBucketsRequest = new ListBucketsRequest();
List<Bucket> buckets = amazonS3.listBuckets(listBucketsRequest);
if (CollectionUtils.isEmpty(buckets)) {
return null;
}
return buckets.stream().filter(bucket -> config.getBucketName().equals(bucket.getName())).map(bucket -> new StorageBucketInfo(bucket.getName(), bucket.getOwner() == null ? null : bucket.getOwner().getId(), bucket.getCreationDate())).findFirst().orElseGet(() -> null);
} catch (AmazonS3Exception e) {
throw new StorageException(e.getErrorCode(), e.getMessage());
} catch (Exception e) {
throw new StorageException("0002", ExceptionUtils.toShortString(e, 2));
} finally {
amazonS3.shutdown();
}
}
use of com.amazonaws.services.s3.model.Filter in project aws-sdk-android by aws-amplify.
the class BucketConfigurationXmlFactory method convertToXmlByteArray.
/**
* Converts the specified
* {@link com.amazonaws.services.s3.model.metrics.MetricsConfiguration}
* object to an XML fragment that can be sent to Amazon S3.
*
* @param config The
* {@link com.amazonaws.services.s3.model.metrics.MetricsConfiguration}
* .
*/
/*
* <MetricsConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
* <Id>metrics-id</Id> <Filter> <!-- A filter should have only one of
* Prefix, Tag or And--> <Prefix>prefix</Prefix> <Tag> <Key>Project</Key>
* <Value>Foo</Value> </Tag> <And> <Prefix>documents/</Prefix> <Tag>
* <Key>foo</Key> <Value>bar</Value> </Tag> </And> </Filter>
* </MetricsConfiguration>
*/
public byte[] convertToXmlByteArray(MetricsConfiguration config) throws AmazonClientException {
final XmlWriter xml = new XmlWriter();
xml.start("MetricsConfiguration", "xmlns", Constants.XML_NAMESPACE);
addParameterIfNotNull(xml, "Id", config.getId());
writeMetricsFilter(xml, config.getFilter());
xml.end();
return xml.getBytes();
}
use of com.amazonaws.services.s3.model.Filter in project aws-sdk-android by aws-amplify.
the class BucketConfigurationXmlFactory method convertToXmlByteArray.
/**
* Converts the specified
* {@link com.amazonaws.services.s3.model.analytics.AnalyticsConfiguration}
* object to an XML fragment that can be sent to Amazon S3.
*
* @param config The
* {@link com.amazonaws.services.s3.model.analytics.AnalyticsConfiguration}
*/
/*
* <AnalyticsConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
* <Id>XXX</Id> <Filter> <And> <Prefix>documents/</Prefix> <Tag>
* <Key>foo</Key> <Value>bar</Value> </Tag> </And> </Filter>
* <StorageClassAnalysis> <DataExport>
* <OutputSchemaVersion>1</OutputSchemaVersion> <Destination>
* <S3BucketDestination> <Format>CSV</Format>
* <BucketAccountId>123456789</BucketAccountId>
* <Bucket>destination-bucket</Bucket> <Prefix>destination-prefix</Prefix>
* </S3BucketDestination> </Destination> </DataExport>
* </StorageClassAnalysis> </AnalyticsConfiguration>
*/
public byte[] convertToXmlByteArray(AnalyticsConfiguration config) throws AmazonClientException {
final XmlWriter xml = new XmlWriter();
xml.start("AnalyticsConfiguration", "xmlns", Constants.XML_NAMESPACE);
addParameterIfNotNull(xml, "Id", config.getId());
writeAnalyticsFilter(xml, config.getFilter());
writeStorageClassAnalysis(xml, config.getStorageClassAnalysis());
xml.end();
return xml.getBytes();
}
use of com.amazonaws.services.s3.model.Filter in project aws-sdk-android by aws-amplify.
the class BucketConfigurationXmlFactory method addEventsAndFilterCriteria.
private void addEventsAndFilterCriteria(XmlWriter xml, NotificationConfiguration config) {
for (final String event : config.getEvents()) {
xml.start("Event").value(event).end();
}
final Filter filter = config.getFilter();
if (filter != null) {
validateFilter(filter);
xml.start("Filter");
if (filter.getS3KeyFilter() != null) {
validateS3KeyFilter(filter.getS3KeyFilter());
xml.start("S3Key");
for (final FilterRule filterRule : filter.getS3KeyFilter().getFilterRules()) {
xml.start("FilterRule");
xml.start("Name").value(filterRule.getName()).end();
xml.start("Value").value(filterRule.getValue()).end();
xml.end();
}
xml.end();
}
xml.end();
}
}
use of com.amazonaws.services.s3.model.Filter in project aws-sdk-android by aws-amplify.
the class FilterStaxUnmarshaller method unmarshall.
@Override
public Filter unmarshall(StaxUnmarshallerContext context) throws Exception {
final int originalDepth = context.getCurrentDepth();
int targetDepth = originalDepth + 1;
if (context.isStartOfDocument()) {
targetDepth += 1;
}
final Filter filter = new Filter();
while (true) {
final int xmlEvent = context.nextEvent();
if (xmlEvent == XmlPullParser.END_DOCUMENT) {
break;
} else if (xmlEvent == XmlPullParser.START_TAG) {
if (context.testExpression("S3Key", targetDepth)) {
filter.withS3KeyFilter(S3KeyFilterStaxUnmarshaller.getInstance().unmarshall(context));
}
} else if (xmlEvent == XmlPullParser.END_TAG) {
if (context.getCurrentDepth() < originalDepth) {
return filter;
}
}
}
return filter;
}
Aggregations