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