Search in sources :

Example 1 with LifecycleFilterPredicate

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

the class BucketLifecycleSaxUnmarshallerTest method unmarshalls_filter_with_AndOperator_containing_prefixAndOneTag.

@Test
public void unmarshalls_filter_with_AndOperator_containing_prefixAndOneTag() throws Exception {
    Rule rule = getRule(parseLifecycleConfiguration(UNKNOWN_STORAGE_CLASS_RESPONSE), 4);
    LifecycleAndOperator predicate = (LifecycleAndOperator) rule.getFilter().getPredicate();
    List<LifecycleFilterPredicate> operands = predicate.getOperands();
    assertEquals(2, operands.size());
    assertEquals("prefix", ((LifecyclePrefixPredicate) operands.get(0)).getPrefix());
    Tag tag = ((LifecycleTagPredicate) operands.get(1)).getTag();
    assertEquals("key1", tag.getKey());
    assertEquals("value1", tag.getValue());
}
Also used : LifecycleAndOperator(com.amazonaws.services.s3.model.lifecycle.LifecycleAndOperator) LifecycleTagPredicate(com.amazonaws.services.s3.model.lifecycle.LifecycleTagPredicate) LifecycleFilterPredicate(com.amazonaws.services.s3.model.lifecycle.LifecycleFilterPredicate) Rule(com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule) Tag(com.amazonaws.services.s3.model.Tag) Test(org.junit.Test)

Example 2 with LifecycleFilterPredicate

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

the class BucketLifecycleSaxUnmarshallerTest method lifecycleConfigurationUnmarshaller_unmarshalls_properly.

@Test
public void lifecycleConfigurationUnmarshaller_unmarshalls_properly() throws Exception {
    Rule rule = getRule(parseLifecycleConfiguration(UNKNOWN_STORAGE_CLASS_RESPONSE), 0);
    assertEquals("logs-rule", rule.getId());
    assertEquals("logs/", rule.getPrefix());
    assertEquals(BucketLifecycleConfiguration.ENABLED, rule.getStatus());
    Transition transition = rule.getTransitions().get(0);
    assertEquals(30, transition.getDays());
    assertEquals(FUTURE_STORAGE_CLASS, transition.getStorageClassAsString());
    assertEquals(365, rule.getExpirationInDays());
    NoncurrentVersionTransition noncurrentVersionTransition = rule.getNoncurrentVersionTransitions().get(0);
    assertEquals(7, noncurrentVersionTransition.getDays());
    assertEquals(14, rule.getNoncurrentVersionExpirationInDays());
    // Test Filter
    LifecycleFilterPredicate predicate = rule.getFilter().getPredicate();
    assertTrue(predicate instanceof LifecycleAndOperator);
    List<LifecycleFilterPredicate> andOperands = ((LifecycleAndOperator) predicate).getOperands();
    assertEquals("prefix", ((LifecyclePrefixPredicate) andOperands.get(0)).getPrefix());
    assertEquals("key1", ((LifecycleTagPredicate) andOperands.get(1)).getTag().getKey());
    assertEquals("value1", ((LifecycleTagPredicate) andOperands.get(1)).getTag().getValue());
    assertEquals("key2", ((LifecycleTagPredicate) andOperands.get(2)).getTag().getKey());
    assertEquals("value2", ((LifecycleTagPredicate) andOperands.get(2)).getTag().getValue());
}
Also used : LifecycleAndOperator(com.amazonaws.services.s3.model.lifecycle.LifecycleAndOperator) LifecycleTagPredicate(com.amazonaws.services.s3.model.lifecycle.LifecycleTagPredicate) LifecycleFilterPredicate(com.amazonaws.services.s3.model.lifecycle.LifecycleFilterPredicate) Rule(com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule) Test(org.junit.Test)

Example 3 with LifecycleFilterPredicate

use of com.amazonaws.services.s3.model.lifecycle.LifecycleFilterPredicate in project nexus-public by sonatype.

the class BucketManager method makeLifecycleConfiguration.

