Search in sources :

Example 1 with InventoryConfiguration

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

the class AmazonS3Client method setBucketInventoryConfiguration.

@Override
public SetBucketInventoryConfigurationResult setBucketInventoryConfiguration(SetBucketInventoryConfigurationRequest setBucketInventoryConfigurationRequest) throws AmazonServiceException, AmazonClientException {
    assertParameterNotNull(setBucketInventoryConfigurationRequest, "The request cannot be null");
    final String bucketName = assertStringNotEmpty(setBucketInventoryConfigurationRequest.getBucketName(), "BucketName");
    final InventoryConfiguration inventoryConfiguration = assertNotNull(setBucketInventoryConfigurationRequest.getInventoryConfiguration(), "InventoryConfiguration");
    final String id = assertNotNull(inventoryConfiguration.getId(), "Inventory id");
    final Request<SetBucketInventoryConfigurationRequest> request = createRequest(bucketName, null, setBucketInventoryConfigurationRequest, HttpMethodName.PUT);
    request.addParameter("inventory", null);
    request.addParameter("id", id);
    final byte[] bytes = bucketConfigurationXmlFactory.convertToXmlByteArray(inventoryConfiguration);
    request.addHeader("Content-Length", String.valueOf(bytes.length));
    request.addHeader("Content-Type", "application/xml");
    request.setContent(new ByteArrayInputStream(bytes));
    return invoke(request, new Unmarshallers.SetBucketInventoryConfigurationUnmarshaller(), bucketName, null);
}
Also used : Unmarshallers(com.amazonaws.services.s3.model.transform.Unmarshallers) ByteArrayInputStream(java.io.ByteArrayInputStream) InventoryConfiguration(com.amazonaws.services.s3.model.inventory.InventoryConfiguration)

Example 2 with InventoryConfiguration

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

the class BucketConfigurationXmlFactory method convertToXmlByteArray.

/**
 * Converts the specified {@link InventoryConfiguration} object to an XML
 * fragment that can be sent to Amazon S3.
 *
 * @param config The {@link InventoryConfiguration}
 */
/*
     * <?xml version="1.0" encoding="UTF-8"?> <InventoryConfiguration
     * xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Destination>
     * <S3BucketDestination> <AccountId>A2OCNCIEQW9MSG</AccountId>
     * <Bucket>s3-object-inventory-list-gamma-us-east-1</Bucket>
     * <Format>CSV</Format> <Prefix>string</Prefix> </S3BucketDestination>
     * </Destination> <IsEnabled>true</IsEnabled> <Filter>
     * <Prefix>string</Prefix> </Filter> <Id>configId</Id>
     * <IncludedObjectVersions>All</IncludedObjectVersions> <OptionalFields>
     * <Field>Size</Field> <Field>LastModifiedDate</Field>
     * <Field>StorageClass</Field> <Field>ETag</Field>
     * <Field>IsMultipartUploaded</Field> <Field>ReplicationStatus</Field>
     * </OptionalFields> <Schedule> <Frequency>Daily</Frequency> </Schedule>
     * </InventoryConfiguration>
     */
public byte[] convertToXmlByteArray(InventoryConfiguration config) throws AmazonClientException {
    final XmlWriter xml = new XmlWriter();
    xml.start("InventoryConfiguration", "xmlns", Constants.XML_NAMESPACE);
    xml.start("Id").value(config.getId()).end();
    xml.start("IsEnabled").value(String.valueOf(config.isEnabled())).end();
    xml.start("IncludedObjectVersions").value(config.getIncludedObjectVersions()).end();
    writeInventoryDestination(xml, config.getDestination());
    writeInventoryFilter(xml, config.getInventoryFilter());
    addInventorySchedule(xml, config.getSchedule());
    addInventoryOptionalFields(xml, config.getOptionalFields());
    // </InventoryConfiguration>
    xml.end();
    return xml.getBytes();
}
Also used : XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Example 3 with InventoryConfiguration

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

the class BucketInventorySaxUnmarshallerTest method getResponse_unmarshalls_properly.

