001package com.box.sdkgen.schemas.weblink; 002 003import com.box.sdkgen.internal.Nullable; 004import com.box.sdkgen.internal.utils.DateTimeUtils; 005import com.box.sdkgen.schemas.collection.Collection; 006import com.box.sdkgen.schemas.foldermini.FolderMini; 007import com.box.sdkgen.schemas.usermini.UserMini; 008import com.box.sdkgen.schemas.weblinkbase.WebLinkBaseTypeField; 009import com.box.sdkgen.schemas.weblinkmini.WebLinkMini; 010import com.box.sdkgen.serialization.json.EnumWrapper; 011import com.box.sdkgen.serialization.json.Valuable; 012import com.fasterxml.jackson.annotation.JsonFilter; 013import com.fasterxml.jackson.annotation.JsonProperty; 014import com.fasterxml.jackson.core.JsonGenerator; 015import com.fasterxml.jackson.core.JsonParser; 016import com.fasterxml.jackson.databind.DeserializationContext; 017import com.fasterxml.jackson.databind.JsonDeserializer; 018import com.fasterxml.jackson.databind.JsonNode; 019import com.fasterxml.jackson.databind.JsonSerializer; 020import com.fasterxml.jackson.databind.SerializerProvider; 021import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 022import com.fasterxml.jackson.databind.annotation.JsonSerialize; 023import java.io.IOException; 024import java.time.OffsetDateTime; 025import java.util.ArrayList; 026import java.util.List; 027import java.util.Objects; 028 029/** 030 * Web links are objects that point to URLs. These objects are also known as bookmarks within the 031 * Box web application. 032 * 033 * <p>Web link objects are treated similarly to file objects, they will also support most actions 034 * that apply to regular files. 035 */ 036@JsonFilter("nullablePropertyFilter") 037public class WebLink extends WebLinkMini { 038 039 protected FolderMini parent; 040 041 /** The description accompanying the web link. This is visible within the Box web application. */ 042 protected String description; 043 044 @JsonProperty("path_collection") 045 protected WebLinkPathCollectionField pathCollection; 046 047 /** When this file was created on Box’s servers. */ 048 @JsonProperty("created_at") 049 @JsonSerialize(using = DateTimeUtils.DateTimeSerializer.class) 050 @JsonDeserialize(using = DateTimeUtils.DateTimeDeserializer.class) 051 protected OffsetDateTime createdAt; 052 053 /** When this file was last updated on the Box servers. */ 054 @JsonProperty("modified_at") 055 @JsonSerialize(using = DateTimeUtils.DateTimeSerializer.class) 056 @JsonDeserialize(using = DateTimeUtils.DateTimeDeserializer.class) 057 protected OffsetDateTime modifiedAt; 058 059 /** When this file was moved to the trash. */ 060 @JsonProperty("trashed_at") 061 @JsonSerialize(using = DateTimeUtils.DateTimeSerializer.class) 062 @JsonDeserialize(using = DateTimeUtils.DateTimeDeserializer.class) 063 @Nullable 064 protected OffsetDateTime trashedAt; 065 066 /** When this file will be permanently deleted. */ 067 @JsonProperty("purged_at") 068 @JsonSerialize(using = DateTimeUtils.DateTimeSerializer.class) 069 @JsonDeserialize(using = DateTimeUtils.DateTimeDeserializer.class) 070 @Nullable 071 protected OffsetDateTime purgedAt; 072 073 @JsonProperty("created_by") 074 protected UserMini createdBy; 075 076 @JsonProperty("modified_by") 077 protected UserMini modifiedBy; 078 079 @JsonProperty("owned_by") 080 protected UserMini ownedBy; 081 082 @JsonProperty("shared_link") 083 protected WebLinkSharedLinkField sharedLink; 084 085 /** 086 * Whether this item is deleted or not. Values include `active`, `trashed` if the file has been 087 * moved to the trash, and `deleted` if the file has been permanently deleted. 088 */ 089 @JsonDeserialize(using = WebLinkItemStatusField.WebLinkItemStatusFieldDeserializer.class) 090 @JsonSerialize(using = WebLinkItemStatusField.WebLinkItemStatusFieldSerializer.class) 091 @JsonProperty("item_status") 092 protected EnumWrapper<WebLinkItemStatusField> itemStatus; 093 094 /** 095 * The collections that this web link belongs to. 096 * 097 * <p>For more information, see the [collections 098 * guide](https://developer.box.com/guides/collections). 099 */ 100 protected List<Collection> collections; 101 102 /** 103 * The shared link access levels the authenticated user is allowed to use when creating or 104 * updating a shared link for this web link. 105 * 106 * <p>The list depends on item policy and user authorization, so it may be narrower than the 107 * levels available to the owner. An empty array means no access level is available to this user. 108 */ 109 @JsonDeserialize(using = AllowedSharedLinkAccessLevelsDeserializer.class) 110 @JsonSerialize(using = AllowedSharedLinkAccessLevelsSerializer.class) 111 @JsonProperty("allowed_shared_link_access_levels") 112 protected List<EnumWrapper<WebLinkAllowedSharedLinkAccessLevelsField>> 113 allowedSharedLinkAccessLevels; 114 115 public WebLink(@JsonProperty("id") String id) { 116 super(id); 117 } 118 119 protected WebLink(Builder builder) { 120 super(builder); 121 this.parent = builder.parent; 122 this.description = builder.description; 123 this.pathCollection = builder.pathCollection; 124 this.createdAt = builder.createdAt; 125 this.modifiedAt = builder.modifiedAt; 126 this.trashedAt = builder.trashedAt; 127 this.purgedAt = builder.purgedAt; 128 this.createdBy = builder.createdBy; 129 this.modifiedBy = builder.modifiedBy; 130 this.ownedBy = builder.ownedBy; 131 this.sharedLink = builder.sharedLink; 132 this.itemStatus = builder.itemStatus; 133 this.collections = builder.collections; 134 this.allowedSharedLinkAccessLevels = builder.allowedSharedLinkAccessLevels; 135 markNullableFieldsAsSet(builder.getExplicitlySetNullableFields()); 136 } 137 138 public FolderMini getParent() { 139 return parent; 140 } 141 142 public String getDescription() { 143 return description; 144 } 145 146 public WebLinkPathCollectionField getPathCollection() { 147 return pathCollection; 148 } 149 150 public OffsetDateTime getCreatedAt() { 151 return createdAt; 152 } 153 154 public OffsetDateTime getModifiedAt() { 155 return modifiedAt; 156 } 157 158 public OffsetDateTime getTrashedAt() { 159 return trashedAt; 160 } 161 162 public OffsetDateTime getPurgedAt() { 163 return purgedAt; 164 } 165 166 public UserMini getCreatedBy() { 167 return createdBy; 168 } 169 170 public UserMini getModifiedBy() { 171 return modifiedBy; 172 } 173 174 public UserMini getOwnedBy() { 175 return ownedBy; 176 } 177 178 public WebLinkSharedLinkField getSharedLink() { 179 return sharedLink; 180 } 181 182 public EnumWrapper<WebLinkItemStatusField> getItemStatus() { 183 return itemStatus; 184 } 185 186 public List<Collection> getCollections() { 187 return collections; 188 } 189 190 public List<EnumWrapper<WebLinkAllowedSharedLinkAccessLevelsField>> 191 getAllowedSharedLinkAccessLevels() { 192 return allowedSharedLinkAccessLevels; 193 } 194 195 @Override 196 public boolean equals(Object o) { 197 if (this == o) { 198 return true; 199 } 200 if (o == null || getClass() != o.getClass()) { 201 return false; 202 } 203 WebLink casted = (WebLink) o; 204 return Objects.equals(id, casted.id) 205 && Objects.equals(type, casted.type) 206 && Objects.equals(etag, casted.etag) 207 && Objects.equals(url, casted.url) 208 && Objects.equals(sequenceId, casted.sequenceId) 209 && Objects.equals(name, casted.name) 210 && Objects.equals(parent, casted.parent) 211 && Objects.equals(description, casted.description) 212 && Objects.equals(pathCollection, casted.pathCollection) 213 && Objects.equals(createdAt, casted.createdAt) 214 && Objects.equals(modifiedAt, casted.modifiedAt) 215 && Objects.equals(trashedAt, casted.trashedAt) 216 && Objects.equals(purgedAt, casted.purgedAt) 217 && Objects.equals(createdBy, casted.createdBy) 218 && Objects.equals(modifiedBy, casted.modifiedBy) 219 && Objects.equals(ownedBy, casted.ownedBy) 220 && Objects.equals(sharedLink, casted.sharedLink) 221 && Objects.equals(itemStatus, casted.itemStatus) 222 && Objects.equals(collections, casted.collections) 223 && Objects.equals(allowedSharedLinkAccessLevels, casted.allowedSharedLinkAccessLevels); 224 } 225 226 @Override 227 public int hashCode() { 228 return Objects.hash( 229 id, 230 type, 231 etag, 232 url, 233 sequenceId, 234 name, 235 parent, 236 description, 237 pathCollection, 238 createdAt, 239 modifiedAt, 240 trashedAt, 241 purgedAt, 242 createdBy, 243 modifiedBy, 244 ownedBy, 245 sharedLink, 246 itemStatus, 247 collections, 248 allowedSharedLinkAccessLevels); 249 } 250 251 @Override 252 public String toString() { 253 return "WebLink{" 254 + "id='" 255 + id 256 + '\'' 257 + ", " 258 + "type='" 259 + type 260 + '\'' 261 + ", " 262 + "etag='" 263 + etag 264 + '\'' 265 + ", " 266 + "url='" 267 + url 268 + '\'' 269 + ", " 270 + "sequenceId='" 271 + sequenceId 272 + '\'' 273 + ", " 274 + "name='" 275 + name 276 + '\'' 277 + ", " 278 + "parent='" 279 + parent 280 + '\'' 281 + ", " 282 + "description='" 283 + description 284 + '\'' 285 + ", " 286 + "pathCollection='" 287 + pathCollection 288 + '\'' 289 + ", " 290 + "createdAt='" 291 + createdAt 292 + '\'' 293 + ", " 294 + "modifiedAt='" 295 + modifiedAt 296 + '\'' 297 + ", " 298 + "trashedAt='" 299 + trashedAt 300 + '\'' 301 + ", " 302 + "purgedAt='" 303 + purgedAt 304 + '\'' 305 + ", " 306 + "createdBy='" 307 + createdBy 308 + '\'' 309 + ", " 310 + "modifiedBy='" 311 + modifiedBy 312 + '\'' 313 + ", " 314 + "ownedBy='" 315 + ownedBy 316 + '\'' 317 + ", " 318 + "sharedLink='" 319 + sharedLink 320 + '\'' 321 + ", " 322 + "itemStatus='" 323 + itemStatus 324 + '\'' 325 + ", " 326 + "collections='" 327 + collections 328 + '\'' 329 + ", " 330 + "allowedSharedLinkAccessLevels='" 331 + allowedSharedLinkAccessLevels 332 + '\'' 333 + "}"; 334 } 335 336 public static class Builder extends WebLinkMini.Builder { 337 338 protected FolderMini parent; 339 340 protected String description; 341 342 protected WebLinkPathCollectionField pathCollection; 343 344 protected OffsetDateTime createdAt; 345 346 protected OffsetDateTime modifiedAt; 347 348 protected OffsetDateTime trashedAt; 349 350 protected OffsetDateTime purgedAt; 351 352 protected UserMini createdBy; 353 354 protected UserMini modifiedBy; 355 356 protected UserMini ownedBy; 357 358 protected WebLinkSharedLinkField sharedLink; 359 360 protected EnumWrapper<WebLinkItemStatusField> itemStatus; 361 362 protected List<Collection> collections; 363 364 protected List<EnumWrapper<WebLinkAllowedSharedLinkAccessLevelsField>> 365 allowedSharedLinkAccessLevels; 366 367 public Builder(String id) { 368 super(id); 369 } 370 371 public Builder parent(FolderMini parent) { 372 this.parent = parent; 373 return this; 374 } 375 376 public Builder description(String description) { 377 this.description = description; 378 return this; 379 } 380 381 public Builder pathCollection(WebLinkPathCollectionField pathCollection) { 382 this.pathCollection = pathCollection; 383 return this; 384 } 385 386 public Builder createdAt(OffsetDateTime createdAt) { 387 this.createdAt = createdAt; 388 return this; 389 } 390 391 public Builder modifiedAt(OffsetDateTime modifiedAt) { 392 this.modifiedAt = modifiedAt; 393 return this; 394 } 395 396 public Builder trashedAt(OffsetDateTime trashedAt) { 397 this.trashedAt = trashedAt; 398 this.markNullableFieldAsSet("trashed_at"); 399 return this; 400 } 401 402 public Builder purgedAt(OffsetDateTime purgedAt) { 403 this.purgedAt = purgedAt; 404 this.markNullableFieldAsSet("purged_at"); 405 return this; 406 } 407 408 public Builder createdBy(UserMini createdBy) { 409 this.createdBy = createdBy; 410 return this; 411 } 412 413 public Builder modifiedBy(UserMini modifiedBy) { 414 this.modifiedBy = modifiedBy; 415 return this; 416 } 417 418 public Builder ownedBy(UserMini ownedBy) { 419 this.ownedBy = ownedBy; 420 return this; 421 } 422 423 public Builder sharedLink(WebLinkSharedLinkField sharedLink) { 424 this.sharedLink = sharedLink; 425 return this; 426 } 427 428 public Builder itemStatus(WebLinkItemStatusField itemStatus) { 429 this.itemStatus = new EnumWrapper<WebLinkItemStatusField>(itemStatus); 430 return this; 431 } 432 433 public Builder itemStatus(EnumWrapper<WebLinkItemStatusField> itemStatus) { 434 this.itemStatus = itemStatus; 435 return this; 436 } 437 438 public Builder collections(List<Collection> collections) { 439 this.collections = collections; 440 return this; 441 } 442 443 public Builder allowedSharedLinkAccessLevels( 444 List<? extends Valuable> allowedSharedLinkAccessLevels) { 445 this.allowedSharedLinkAccessLevels = 446 EnumWrapper.wrapValuableEnumList( 447 allowedSharedLinkAccessLevels, WebLinkAllowedSharedLinkAccessLevelsField.class); 448 return this; 449 } 450 451 @Override 452 public Builder type(WebLinkBaseTypeField type) { 453 this.type = new EnumWrapper<WebLinkBaseTypeField>(type); 454 return this; 455 } 456 457 @Override 458 public Builder type(EnumWrapper<WebLinkBaseTypeField> type) { 459 this.type = type; 460 return this; 461 } 462 463 @Override 464 public Builder etag(String etag) { 465 this.etag = etag; 466 return this; 467 } 468 469 @Override 470 public Builder url(String url) { 471 this.url = url; 472 return this; 473 } 474 475 @Override 476 public Builder sequenceId(String sequenceId) { 477 this.sequenceId = sequenceId; 478 return this; 479 } 480 481 @Override 482 public Builder name(String name) { 483 this.name = name; 484 return this; 485 } 486 487 public WebLink build() { 488 if (this.type == null) { 489 this.type = new EnumWrapper<WebLinkBaseTypeField>(WebLinkBaseTypeField.WEB_LINK); 490 } 491 return new WebLink(this); 492 } 493 } 494 495 public static class AllowedSharedLinkAccessLevelsDeserializer 496 extends JsonDeserializer<List<EnumWrapper<WebLinkAllowedSharedLinkAccessLevelsField>>> { 497 498 public final JsonDeserializer<EnumWrapper<WebLinkAllowedSharedLinkAccessLevelsField>> 499 elementDeserializer; 500 501 public AllowedSharedLinkAccessLevelsDeserializer() { 502 super(); 503 this.elementDeserializer = 504 new WebLinkAllowedSharedLinkAccessLevelsField 505 .WebLinkAllowedSharedLinkAccessLevelsFieldDeserializer(); 506 } 507 508 @Override 509 public List<EnumWrapper<WebLinkAllowedSharedLinkAccessLevelsField>> deserialize( 510 JsonParser p, DeserializationContext ctxt) throws IOException { 511 JsonNode node = p.getCodec().readTree(p); 512 List<EnumWrapper<WebLinkAllowedSharedLinkAccessLevelsField>> elements = new ArrayList<>(); 513 for (JsonNode item : node) { 514 JsonParser pa = item.traverse(p.getCodec()); 515 pa.nextToken(); 516 elements.add(elementDeserializer.deserialize(pa, ctxt)); 517 } 518 return elements; 519 } 520 } 521 522 public static class AllowedSharedLinkAccessLevelsSerializer 523 extends JsonSerializer<List<EnumWrapper<WebLinkAllowedSharedLinkAccessLevelsField>>> { 524 525 public final JsonSerializer<EnumWrapper<WebLinkAllowedSharedLinkAccessLevelsField>> 526 elementSerializer; 527 528 public AllowedSharedLinkAccessLevelsSerializer() { 529 super(); 530 this.elementSerializer = 531 new WebLinkAllowedSharedLinkAccessLevelsField 532 .WebLinkAllowedSharedLinkAccessLevelsFieldSerializer(); 533 } 534 535 @Override 536 public void serialize( 537 List<EnumWrapper<WebLinkAllowedSharedLinkAccessLevelsField>> value, 538 JsonGenerator gen, 539 SerializerProvider serializers) 540 throws IOException { 541 gen.writeStartArray(); 542 for (EnumWrapper<WebLinkAllowedSharedLinkAccessLevelsField> item : value) { 543 elementSerializer.serialize(item, gen, serializers); 544 } 545 gen.writeEndArray(); 546 } 547 } 548}