001package com.box.sdk; 002 003import com.box.sdk.internal.utils.JsonUtils; 004import com.eclipsesource.json.JsonObject; 005import com.eclipsesource.json.JsonValue; 006import java.util.ArrayList; 007import java.util.Date; 008import java.util.List; 009 010/** 011 * Represents a signer in BoxSignRequest. 012 */ 013public class BoxSignRequestSigner extends BoxJSONObject { 014 private String email; 015 private BoxSignRequestSignerRole role; 016 private Boolean isInPerson; 017 private Integer order; 018 private String embedUrlExternalUserId; 019 private Boolean hasViewedEmail; 020 private Boolean hasViewedDocument; 021 private BoxSignerDecision signerDecision; 022 private List<BoxSignerInput> inputs; 023 private String embedUrl; 024 private BoxAPIConnection api; 025 026 /** 027 * Constructs a BoxSignRequestSigner with an email. 028 * 029 * @param email of signer. 030 */ 031 public BoxSignRequestSigner(String email) { 032 this.email = email; 033 } 034 035 /** 036 * Construct a BoxSignRequestSigner. 037 * 038 * @param jsonObject the parsed JSON object. 039 * @param api the API connection to be used to fetch interacted item 040 */ 041 public BoxSignRequestSigner(JsonObject jsonObject, BoxAPIConnection api) { 042 super(jsonObject); 043 this.api = api; 044 } 045 046 /** 047 * Gets the email address of the signer. 048 * 049 * @return email address of the signer. 050 */ 051 public String getEmail() { 052 return this.email; 053 } 054 055 /** 056 * Sets the email address of the signer. 057 * 058 * @param email address of the signer. 059 * @return this BoxSignRequestSigner object for chaining. 060 */ 061 public BoxSignRequestSigner setEmail(String email) { 062 this.email = email; 063 return this; 064 } 065 066 /** 067 * Gets the role of the signer. 068 * 069 * @return role of the signer. 070 */ 071 public BoxSignRequestSignerRole getRole() { 072 return this.role; 073 } 074 075 /** 076 * Sets the role of the signer. If role is not set it's FinalCopyReader by default. 077 * 078 * @param role of the signer. 079 * @return this BoxSignRequestSigner object for chaining. 080 */ 081 public BoxSignRequestSigner setRole(BoxSignRequestSignerRole role) { 082 this.role = role; 083 return this; 084 } 085 086 /** 087 * Gets the flag that when used in combination with an embed url on the sender. After the sender signs, 088 * they will be redirected to the next InPerson signer. 089 * 090 * @return true if is in person signer, otherwise false. 091 */ 092 public boolean getIsInPerson() { 093 return this.isInPerson; 094 } 095 096 /** 097 * Gets the order of signer. 098 * 099 * @return order of signer. 100 */ 101 public int getOrder() { 102 return this.order; 103 } 104 105 /** 106 * Sets the order of signer. 107 * 108 * @param order of signer. 109 * @return this BoxSignRequestSigner object for chaining. 110 */ 111 public BoxSignRequestSigner setOrder(Integer order) { 112 this.order = order; 113 return this; 114 } 115 116 /** 117 * Gets the user id for this signer in external application responsible 118 * for authentication when accessing the embed url. 119 * 120 * @return embed url external user id. 121 */ 122 public String getEmbedUrlExternalUserId() { 123 return this.embedUrlExternalUserId; 124 } 125 126 /** 127 * Sets the user id for this signer in external application responsible 128 * for authentication when accessing the embed url. 129 * 130 * @param embedUrlExternalUserId for this signer in external application responsible 131 * for authentication when accessing the embed url. 132 * @return this BoxSignRequestSigner object for chaining. 133 */ 134 public BoxSignRequestSigner setEmbedUrlExternalUserId(String embedUrlExternalUserId) { 135 this.embedUrlExternalUserId = embedUrlExternalUserId; 136 return this; 137 } 138 139 /** 140 * Gets the flag indicating if signer has viewed the sign request email. 141 * 142 * @return true if the signer has viewed the sign request email, otherwise false. 143 */ 144 public boolean getHasViewedEmail() { 145 return this.hasViewedEmail; 146 } 147 148 /** 149 * Gets the flag indicating if signer has viewed the document. 150 * 151 * @return true if the signer has viewed the document, otherwise false. 152 */ 153 public boolean getHasViewedDocument() { 154 return this.hasViewedDocument; 155 } 156 157 /** 158 * Gets the final decision made by signer. 159 * 160 * @return final decision made by signer. 161 */ 162 public BoxSignerDecision getSignerDecision() { 163 return this.signerDecision; 164 } 165 166 /** 167 * Gets the inputs created by a signer on a sign request. 168 * 169 * @return list of inputs created by a signer on a sign request. 170 */ 171 public List<BoxSignerInput> getInputs() { 172 return this.inputs; 173 } 174 175 /** 176 * Gets the url to direct signer to for signing. 177 * 178 * @return url to direct signer to for signing. 179 */ 180 public String getEmbedUrl() { 181 return this.embedUrl; 182 } 183 184 /** 185 * Gets the flag that is used in combination with an embed url for a the sender. After the sender signs, 186 * they will be redirected to the next InPerson signer. 187 * 188 * @return true if is in person signer, otherwise false. 189 */ 190 public Boolean getInPerson() { 191 return this.isInPerson; 192 } 193 194 /** 195 * Sets the flag that is used in combination with an embed url for a the sender. After the sender signs, 196 * they will be redirected to the next InPerson signer. 197 * 198 * @param isInPerson flag. 199 * @return this BoxSignRequestSigner object for chaining. 200 */ 201 public BoxSignRequestSigner setInPerson(Boolean isInPerson) { 202 this.isInPerson = isInPerson; 203 return this; 204 } 205 206 /** 207 * {@inheritDoc} 208 */ 209 @Override 210 void parseJSONMember(JsonObject.Member member) { 211 JsonValue value = member.getValue(); 212 String memberName = member.getName(); 213 try { 214 if ("email".equals(memberName)) { 215 this.email = value.asString(); 216 } else if ("role".equals(memberName)) { 217 this.role = BoxSignRequestSignerRole.fromJSONString(value.asString()); 218 } else if ("is_in_person".equals(memberName)) { 219 this.isInPerson = value.asBoolean(); 220 } else if ("order".equals(memberName)) { 221 this.order = value.asInt(); 222 } else if ("embed_url_external_user_id".equals(memberName)) { 223 this.embedUrlExternalUserId = value.asString(); 224 } else if ("has_viewed_email".equals(memberName)) { 225 this.hasViewedEmail = value.asBoolean(); 226 } else if ("has_viewed_document".equals(memberName)) { 227 this.hasViewedDocument = value.asBoolean(); 228 } else if ("signer_decision".equals(memberName)) { 229 JsonObject signerDecisionJSON = value.asObject(); 230 BoxSignerDecision signerDecision = new BoxSignerDecision(signerDecisionJSON); 231 this.signerDecision = signerDecision; 232 } else if ("inputs".equals(memberName)) { 233 List<BoxSignerInput> inputs = new ArrayList<BoxSignerInput>(); 234 for (JsonValue inputJSON : value.asArray()) { 235 BoxSignerInput input = new BoxSignerInput(inputJSON.asObject()); 236 inputs.add(input); 237 } 238 this.inputs = inputs; 239 } else if ("embed_url".equals(memberName)) { 240 this.embedUrl = value.asString(); 241 } 242 } catch (Exception e) { 243 throw new BoxDeserializationException(memberName, value.toString(), e); 244 } 245 } 246 247 /** 248 * Gets a JSON object representing this class. 249 * 250 * @return the JSON object representing this class. 251 */ 252 public JsonObject getJSONObject() { 253 JsonObject jsonObj = new JsonObject(); 254 JsonUtils.addIfNotNull(jsonObj, "email", this.email); 255 JsonUtils.addIfNotNull(jsonObj, "role", this.role); 256 JsonUtils.addIfNotNull(jsonObj, "is_in_person", this.isInPerson); 257 JsonUtils.addIfNotNull(jsonObj, "order", this.order); 258 JsonUtils.addIfNotNull(jsonObj, "embed_url_external_user_id", this.embedUrlExternalUserId); 259 260 return jsonObj; 261 } 262 263 /** 264 * Type of decision made by signer. 265 */ 266 public enum BoxSignRequestSignerDecisionType { 267 268 /** 269 * Signed decision. 270 */ 271 Signed("signed"), 272 273 /** 274 * Declined decision. 275 */ 276 Declined("declined"); 277 278 private final String jsonValue; 279 280 BoxSignRequestSignerDecisionType(String jsonValue) { 281 this.jsonValue = jsonValue; 282 } 283 284 static BoxSignRequestSignerDecisionType fromJSONString(String jsonValue) { 285 if ("signed".equals(jsonValue)) { 286 return Signed; 287 } else if ("declined".equals(jsonValue)) { 288 return Declined; 289 } 290 throw new IllegalArgumentException("The provided JSON value isn't a valid " 291 + "BoxSignRequestSignerDecisionType."); 292 } 293 } 294 295 /** 296 * Represents a type of input. 297 */ 298 public enum BoxSignRequestInputType { 299 300 /** 301 * Signature input. 302 */ 303 Signature("signature"), 304 305 /** 306 * Text input. 307 */ 308 Text("text"), 309 310 /** 311 * Checkbox input. 312 */ 313 Checkbox("checkbox"), 314 315 /** 316 * Date input. 317 */ 318 Date("date"); 319 320 private final String jsonValue; 321 322 BoxSignRequestInputType(String jsonValue) { 323 this.jsonValue = jsonValue; 324 } 325 326 static BoxSignRequestInputType fromJSONString(String jsonValue) { 327 if ("signature".equals(jsonValue)) { 328 return Signature; 329 } else if ("text".equals(jsonValue)) { 330 return Text; 331 } else if ("checkbox".equals(jsonValue)) { 332 return Checkbox; 333 } else if ("date".equals(jsonValue)) { 334 return Date; 335 } 336 throw new IllegalArgumentException("The provided JSON value isn't a valid " 337 + "BoxSignRequestInputType."); 338 } 339 } 340 341 /** 342 * Represents a final decision made by signer (type and time the decision was made). 343 */ 344 public class BoxSignerDecision extends BoxJSONObject { 345 private BoxSignRequestSignerDecisionType type; 346 private Date finalizedAt; 347 348 /** 349 * Constructs a BoxSignerDecision object using an already parsed JSON object. 350 * 351 * @param jsonObject the parsed JSON object. 352 */ 353 public BoxSignerDecision(JsonObject jsonObject) { 354 super(jsonObject); 355 } 356 357 /** 358 * Gets the type of decision made by signer. 359 * 360 * @return type of decision made by signer. 361 */ 362 public BoxSignRequestSignerDecisionType getType() { 363 return this.type; 364 } 365 366 /** 367 * Gets the date/time that the decision was made. 368 * 369 * @return date/time that the decision was made. 370 */ 371 public Date getFinalizedAt() { 372 return this.finalizedAt; 373 } 374 375 /** 376 * {@inheritDoc} 377 */ 378 @Override 379 void parseJSONMember(JsonObject.Member member) { 380 JsonValue value = member.getValue(); 381 String memberName = member.getName(); 382 try { 383 if (memberName.equals("type")) { 384 this.type = BoxSignRequestSignerDecisionType.fromJSONString(value.asString()); 385 } else if (memberName.equals("finalized_at")) { 386 this.finalizedAt = BoxDateFormat.parse(value.asString()); 387 } 388 } catch (Exception e) { 389 throw new BoxDeserializationException(memberName, value.toString(), e); 390 } 391 } 392 } 393 394 /** 395 * Represents an input created by a signer on a sign request. 396 */ 397 public class BoxSignerInput extends BoxJSONObject { 398 private String documentTagId; 399 private String textValue; 400 private boolean checkboxValue; 401 private Date dateValue; 402 private BoxSignRequestInputType type; 403 private int pageIndex; 404 405 /** 406 * Constructs a BoxSignerInput object using an already parsed JSON object. 407 * 408 * @param jsonObject the parsed JSON object. 409 */ 410 public BoxSignerInput(JsonObject jsonObject) { 411 super(jsonObject); 412 } 413 414 /** 415 * Gets the reference of the id of a particular tag added to the content 416 * of the files being used to create the sign request. 417 * 418 * @return document tag id. 419 */ 420 public String getDocumentTagId() { 421 return this.documentTagId; 422 } 423 424 /** 425 * Gets the text prefill value. 426 * 427 * @return text prefill value. 428 */ 429 public String getTextValue() { 430 return this.textValue; 431 } 432 433 /** 434 * Gets the checkbox prefill value. 435 * 436 * @return checkbox prefill value. 437 */ 438 public boolean getIsCheckboxValue() { 439 return this.checkboxValue; 440 } 441 442 /** 443 * Gets the date prefill value. 444 * 445 * @return date prefill value. 446 */ 447 public Date getDateValue() { 448 return this.dateValue; 449 } 450 451 /** 452 * Gets the type of input. 453 * 454 * @return type of input. 455 */ 456 public BoxSignRequestInputType getType() { 457 return this.type; 458 } 459 460 /** 461 * Gets the index of page that input is on. 462 * 463 * @return index of page that input is on. 464 */ 465 public int getPageIndex() { 466 return this.pageIndex; 467 } 468 469 /** 470 * {@inheritDoc} 471 */ 472 @Override 473 void parseJSONMember(JsonObject.Member member) { 474 JsonValue value = member.getValue(); 475 String memberName = member.getName(); 476 try { 477 if ("documentTagId".equals(memberName)) { 478 this.documentTagId = value.asString(); 479 } else if ("text_value".equals(memberName)) { 480 this.textValue = value.asString(); 481 } else if ("checkbox_value".equals(memberName)) { 482 this.checkboxValue = value.asBoolean(); 483 } else if ("date_value".equals(memberName)) { 484 this.dateValue = BoxDateFormat.parse(value.asString()); 485 } else if ("type".equals(memberName)) { 486 this.type = BoxSignRequestInputType.fromJSONString(value.asString()); 487 } else if ("page_index".equals(memberName)) { 488 this.pageIndex = value.asInt(); 489 } 490 } catch (Exception e) { 491 throw new BoxDeserializationException(memberName, value.toString(), e); 492 } 493 } 494 } 495} 496 497