Skip to content

Commit 5489662

Browse files
committed
feat: Add bucket.getProjectNumber
1 parent 62b6248 commit 5489662

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/Bucket.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.io.InputStream;
3636
import java.io.ObjectInputStream;
3737
import java.io.Serializable;
38+
import java.math.BigInteger;
3839
import java.security.Key;
3940
import java.time.Duration;
4041
import java.time.OffsetDateTime;
@@ -631,6 +632,12 @@ Builder setMetageneration(Long metageneration) {
631632
return this;
632633
}
633634

635+
@Override
636+
Builder setProjectNumber(BigInteger projectNumber) {
637+
infoBuilder.setProjectNumber(projectNumber);
638+
return this;
639+
}
640+
634641
@Override
635642
public Builder setCors(Iterable<Cors> cors) {
636643
infoBuilder.setCors(cors);
@@ -857,6 +864,12 @@ Builder clearMetageneration() {
857864
return this;
858865
}
859866

867+
@Override
868+
Builder clearProjectNumber() {
869+
infoBuilder.clearProjectNumber();
870+
return this;
871+
}
872+
860873
@Override
861874
Builder clearCors() {
862875
infoBuilder.clearCors();

google-cloud-storage/src/main/java/com/google/cloud/storage/BucketInfo.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.io.ObjectInputStream;
4646
import java.io.ObjectOutputStream;
4747
import java.io.Serializable;
48+
import java.math.BigInteger;
4849
import java.time.Duration;
4950
import java.time.OffsetDateTime;
5051
import java.util.ArrayList;
@@ -100,6 +101,7 @@ public class BucketInfo implements Serializable {
100101
private final OffsetDateTime createTime;
101102
private final OffsetDateTime updateTime;
102103
private final Long metageneration;
104+
private final BigInteger projectNumber;
103105
private final List<Cors> cors;
104106
private final List<Acl> acl;
105107
private final List<Acl> defaultAcl;
@@ -1747,6 +1749,8 @@ Builder setUpdateTimeOffsetDateTime(OffsetDateTime updateTime) {
17471749
return this;
17481750
}
17491751

1752+
abstract Builder setProjectNumber(BigInteger projectNumber);
1753+
17501754
abstract Builder setMetageneration(Long metageneration);
17511755

17521756
abstract Builder setLocationType(String locationType);
@@ -1878,6 +1882,8 @@ public Builder setRetentionPeriodDuration(Duration retentionPeriod) {
18781882

18791883
abstract Builder clearMetageneration();
18801884

1885+
abstract Builder clearProjectNumber();
1886+
18811887
abstract Builder clearCors();
18821888

18831889
abstract Builder clearAcl();
@@ -1924,6 +1930,7 @@ static final class BuilderImpl extends Builder {
19241930
private OffsetDateTime createTime;
19251931
private OffsetDateTime updateTime;
19261932
private Long metageneration;
1933+
private BigInteger projectNumber;
19271934
private List<Cors> cors;
19281935
private List<Acl> acl;
19291936
private List<Acl> defaultAcl;
@@ -1956,6 +1963,7 @@ static final class BuilderImpl extends Builder {
19561963
createTime = bucketInfo.createTime;
19571964
updateTime = bucketInfo.updateTime;
19581965
metageneration = bucketInfo.metageneration;
1966+
projectNumber = bucketInfo.projectNumber;
19591967
location = bucketInfo.location;
19601968
rpo = bucketInfo.rpo;
19611969
storageClass = bucketInfo.storageClass;
@@ -2194,6 +2202,12 @@ Builder setMetageneration(Long metageneration) {
21942202
return this;
21952203
}
21962204

2205+
@Override
2206+
Builder setProjectNumber(BigInteger projectNumber) {
2207+
this.projectNumber = projectNumber;
2208+
return this;
2209+
}
2210+
21972211
@Override
21982212
public Builder setCors(Iterable<Cors> cors) {
21992213
ImmutableList<Cors> tmp = cors != null ? ImmutableList.copyOf(cors) : ImmutableList.of();
@@ -2483,6 +2497,12 @@ BuilderImpl clearMetageneration() {
24832497
return this;
24842498
}
24852499

2500+
@Override
2501+
BuilderImpl clearProjectNumber() {
2502+
this.projectNumber = null;
2503+
return this;
2504+
}
2505+
24862506
@Override
24872507
BuilderImpl clearCors() {
24882508
this.cors = null;
@@ -2582,6 +2602,7 @@ private Builder clearDeleteLifecycleRules() {
25822602
createTime = builder.createTime;
25832603
updateTime = builder.updateTime;
25842604
metageneration = builder.metageneration;
2605+
projectNumber = builder.projectNumber;
25852606
location = builder.location;
25862607
rpo = builder.rpo;
25872608
storageClass = builder.storageClass;
@@ -2755,6 +2776,11 @@ public Long getMetageneration() {
27552776
return metageneration;
27562777
}
27572778

2779+
/** Returns the project number of the bucket. */
2780+
public BigInteger getProjectNumber() {
2781+
return projectNumber;
2782+
}
2783+
27582784
/**
27592785
* Returns the bucket's location. Data for blobs in the bucket resides in physical storage within
27602786
* this region or regions. If specifying more than one region `customPlacementConfig` should be
@@ -2980,6 +3006,7 @@ public int hashCode() {
29803006
createTime,
29813007
updateTime,
29823008
metageneration,
3009+
projectNumber,
29833010
cors,
29843011
acl,
29853012
defaultAcl,
@@ -3023,6 +3050,7 @@ public boolean equals(Object o) {
30233050
&& Objects.equals(createTime, that.createTime)
30243051
&& Objects.equals(updateTime, that.updateTime)
30253052
&& Objects.equals(metageneration, that.metageneration)
3053+
&& Objects.equals(projectNumber, that.projectNumber)
30263054
&& Objects.equals(cors, that.cors)
30273055
&& Objects.equals(acl, that.acl)
30283056
&& Objects.equals(defaultAcl, that.defaultAcl)

google-cloud-storage/src/main/java/com/google/cloud/storage/JsonConversions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ private Bucket bucketInfoEncode(BucketInfo from) {
402402
ifNonNull(from.getLocation(), to::setLocation);
403403
ifNonNull(from.getLocationType(), to::setLocationType);
404404
ifNonNull(from.getMetageneration(), to::setMetageneration);
405+
ifNonNull(from.getProjectNumber(), to::setProjectNumber);
405406
ifNonNull(
406407
from.getOwner(),
407408
lift(this::entityEncode).andThen(o -> new Bucket.Owner().setEntity(o)),
@@ -489,6 +490,7 @@ private BucketInfo bucketInfoDecode(com.google.api.services.storage.model.Bucket
489490
ifNonNull(from.getLocation(), to::setLocation);
490491
ifNonNull(from.getLocationType(), to::setLocationType);
491492
ifNonNull(from.getMetageneration(), to::setMetageneration);
493+
ifNonNull(from.getProjectNumber(), to::setProjectNumber);
492494
ifNonNull(
493495
from.getOwner(), lift(Bucket.Owner::getEntity).andThen(this::entityDecode), to::setOwner);
494496
ifNonNull(from.getRpo(), Rpo::valueOf, to::setRpo);

google-cloud-storage/src/test/java/com/google/cloud/storage/BucketInfoTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.google.common.collect.ImmutableList;
4949
import java.io.IOException;
5050
import java.io.StringWriter;
51+
import java.math.BigInteger;
5152
import java.util.Arrays;
5253
import java.util.Collections;
5354
import java.util.List;
@@ -110,6 +111,7 @@ public class BucketInfoTest {
110111
private static final List<String> LOCATION_TYPES =
111112
ImmutableList.of("multi-region", "region", "dual-region");
112113
private static final String LOCATION_TYPE = "multi-region";
114+
private static final BigInteger PROJECT_NUMBER = BigInteger.valueOf(42);
113115

114116
@SuppressWarnings({"unchecked", "deprecation"})
115117
private static final BucketInfo BUCKET_INFO =
@@ -118,6 +120,7 @@ public class BucketInfoTest {
118120
.setEtag(ETAG)
119121
.setGeneratedId(GENERATED_ID)
120122
.setMetageneration(META_GENERATION)
123+
.setProjectNumber(PROJECT_NUMBER)
121124
.setOwner(OWNER)
122125
.setSelfLink(SELF_LINK)
123126
.setCors(CORS)
@@ -150,6 +153,7 @@ public class BucketInfoTest {
150153
.setEtag(ETAG)
151154
.setGeneratedId(GENERATED_ID)
152155
.setMetageneration(META_GENERATION)
156+
.setProjectNumber(PROJECT_NUMBER)
153157
.setOwner(OWNER)
154158
.setSelfLink(SELF_LINK)
155159
.setCors(CORS)
@@ -209,6 +213,7 @@ public void testBuilder() throws Exception {
209213
() -> assertEquals(ETAG, BUCKET_INFO.getEtag()),
210214
() -> assertEquals(GENERATED_ID, BUCKET_INFO.getGeneratedId()),
211215
() -> assertEquals(META_GENERATION, BUCKET_INFO.getMetageneration()),
216+
() -> assertEquals(PROJECT_NUMBER, BUCKET_INFO.getProjectNumber()),
212217
() -> assertEquals(OWNER, BUCKET_INFO.getOwner()),
213218
() -> assertEquals(SELF_LINK, BUCKET_INFO.getSelfLink()),
214219
() -> assertEquals(CREATE_TIME, BUCKET_INFO.getCreateTime()),
@@ -290,6 +295,7 @@ private void compareBuckets(BucketInfo expected, BucketInfo value) throws Except
290295
assertEquals(expected.getRetentionPeriodDuration(), value.getRetentionPeriodDuration()),
291296
() -> assertEquals(expected.retentionPolicyIsLocked(), value.retentionPolicyIsLocked()),
292297
() -> assertEquals(expected.getLogging(), value.getLogging()),
298+
() -> assertEquals(expected.getProjectNumber(), value.getProjectNumber()),
293299
() -> assertEquals(expected, value));
294300
}
295301

0 commit comments

Comments
 (0)