private BucketLifecycleConfiguration makeLifecycleConfiguration(final BucketLifecycleConfiguration existing, final BlobStoreConfiguration blobStoreConfiguration) {
    String blobStoreName = blobStoreConfiguration.getName();
    String bucketPrefix = getBucketPrefix(blobStoreConfiguration);
    int expirationInDays = getConfiguredExpirationInDays(blobStoreConfiguration);
    LifecycleFilterPredicate filterPredicate;
    if (bucketPrefix.isEmpty()) {
        filterPredicate = new LifecycleTagPredicate(S3BlobStore.DELETED_TAG);
    } else {
        filterPredicate = new LifecycleAndOperator(asList(new LifecyclePrefixPredicate(bucketPrefix), new LifecycleTagPredicate(S3BlobStore.DELETED_TAG)));
    }
    BucketLifecycleConfiguration.Rule rule = new BucketLifecycleConfiguration.Rule().withId(LIFECYCLE_EXPIRATION_RULE_ID_PREFIX + blobStoreName).withFilter(new LifecycleFilter(filterPredicate)).withExpirationInDays(expirationInDays).withStatus(BucketLifecycleConfiguration.ENABLED);
    BucketLifecycleConfiguration newConfiguration = null;
    if (existing != null && !existing.getRules().isEmpty()) {
        List<Rule> rules = nonBlobstoreRules(existing, blobStoreName);
        if (expirationInDays > 0) {
            rules.add(rule);
        }
        if (!rules.isEmpty()) {
            existing.setRules(rules);
            newConfiguration = existing;
        }
    } else {
        if (expirationInDays > 0) {
            newConfiguration = new BucketLifecycleConfiguration().withRules(rule);
        }
    }
    return newConfiguration;
}
Also used : BucketLifecycleConfiguration(com.amazonaws.services.s3.model.BucketLifecycleConfiguration) LifecycleAndOperator(com.amazonaws.services.s3.model.lifecycle.LifecycleAndOperator) LifecyclePrefixPredicate(com.amazonaws.services.s3.model.lifecycle.LifecyclePrefixPredicate) LifecycleFilter(com.amazonaws.services.s3.model.lifecycle.LifecycleFilter) LifecycleTagPredicate(com.amazonaws.services.s3.model.lifecycle.LifecycleTagPredicate) LifecycleFilterPredicate(com.amazonaws.services.s3.model.lifecycle.LifecycleFilterPredicate) Rule(com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule) Rule(com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule)

Example 4 with LifecycleFilterPredicate

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

the class BucketLifecycleSaxUnmarshallerTest method unmarshalls_filter_with_AndOperator_containing_multipleTags.

@Test
public void unmarshalls_filter_with_AndOperator_containing_multipleTags() throws Exception {
    Rule rule = getRule(parseLifecycleConfiguration(UNKNOWN_STORAGE_CLASS_RESPONSE), 5);
    LifecycleAndOperator predicate = (LifecycleAndOperator) rule.getFilter().getPredicate();
    List<LifecycleFilterPredicate> operands = predicate.getOperands();
    assertEquals(3, operands.size());
    assertEquals("key0", ((LifecycleTagPredicate) operands.get(0)).getTag().getKey());
    assertEquals("value0", ((LifecycleTagPredicate) operands.get(0)).getTag().getValue());
    assertEquals("key1", ((LifecycleTagPredicate) operands.get(1)).getTag().getKey());
    assertEquals("value1", ((LifecycleTagPredicate) operands.get(1)).getTag().getValue());
    assertEquals("key2", ((LifecycleTagPredicate) operands.get(2)).getTag().getKey());
    assertEquals("value2", ((LifecycleTagPredicate) operands.get(2)).getTag().getValue());
}
Also used : LifecycleAndOperator(com.amazonaws.services.s3.model.lifecycle.LifecycleAndOperator) LifecycleTagPredicate(com.amazonaws.services.s3.model.lifecycle.LifecycleTagPredicate) LifecycleFilterPredicate(com.amazonaws.services.s3.model.lifecycle.LifecycleFilterPredicate) Rule(com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule) Test(org.junit.Test)

Aggregations

Rule (com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule)4 LifecycleAndOperator (com.amazonaws.services.s3.model.lifecycle.LifecycleAndOperator)4 LifecycleFilterPredicate (com.amazonaws.services.s3.model.lifecycle.LifecycleFilterPredicate)4 LifecycleTagPredicate (com.amazonaws.services.s3.model.lifecycle.LifecycleTagPredicate)4 Test (org.junit.Test)3 BucketLifecycleConfiguration (com.amazonaws.services.s3.model.BucketLifecycleConfiguration)1 Tag (com.amazonaws.services.s3.model.Tag)1 LifecycleFilter (com.amazonaws.services.s3.model.lifecycle.LifecycleFilter)1 LifecyclePrefixPredicate (com.amazonaws.services.s3.model.lifecycle.LifecyclePrefixPredicate)1