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