Search in sources :

Example 1 with AnalyticsConfiguration

use of com.amazonaws.services.s3.model.analytics.AnalyticsConfiguration 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();
}
Also used : XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Example 2 with AnalyticsConfiguration

use of com.amazonaws.services.s3.model.analytics.AnalyticsConfiguration in project aws-sdk-android by aws-amplify.

the class BucketAnalyticsSaxUnmarshallerTest method getResponse_unmarshalls_properly.

@Test
public void getResponse_unmarshalls_properly() throws Exception {
    AnalyticsConfiguration configuration = parseGetAnalyticsConfigurationResponse(GET_RESPONSE).getAnalyticsConfiguration();
    AnalyticsFilter filter = configuration.getFilter();
    StorageClassAnalysis storageClassAnalysis = configuration.getStorageClassAnalysis();
    assertEquals("analytics-id", configuration.getId());
    assertNotNull(filter);
    List<AnalyticsFilterPredicate> operands = ((AnalyticsAndOperator) filter.getPredicate()).getOperands();
    assertEquals(2, operands.size());
    assertEquals("documents/", ((AnalyticsPrefixPredicate) operands.get(0)).getPrefix());
    assertEquals("foo", ((AnalyticsTagPredicate) operands.get(1)).getTag().getKey());
    assertEquals("bar", ((AnalyticsTagPredicate) operands.get(1)).getTag().getValue());
    assertEquals(StorageClassAnalysisSchemaVersion.V_1.toString(), storageClassAnalysis.getDataExport().getOutputSchemaVersion());
    AnalyticsS3BucketDestination s3BucketDestination = storageClassAnalysis.getDataExport().getDestination().getS3BucketDestination();
    assertEquals(AnalyticsS3ExportFileFormat.CSV.toString(), s3BucketDestination.getFormat());
    assertEquals("123456789", s3BucketDestination.getBucketAccountId());
    assertEquals("arn:aws:s3:::destination-bucket", s3BucketDestination.getBucketArn());
    assertEquals("destination-prefix", s3BucketDestination.getPrefix());
}
Also used : AnalyticsConfiguration(com.amazonaws.services.s3.model.analytics.AnalyticsConfiguration) StorageClassAnalysis(com.amazonaws.services.s3.model.analytics.StorageClassAnalysis) AnalyticsFilterPredicate(com.amazonaws.services.s3.model.analytics.AnalyticsFilterPredicate) AnalyticsS3BucketDestination(com.amazonaws.services.s3.model.analytics.AnalyticsS3BucketDestination) AnalyticsFilter(com.amazonaws.services.s3.model.analytics.AnalyticsFilter) AnalyticsTagPredicate(com.amazonaws.services.s3.model.analytics.AnalyticsTagPredicate) AnalyticsAndOperator(com.amazonaws.services.s3.model.analytics.AnalyticsAndOperator) Test(org.junit.Test)

Example 3 with AnalyticsConfiguration

use of com.amazonaws.services.s3.model.analytics.AnalyticsConfiguration in project aws-sdk-android by aws-amplify.

the class BucketAnalyticsSaxUnmarshallerTest method listResponse_unmarshalls_properly.

