diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/Bucket.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/Bucket.java index 6aa7aaec9b..f3c529102f 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/Bucket.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/Bucket.java @@ -35,6 +35,7 @@ import java.io.InputStream; import java.io.ObjectInputStream; import java.io.Serializable; +import java.math.BigInteger; import java.security.Key; import java.time.Duration; import java.time.OffsetDateTime; @@ -631,6 +632,12 @@ Builder setMetageneration(Long metageneration) { return this; } + @Override + Builder setProjectNumber(BigInteger projectNumber) { + infoBuilder.setProjectNumber(projectNumber); + return this; + } + @Override public Builder setCors(Iterable cors) { infoBuilder.setCors(cors); @@ -857,6 +864,12 @@ Builder clearMetageneration() { return this; } + @Override + Builder clearProjectNumber() { + infoBuilder.clearProjectNumber(); + return this; + } + @Override Builder clearCors() { infoBuilder.clearCors(); diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java index 3235559222..1087cf8864 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java @@ -45,6 +45,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.math.BigInteger; import java.time.Duration; import java.time.OffsetDateTime; import java.util.ArrayList; @@ -100,6 +101,7 @@ public class BucketInfo implements Serializable { private final OffsetDateTime createTime; private final OffsetDateTime updateTime; private final Long metageneration; + private final BigInteger projectNumber; private final List cors; private final List acl; private final List defaultAcl; @@ -1747,6 +1749,8 @@ Builder setUpdateTimeOffsetDateTime(OffsetDateTime updateTime) { return this; } + abstract Builder setProjectNumber(BigInteger projectNumber); + abstract Builder setMetageneration(Long metageneration); abstract Builder setLocationType(String locationType); @@ -1878,6 +1882,8 @@ public Builder setRetentionPeriodDuration(Duration retentionPeriod) { abstract Builder clearMetageneration(); + abstract Builder clearProjectNumber(); + abstract Builder clearCors(); abstract Builder clearAcl(); @@ -1924,6 +1930,7 @@ static final class BuilderImpl extends Builder { private OffsetDateTime createTime; private OffsetDateTime updateTime; private Long metageneration; + private BigInteger projectNumber; private List cors; private List acl; private List defaultAcl; @@ -1956,6 +1963,7 @@ static final class BuilderImpl extends Builder { createTime = bucketInfo.createTime; updateTime = bucketInfo.updateTime; metageneration = bucketInfo.metageneration; + projectNumber = bucketInfo.projectNumber; location = bucketInfo.location; rpo = bucketInfo.rpo; storageClass = bucketInfo.storageClass; @@ -2194,6 +2202,12 @@ Builder setMetageneration(Long metageneration) { return this; } + @Override + Builder setProjectNumber(BigInteger projectNumber) { + this.projectNumber = projectNumber; + return this; + } + @Override public Builder setCors(Iterable cors) { ImmutableList tmp = cors != null ? ImmutableList.copyOf(cors) : ImmutableList.of(); @@ -2483,6 +2497,12 @@ BuilderImpl clearMetageneration() { return this; } + @Override + BuilderImpl clearProjectNumber() { + this.projectNumber = null; + return this; + } + @Override BuilderImpl clearCors() { this.cors = null; @@ -2582,6 +2602,7 @@ private Builder clearDeleteLifecycleRules() { createTime = builder.createTime; updateTime = builder.updateTime; metageneration = builder.metageneration; + projectNumber = builder.projectNumber; location = builder.location; rpo = builder.rpo; storageClass = builder.storageClass; @@ -2755,6 +2776,11 @@ public Long getMetageneration() { return metageneration; } + /** Returns the project number of the bucket. */ + public BigInteger getProjectNumber() { + return projectNumber; + } + /** * Returns the bucket's location. Data for blobs in the bucket resides in physical storage within * this region or regions. If specifying more than one region `customPlacementConfig` should be @@ -2980,6 +3006,7 @@ public int hashCode() { createTime, updateTime, metageneration, + projectNumber, cors, acl, defaultAcl, @@ -3023,6 +3050,7 @@ public boolean equals(Object o) { && Objects.equals(createTime, that.createTime) && Objects.equals(updateTime, that.updateTime) && Objects.equals(metageneration, that.metageneration) + && Objects.equals(projectNumber, that.projectNumber) && Objects.equals(cors, that.cors) && Objects.equals(acl, that.acl) && Objects.equals(defaultAcl, that.defaultAcl) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/JsonConversions.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/JsonConversions.java index 12562cb020..0313cf52d2 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/JsonConversions.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/JsonConversions.java @@ -402,6 +402,7 @@ private Bucket bucketInfoEncode(BucketInfo from) { ifNonNull(from.getLocation(), to::setLocation); ifNonNull(from.getLocationType(), to::setLocationType); ifNonNull(from.getMetageneration(), to::setMetageneration); + ifNonNull(from.getProjectNumber(), to::setProjectNumber); ifNonNull( from.getOwner(), lift(this::entityEncode).andThen(o -> new Bucket.Owner().setEntity(o)), @@ -489,6 +490,7 @@ private BucketInfo bucketInfoDecode(com.google.api.services.storage.model.Bucket ifNonNull(from.getLocation(), to::setLocation); ifNonNull(from.getLocationType(), to::setLocationType); ifNonNull(from.getMetageneration(), to::setMetageneration); + ifNonNull(from.getProjectNumber(), to::setProjectNumber); ifNonNull( from.getOwner(), lift(Bucket.Owner::getEntity).andThen(this::entityDecode), to::setOwner); ifNonNull(from.getRpo(), Rpo::valueOf, to::setRpo); diff --git a/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java b/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java index 2e3cb4bd9f..90a174b7b8 100644 --- a/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java +++ b/google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java @@ -48,6 +48,7 @@ import com.google.common.collect.ImmutableList; import java.io.IOException; import java.io.StringWriter; +import java.math.BigInteger; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -110,6 +111,7 @@ public class BucketInfoTest { private static final List LOCATION_TYPES = ImmutableList.of("multi-region", "region", "dual-region"); private static final String LOCATION_TYPE = "multi-region"; + private static final BigInteger PROJECT_NUMBER = BigInteger.valueOf(42); @SuppressWarnings({"unchecked", "deprecation"}) private static final BucketInfo BUCKET_INFO = @@ -118,6 +120,7 @@ public class BucketInfoTest { .setEtag(ETAG) .setGeneratedId(GENERATED_ID) .setMetageneration(META_GENERATION) + .setProjectNumber(PROJECT_NUMBER) .setOwner(OWNER) .setSelfLink(SELF_LINK) .setCors(CORS) @@ -150,6 +153,7 @@ public class BucketInfoTest { .setEtag(ETAG) .setGeneratedId(GENERATED_ID) .setMetageneration(META_GENERATION) + .setProjectNumber(PROJECT_NUMBER) .setOwner(OWNER) .setSelfLink(SELF_LINK) .setCors(CORS) @@ -209,6 +213,7 @@ public void testBuilder() throws Exception { () -> assertEquals(ETAG, BUCKET_INFO.getEtag()), () -> assertEquals(GENERATED_ID, BUCKET_INFO.getGeneratedId()), () -> assertEquals(META_GENERATION, BUCKET_INFO.getMetageneration()), + () -> assertEquals(PROJECT_NUMBER, BUCKET_INFO.getProjectNumber()), () -> assertEquals(OWNER, BUCKET_INFO.getOwner()), () -> assertEquals(SELF_LINK, BUCKET_INFO.getSelfLink()), () -> assertEquals(CREATE_TIME, BUCKET_INFO.getCreateTime()), @@ -290,6 +295,7 @@ private void compareBuckets(BucketInfo expected, BucketInfo value) throws Except assertEquals(expected.getRetentionPeriodDuration(), value.getRetentionPeriodDuration()), () -> assertEquals(expected.retentionPolicyIsLocked(), value.retentionPolicyIsLocked()), () -> assertEquals(expected.getLogging(), value.getLogging()), + () -> assertEquals(expected.getProjectNumber(), value.getProjectNumber()), () -> assertEquals(expected, value)); }