@Override protected void doStartElement( String uri, String name, String qName, Attributes attrs) { if (in("ListMetricsConfigurationsResult")) { if (name.equals("MetricsConfiguration")) { currentConfiguration = new MetricsConfiguration(); } } else if (in("ListMetricsConfigurationsResult", "MetricsConfiguration")) { if (name.equals("Filter")) { currentFilter = new MetricsFilter(); } } else if (in("ListMetricsConfigurationsResult", "MetricsConfiguration", "Filter")) { if (name.equals("And")) { andOperandsList = new ArrayList<MetricsFilterPredicate>(); } } }
/** * 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 SdkClientException { 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(); }
@Test public void testNonInjectableMocks_shouldReturnNormal() { assertNotNull(getBuckets()); String leadBucket = "lead-maybe-gold"; assertNotNull(s3.deleteBucketAnalyticsConfiguration(new DeleteBucketAnalyticsConfigurationRequest() .withBucketName(leadBucket).withId("very analytic"))); s3.deleteBucketCrossOriginConfiguration(new DeleteBucketCrossOriginConfigurationRequest(leadBucket)); assertNotNull(s3.deleteBucketInventoryConfiguration(new DeleteBucketInventoryConfigurationRequest().withBucketName(leadBucket).withId("1"))); s3.deleteBucketLifecycleConfiguration(new DeleteBucketLifecycleConfigurationRequest(leadBucket)); assertNotNull(s3.deleteBucketMetricsConfiguration(new DeleteBucketMetricsConfigurationRequest().withBucketName(leadBucket).withId("1"))); s3.deleteBucketReplicationConfiguration(new DeleteBucketReplicationConfigurationRequest(leadBucket)); s3.deleteBucketTaggingConfiguration(new DeleteBucketTaggingConfigurationRequest(leadBucket)); s3.deleteBucketWebsiteConfiguration(new DeleteBucketWebsiteConfigurationRequest(leadBucket)); assertNotNull(s3.deleteObjectTagging(new DeleteObjectTaggingRequest(leadBucket, "1"))); s3.disableRequesterPays(leadBucket); s3.enableRequesterPays(leadBucket); assertNotNull(s3.getBucketAccelerateConfiguration(new GetBucketAccelerateConfigurationRequest(leadBucket))); assertNotNull(s3.getBucketAnalyticsConfiguration(new GetBucketAnalyticsConfigurationRequest().withBucketName(leadBucket).withId("1"))); assertNotNull(s3.getBucketCrossOriginConfiguration(new GetBucketCrossOriginConfigurationRequest(leadBucket))); assertNotNull(s3.getBucketInventoryConfiguration(new GetBucketInventoryConfigurationRequest().withBucketName(leadBucket).withId("1"))); assertNotNull(s3.getBucketLifecycleConfiguration(new GetBucketLifecycleConfigurationRequest(leadBucket))); assertNotNull(s3.getBucketLoggingConfiguration(new GetBucketLoggingConfigurationRequest(leadBucket))); assertNotNull(s3.getBucketMetricsConfiguration(new GetBucketMetricsConfigurationRequest().withBucketName(leadBucket).withId("1"))); assertNotNull(s3.getBucketNotificationConfiguration(new GetBucketNotificationConfigurationRequest(leadBucket))); assertNotNull(s3.getBucketReplicationConfiguration(new GetBucketReplicationConfigurationRequest(leadBucket))); assertNotNull(s3.getBucketTaggingConfiguration(new GetBucketTaggingConfigurationRequest(leadBucket))); assertNotNull(s3.getBucketVersioningConfiguration(new GetBucketVersioningConfigurationRequest(leadBucket))); assertNotNull(s3.getBucketWebsiteConfiguration(new GetBucketWebsiteConfigurationRequest(leadBucket))); assertNotNull(s3.listBucketAnalyticsConfigurations(new ListBucketAnalyticsConfigurationsRequest().withBucketName(leadBucket))); assertNotNull(s3.listBucketInventoryConfigurations(new ListBucketInventoryConfigurationsRequest().withBucketName(leadBucket))); assertNotNull(s3.listBucketMetricsConfigurations(new ListBucketMetricsConfigurationsRequest().withBucketName(leadBucket))); s3.setBucketAccelerateConfiguration(new SetBucketAccelerateConfigurationRequest(leadBucket, new BucketAccelerateConfiguration(""))); assertNotNull(s3.setBucketInventoryConfiguration(new SetBucketInventoryConfigurationRequest().withBucketName(leadBucket).withInventoryConfiguration(new InventoryConfiguration().withId("1")))); s3.setBucketLoggingConfiguration(new SetBucketLoggingConfigurationRequest(leadBucket, new BucketLoggingConfiguration())); assertNotNull(s3.setBucketMetricsConfiguration(new SetBucketMetricsConfigurationRequest().withBucketName(leadBucket).withMetricsConfiguration(new MetricsConfiguration().withId("1")))); s3.setBucketVersioningConfiguration(new SetBucketVersioningConfigurationRequest(leadBucket, new BucketVersioningConfiguration().withStatus("ENABLED"))); BucketWebsiteConfiguration bucketWebsiteConfig = new BucketWebsiteConfiguration(); bucketWebsiteConfig.setIndexDocumentSuffix("1"); s3.setBucketWebsiteConfiguration(new SetBucketWebsiteConfigurationRequest(leadBucket, bucketWebsiteConfig)); assertNotNull(s3.headBucket(new HeadBucketRequest(leadBucket))); assertNotNull(s3.getBucketPolicy(leadBucket)); s3.setBucketPolicy(new SetBucketPolicyRequest(leadBucket, "very strict policy")); s3.deleteBucketPolicy(leadBucket); try { assertNotNull(s3.getObjectMetadata(new GetObjectMetadataRequest(leadBucket, "23423kjh"))); } catch(AmazonS3Exception s3Exception) { assertEquals("should return not found", 404,s3Exception.getStatusCode()); } s3.restoreObject(new RestoreObjectRequest(leadBucket, "bullet.jpg").withExpirationInDays(23)); s3.deleteVersion(new DeleteVersionRequest(leadBucket, "bullet.exe", "v3")); assertNotNull(s3.listNextBatchOfVersions(new ListNextBatchOfVersionsRequest(new VersionListing()))); assertNotNull(s3.generatePresignedUrl("nonExistante", "somekey", new Date())); assertNotNull(s3.getS3AccountOwner()); }
@Override protected void doEndElement(String uri, String name, String qName) { if (in("ListMetricsConfigurationsResult")) { if (name.equals("MetricsConfiguration")) { if (result.getMetricsConfigurationList() == null) { result.setMetricsConfigurationList(new ArrayList<MetricsConfiguration>()); } result.getMetricsConfigurationList().add(currentConfiguration); currentConfiguration = null; } else if (name.equals("IsTruncated")) { result.setTruncated("true".equals(getText())); } else if (name.equals("ContinuationToken")) { result.setContinuationToken(getText()); } else if (name.equals("NextContinuationToken")) { result.setNextContinuationToken(getText()); } } else if (in("ListMetricsConfigurationsResult", "MetricsConfiguration")) { if (name.equals("Id")) { currentConfiguration.setId(getText()); } else if (name.equals("Filter")) { currentConfiguration.setFilter(currentFilter); currentFilter = null; } } else if (in("ListMetricsConfigurationsResult", "MetricsConfiguration", "Filter")) { if (name.equals("Prefix")) { currentFilter.setPredicate(new MetricsPrefixPredicate(getText())); } else if (name.equals("Tag")) { currentFilter.setPredicate(new MetricsTagPredicate(new Tag(currentTagKey, currentTagValue))); currentTagKey = null; currentTagValue = null; } else if (name.equals("And")) { currentFilter.setPredicate(new MetricsAndOperator(andOperandsList)); andOperandsList = null; } } else if (in("ListMetricsConfigurationsResult", "MetricsConfiguration", "Filter", "Tag")) { if (name.equals("Key")) { currentTagKey = getText(); } else if (name.equals("Value")) { currentTagValue = getText(); } } else if (in("ListMetricsConfigurationsResult", "MetricsConfiguration", "Filter", "And")) { if (name.equals("Prefix")) { andOperandsList.add(new MetricsPrefixPredicate(getText())); } else if (name.equals("Tag")) { andOperandsList.add(new MetricsTagPredicate(new Tag(currentTagKey, currentTagValue))); currentTagKey = null; currentTagValue = null; } } else if (in("ListMetricsConfigurationsResult", "MetricsConfiguration", "Filter", "And", "Tag")) { if (name.equals("Key")) { currentTagKey = getText(); } else if (name.equals("Value")) { currentTagValue = getText(); } } }
public SetBucketMetricsConfigurationRequest(String bucketName, MetricsConfiguration metricsConfiguration) { this.bucketName = bucketName; this.metricsConfiguration = metricsConfiguration; }
/** * Returns the metrics configuration that is set on the bucket. */ public MetricsConfiguration getMetricsConfiguration() { return metricsConfiguration; }
/** * Sets the metrics configuration. */ public void setMetricsConfiguration(MetricsConfiguration metricsConfiguration) { this.metricsConfiguration = metricsConfiguration; }
/** * Sets the metrics configuration and returns the * {@link SetBucketMetricsConfigurationRequest} object for method chaining. */ public SetBucketMetricsConfigurationRequest withMetricsConfiguration(MetricsConfiguration metricsConfiguration) { setMetricsConfiguration(metricsConfiguration); return this; }
/** * Returns the list of metrics configurations for a bucket. */ public List<MetricsConfiguration> getMetricsConfigurationList() { return metricsConfigurationList; }
/** * Sets the list of metrics configurations. */ public void setMetricsConfigurationList(List<MetricsConfiguration> metricsConfigurationList) { this.metricsConfigurationList = metricsConfigurationList; }
/** * Sets the list of metrics configurations and returns the * {@link ListBucketMetricsConfigurationsResult} object for method chaining. */ public ListBucketMetricsConfigurationsResult withMetricsConfigurationList(List<MetricsConfiguration> metricsConfigurationList) { setMetricsConfigurationList(metricsConfigurationList); return this; }
/** * Returns the requested metrics configuration. */ public MetricsConfiguration getMetricsConfiguration() { return metricsConfiguration; }
/** * Sets the requested metrics configuration. */ public void setMetricsConfiguration(MetricsConfiguration metricsConfiguration) { this.metricsConfiguration = metricsConfiguration; }
/** * Sets the requested metrics configuration and returns * {@link GetBucketMetricsConfigurationResult} object for method chaining. */ public GetBucketMetricsConfigurationResult withMetricsConfiguration(MetricsConfiguration metricsConfiguration) { setMetricsConfiguration(metricsConfiguration); return this; }
@Override public SetBucketMetricsConfigurationResult setBucketMetricsConfiguration(String bucketName, MetricsConfiguration metricsConfiguration) throws AmazonServiceException, AmazonServiceException { return call(() -> getDelegate().setBucketMetricsConfiguration(bucketName, metricsConfiguration)); }