Search in sources :

Example 1 with Rule

use of com.google.api.services.storage.model.Bucket.Lifecycle.Rule in project google-cloud-java by GoogleCloudPlatform.

the class BucketInfo method fromPb.

static BucketInfo fromPb(com.google.api.services.storage.model.Bucket bucketPb) {
    Builder builder = new BuilderImpl(bucketPb.getName());
    if (bucketPb.getId() != null) {
        builder.setGeneratedId(bucketPb.getId());
    }
    if (bucketPb.getEtag() != null) {
        builder.setEtag(bucketPb.getEtag());
    }
    if (bucketPb.getMetageneration() != null) {
        builder.setMetageneration(bucketPb.getMetageneration());
    }
    if (bucketPb.getSelfLink() != null) {
        builder.setSelfLink(bucketPb.getSelfLink());
    }
    if (bucketPb.getTimeCreated() != null) {
        builder.setCreateTime(bucketPb.getTimeCreated().getValue());
    }
    if (bucketPb.getLocation() != null) {
        builder.setLocation(bucketPb.getLocation());
    }
    if (bucketPb.getStorageClass() != null) {
        builder.setStorageClass(StorageClass.valueOf(bucketPb.getStorageClass()));
    }
    if (bucketPb.getCors() != null) {
        builder.setCors(transform(bucketPb.getCors(), Cors.FROM_PB_FUNCTION));
    }
    if (bucketPb.getAcl() != null) {
        builder.setAcl(transform(bucketPb.getAcl(), new Function<BucketAccessControl, Acl>() {

            @Override
            public Acl apply(BucketAccessControl bucketAccessControl) {
                return Acl.fromPb(bucketAccessControl);
            }
        }));
    }
    if (bucketPb.getDefaultObjectAcl() != null) {
        builder.setDefaultAcl(transform(bucketPb.getDefaultObjectAcl(), new Function<ObjectAccessControl, Acl>() {

            @Override
            public Acl apply(ObjectAccessControl objectAccessControl) {
                return Acl.fromPb(objectAccessControl);
            }
        }));
    }
    if (bucketPb.getOwner() != null) {
        builder.setOwner(Entity.fromPb(bucketPb.getOwner().getEntity()));
    }
    if (bucketPb.getVersioning() != null) {
        builder.setVersioningEnabled(bucketPb.getVersioning().getEnabled());
    }
    Website website = bucketPb.getWebsite();
    if (website != null) {
        builder.setIndexPage(website.getMainPageSuffix());
        builder.setNotFoundPage(website.getNotFoundPage());
    }
    if (bucketPb.getLifecycle() != null && bucketPb.getLifecycle().getRule() != null) {
        builder.setDeleteRules(transform(bucketPb.getLifecycle().getRule(), new Function<Rule, DeleteRule>() {

            @Override
            public DeleteRule apply(Rule rule) {
                return DeleteRule.fromPb(rule);
            }
        }));
    }
    return builder.build();
}
Also used : Function(com.google.common.base.Function) BucketAccessControl(com.google.api.services.storage.model.BucketAccessControl) Website(com.google.api.services.storage.model.Bucket.Website) ObjectAccessControl(com.google.api.services.storage.model.ObjectAccessControl) Rule(com.google.api.services.storage.model.Bucket.Lifecycle.Rule)

Example 2 with Rule

use of com.google.api.services.storage.model.Bucket.Lifecycle.Rule in project google-cloud-java by GoogleCloudPlatform.

the class BucketInfoTest method testDeleteRules.

