001package com.box.sdkgen.schemas.searchresultitem;
002
003import com.box.sdkgen.internal.OneOfThree;
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.schemas.weblink.WebLink;
010import com.box.sdkgen.serialization.json.EnumWrapper;
011import com.box.sdkgen.serialization.json.JsonManager;
012import com.fasterxml.jackson.core.JsonParser;
013import com.fasterxml.jackson.databind.DeserializationContext;
014import com.fasterxml.jackson.databind.JsonDeserializer;
015import com.fasterxml.jackson.databind.JsonMappingException;
016import com.fasterxml.jackson.databind.JsonNode;
017import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
018import com.fasterxml.jackson.databind.annotation.JsonSerialize;
019import java.io.IOException;
020import java.time.OffsetDateTime;
021import java.util.List;
022
023@JsonDeserialize(using = SearchResultItem.SearchResultItemDeserializer.class)
024@JsonSerialize(using = OneOfThree.OneOfThreeSerializer.class)
025public class SearchResultItem extends OneOfThree<FileFull, FolderFull, WebLink> {
026
027  protected final List<Collection> collections;
028
029  protected final List<String> allowedSharedLinkAccessLevels;
030
031  protected final String description;
032
033  protected final OffsetDateTime createdAt;
034
035  protected final OffsetDateTime modifiedAt;
036
037  protected final OffsetDateTime trashedAt;
038
039  protected final OffsetDateTime purgedAt;
040
041  protected final UserMini createdBy;
042
043  protected final UserMini modifiedBy;
044
045  protected final UserMini ownedBy;
046
047  protected final FolderMini parent;
048
049  protected final String itemStatus;
050
051  protected final String sequenceId;
052
053  protected final String name;
054
055  protected final String id;
056
057  protected final String etag;
058
059  protected final String type;
060
061  public SearchResultItem(FileFull fileFull) {
062    super(fileFull, null, null);
063    this.collections = fileFull.getCollections();
064    this.allowedSharedLinkAccessLevels =
065        EnumWrapper.convertToString(fileFull.getAllowedSharedLinkAccessLevels());
066    this.description = fileFull.getDescription();
067    this.createdAt = fileFull.getCreatedAt();
068    this.modifiedAt = fileFull.getModifiedAt();
069    this.trashedAt = fileFull.getTrashedAt();
070    this.purgedAt = fileFull.getPurgedAt();
071    this.createdBy = fileFull.getCreatedBy();
072    this.modifiedBy = fileFull.getModifiedBy();
073    this.ownedBy = fileFull.getOwnedBy();
074    this.parent = fileFull.getParent();
075    this.itemStatus = EnumWrapper.convertToString(fileFull.getItemStatus());
076    this.sequenceId = fileFull.getSequenceId();
077    this.name = fileFull.getName();
078    this.id = fileFull.getId();
079    this.etag = fileFull.getEtag();
080    this.type = EnumWrapper.convertToString(fileFull.getType());
081  }
082
083  public SearchResultItem(FolderFull folderFull) {
084    super(null, folderFull, null);
085    this.collections = folderFull.getCollections();
086    this.allowedSharedLinkAccessLevels =
087        EnumWrapper.convertToString(folderFull.getAllowedSharedLinkAccessLevels());
088    this.description = folderFull.getDescription();
089    this.createdAt = folderFull.getCreatedAt();
090    this.modifiedAt = folderFull.getModifiedAt();
091    this.trashedAt = folderFull.getTrashedAt();
092    this.purgedAt = folderFull.getPurgedAt();
093    this.createdBy = folderFull.getCreatedBy();
094    this.modifiedBy = folderFull.getModifiedBy();
095    this.ownedBy = folderFull.getOwnedBy();
096    this.parent = folderFull.getParent();
097    this.itemStatus = EnumWrapper.convertToString(folderFull.getItemStatus());
098    this.sequenceId = folderFull.getSequenceId();
099    this.name = folderFull.getName();
100    this.id = folderFull.getId();
101    this.etag = folderFull.getEtag();
102    this.type = EnumWrapper.convertToString(folderFull.getType());
103  }
104
105  public SearchResultItem(WebLink webLink) {
106    super(null, null, webLink);
107    this.collections = webLink.getCollections();
108    this.allowedSharedLinkAccessLevels =
109        EnumWrapper.convertToString(webLink.getAllowedSharedLinkAccessLevels());
110    this.description = webLink.getDescription();
111    this.createdAt = webLink.getCreatedAt();
112    this.modifiedAt = webLink.getModifiedAt();
113    this.trashedAt = webLink.getTrashedAt();
114    this.purgedAt = webLink.getPurgedAt();
115    this.createdBy = webLink.getCreatedBy();
116    this.modifiedBy = webLink.getModifiedBy();
117    this.ownedBy = webLink.getOwnedBy();
118    this.parent = webLink.getParent();
119    this.itemStatus = EnumWrapper.convertToString(webLink.getItemStatus());
120    this.sequenceId = webLink.getSequenceId();
121    this.name = webLink.getName();
122    this.id = webLink.getId();
123    this.etag = webLink.getEtag();
124    this.type = EnumWrapper.convertToString(webLink.getType());
125  }
126
127  public boolean isFileFull() {
128    return value0 != null;
129  }
130
131  public FileFull getFileFull() {
132    return value0;
133  }
134
135  public boolean isFolderFull() {
136    return value1 != null;
137  }
138
139  public FolderFull getFolderFull() {
140    return value1;
141  }
142
143  public boolean isWebLink() {
144    return value2 != null;
145  }
146
147  public WebLink getWebLink() {
148    return value2;
149  }
150
151  public List<Collection> getCollections() {
152    return collections;
153  }
154
155  public List<String> getAllowedSharedLinkAccessLevels() {
156    return allowedSharedLinkAccessLevels;
157  }
158
159  public String getDescription() {
160    return description;
161  }
162
163  public OffsetDateTime getCreatedAt() {
164    return createdAt;
165  }
166
167  public OffsetDateTime getModifiedAt() {
168    return modifiedAt;
169  }
170
171  public OffsetDateTime getTrashedAt() {
172    return trashedAt;
173  }
174
175  public OffsetDateTime getPurgedAt() {
176    return purgedAt;
177  }
178
179  public UserMini getCreatedBy() {
180    return createdBy;
181  }
182
183  public UserMini getModifiedBy() {
184    return modifiedBy;
185  }
186
187  public UserMini getOwnedBy() {
188    return ownedBy;
189  }
190
191  public FolderMini getParent() {
192    return parent;
193  }
194
195  public String getItemStatus() {
196    return itemStatus;
197  }
198
199  public String getSequenceId() {
200    return sequenceId;
201  }
202
203  public String getName() {
204    return name;
205  }
206
207  public String getId() {
208    return id;
209  }
210
211  public String getEtag() {
212    return etag;
213  }
214
215  public String getType() {
216    return type;
217  }
218
219  static class SearchResultItemDeserializer extends JsonDeserializer<SearchResultItem> {
220
221    public SearchResultItemDeserializer() {
222      super();
223    }
224
225    @Override
226    public SearchResultItem deserialize(JsonParser jp, DeserializationContext ctxt)
227        throws IOException {
228      JsonNode node = JsonManager.jsonToSerializedData(jp);
229      JsonNode discriminant0 = node.get("type");
230      if (!(discriminant0 == null)) {
231        switch (discriminant0.asText()) {
232          case "file":
233            return new SearchResultItem(JsonManager.deserialize(node, FileFull.class));
234          case "folder":
235            return new SearchResultItem(JsonManager.deserialize(node, FolderFull.class));
236          case "web_link":
237            return new SearchResultItem(JsonManager.deserialize(node, WebLink.class));
238        }
239      }
240      throw new JsonMappingException(jp, "Unable to deserialize SearchResultItem");
241    }
242  }
243}