001package com.box.sdk; 002 003import static java.lang.String.format; 004 005import com.eclipsesource.json.JsonObject; 006import com.eclipsesource.json.JsonValue; 007import java.util.ArrayList; 008import java.util.Date; 009import java.util.List; 010 011 012/** 013 * Box Sign Template signer. 014 */ 015public class BoxSignTemplateSigner extends BoxJSONObject { 016 private String email; 017 private List<BoxSignTemplateSignerInput> inputs; 018 private Boolean isInPerson; 019 private int order; 020 private BoxSignRequestSignerRole role; 021 private BoxAPIConnection api; 022 023 /** 024 * Constructs a BoxSignTemplateSigner object with the provided information. 025 * 026 * @param email the email. 027 * @param inputs the inputs. 028 * @param isInPerson whether the signer is in person or not. 029 * @param order the order. 030 * @param role the role. 031 */ 032 public BoxSignTemplateSigner(String email, List<BoxSignTemplateSignerInput> inputs, Boolean isInPerson, 033 int order, BoxSignRequestSignerRole role) { 034 this.email = email; 035 this.inputs = inputs; 036 this.isInPerson = isInPerson; 037 this.order = order; 038 this.role = role; 039 } 040 041 /** 042 * Constructs a BoxSignTemplateSigner object with the provided JSON object. 043 * 044 * @param jsonObject the JSON object representing the Sign Template Signer. 045 */ 046 public BoxSignTemplateSigner(JsonObject jsonObject, BoxAPIConnection api) { 047 super(jsonObject); 048 this.api = api; 049 } 050 051 /** 052 * Gets the email of the signer. 053 * 054 * @return the email of the signer. 055 */ 056 public String getEmail() { 057 return this.email; 058 } 059 060 /** 061 * Gets the inputs of the signer. 062 * 063 * @return the inputs of the signer. 064 */ 065 public List<BoxSignTemplateSignerInput> getInputs() { 066 return this.inputs; 067 } 068 069 /** 070 * Used in combination with an embed URL for a sender. 071 * After the sender signs, they will be redirected to the next in_person signer. 072 * 073 * @return true if the signer is in person; otherwise false. 074 */ 075 public Boolean getIsInPerson() { 076 return this.isInPerson; 077 } 078 079 /** 080 * Gets the order of the signer. 081 * 082 * @return the order of the signer. 083 */ 084 public int getOrder() { 085 return this.order; 086 } 087 088 /** 089 * Gets the role of the signer. 090 * 091 * @return the role of the signer. 092 */ 093 public BoxSignRequestSignerRole getRole() { 094 return this.role; 095 } 096 097 /** 098 * {@inheritDoc} 099 */ 100 @Override 101 void parseJSONMember(JsonObject.Member member) { 102 JsonValue value = member.getValue(); 103 String memberName = member.getName(); 104 try { 105 switch (memberName) { 106 case "email": 107 this.email = value.asString(); 108 break; 109 case "inputs": 110 this.inputs = new ArrayList<BoxSignTemplateSignerInput>(); 111 for (JsonValue inputJSON : value.asArray()) { 112 this.inputs.add(new BoxSignTemplateSignerInput(inputJSON.asObject(), this.api)); 113 } 114 break; 115 case "is_in_person": 116 this.isInPerson = value.asBoolean(); 117 break; 118 case "order": 119 this.order = value.asInt(); 120 break; 121 case "role": 122 this.role = BoxSignRequestSignerRole.fromJSONString(value.asString()); 123 break; 124 default: 125 return; 126 } 127 } catch (Exception e) { 128 throw new BoxDeserializationException(memberName, value.toString(), e); 129 } 130 } 131 132 /** 133 * Box Sign Template signer input. 134 */ 135 public class BoxSignTemplateSignerInput extends BoxJSONObject { 136 private BoxSignTemplateSignerInputType type; 137 private Boolean checkboxValue; 138 private BoxSignTemplateSignerInputContentType contentType; 139 private BoxSignTemplateSignerInputCoordinates coordinates; 140 private Date dateValue; 141 private BoxSignTemplatesSignerInputDimensions dimensions; 142 private String documentId; 143 private String documentTagId; 144 private List<String> dropdownChoices; 145 private String groupId; 146 private Boolean isRequired; 147 private int pageIndex; 148 private String textValue; 149 private String label; 150 private BoxAPIConnection api; 151 152 /** 153 * Constructs a BoxSignTemplateSignerInput object with the provided information. 154 * 155 * @param type the type. 156 * @param checkboxValue the checkbox value. 157 * @param contentType the content type. 158 * @param coordinates the coordinates. 159 * @param dateValue the date value. 160 * @param dimensions the dimensions. 161 * @param documentId the document ID. 162 * @param documentTagId the document tag ID. 163 * @param dropdownChoices the dropdown choices. 164 * @param groupId the group ID. 165 * @param isRequired whether the input is required or not. 166 * @param pageIndex the page index. 167 * @param textValue the text value. 168 * @param label the label. 169 */ 170 public BoxSignTemplateSignerInput(BoxSignTemplateSignerInputType type, Boolean checkboxValue, 171 BoxSignTemplateSignerInputContentType contentType, 172 BoxSignTemplateSignerInputCoordinates coordinates, Date dateValue, 173 BoxSignTemplatesSignerInputDimensions dimensions, String documentId, 174 String documentTagId, List<String> dropdownChoices, String groupId, 175 Boolean isRequired, int pageIndex, String textValue, String label) { 176 this.type = type; 177 this.checkboxValue = checkboxValue; 178 this.contentType = contentType; 179 this.coordinates = coordinates; 180 this.dateValue = dateValue; 181 this.dimensions = dimensions; 182 this.documentId = documentId; 183 this.documentTagId = documentTagId; 184 this.dropdownChoices = dropdownChoices; 185 this.groupId = groupId; 186 this.isRequired = isRequired; 187 this.pageIndex = pageIndex; 188 this.textValue = textValue; 189 this.label = label; 190 } 191 192 /** 193 * Constructs a BoxSignTemplateSignerInput object with the provided JSON object. 194 * 195 * @param jsonObject the JSON object representing the Sign Template Signer Input. 196 */ 197 public BoxSignTemplateSignerInput(JsonObject jsonObject, BoxAPIConnection api) { 198 super(jsonObject); 199 this.api = api; 200 } 201 202 /** 203 * Gets the type of the input. 204 * 205 * @return the type of the input. 206 */ 207 public BoxSignTemplateSignerInputType getType() { 208 return this.type; 209 } 210 211 /** 212 * Gets the checkbox value. 213 * 214 * @return the checkbox value. 215 */ 216 public Boolean getCheckboxValue() { 217 return this.checkboxValue; 218 } 219 220 /** 221 * Gets the content type. 222 * 223 * @return the content type. 224 */ 225 public BoxSignTemplateSignerInputContentType getContentType() { 226 return this.contentType; 227 } 228 229 /** 230 * Gets the coordinates. 231 * 232 * @return the coordinates. 233 */ 234 public BoxSignTemplateSignerInputCoordinates getCoordinates() { 235 return this.coordinates; 236 } 237 238 /** 239 * Gets the date value. 240 * 241 * @return the date value. 242 */ 243 public Date getDateValue() { 244 return this.dateValue; 245 } 246 247 /** 248 * Gets the dimensions. 249 * 250 * @return the dimensions. 251 */ 252 public BoxSignTemplatesSignerInputDimensions getDimensions() { 253 return this.dimensions; 254 } 255 256 /** 257 * Gets the document ID. 258 * 259 * @return the document ID. 260 */ 261 public String getDocumentId() { 262 return this.documentId; 263 } 264 265 /** 266 * Gets the document tag ID. 267 * 268 * @return the document tag ID. 269 */ 270 public String getDocumentTagId() { 271 return this.documentTagId; 272 } 273 274 /** 275 * Gets the dropdown choices. 276 * 277 * @return the dropdown choices. 278 */ 279 public List<String> getDropdownChoices() { 280 return this.dropdownChoices; 281 } 282 283 /** 284 * Gets the group ID. 285 * 286 * @return the group ID. 287 */ 288 public String getGroupId() { 289 return this.groupId; 290 } 291 292 /** 293 * Gets whether the input is required or not. 294 * 295 * @return true if the input is required; otherwise false. 296 */ 297 public Boolean getIsRequired() { 298 return this.isRequired; 299 } 300 301 /** 302 * Gets the page index. 303 * 304 * @return the page index. 305 */ 306 public int getPageIndex() { 307 return this.pageIndex; 308 } 309 310 /** 311 * Gets the text value. 312 * 313 * @return the text value. 314 */ 315 public String getTextValue() { 316 return this.textValue; 317 } 318 319 /** 320 * Gets the label. 321 * 322 * @return the label. 323 */ 324 public String getLabel() { 325 return this.label; 326 } 327 328 /** 329 * {@inheritDoc} 330 */ 331 @Override 332 void parseJSONMember(JsonObject.Member member) { 333 JsonValue value = member.getValue(); 334 String memberName = member.getName(); 335 try { 336 switch (memberName) { 337 case "type": 338 this.type = BoxSignTemplateSignerInputType.fromJSONString(value.asString()); 339 break; 340 case "checkbox_value": 341 this.checkboxValue = value.asBoolean(); 342 break; 343 case "content_type": 344 this.contentType = BoxSignTemplateSignerInputContentType.fromJSONString(value.asString()); 345 break; 346 case "coordinates": 347 JsonObject coordinatesJSON = value.asObject(); 348 double x = coordinatesJSON.get("x").asFloat(); 349 double y = coordinatesJSON.get("y").asFloat(); 350 this.coordinates = new BoxSignTemplateSignerInputCoordinates(x, y); 351 break; 352 case "date_value": 353 this.dateValue = BoxDateFormat.parse(value.asString()); 354 break; 355 case "dimensions": 356 JsonObject dimensionsJSON = value.asObject(); 357 double height = dimensionsJSON.get("height").asFloat(); 358 double width = dimensionsJSON.get("width").asFloat(); 359 this.dimensions = new BoxSignTemplatesSignerInputDimensions(height, width); 360 break; 361 case "document_id": 362 this.documentId = value.asString(); 363 break; 364 case "document_tag_id": 365 this.documentTagId = value.asString(); 366 break; 367 case "dropdown_choices": 368 this.dropdownChoices = new ArrayList<String>(); 369 for (JsonValue choiceJSON : value.asArray()) { 370 this.dropdownChoices.add(choiceJSON.asString()); 371 } 372 break; 373 case "group_id": 374 this.groupId = value.asString(); 375 break; 376 case "is_required": 377 this.isRequired = value.asBoolean(); 378 break; 379 case "page_index": 380 this.pageIndex = value.asInt(); 381 break; 382 case "text_value": 383 this.textValue = value.asString(); 384 break; 385 case "label": 386 this.label = value.asString(); 387 break; 388 default: 389 return; 390 } 391 } catch (Exception e) { 392 throw new BoxDeserializationException(memberName, value.toString(), e); 393 } 394 } 395 } 396 397 /** 398 * Box Sign Template signer input coordinates. 399 */ 400 public class BoxSignTemplateSignerInputCoordinates { 401 private final double x; 402 private final double y; 403 404 /** 405 * Constructs a BoxSignTemplateSignerInputCoordinates object with the provided information. 406 * 407 * @param x the x coordinate. 408 * @param y the y coordinate. 409 */ 410 public BoxSignTemplateSignerInputCoordinates(double x, double y) { 411 this.x = x; 412 this.y = y; 413 } 414 415 /** 416 * Gets the x coordinate. 417 * 418 * @return the x coordinate. 419 */ 420 public double getX() { 421 return this.x; 422 } 423 424 /** 425 * Gets the y coordinate. 426 * 427 * @return the y coordinate. 428 */ 429 public double getY() { 430 return this.y; 431 } 432 } 433 434 /** 435 * Box Sign Template signer input dimensions. 436 */ 437 public class BoxSignTemplatesSignerInputDimensions { 438 private final double height; 439 private final double width; 440 441 /** 442 * Constructs a BoxSignTemplatesSignerInputDimensions object with the provided information. 443 * 444 * @param height the height. 445 * @param width the width. 446 */ 447 public BoxSignTemplatesSignerInputDimensions(double height, double width) { 448 this.height = height; 449 this.width = width; 450 } 451 452 /** 453 * Gets the height. 454 * 455 * @return the height. 456 */ 457 public double getHeight() { 458 return this.height; 459 } 460 461 /** 462 * Gets the width. 463 * 464 * @return the width. 465 */ 466 public double getWidth() { 467 return this.width; 468 } 469 } 470 471 /** 472 * Box Sign Template signer input type. 473 */ 474 public enum BoxSignTemplateSignerInputType { 475 /** 476 * Signature input type. 477 */ 478 Signature("signature"), 479 /** 480 * Date input type. 481 */ 482 Date("date"), 483 /** 484 * Text input type. 485 */ 486 Text("text"), 487 /** 488 * Checkbox input type. 489 */ 490 Checkbox("checkbox"), 491 /** 492 * Attachment input type. 493 */ 494 Attachment("attachment"), 495 /** 496 * Radio input type. 497 */ 498 Radio("radio"), 499 /** 500 * Dropdown input type. 501 */ 502 Dropdown("dropdown"); 503 504 private final String jsonValue; 505 506 BoxSignTemplateSignerInputType(String jsonValue) { 507 this.jsonValue = jsonValue; 508 } 509 510 static BoxSignTemplateSignerInputType fromJSONString(String jsonValue) { 511 switch (jsonValue) { 512 case "signature": 513 return Signature; 514 case "date": 515 return Date; 516 case "text": 517 return Text; 518 case "checkbox": 519 return Checkbox; 520 case "attachment": 521 return Attachment; 522 case "radio": 523 return Radio; 524 case "dropdown": 525 return Dropdown; 526 default: 527 throw new IllegalArgumentException( 528 format("The provided JSON value '%s' isn't a valid BoxSignTemplateSignerInputType.", 529 jsonValue) 530 ); 531 } 532 } 533 } 534 535 /** 536 * Box Sign Template signer input content type. 537 */ 538 public enum BoxSignTemplateSignerInputContentType { 539 /** 540 * Initial content type 541 */ 542 Initial("initial"), 543 /** 544 * Stamp content type 545 */ 546 Stamp("stamp"), 547 /** 548 * Signature content type 549 */ 550 Signature("signature"), 551 /** 552 * Company content type 553 */ 554 Company("company"), 555 /** 556 * Title content type 557 */ 558 Title("title"), 559 /** 560 * Email content type 561 */ 562 Email("email"), 563 /** 564 * Full name content type 565 */ 566 FullName("full_name"), 567 /** 568 * First name content type 569 */ 570 FirstName("first_name"), 571 /** 572 * Last name content type 573 */ 574 LastName("last_name"), 575 /** 576 * Text content type 577 */ 578 Text("text"), 579 /** 580 * Date content type 581 */ 582 Date("date"), 583 /** 584 * Checkbox content type 585 */ 586 Checkbox("checkbox"), 587 /** 588 * Attachement content type 589 */ 590 Attachement("attachment"), 591 /** 592 * Radio content type 593 */ 594 Radio("radio"), 595 /** 596 * Dropdown content type 597 */ 598 Dropdown("dropdown"); 599 600 private final String jsonValue; 601 602 BoxSignTemplateSignerInputContentType(String jsonValue) { 603 this.jsonValue = jsonValue; 604 } 605 606 static BoxSignTemplateSignerInputContentType fromJSONString(String jsonValue) { 607 switch (jsonValue) { 608 case "initial": 609 return Initial; 610 case "stamp": 611 return Stamp; 612 case "signature": 613 return Signature; 614 case "company": 615 return Company; 616 case "title": 617 return Title; 618 case "email": 619 return Email; 620 case "full_name": 621 return FullName; 622 case "first_name": 623 return FirstName; 624 case "last_name": 625 return LastName; 626 case "text": 627 return Text; 628 case "date": 629 return Date; 630 case "checkbox": 631 return Checkbox; 632 case "attachment": 633 return Attachement; 634 case "radio": 635 return Radio; 636 case "dropdown": 637 return Dropdown; 638 default: 639 throw new IllegalArgumentException( 640 format("The provided JSON value '%s' isn't a valid BoxSignTemplateSignerInputContentType.", 641 jsonValue) 642 ); 643 } 644 } 645 } 646}