001package com.box.sdkgen.schemas.uploadsession;
002
003import com.box.sdkgen.internal.NullableFieldTracker;
004import com.box.sdkgen.internal.SerializableObject;
005import com.box.sdkgen.internal.utils.DateTimeUtils;
006import com.box.sdkgen.serialization.json.EnumWrapper;
007import com.fasterxml.jackson.annotation.JsonFilter;
008import com.fasterxml.jackson.annotation.JsonProperty;
009import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
010import com.fasterxml.jackson.databind.annotation.JsonSerialize;
011import java.time.OffsetDateTime;
012import java.util.Objects;
013
014/** An upload session for chunk uploading a file. */
015@JsonFilter("nullablePropertyFilter")
016public class UploadSession extends SerializableObject {
017
018  /** The unique identifier for this session. */
019  protected String id;
020
021  /** The value will always be `upload_session`. */
022  @JsonDeserialize(using = UploadSessionTypeField.UploadSessionTypeFieldDeserializer.class)
023  @JsonSerialize(using = UploadSessionTypeField.UploadSessionTypeFieldSerializer.class)
024  protected EnumWrapper<UploadSessionTypeField> type;
025
026  /** The date and time when this session expires. */
027  @JsonProperty("session_expires_at")
028  @JsonSerialize(using = DateTimeUtils.DateTimeSerializer.class)
029  @JsonDeserialize(using = DateTimeUtils.DateTimeDeserializer.class)
030  protected OffsetDateTime sessionExpiresAt;
031
032  /**
033   * The size in bytes that must be used for all parts of of the upload.
034   *
035   * <p>Only the last part is allowed to be of a smaller size.
036   */
037  @JsonProperty("part_size")
038  protected Long partSize;
039
040  /**
041   * The total number of parts expected in this upload session, as determined by the file size and
042   * part size.
043   */
044  @JsonProperty("total_parts")
045  protected Integer totalParts;
046
047  /**
048   * The number of parts that have been uploaded and processed by the server. This starts at `0`.
049   *
050   * <p>When committing a file files, inspecting this property can provide insight if all parts have
051   * been uploaded correctly.
052   */
053  @JsonProperty("num_parts_processed")
054  protected Integer numPartsProcessed;
055
056  @JsonProperty("session_endpoints")
057  protected UploadSessionSessionEndpointsField sessionEndpoints;
058
059  public UploadSession() {
060    super();
061  }
062
063  protected UploadSession(Builder builder) {
064    super();
065    this.id = builder.id;
066    this.type = builder.type;
067    this.sessionExpiresAt = builder.sessionExpiresAt;
068    this.partSize = builder.partSize;
069    this.totalParts = builder.totalParts;
070    this.numPartsProcessed = builder.numPartsProcessed;
071    this.sessionEndpoints = builder.sessionEndpoints;
072    markNullableFieldsAsSet(builder.getExplicitlySetNullableFields());
073  }
074
075  public String getId() {
076    return id;
077  }
078
079  public EnumWrapper<UploadSessionTypeField> getType() {
080    return type;
081  }
082
083  public OffsetDateTime getSessionExpiresAt() {
084    return sessionExpiresAt;
085  }
086
087  public Long getPartSize() {
088    return partSize;
089  }
090
091  public Integer getTotalParts() {
092    return totalParts;
093  }
094
095  public Integer getNumPartsProcessed() {
096    return numPartsProcessed;
097  }
098
099  public UploadSessionSessionEndpointsField getSessionEndpoints() {
100    return sessionEndpoints;
101  }
102
103  @Override
104  public boolean equals(Object o) {
105    if (this == o) {
106      return true;
107    }
108    if (o == null || getClass() != o.getClass()) {
109      return false;
110    }
111    UploadSession casted = (UploadSession) o;
112    return Objects.equals(id, casted.id)
113        && Objects.equals(type, casted.type)
114        && Objects.equals(sessionExpiresAt, casted.sessionExpiresAt)
115        && Objects.equals(partSize, casted.partSize)
116        && Objects.equals(totalParts, casted.totalParts)
117        && Objects.equals(numPartsProcessed, casted.numPartsProcessed)
118        && Objects.equals(sessionEndpoints, casted.sessionEndpoints);
119  }
120
121  @Override
122  public int hashCode() {
123    return Objects.hash(
124        id, type, sessionExpiresAt, partSize, totalParts, numPartsProcessed, sessionEndpoints);
125  }
126
127  @Override
128  public String toString() {
129    return "UploadSession{"
130        + "id='"
131        + id
132        + '\''
133        + ", "
134        + "type='"
135        + type
136        + '\''
137        + ", "
138        + "sessionExpiresAt='"
139        + sessionExpiresAt
140        + '\''
141        + ", "
142        + "partSize='"
143        + partSize
144        + '\''
145        + ", "
146        + "totalParts='"
147        + totalParts
148        + '\''
149        + ", "
150        + "numPartsProcessed='"
151        + numPartsProcessed
152        + '\''
153        + ", "
154        + "sessionEndpoints='"
155        + sessionEndpoints
156        + '\''
157        + "}";
158  }
159
160  public static class Builder extends NullableFieldTracker {
161
162    protected String id;
163
164    protected EnumWrapper<UploadSessionTypeField> type;
165
166    protected OffsetDateTime sessionExpiresAt;
167
168    protected Long partSize;
169
170    protected Integer totalParts;
171
172    protected Integer numPartsProcessed;
173
174    protected UploadSessionSessionEndpointsField sessionEndpoints;
175
176    public Builder id(String id) {
177      this.id = id;
178      return this;
179    }
180
181    public Builder type(UploadSessionTypeField type) {
182      this.type = new EnumWrapper<UploadSessionTypeField>(type);
183      return this;
184    }
185
186    public Builder type(EnumWrapper<UploadSessionTypeField> type) {
187      this.type = type;
188      return this;
189    }
190
191    public Builder sessionExpiresAt(OffsetDateTime sessionExpiresAt) {
192      this.sessionExpiresAt = sessionExpiresAt;
193      return this;
194    }
195
196    public Builder partSize(Long partSize) {
197      this.partSize = partSize;
198      return this;
199    }
200
201    public Builder totalParts(Integer totalParts) {
202      this.totalParts = totalParts;
203      return this;
204    }
205
206    public Builder numPartsProcessed(Integer numPartsProcessed) {
207      this.numPartsProcessed = numPartsProcessed;
208      return this;
209    }
210
211    public Builder sessionEndpoints(UploadSessionSessionEndpointsField sessionEndpoints) {
212      this.sessionEndpoints = sessionEndpoints;
213      return this;
214    }
215
216    public UploadSession build() {
217      return new UploadSession(this);
218    }
219  }
220}