@Test
public void getResponse_unmarshalls_properly() throws Exception {
    InventoryConfiguration configuration = parseGetBucketInventoryConfigurationResponse(GET_RESPONSE).getInventoryConfiguration();
    assertEquals("inventory-id", configuration.getId());
    InventoryS3BucketDestination s3BucketDestination = configuration.getDestination().getS3BucketDestination();
    assertEquals(InventoryFormat.CSV.toString(), s3BucketDestination.getFormat());
    assertEquals("accountId", s3BucketDestination.getAccountId());
    assertEquals("arn:aws:s3:::bucket", s3BucketDestination.getBucketArn());
    assertEquals("prefix", s3BucketDestination.getPrefix());
    assertTrue(configuration.isEnabled());
    assertEquals("prefix", ((InventoryPrefixPredicate) configuration.getInventoryFilter().getPredicate()).getPrefix());
    assertEquals(InventoryIncludedObjectVersions.All.toString(), configuration.getIncludedObjectVersions());
    List<String> optionalFields = configuration.getOptionalFields();
    assertEquals(3, optionalFields.size());
    assertTrue(optionalFields.containsAll(Arrays.asList(InventoryOptionalField.LastModifiedDate.toString(), InventoryOptionalField.StorageClass.toString(), InventoryOptionalField.ReplicationStatus.toString())));
    assertFalse(optionalFields.contains(InventoryOptionalField.Size.toString()));
    assertEquals(InventoryFrequency.Daily.toString(), configuration.getSchedule().getFrequency());
}
Also used : InventoryS3BucketDestination(com.amazonaws.services.s3.model.inventory.InventoryS3BucketDestination) InventoryConfiguration(com.amazonaws.services.s3.model.inventory.InventoryConfiguration) Test(org.junit.Test)

Example 4 with InventoryConfiguration

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

the class BucketInventorySaxUnmarshallerTest method listResponse_unmarshalls_properly.

@Test
public void listResponse_unmarshalls_properly() throws Exception {
    ListBucketInventoryConfigurationsResult result = parseListBucketInventoryConfigurationsResponse(LIST_RESPONSE);
    assertTrue(result.isTruncated());
    assertEquals("token1", result.getContinuationToken());
    assertEquals("token2", result.getNextContinuationToken());
    List<InventoryConfiguration> inventoryConfigurationList = result.getInventoryConfigurationList();
    assertEquals(2, inventoryConfigurationList.size());
    InventoryConfiguration configuration = inventoryConfigurationList.get(0);
    assertEquals("configId", configuration.getId());
    InventoryS3BucketDestination s3BucketDestination = configuration.getDestination().getS3BucketDestination();
    assertEquals(InventoryFormat.CSV.toString(), s3BucketDestination.getFormat());
    assertEquals("accountId", s3BucketDestination.getAccountId());
    assertEquals("arn:aws:s3:::bucket", s3BucketDestination.getBucketArn());
    assertEquals("prefix", s3BucketDestination.getPrefix());
    assertTrue(configuration.isEnabled());
    assertEquals("prefix", ((InventoryPrefixPredicate) configuration.getInventoryFilter().getPredicate()).getPrefix());
    assertEquals(InventoryIncludedObjectVersions.All.toString(), configuration.getIncludedObjectVersions());
    List<String> optionalFields = configuration.getOptionalFields();
    assertEquals(3, optionalFields.size());
    assertTrue(optionalFields.containsAll(Arrays.asList(InventoryOptionalField.LastModifiedDate.toString(), InventoryOptionalField.StorageClass.toString(), InventoryOptionalField.ReplicationStatus.toString())));
    assertFalse(optionalFields.contains(InventoryOptionalField.Size.toString()));
    assertEquals(InventoryFrequency.Daily.toString(), configuration.getSchedule().getFrequency());
    // Assert second Inventory configuration
    configuration = inventoryConfigurationList.get(1);
    assertEquals("configId2", configuration.getId());
    assertNull(configuration.getInventoryFilter().getPredicate());
}
Also used : InventoryS3BucketDestination(com.amazonaws.services.s3.model.inventory.InventoryS3BucketDestination) InventoryConfiguration(com.amazonaws.services.s3.model.inventory.InventoryConfiguration) ListBucketInventoryConfigurationsResult(com.amazonaws.services.s3.model.ListBucketInventoryConfigurationsResult) Test(org.junit.Test)

Aggregations

InventoryConfiguration (com.amazonaws.services.s3.model.inventory.InventoryConfiguration)3 InventoryS3BucketDestination (com.amazonaws.services.s3.model.inventory.InventoryS3BucketDestination)2 Test (org.junit.Test)2 XmlWriter (com.amazonaws.services.s3.internal.XmlWriter)1 ListBucketInventoryConfigurationsResult (com.amazonaws.services.s3.model.ListBucketInventoryConfigurationsResult)1 Unmarshallers (com.amazonaws.services.s3.model.transform.Unmarshallers)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1