Search in sources :

Example 1 with Website

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

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

the class BucketInfo method toPb.

com.google.api.services.storage.model.Bucket toPb() {
    com.google.api.services.storage.model.Bucket bucketPb = new com.google.api.services.storage.model.Bucket();
    bucketPb.setId(generatedId);
    bucketPb.setName(name);
    bucketPb.setEtag(etag);
    if (createTime != null) {
        bucketPb.setTimeCreated(new DateTime(createTime));
    }
    if (metageneration != null) {
        bucketPb.setMetageneration(metageneration);
    }
    if (location != null) {
        bucketPb.setLocation(location);
    }
    if (storageClass != null) {
        bucketPb.setStorageClass(storageClass.toString());
    }
    if (cors != null) {
        bucketPb.setCors(transform(cors, Cors.TO_PB_FUNCTION));
    }
    if (acl != null) {
        bucketPb.setAcl(transform(acl, new Function<Acl, BucketAccessControl>() {

            @Override
            public BucketAccessControl apply(Acl acl) {
                return acl.toBucketPb();
            }
        }));
    }
    if (defaultAcl != null) {
        bucketPb.setDefaultObjectAcl(transform(defaultAcl, new Function<Acl, ObjectAccessControl>() {

            @Override
            public ObjectAccessControl apply(Acl acl) {
                return acl.toObjectPb();
            }
        }));
    }
    if (owner != null) {
        bucketPb.setOwner(new Owner().setEntity(owner.toPb()));
    }
    bucketPb.setSelfLink(selfLink);
    if (versioningEnabled != null) {
        bucketPb.setVersioning(new Versioning().setEnabled(versioningEnabled));
    }
    if (indexPage != null || notFoundPage != null) {
        Website website = new Website();
        website.setMainPageSuffix(indexPage);
        website.setNotFoundPage(notFoundPage);
        bucketPb.setWebsite(website);
    }
    if (deleteRules != null) {
        Lifecycle lifecycle = new Lifecycle();
        lifecycle.setRule(transform(deleteRules, new Function<DeleteRule, Rule>() {

            @Override
            public Rule apply(DeleteRule deleteRule) {
                return deleteRule.toPb();
            }
        }));
        bucketPb.setLifecycle(lifecycle);
    }
    return bucketPb;
}
Also used : Owner(com.google.api.services.storage.model.Bucket.Owner) Lifecycle(com.google.api.services.storage.model.Bucket.Lifecycle) Website(com.google.api.services.storage.model.Bucket.Website) DateTime(com.google.api.client.util.DateTime) Function(com.google.common.base.Function) Versioning(com.google.api.services.storage.model.Bucket.Versioning)

Aggregations

Website (com.google.api.services.storage.model.Bucket.Website)2 Function (com.google.common.base.Function)2 DateTime (com.google.api.client.util.DateTime)1 Lifecycle (com.google.api.services.storage.model.Bucket.Lifecycle)1 Rule (com.google.api.services.storage.model.Bucket.Lifecycle.Rule)1 Owner (com.google.api.services.storage.model.Bucket.Owner)1 Versioning (com.google.api.services.storage.model.Bucket.Versioning)1 BucketAccessControl (com.google.api.services.storage.model.BucketAccessControl)1 ObjectAccessControl (com.google.api.services.storage.model.ObjectAccessControl)1