@Test
public void listResponse_unmarshalls_properly() throws Exception {
    ListBucketAnalyticsConfigurationsResult result = parseListAnalyticsConfigurationResponse(LIST_RESPONSE);
    assertTrue(result.isTruncated());
    assertEquals("token1", result.getContinuationToken());
    assertEquals("token2", result.getNextContinuationToken());
    List<AnalyticsConfiguration> analyticsConfigurationList = result.getAnalyticsConfigurationList();
    assertEquals(2, analyticsConfigurationList.size());
    // Test first analytics configuration
    AnalyticsConfiguration configuration = analyticsConfigurationList.get(0);
    AnalyticsFilter filter = configuration.getFilter();
    StorageClassAnalysis storageClassAnalysis = configuration.getStorageClassAnalysis();
    assertEquals("XXX", configuration.getId());
    assertNotNull(filter);
    List<AnalyticsFilterPredicate> operands = ((AnalyticsAndOperator) filter.getPredicate()).getOperands();
    assertEquals(2, operands.size());
    assertEquals("documents/", ((AnalyticsPrefixPredicate) operands.get(0)).getPrefix());
    assertEquals("foo", ((AnalyticsTagPredicate) operands.get(1)).getTag().getKey());
    assertEquals("bar", ((AnalyticsTagPredicate) operands.get(1)).getTag().getValue());
    assertEquals(StorageClassAnalysisSchemaVersion.V_1.toString(), storageClassAnalysis.getDataExport().getOutputSchemaVersion());
    AnalyticsS3BucketDestination s3BucketDestination = storageClassAnalysis.getDataExport().getDestination().getS3BucketDestination();
    assertEquals(AnalyticsS3ExportFileFormat.CSV.toString(), s3BucketDestination.getFormat());
    assertEquals("123456789", s3BucketDestination.getBucketAccountId());
    assertEquals("arn:aws:s3:::destination-bucket", s3BucketDestination.getBucketArn());
    assertEquals("destination-prefix", s3BucketDestination.getPrefix());
    // Test second analytics configuration
    configuration = analyticsConfigurationList.get(1);
    storageClassAnalysis = configuration.getStorageClassAnalysis();
    assertEquals("YYY", configuration.getId());
    assertEquals("prefix", ((AnalyticsPrefixPredicate) configuration.getFilter().getPredicate()).getPrefix());
    assertEquals("V_2", storageClassAnalysis.getDataExport().getOutputSchemaVersion());
    s3BucketDestination = storageClassAnalysis.getDataExport().getDestination().getS3BucketDestination();
    assertEquals("JSON", s3BucketDestination.getFormat());
    assertEquals("123", s3BucketDestination.getBucketAccountId());
    assertEquals("arn:aws:s3:::bucket2", s3BucketDestination.getBucketArn());
    assertEquals("prefix2", s3BucketDestination.getPrefix());
}
Also used : AnalyticsConfiguration(com.amazonaws.services.s3.model.analytics.AnalyticsConfiguration) StorageClassAnalysis(com.amazonaws.services.s3.model.analytics.StorageClassAnalysis) AnalyticsFilterPredicate(com.amazonaws.services.s3.model.analytics.AnalyticsFilterPredicate) AnalyticsS3BucketDestination(com.amazonaws.services.s3.model.analytics.AnalyticsS3BucketDestination) ListBucketAnalyticsConfigurationsResult(com.amazonaws.services.s3.model.ListBucketAnalyticsConfigurationsResult) AnalyticsFilter(com.amazonaws.services.s3.model.analytics.AnalyticsFilter) AnalyticsTagPredicate(com.amazonaws.services.s3.model.analytics.AnalyticsTagPredicate) AnalyticsAndOperator(com.amazonaws.services.s3.model.analytics.AnalyticsAndOperator) Test(org.junit.Test)

Example 4 with AnalyticsConfiguration

use of com.amazonaws.services.s3.model.analytics.AnalyticsConfiguration in project aws-sdk-android by aws-amplify.

the class AmazonS3Client method setBucketAnalyticsConfiguration.

@Override
public SetBucketAnalyticsConfigurationResult setBucketAnalyticsConfiguration(SetBucketAnalyticsConfigurationRequest setBucketAnalyticsConfigurationRequest) throws AmazonServiceException, AmazonClientException {
    assertParameterNotNull(setBucketAnalyticsConfigurationRequest, "The request cannot be null");
    final String bucketName = assertStringNotEmpty(setBucketAnalyticsConfigurationRequest.getBucketName(), "BucketName");
    final AnalyticsConfiguration analyticsConfiguration = assertNotNull(setBucketAnalyticsConfigurationRequest.getAnalyticsConfiguration(), "Analytics Configuration");
    final String id = assertNotNull(analyticsConfiguration.getId(), "Analytics Id");
    final Request<SetBucketAnalyticsConfigurationRequest> request = createRequest(bucketName, null, setBucketAnalyticsConfigurationRequest, HttpMethodName.PUT);
    request.addParameter("analytics", null);
    request.addParameter("id", id);
    final byte[] bytes = bucketConfigurationXmlFactory.convertToXmlByteArray(analyticsConfiguration);
    request.addHeader("Content-Length", String.valueOf(bytes.length));
    request.addHeader("Content-Type", "application/xml");
    request.setContent(new ByteArrayInputStream(bytes));
    return invoke(request, new Unmarshallers.SetBucketAnalyticsConfigurationUnmarshaller(), bucketName, null);
}
Also used : AnalyticsConfiguration(com.amazonaws.services.s3.model.analytics.AnalyticsConfiguration) Unmarshallers(com.amazonaws.services.s3.model.transform.Unmarshallers) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

AnalyticsConfiguration (com.amazonaws.services.s3.model.analytics.AnalyticsConfiguration)3 AnalyticsAndOperator (com.amazonaws.services.s3.model.analytics.AnalyticsAndOperator)2 AnalyticsFilter (com.amazonaws.services.s3.model.analytics.AnalyticsFilter)2 AnalyticsFilterPredicate (com.amazonaws.services.s3.model.analytics.AnalyticsFilterPredicate)2 AnalyticsS3BucketDestination (com.amazonaws.services.s3.model.analytics.AnalyticsS3BucketDestination)2 AnalyticsTagPredicate (com.amazonaws.services.s3.model.analytics.AnalyticsTagPredicate)2 StorageClassAnalysis (com.amazonaws.services.s3.model.analytics.StorageClassAnalysis)2 Test (org.junit.Test)2 XmlWriter (com.amazonaws.services.s3.internal.XmlWriter)1 ListBucketAnalyticsConfigurationsResult (com.amazonaws.services.s3.model.ListBucketAnalyticsConfigurationsResult)1 Unmarshallers (com.amazonaws.services.s3.model.transform.Unmarshallers)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1