Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions google-cloud-storage/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<method>com.google.cloud.storage.BucketInfo$Builder setHierarchicalNamespace(com.google.cloud.storage.BucketInfo$HierarchicalNamespace)</method>
</difference>

<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/storage/BlobInfo$Builder</className>
<method>com.google.cloud.storage.BlobInfo$Builder setContexts(com.google.cloud.storage.BlobInfo$ObjectContexts)</method>
</difference>

<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/storage/BlobInfo$Builder</className>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,12 @@ public Builder setRetention(Retention retention) {
return this;
}

@Override
public Builder setContexts(ObjectContexts contexts) {
infoBuilder.setContexts(contexts);
return this;
}

@Override
public Blob build() {
return new Blob(storage, infoBuilder);
Expand Down Expand Up @@ -739,6 +745,12 @@ Builder clearRetentionExpirationTime() {
infoBuilder.clearRetentionExpirationTime();
return this;
}

@Override
Builder clearContexts() {
infoBuilder.clearContexts();
return this;
}
}

Blob(Storage storage, BlobInfo.BuilderImpl infoBuilder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.cloud.storage.UnifiedOpts.NamedField;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.BaseEncoding;
import java.io.Serializable;
Expand Down Expand Up @@ -112,6 +113,7 @@ public class BlobInfo implements Serializable {
private final Retention retention;
private final OffsetDateTime softDeleteTime;
private final OffsetDateTime hardDeleteTime;
private ObjectContexts contexts;
private final transient ImmutableSet<NamedField> modifiedFields;

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

public static final class ObjectContexts implements Serializable {

private static final long serialVersionUID = -5993852233545224424L;

private final ImmutableMap<String, ObjectCustomContextPayload> custom;

private ObjectContexts(Builder builder) {
this.custom = builder.custom;
}

public static Builder newBuilder() {
return new Builder();
}

public Builder toBuilder() {
return new Builder().setCustom(this.custom);
}

/** Returns the map of user-defined object contexts. */
public Map<String, ObjectCustomContextPayload> getCustom() {
return custom;
}

@Override
public int hashCode() {
return Objects.hash(custom);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final ObjectContexts other = (ObjectContexts) obj;
return Objects.equals(this.custom, other.custom);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("custom", custom).toString();
}

public static final class Builder {

private ImmutableMap<String, ObjectCustomContextPayload> custom;

private Builder() {}

public Builder setCustom(Map<String, ObjectCustomContextPayload> custom) {
this.custom = custom == null ? ImmutableMap.of() : ImmutableMap.copyOf(custom);
return this;
}

public ObjectContexts build() {
return new ObjectContexts(this);
}
}
}

/** Represents the payload of a user-defined object context. */
public static final class ObjectCustomContextPayload implements Serializable {

private static final long serialVersionUID = 557621132294323214L;

private final String value;
private final OffsetDateTime createTime;
private final OffsetDateTime updateTime;

private ObjectCustomContextPayload(Builder builder) {
this.value = builder.value;
this.createTime = builder.createTime;
this.updateTime = builder.updateTime;
}

public static Builder newBuilder() {
return new Builder();
}

public Builder toBuilder() {
return new Builder()
.setValue(this.value)
.setCreateTime(this.createTime)
.setUpdateTime(this.updateTime);
}

public String getValue() {
return value;
}

public OffsetDateTime getCreateTime() {
return createTime;
}

public OffsetDateTime getUpdateTime() {
return updateTime;
}

@Override
public int hashCode() {
return Objects.hash(value, createTime, updateTime);
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
ObjectCustomContextPayload other = (ObjectCustomContextPayload) obj;
return Objects.equals(value, other.value)
&& Objects.equals(createTime, other.createTime)
&& Objects.equals(updateTime, other.updateTime);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("value", value)
.add("createTime", createTime)
.add("updateTime", updateTime)
.toString();
}

public static final class Builder {

private String value;
private OffsetDateTime createTime;
private OffsetDateTime updateTime;

private Builder() {}

public Builder(String value) {
setValue(value);
}

public Builder setValue(String value) {
this.value = value;
return this;
}

public Builder setCreateTime(OffsetDateTime createTime) {
this.createTime = createTime;
return this;
}

public Builder setUpdateTime(OffsetDateTime updateTime) {
this.updateTime = updateTime;
return this;
}

public ObjectCustomContextPayload build() {
return new ObjectCustomContextPayload(this);
}
}
}

/** Builder for {@code BlobInfo}. */
public abstract static class Builder {

Expand Down Expand Up @@ -543,6 +706,8 @@ Builder setRetentionExpirationTimeOffsetDateTime(OffsetDateTime retentionExpirat

public abstract Builder setRetention(Retention retention);

public abstract Builder setContexts(ObjectContexts contexts);

/** Creates a {@code BlobInfo} object. */
public abstract BlobInfo build();

Expand Down Expand Up @@ -607,6 +772,8 @@ Builder setRetentionExpirationTimeOffsetDateTime(OffsetDateTime retentionExpirat
abstract Builder clearTemporaryHold();

abstract Builder clearRetentionExpirationTime();

abstract Builder clearContexts();
}

static final class BuilderImpl extends Builder {
Expand Down Expand Up @@ -644,6 +811,7 @@ static final class BuilderImpl extends Builder {
private Retention retention;
private OffsetDateTime softDeleteTime;
private OffsetDateTime hardDeleteTime;
private ObjectContexts contexts;
private final ImmutableSet.Builder<NamedField> modifiedFields = ImmutableSet.builder();

BuilderImpl(BlobId blobId) {
Expand Down Expand Up @@ -684,6 +852,7 @@ static final class BuilderImpl extends Builder {
retention = blobInfo.retention;
softDeleteTime = blobInfo.softDeleteTime;
hardDeleteTime = blobInfo.hardDeleteTime;
contexts = blobInfo.contexts;
}

@Override
Expand Down Expand Up @@ -1095,6 +1264,13 @@ public Builder setRetention(Retention retention) {
return this;
}

@Override
public Builder setContexts(ObjectContexts contexts) {
modifiedFields.add(BlobField.OBJECT_CONTEXTS);
this.contexts = contexts;
return this;
}

@Override
public BlobInfo build() {
checkNotNull(blobId);
Expand Down Expand Up @@ -1285,6 +1461,12 @@ Builder clearRetentionExpirationTime() {
this.retentionExpirationTime = null;
return this;
}

@Override
Builder clearContexts() {
this.contexts = null;
return this;
}
}

BlobInfo(BuilderImpl builder) {
Expand Down Expand Up @@ -1321,6 +1503,7 @@ Builder clearRetentionExpirationTime() {
retention = builder.retention;
softDeleteTime = builder.softDeleteTime;
hardDeleteTime = builder.hardDeleteTime;
contexts = builder.contexts;
modifiedFields = builder.modifiedFields.build();
}

Expand Down Expand Up @@ -1731,6 +1914,10 @@ public Retention getRetention() {
return retention;
}

public ObjectContexts getContexts() {
return contexts;
}

/** Returns a builder for the current blob. */
public Builder toBuilder() {
return new BuilderImpl(this);
Expand All @@ -1745,6 +1932,7 @@ public String toString() {
.add("size", getSize())
.add("content-type", getContentType())
.add("metadata", getMetadata())
.add("contexts", getContexts())
.toString();
}

Expand Down Expand Up @@ -1783,7 +1971,8 @@ public int hashCode() {
retention,
retentionExpirationTime,
softDeleteTime,
hardDeleteTime);
hardDeleteTime,
contexts);
}

@Override
Expand Down Expand Up @@ -1827,7 +2016,8 @@ public boolean equals(Object o) {
&& Objects.equals(retentionExpirationTime, blobInfo.retentionExpirationTime)
&& Objects.equals(retention, blobInfo.retention)
&& Objects.equals(softDeleteTime, blobInfo.softDeleteTime)
&& Objects.equals(hardDeleteTime, blobInfo.hardDeleteTime);
&& Objects.equals(hardDeleteTime, blobInfo.hardDeleteTime)
&& Objects.equals(contexts, blobInfo.contexts);
}

ImmutableSet<NamedField> getModifiedFields() {
Expand Down
Loading
Loading