Skip to content

Commit 485aefd

Browse files
authored
feat: add BlobInfo.ObjectContexts (#3259)
1 parent dcbe96c commit 485aefd

File tree

15 files changed

+415
-7
lines changed

15 files changed

+415
-7
lines changed

google-cloud-storage/clirr-ignored-differences.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
<method>com.google.cloud.storage.BucketInfo$Builder setHierarchicalNamespace(com.google.cloud.storage.BucketInfo$HierarchicalNamespace)</method>
2222
</difference>
2323

24+
<difference>
25+
<differenceType>7013</differenceType>
26+
<className>com/google/cloud/storage/BlobInfo$Builder</className>
27+
<method>com.google.cloud.storage.BlobInfo$Builder setContexts(com.google.cloud.storage.BlobInfo$ObjectContexts)</method>
28+
</difference>
29+
2430
<difference>
2531
<differenceType>7013</differenceType>
2632
<className>com/google/cloud/storage/BlobInfo$Builder</className>

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,12 @@ public Builder setRetention(Retention retention) {
550550
return this;
551551
}
552552

553+
@Override
554+
public Builder setContexts(ObjectContexts contexts) {
555+
infoBuilder.setContexts(contexts);
556+
return this;
557+
}
558+
553559
@Override
554560
public Blob build() {
555561
return new Blob(storage, infoBuilder);
@@ -739,6 +745,12 @@ Builder clearRetentionExpirationTime() {
739745
infoBuilder.clearRetentionExpirationTime();
740746
return this;
741747
}
748+
749+
@Override
750+
Builder clearContexts() {
751+
infoBuilder.clearContexts();
752+
return this;
753+
}
742754
}
743755

744756
Blob(Storage storage, BlobInfo.BuilderImpl infoBuilder) {

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

Lines changed: 192 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.google.cloud.storage.UnifiedOpts.NamedField;
3232
import com.google.common.base.MoreObjects;
3333
import com.google.common.collect.ImmutableList;
34+
import com.google.common.collect.ImmutableMap;
3435
import com.google.common.collect.ImmutableSet;
3536
import com.google.common.io.BaseEncoding;
3637
import java.io.Serializable;
@@ -112,6 +113,7 @@ public class BlobInfo implements Serializable {
112113
private final Retention retention;
113114
private final OffsetDateTime softDeleteTime;
114115
private final OffsetDateTime hardDeleteTime;
116+
private ObjectContexts contexts;
115117
private final transient ImmutableSet<NamedField> modifiedFields;
116118

117119
/** This class is meant for internal use only. Users are discouraged from using this class. */
@@ -289,6 +291,167 @@ public static Mode[] values() {
289291
}
290292
}
291293

294+
public static final class ObjectContexts implements Serializable {
295+
296+
private static final long serialVersionUID = -5993852233545224424L;
297+
298+
private final ImmutableMap<String, ObjectCustomContextPayload> custom;
299+
300+
private ObjectContexts(Builder builder) {
301+
this.custom = builder.custom;
302+
}
303+
304+
public static Builder newBuilder() {
305+
return new Builder();
306+
}
307+
308+
public Builder toBuilder() {
309+
return new Builder().setCustom(this.custom);
310+
}
311+
312+
/** Returns the map of user-defined object contexts. */
313+
public Map<String, ObjectCustomContextPayload> getCustom() {
314+
return custom;
315+
}
316+
317+
@Override
318+
public int hashCode() {
319+
return Objects.hash(custom);
320+
}
321+
322+
@Override
323+
public boolean equals(Object obj) {
324+
if (this == obj) {
325+
return true;
326+
}
327+
if (obj == null || getClass() != obj.getClass()) {
328+
return false;
329+
}
330+
final ObjectContexts other = (ObjectContexts) obj;
331+
return Objects.equals(this.custom, other.custom);
332+
}
333+
334+
@Override
335+
public String toString() {
336+
return MoreObjects.toStringHelper(this).add("custom", custom).toString();
337+
}
338+
339+
public static final class Builder {
340+
341+
private ImmutableMap<String, ObjectCustomContextPayload> custom;
342+
343+
private Builder() {}
344+
345+
public Builder setCustom(Map<String, ObjectCustomContextPayload> custom) {
346+
this.custom = custom == null ? ImmutableMap.of() : ImmutableMap.copyOf(custom);
347+
return this;
348+
}
349+
350+
public ObjectContexts build() {
351+
return new ObjectContexts(this);
352+
}
353+
}
354+
}
355+
356+
/** Represents the payload of a user-defined object context. */
357+
public static final class ObjectCustomContextPayload implements Serializable {
358+
359+
private static final long serialVersionUID = 557621132294323214L;
360+
361+
private final String value;
362+
private final OffsetDateTime createTime;
363+
private final OffsetDateTime updateTime;
364+
365+
private ObjectCustomContextPayload(Builder builder) {
366+
this.value = builder.value;
367+
this.createTime = builder.createTime;
368+
this.updateTime = builder.updateTime;
369+
}
370+
371+
public static Builder newBuilder() {
372+
return new Builder();
373+
}
374+
375+
public Builder toBuilder() {
376+
return new Builder()
377+
.setValue(this.value)
378+
.setCreateTime(this.createTime)
379+
.setUpdateTime(this.updateTime);
380+
}
381+
382+
public String getValue() {
383+
return value;
384+
}
385+
386+
public OffsetDateTime getCreateTime() {
387+
return createTime;
388+
}
389+
390+
public OffsetDateTime getUpdateTime() {
391+
return updateTime;
392+
}
393+
394+
@Override
395+
public int hashCode() {
396+
return Objects.hash(value, createTime, updateTime);
397+
}
398+
399+
@Override
400+
public boolean equals(Object obj) {
401+
if (obj == this) {
402+
return true;
403+
}
404+
if (obj == null || getClass() != obj.getClass()) {
405+
return false;
406+
}
407+
ObjectCustomContextPayload other = (ObjectCustomContextPayload) obj;
408+
return Objects.equals(value, other.value)
409+
&& Objects.equals(createTime, other.createTime)
410+
&& Objects.equals(updateTime, other.updateTime);
411+
}
412+
413+
@Override
414+
public String toString() {
415+
return MoreObjects.toStringHelper(this)
416+
.add("value", value)
417+
.add("createTime", createTime)
418+
.add("updateTime", updateTime)
419+
.toString();
420+
}
421+
422+
public static final class Builder {
423+
424+
private String value;
425+
private OffsetDateTime createTime;
426+
private OffsetDateTime updateTime;
427+
428+
private Builder() {}
429+
430+
public Builder(String value) {
431+
setValue(value);
432+
}
433+
434+
public Builder setValue(String value) {
435+
this.value = value;
436+
return this;
437+
}
438+
439+
public Builder setCreateTime(OffsetDateTime createTime) {
440+
this.createTime = createTime;
441+
return this;
442+
}
443+
444+
public Builder setUpdateTime(OffsetDateTime updateTime) {
445+
this.updateTime = updateTime;
446+
return this;
447+
}
448+
449+
public ObjectCustomContextPayload build() {
450+
return new ObjectCustomContextPayload(this);
451+
}
452+
}
453+
}
454+
292455
/** Builder for {@code BlobInfo}. */
293456
public abstract static class Builder {
294457

@@ -543,6 +706,8 @@ Builder setRetentionExpirationTimeOffsetDateTime(OffsetDateTime retentionExpirat
543706

544707
public abstract Builder setRetention(Retention retention);
545708

709+
public abstract Builder setContexts(ObjectContexts contexts);
710+
546711
/** Creates a {@code BlobInfo} object. */
547712
public abstract BlobInfo build();
548713

@@ -607,6 +772,8 @@ Builder setRetentionExpirationTimeOffsetDateTime(OffsetDateTime retentionExpirat
607772
abstract Builder clearTemporaryHold();
608773

609774
abstract Builder clearRetentionExpirationTime();
775+
776+
abstract Builder clearContexts();
610777
}
611778

612779
static final class BuilderImpl extends Builder {
@@ -644,6 +811,7 @@ static final class BuilderImpl extends Builder {
644811
private Retention retention;
645812
private OffsetDateTime softDeleteTime;
646813
private OffsetDateTime hardDeleteTime;
814+
private ObjectContexts contexts;
647815
private final ImmutableSet.Builder<NamedField> modifiedFields = ImmutableSet.builder();
648816

649817
BuilderImpl(BlobId blobId) {
@@ -684,6 +852,7 @@ static final class BuilderImpl extends Builder {
684852
retention = blobInfo.retention;
685853
softDeleteTime = blobInfo.softDeleteTime;
686854
hardDeleteTime = blobInfo.hardDeleteTime;
855+
contexts = blobInfo.contexts;
687856
}
688857

689858
@Override
@@ -1095,6 +1264,13 @@ public Builder setRetention(Retention retention) {
10951264
return this;
10961265
}
10971266

1267+
@Override
1268+
public Builder setContexts(ObjectContexts contexts) {
1269+
modifiedFields.add(BlobField.OBJECT_CONTEXTS);
1270+
this.contexts = contexts;
1271+
return this;
1272+
}
1273+
10981274
@Override
10991275
public BlobInfo build() {
11001276
checkNotNull(blobId);
@@ -1285,6 +1461,12 @@ Builder clearRetentionExpirationTime() {
12851461
this.retentionExpirationTime = null;
12861462
return this;
12871463
}
1464+
1465+
@Override
1466+
Builder clearContexts() {
1467+
this.contexts = null;
1468+
return this;
1469+
}
12881470
}
12891471

12901472
BlobInfo(BuilderImpl builder) {
@@ -1321,6 +1503,7 @@ Builder clearRetentionExpirationTime() {
13211503
retention = builder.retention;
13221504
softDeleteTime = builder.softDeleteTime;
13231505
hardDeleteTime = builder.hardDeleteTime;
1506+
contexts = builder.contexts;
13241507
modifiedFields = builder.modifiedFields.build();
13251508
}
13261509

@@ -1731,6 +1914,10 @@ public Retention getRetention() {
17311914
return retention;
17321915
}
17331916

1917+
public ObjectContexts getContexts() {
1918+
return contexts;
1919+
}
1920+
17341921
/** Returns a builder for the current blob. */
17351922
public Builder toBuilder() {
17361923
return new BuilderImpl(this);
@@ -1745,6 +1932,7 @@ public String toString() {
17451932
.add("size", getSize())
17461933
.add("content-type", getContentType())
17471934
.add("metadata", getMetadata())
1935+
.add("contexts", getContexts())
17481936
.toString();
17491937
}
17501938

@@ -1783,7 +1971,8 @@ public int hashCode() {
17831971
retention,
17841972
retentionExpirationTime,
17851973
softDeleteTime,
1786-
hardDeleteTime);
1974+
hardDeleteTime,
1975+
contexts);
17871976
}
17881977

17891978
@Override
@@ -1827,7 +2016,8 @@ public boolean equals(Object o) {
18272016
&& Objects.equals(retentionExpirationTime, blobInfo.retentionExpirationTime)
18282017
&& Objects.equals(retention, blobInfo.retention)
18292018
&& Objects.equals(softDeleteTime, blobInfo.softDeleteTime)
1830-
&& Objects.equals(hardDeleteTime, blobInfo.hardDeleteTime);
2019+
&& Objects.equals(hardDeleteTime, blobInfo.hardDeleteTime)
2020+
&& Objects.equals(contexts, blobInfo.contexts);
18312021
}
18322022

18332023
ImmutableSet<NamedField> getModifiedFields() {

0 commit comments

Comments
 (0)