Search in sources :

Example 1 with ObjectAccessControl

use of com.google.api.services.storage.model.ObjectAccessControl 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 ObjectAccessControl

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

the class Acl method toObjectPb.

ObjectAccessControl toObjectPb() {
    ObjectAccessControl objectPb = new ObjectAccessControl();
    objectPb.setEntity(getEntity().toPb());
    objectPb.setRole(getRole().name());
    objectPb.setId(getId());
    objectPb.setEtag(getEtag());
    return objectPb;
}
Also used : ObjectAccessControl(com.google.api.services.storage.model.ObjectAccessControl)

Example 3 with ObjectAccessControl

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

the class AclTest method testOf.

@Test
public void testOf() {
    Acl acl = Acl.of(User.ofAllUsers(), Role.READER);
    assertEquals(User.ofAllUsers(), acl.getEntity());
    assertEquals(Role.READER, acl.getRole());
    ObjectAccessControl objectPb = acl.toObjectPb();
    assertEquals(acl, Acl.fromPb(objectPb));
    BucketAccessControl bucketPb = acl.toBucketPb();
    assertEquals(acl, Acl.fromPb(bucketPb));
}
Also used : BucketAccessControl(com.google.api.services.storage.model.BucketAccessControl) ObjectAccessControl(com.google.api.services.storage.model.ObjectAccessControl) Test(org.junit.Test)

Aggregations

ObjectAccessControl (com.google.api.services.storage.model.ObjectAccessControl)3 BucketAccessControl (com.google.api.services.storage.model.BucketAccessControl)2 Rule (com.google.api.services.storage.model.Bucket.Lifecycle.Rule)1 Website (com.google.api.services.storage.model.Bucket.Website)1 Function (com.google.common.base.Function)1 Test (org.junit.Test)1