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