001package com.box.sdkgen.schemas.metadataqueryresultitem;
002
003import com.box.sdkgen.internal.OneOfTwo;
004import com.box.sdkgen.schemas.collection.Collection;
005import com.box.sdkgen.schemas.filefull.FileFull;
006import com.box.sdkgen.schemas.folderfull.FolderFull;
007import com.box.sdkgen.schemas.foldermini.FolderMini;
008import com.box.sdkgen.schemas.usermini.UserMini;
009import com.box.sdkgen.serialization.json.EnumWrapper;
010import com.box.sdkgen.serialization.json.JsonManager;
011import com.fasterxml.jackson.core.JsonParser;
012import com.fasterxml.jackson.databind.DeserializationContext;
013import com.fasterxml.jackson.databind.JsonDeserializer;
014import com.fasterxml.jackson.databind.JsonMappingException;
015import com.fasterxml.jackson.databind.JsonNode;
016import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
017import com.fasterxml.jackson.databind.annotation.JsonSerialize;
018import java.io.IOException;
019import java.time.OffsetDateTime;
020import java.util.List;
021
022@JsonDeserialize(using = MetadataQueryResultItem.MetadataQueryResultItemDeserializer.class)
023@JsonSerialize(using = OneOfTwo.OneOfTwoSerializer.class)
024public class MetadataQueryResultItem extends OneOfTwo<FileFull, FolderFull> {
025
026  protected final List<String> tags;
027
028  protected final Boolean isAccessibleViaSharedLink;
029
030  protected final List<String> allowedInviteeRoles;
031
032  protected final Boolean isExternallyOwned;
033
034  protected final Boolean hasCollaborations;
035
036  protected final Boolean isAssociatedWithAppItem;
037
038  protected final List<Collection> collections;
039
040  protected final List<String> allowedSharedLinkAccessLevels;
041
042  protected final String description;
043
044  protected final Long size;
045
046  protected final OffsetDateTime createdAt;
047
048  protected final OffsetDateTime modifiedAt;
049
050  protected final OffsetDateTime trashedAt;
051
052  protected final OffsetDateTime purgedAt;
053
054  protected final OffsetDateTime contentCreatedAt;
055
056  protected final OffsetDateTime contentModifiedAt;
057
058  protected final UserMini createdBy;
059
060  protected final UserMini modifiedBy;
061
062  protected final UserMini ownedBy;
063
064  protected final FolderMini parent;
065
066  protected final String itemStatus;
067
068  protected final String sequenceId;
069
070  protected final String name;
071
072  protected final String id;
073
074  protected final String etag;
075
076  protected final String type;
077
078  public MetadataQueryResultItem(FileFull fileFull) {
079    super(fileFull, null);
080    this.tags = fileFull.getTags();
081    this.isAccessibleViaSharedLink = fileFull.getIsAccessibleViaSharedLink();
082    this.allowedInviteeRoles = EnumWrapper.convertToString(fileFull.getAllowedInviteeRoles());
083    this.isExternallyOwned = fileFull.getIsExternallyOwned();
084    this.hasCollaborations = fileFull.getHasCollaborations();
085    this.isAssociatedWithAppItem = fileFull.getIsAssociatedWithAppItem();
086    this.collections = fileFull.getCollections();
087    this.allowedSharedLinkAccessLevels =
088        EnumWrapper.convertToString(fileFull.getAllowedSharedLinkAccessLevels());
089    this.description = fileFull.getDescription();
090    this.size = fileFull.getSize();
091    this.createdAt = fileFull.getCreatedAt();
092    this.modifiedAt = fileFull.getModifiedAt();
093    this.trashedAt = fileFull.getTrashedAt();
094    this.purgedAt = fileFull.getPurgedAt();
095    this.contentCreatedAt = fileFull.getContentCreatedAt();
096    this.contentModifiedAt = fileFull.getContentModifiedAt();
097    this.createdBy = fileFull.getCreatedBy();
098    this.modifiedBy = fileFull.getModifiedBy();
099    this.ownedBy = fileFull.getOwnedBy();
100    this.parent = fileFull.getParent();
101    this.itemStatus = EnumWrapper.convertToString(fileFull.getItemStatus());
102    this.sequenceId = fileFull.getSequenceId();
103    this.name = fileFull.getName();
104    this.id = fileFull.getId();
105    this.etag = fileFull.getEtag();
106    this.type = EnumWrapper.convertToString(fileFull.getType());
107  }
108
109  public MetadataQueryResultItem(FolderFull folderFull) {
110    super(null, folderFull);
111    this.tags = folderFull.getTags();
112    this.isAccessibleViaSharedLink = folderFull.getIsAccessibleViaSharedLink();
113    this.allowedInviteeRoles = EnumWrapper.convertToString(folderFull.getAllowedInviteeRoles());
114    this.isExternallyOwned = folderFull.getIsExternallyOwned();
115    this.hasCollaborations = folderFull.getHasCollaborations();
116    this.isAssociatedWithAppItem = folderFull.getIsAssociatedWithAppItem();
117    this.collections = folderFull.getCollections();
118    this.allowedSharedLinkAccessLevels =
119        EnumWrapper.convertToString(folderFull.getAllowedSharedLinkAccessLevels());
120    this.description = folderFull.getDescription();
121    this.size = folderFull.getSize();
122    this.createdAt = folderFull.getCreatedAt();
123    this.modifiedAt = folderFull.getModifiedAt();
124    this.trashedAt = folderFull.getTrashedAt();
125    this.purgedAt = folderFull.getPurgedAt();
126    this.contentCreatedAt = folderFull.getContentCreatedAt();
127    this.contentModifiedAt = folderFull.getContentModifiedAt();
128    this.createdBy = folderFull.getCreatedBy();
129    this.modifiedBy = folderFull.getModifiedBy();
130    this.ownedBy = folderFull.getOwnedBy();
131    this.parent = folderFull.getParent();
132    this.itemStatus = EnumWrapper.convertToString(folderFull.getItemStatus());
133    this.sequenceId = folderFull.getSequenceId();
134    this.name = folderFull.getName();
135    this.id = folderFull.getId();
136    this.etag = folderFull.getEtag();
137    this.type = EnumWrapper.convertToString(folderFull.getType());
138  }
139
140  public boolean isFileFull() {
141    return value0 != null;
142  }
143
144  public FileFull getFileFull() {
145    return value0;
146  }
147
148  public boolean isFolderFull() {
149    return value1 != null;
150  }
151
152  public FolderFull getFolderFull() {
153    return value1;
154  }
155
156  public List<String> getTags() {
157    return tags;
158  }
159
160  public boolean getIsAccessibleViaSharedLink() {
161    return isAccessibleViaSharedLink;
162  }
163
164  public List<String> getAllowedInviteeRoles() {
165    return allowedInviteeRoles;
166  }
167
168  public boolean getIsExternallyOwned() {
169    return isExternallyOwned;
170  }
171
172  public boolean getHasCollaborations() {
173    return hasCollaborations;
174  }
175
176  public boolean getIsAssociatedWithAppItem() {
177    return isAssociatedWithAppItem;
178  }
179
180  public List<Collection> getCollections() {
181    return collections;
182  }
183
184  public List<String> getAllowedSharedLinkAccessLevels() {
185    return allowedSharedLinkAccessLevels;
186  }
187
188  public String getDescription() {
189    return description;
190  }
191
192  public long getSize() {
193    return size;
194  }
195
196  public OffsetDateTime getCreatedAt() {
197    return createdAt;
198  }
199
200  public OffsetDateTime getModifiedAt() {
201    return modifiedAt;
202  }
203
204  public OffsetDateTime getTrashedAt() {
205    return trashedAt;
206  }
207
208  public OffsetDateTime getPurgedAt() {
209    return purgedAt;
210  }
211
212  public OffsetDateTime getContentCreatedAt() {
213    return contentCreatedAt;
214  }
215
216  public OffsetDateTime getContentModifiedAt() {
217    return contentModifiedAt;
218  }
219
220  public UserMini getCreatedBy() {
221    return createdBy;
222  }
223
224  public UserMini getModifiedBy() {
225    return modifiedBy;
226  }
227
228  public UserMini getOwnedBy() {
229    return ownedBy;
230  }
231
232  public FolderMini getParent() {
233    return parent;
234  }
235
236  public String getItemStatus() {
237    return itemStatus;
238  }
239
240  public String getSequenceId() {
241    return sequenceId;
242  }
243
244  public String getName() {
245    return name;
246  }
247
248  public String getId() {
249    return id;
250  }
251
252  public String getEtag() {
253    return etag;
254  }
255
256  public String getType() {
257    return type;
258  }
259
260  static class MetadataQueryResultItemDeserializer
261      extends JsonDeserializer<MetadataQueryResultItem> {
262
263    public MetadataQueryResultItemDeserializer() {
264      super();
265    }
266
267    @Override
268    public MetadataQueryResultItem deserialize(JsonParser jp, DeserializationContext ctxt)
269        throws IOException {
270      JsonNode node = JsonManager.jsonToSerializedData(jp);
271      JsonNode discriminant0 = node.get("type");
272      if (!(discriminant0 == null)) {
273        switch (discriminant0.asText()) {
274          case "file":
275            return new MetadataQueryResultItem(JsonManager.deserialize(node, FileFull.class));
276          case "folder":
277            return new MetadataQueryResultItem(JsonManager.deserialize(node, FolderFull.class));
278        }
279      }
280      throw new JsonMappingException(jp, "Unable to deserialize MetadataQueryResultItem");
281    }
282  }
283}