@Test
public void testDeleteRules() {
    AgeDeleteRule ageRule = new AgeDeleteRule(10);
    assertEquals(10, ageRule.getDaysToLive());
    assertEquals(10, ageRule.getDaysToLive());
    assertEquals(Type.AGE, ageRule.getType());
    assertEquals(Type.AGE, ageRule.getType());
    CreatedBeforeDeleteRule createBeforeRule = new CreatedBeforeDeleteRule(1);
    assertEquals(1, createBeforeRule.getTimeMillis());
    assertEquals(1, createBeforeRule.getTimeMillis());
    assertEquals(Type.CREATE_BEFORE, createBeforeRule.getType());
    NumNewerVersionsDeleteRule versionsRule = new NumNewerVersionsDeleteRule(2);
    assertEquals(2, versionsRule.getNumNewerVersions());
    assertEquals(2, versionsRule.getNumNewerVersions());
    assertEquals(Type.NUM_NEWER_VERSIONS, versionsRule.getType());
    IsLiveDeleteRule isLiveRule = new IsLiveDeleteRule(true);
    assertTrue(isLiveRule.isLive());
    assertEquals(Type.IS_LIVE, isLiveRule.getType());
    assertEquals(Type.IS_LIVE, isLiveRule.getType());
    Rule rule = new Rule().set("a", "b");
    RawDeleteRule rawRule = new RawDeleteRule(rule);
    assertEquals(Type.IS_LIVE, isLiveRule.getType());
    assertEquals(Type.IS_LIVE, isLiveRule.getType());
    ImmutableList<DeleteRule> rules = ImmutableList.of(ageRule, createBeforeRule, versionsRule, isLiveRule, rawRule);
    for (DeleteRule delRule : rules) {
        assertEquals(delRule, DeleteRule.fromPb(delRule.toPb()));
    }
}
Also used : AgeDeleteRule(com.google.cloud.storage.BucketInfo.AgeDeleteRule) CreatedBeforeDeleteRule(com.google.cloud.storage.BucketInfo.CreatedBeforeDeleteRule) NumNewerVersionsDeleteRule(com.google.cloud.storage.BucketInfo.NumNewerVersionsDeleteRule) IsLiveDeleteRule(com.google.cloud.storage.BucketInfo.IsLiveDeleteRule) NumNewerVersionsDeleteRule(com.google.cloud.storage.BucketInfo.NumNewerVersionsDeleteRule) CreatedBeforeDeleteRule(com.google.cloud.storage.BucketInfo.CreatedBeforeDeleteRule) AgeDeleteRule(com.google.cloud.storage.BucketInfo.AgeDeleteRule) IsLiveDeleteRule(com.google.cloud.storage.BucketInfo.IsLiveDeleteRule) RawDeleteRule(com.google.cloud.storage.BucketInfo.RawDeleteRule) DeleteRule(com.google.cloud.storage.BucketInfo.DeleteRule) RawDeleteRule(com.google.cloud.storage.BucketInfo.RawDeleteRule) Rule(com.google.api.services.storage.model.Bucket.Lifecycle.Rule) NumNewerVersionsDeleteRule(com.google.cloud.storage.BucketInfo.NumNewerVersionsDeleteRule) CreatedBeforeDeleteRule(com.google.cloud.storage.BucketInfo.CreatedBeforeDeleteRule) AgeDeleteRule(com.google.cloud.storage.BucketInfo.AgeDeleteRule) IsLiveDeleteRule(com.google.cloud.storage.BucketInfo.IsLiveDeleteRule) RawDeleteRule(com.google.cloud.storage.BucketInfo.RawDeleteRule) DeleteRule(com.google.cloud.storage.BucketInfo.DeleteRule) Test(org.junit.Test)

Aggregations

Rule (com.google.api.services.storage.model.Bucket.Lifecycle.Rule)2 Website (com.google.api.services.storage.model.Bucket.Website)1 BucketAccessControl (com.google.api.services.storage.model.BucketAccessControl)1 ObjectAccessControl (com.google.api.services.storage.model.ObjectAccessControl)1 AgeDeleteRule (com.google.cloud.storage.BucketInfo.AgeDeleteRule)1 CreatedBeforeDeleteRule (com.google.cloud.storage.BucketInfo.CreatedBeforeDeleteRule)1 DeleteRule (com.google.cloud.storage.BucketInfo.DeleteRule)1 IsLiveDeleteRule (com.google.cloud.storage.BucketInfo.IsLiveDeleteRule)1 NumNewerVersionsDeleteRule (com.google.cloud.storage.BucketInfo.NumNewerVersionsDeleteRule)1 RawDeleteRule (com.google.cloud.storage.BucketInfo.RawDeleteRule)1 Function (com.google.common.base.Function)1 Test (org.junit.Test)1