001package com.box.sdkgen.schemas.collaborationitem; 002 003import com.box.sdkgen.internal.OneOfThree; 004import com.box.sdkgen.schemas.file.File; 005import com.box.sdkgen.schemas.folder.Folder; 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 = CollaborationItem.CollaborationItemDeserializer.class) 022@JsonSerialize(using = OneOfThree.OneOfThreeSerializer.class) 023public class CollaborationItem extends OneOfThree<File, Folder, 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 CollaborationItem(File file) { 056 super(file, null, null); 057 this.description = file.getDescription(); 058 this.createdAt = file.getCreatedAt(); 059 this.modifiedAt = file.getModifiedAt(); 060 this.trashedAt = file.getTrashedAt(); 061 this.purgedAt = file.getPurgedAt(); 062 this.createdBy = file.getCreatedBy(); 063 this.modifiedBy = file.getModifiedBy(); 064 this.ownedBy = file.getOwnedBy(); 065 this.parent = file.getParent(); 066 this.itemStatus = EnumWrapper.convertToString(file.getItemStatus()); 067 this.sequenceId = file.getSequenceId(); 068 this.name = file.getName(); 069 this.id = file.getId(); 070 this.etag = file.getEtag(); 071 this.type = EnumWrapper.convertToString(file.getType()); 072 } 073 074 public CollaborationItem(Folder folder) { 075 super(null, folder, null); 076 this.description = folder.getDescription(); 077 this.createdAt = folder.getCreatedAt(); 078 this.modifiedAt = folder.getModifiedAt(); 079 this.trashedAt = folder.getTrashedAt(); 080 this.purgedAt = folder.getPurgedAt(); 081 this.createdBy = folder.getCreatedBy(); 082 this.modifiedBy = folder.getModifiedBy(); 083 this.ownedBy = folder.getOwnedBy(); 084 this.parent = folder.getParent(); 085 this.itemStatus = EnumWrapper.convertToString(folder.getItemStatus()); 086 this.sequenceId = folder.getSequenceId(); 087 this.name = folder.getName(); 088 this.id = folder.getId(); 089 this.etag = folder.getEtag(); 090 this.type = EnumWrapper.convertToString(folder.getType()); 091 } 092 093 public CollaborationItem(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 isFile() { 113 return value0 != null; 114 } 115 116 public File getFile() { 117 return value0; 118 } 119 120 public boolean isFolder() { 121 return value1 != null; 122 } 123 124 public Folder getFolder() { 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 CollaborationItemDeserializer extends JsonDeserializer<CollaborationItem> { 197 198 public CollaborationItemDeserializer() { 199 super(); 200 } 201 202 @Override 203 public CollaborationItem 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 CollaborationItem(JsonManager.deserialize(node, File.class)); 211 case "folder": 212 return new CollaborationItem(JsonManager.deserialize(node, Folder.class)); 213 case "web_link": 214 return new CollaborationItem(JsonManager.deserialize(node, WebLink.class)); 215 } 216 } 217 throw new JsonMappingException(jp, "Unable to deserialize CollaborationItem"); 218 } 219 } 220}