Skip to content

Commit

Permalink
feat: Add redirect_url and declined_redirect_url to Sign Request (#…
Browse files Browse the repository at this point in the history
…1089)

* feat: Add `redirect_url` and `declined_redirect_url` to Sign Request
  • Loading branch information
congminh1254 authored Aug 26, 2022
1 parent 5477223 commit 3921fe1
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 91 deletions.
166 changes: 107 additions & 59 deletions src/main/java/com/box/sdk/BoxSignRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ public class Info extends BoxResource.Info {
private BoxSignRequestStatus status;
private BoxSignRequestSignFiles signFiles;
private Date autoExpireAt;
private String redirectUrl;
private String declinedRedirectUrl;

/**
* Constructs an empty Info object.
Expand Down Expand Up @@ -557,6 +559,24 @@ public Date getAutoExpireAt() {
return this.autoExpireAt;
}

/**
* Gets the URL that will be redirected to after the signer completes the sign request.
*
* @return redirect url.
*/
public String getRedirectUrl() {
return this.redirectUrl;
}

/**
* Gets the URL that will be redirected to after the signer declines the sign request.
*
* @return declined redirect url.
*/
public String getDeclinedRedirectUrl() {
return this.declinedRedirectUrl;
}

/**
* {@inheritDoc}
*/
Expand All @@ -574,65 +594,93 @@ void parseJSONMember(JsonObject.Member member) {
String memberName = member.getName();
JsonValue value = member.getValue();
try {
if ("is_document_preparation_needed".equals(memberName)) {
this.isDocumentPreparationNeeded = value.asBoolean();
} else if ("are_text_signatures_enabled".equals(memberName)) {
this.areTextSignaturesEnabled = value.asBoolean();
} else if ("are_dates_enabled".equals(memberName)) {
this.areDatesEnabled = value.asBoolean();
} else if ("signature_color".equals(memberName)) {
this.signatureColor = BoxSignRequestSignatureColor.fromJSONString(value.asString());
} else if ("email_subject".equals(memberName)) {
this.emailSubject = value.asString();
} else if ("email_message".equals(memberName)) {
this.emailMessage = value.asString();
} else if ("are_reminders_enabled".equals(memberName)) {
this.areRemindersEnabled = value.asBoolean();
} else if ("signers".equals(memberName)) {
List<BoxSignRequestSigner> signers = new ArrayList<>();
for (JsonValue signerJSON : value.asArray()) {
BoxSignRequestSigner signer = new BoxSignRequestSigner(signerJSON.asObject(), getAPI());
signers.add(signer);
}
this.signers = signers;
} else if ("source_files".equals(memberName)) {
this.sourceFiles = this.getFiles(value.asArray());
} else if ("parent_folder".equals(memberName)) {
JsonObject folderJSON = value.asObject();
String folderID = folderJSON.get("id").asString();
BoxFolder folder = new BoxFolder(getAPI(), folderID);
this.parentFolder = folder.new Info(folderJSON);
} else if ("name".equals(memberName)) {
this.name = value.asString();
} else if ("prefill_tags".equals(memberName)) {
List<BoxSignRequestPrefillTag> prefillTags = new ArrayList<>();
for (JsonValue prefillTagJSON : value.asArray()) {
BoxSignRequestPrefillTag prefillTag =
new BoxSignRequestPrefillTag(prefillTagJSON.asObject());
prefillTags.add(prefillTag);
}
this.prefillTags = prefillTags;
} else if ("days_valid".equals(memberName)) {
this.daysValid = value.asInt();
} else if ("external_id".equals(memberName)) {
this.externalId = value.asString();
} else if ("prepare_url".equals(memberName)) {
this.prepareUrl = value.asString();
} else if ("signing_log".equals(memberName)) {
JsonObject signingLogJSON = value.asObject();
String fileID = signingLogJSON.get("id").asString();
BoxFile file = new BoxFile(getAPI(), fileID);
this.signingLog = file.new Info(signingLogJSON);
} else if ("status".equals(memberName)) {
this.status = BoxSignRequestStatus.fromJSONString(value.asString());
} else if ("sign_files".equals(memberName)) {
JsonObject signFilesJSON = value.asObject();
JsonValue filesArray = signFilesJSON.get("files");
List<BoxFile.Info> signFiles = this.getFiles(filesArray);
boolean isReadyForDownload = signFilesJSON.get("is_ready_for_download").asBoolean();
this.signFiles = new BoxSignRequestSignFiles(signFiles, isReadyForDownload);
} else if ("auto_expire_at".equals(memberName)) {
this.autoExpireAt = BoxDateFormat.parse(value.asString());
switch (memberName) {
case "is_document_preparation_needed":
this.isDocumentPreparationNeeded = value.asBoolean();
break;
case "are_text_signatures_enabled":
this.areTextSignaturesEnabled = value.asBoolean();
break;
case "are_dates_enabled":
this.areDatesEnabled = value.asBoolean();
break;
case "signature_color":
this.signatureColor = BoxSignRequestSignatureColor.fromJSONString(value.asString());
break;
case "email_subject":
this.emailSubject = value.asString();
break;
case "email_message":
this.emailMessage = value.asString();
break;
case "are_reminders_enabled":
this.areRemindersEnabled = value.asBoolean();
break;
case "signers":
List<BoxSignRequestSigner> signers = new ArrayList<>();
for (JsonValue signerJSON : value.asArray()) {
BoxSignRequestSigner signer = new BoxSignRequestSigner(signerJSON.asObject(), getAPI());
signers.add(signer);
}
this.signers = signers;
break;
case "source_files":
this.sourceFiles = this.getFiles(value.asArray());
break;
case "parent_folder":
JsonObject folderJSON = value.asObject();
String folderID = folderJSON.get("id").asString();
BoxFolder folder = new BoxFolder(getAPI(), folderID);
this.parentFolder = folder.new Info(folderJSON);
break;
case "name":
this.name = value.asString();
break;
case "prefill_tags":
List<BoxSignRequestPrefillTag> prefillTags = new ArrayList<>();
for (JsonValue prefillTagJSON : value.asArray()) {
BoxSignRequestPrefillTag prefillTag =
new BoxSignRequestPrefillTag(prefillTagJSON.asObject());
prefillTags.add(prefillTag);
}
this.prefillTags = prefillTags;
break;
case "days_valid":
this.daysValid = value.asInt();
break;
case "external_id":
this.externalId = value.asString();
break;
case "prepare_url":
this.prepareUrl = value.asString();
break;
case "signing_log":
JsonObject signingLogJSON = value.asObject();
String fileID = signingLogJSON.get("id").asString();
BoxFile file = new BoxFile(getAPI(), fileID);
this.signingLog = file.new Info(signingLogJSON);
break;
case "status":
this.status = BoxSignRequestStatus.fromJSONString(value.asString());
break;
case "sign_files":
JsonObject signFilesJSON = value.asObject();
JsonValue filesArray = signFilesJSON.get("files");
List<BoxFile.Info> signFiles = this.getFiles(filesArray);
boolean isReadyForDownload = signFilesJSON.get("is_ready_for_download").asBoolean();
this.signFiles = new BoxSignRequestSignFiles(signFiles, isReadyForDownload);
break;
case "auto_expire_at":
this.autoExpireAt = BoxDateFormat.parse(value.asString());
break;
case "redirect_url":
this.redirectUrl = value.asString();
break;
case "declined_redirect_url":
this.declinedRedirectUrl = value.asString();
break;
default:
return;
}
} catch (Exception e) {
throw new BoxDeserializationException(memberName, value.toString(), e);
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/com/box/sdk/BoxSignRequestCreateParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class BoxSignRequestCreateParams {
private List<BoxSignRequestPrefillTag> prefillTags;
private Integer daysValid;
private String externalId;
private String redirectUrl;
private String declinedRedirectUrl;

/**
* Gets the flag indicating if the sender should be taken into the builder flow to prepare the document.
Expand Down Expand Up @@ -254,6 +256,46 @@ public BoxSignRequestCreateParams setPrefillTags(List<BoxSignRequestPrefillTag>
return this;
}

/**
* Gets the redirect URL that a signer will be redirected to after signing a document.
*
* @return redirect url.
*/
public String getRedirectUrl() {
return this.redirectUrl;
}

/**
* Sets the redirect URL that a signer will be redirected to after signing a document.
*
* @param redirectUrl of this sign request.
* @return this BoxSignRequestCreateParams object for chaining.
*/
public BoxSignRequestCreateParams setRedirectUrl(String redirectUrl) {
this.redirectUrl = redirectUrl;
return this;
}

/**
* Gets the URL that a signer will be redirected to after declining to sign a document.
*
* @return decline redirect url.
*/
public String getDeclinedRedirectUrl() {
return this.declinedRedirectUrl;
}

/**
* Sets the URL that a signer will be redirected to after declining to sign a document.
*
* @param declinedRedirectUrl of this sign request.
* @return this BoxSignRequestCreateParams object for chaining.
*/
public BoxSignRequestCreateParams setDeclinedRedirectUrl(String declinedRedirectUrl) {
this.declinedRedirectUrl = declinedRedirectUrl;
return this;
}

/**
* Used to append BoxSignRequestCreateParams to request.
*
Expand All @@ -271,6 +313,8 @@ public void appendParamsAsJson(JsonObject requestJSON) {
JsonUtils.addIfNotNull(requestJSON, "name", this.name);
JsonUtils.addIfNotNull(requestJSON, "days_valid", this.daysValid);
JsonUtils.addIfNotNull(requestJSON, "external_id", this.externalId);
JsonUtils.addIfNotNull(requestJSON, "redirect_url", this.redirectUrl);
JsonUtils.addIfNotNull(requestJSON, "declined_redirect_url", this.declinedRedirectUrl);

if (this.prefillTags != null) {
JsonArray prefillTagsJSON = new JsonArray();
Expand Down
116 changes: 89 additions & 27 deletions src/main/java/com/box/sdk/BoxSignRequestSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class BoxSignRequestSigner extends BoxJSONObject {
private BoxSignerDecision signerDecision;
private List<BoxSignerInput> inputs;
private String embedUrl;
private String redirectUrl;
private String declinedRedirectUrl;
private BoxAPIConnection api;

/**
Expand Down Expand Up @@ -205,6 +207,46 @@ public BoxSignRequestSigner setInPerson(Boolean isInPerson) {
return this;
}

/**
* Gets the redirect url for the signer.
*
* @return redirect url for the signer.
*/
public String getRedirectUrl() {
return this.redirectUrl;
}

/**
* Sets the redirect url for the signer.
*
* @param redirectUrl for the signer.
* @return this BoxSignRequestSigner object for chaining.
*/
public BoxSignRequestSigner setRedirectUrl(String redirectUrl) {
this.redirectUrl = redirectUrl;
return this;
}

/**
* Gets the declined redirect url for the signer.
*
* @return declined redirect url for the signer.
*/
public String getDeclinedRedirectUrl() {
return this.declinedRedirectUrl;
}

/**
* Sets the declined redirect url for the signer.
*
* @param declinedRedirectUrl for the signer.
* @return this BoxSignRequestSigner object for chaining.
*/
public BoxSignRequestSigner setDeclinedRedirectUrl(String declinedRedirectUrl) {
this.declinedRedirectUrl = declinedRedirectUrl;
return this;
}

/**
* {@inheritDoc}
*/
Expand All @@ -213,32 +255,51 @@ void parseJSONMember(JsonObject.Member member) {
JsonValue value = member.getValue();
String memberName = member.getName();
try {
if ("email".equals(memberName)) {
this.email = value.asString();
} else if ("role".equals(memberName)) {
this.role = BoxSignRequestSignerRole.fromJSONString(value.asString());
} else if ("is_in_person".equals(memberName)) {
this.isInPerson = value.asBoolean();
} else if ("order".equals(memberName)) {
this.order = value.asInt();
} else if ("embed_url_external_user_id".equals(memberName)) {
this.embedUrlExternalUserId = value.asString();
} else if ("has_viewed_email".equals(memberName)) {
this.hasViewedEmail = value.asBoolean();
} else if ("has_viewed_document".equals(memberName)) {
this.hasViewedDocument = value.asBoolean();
} else if ("signer_decision".equals(memberName)) {
JsonObject signerDecisionJSON = value.asObject();
this.signerDecision = new BoxSignerDecision(signerDecisionJSON);
} else if ("inputs".equals(memberName)) {
List<BoxSignerInput> inputs = new ArrayList<>();
for (JsonValue inputJSON : value.asArray()) {
BoxSignerInput input = new BoxSignerInput(inputJSON.asObject());
inputs.add(input);
}
this.inputs = inputs;
} else if ("embed_url".equals(memberName)) {
this.embedUrl = value.asString();
switch (memberName) {
case "email":
this.email = value.asString();
break;
case "role":
this.role = BoxSignRequestSignerRole.fromJSONString(value.asString());
break;
case "is_in_person":
this.isInPerson = value.asBoolean();
break;
case "order":
this.order = value.asInt();
break;
case "embed_url_external_user_id":
this.embedUrlExternalUserId = value.asString();
break;
case "has_viewed_email":
this.hasViewedEmail = value.asBoolean();
break;
case "has_viewed_document":
this.hasViewedDocument = value.asBoolean();
break;
case "signer_decision":
JsonObject signerDecisionJSON = value.asObject();
this.signerDecision = new BoxSignerDecision(signerDecisionJSON);
break;
case "inputs":
List<BoxSignerInput> inputs = new ArrayList<>();
for (JsonValue inputJSON : value.asArray()) {
BoxSignerInput input = new BoxSignerInput(inputJSON.asObject());
inputs.add(input);
}
this.inputs = inputs;
break;
case "embed_url":
this.embedUrl = value.asString();
break;
case "redirect_url":
this.redirectUrl = value.asString();
break;
case "declined_redirect_url":
this.declinedRedirectUrl = value.asString();
break;
default:
return;
}
} catch (Exception e) {
throw new BoxDeserializationException(memberName, value.toString(), e);
Expand All @@ -257,7 +318,8 @@ public JsonObject getJSONObject() {
JsonUtils.addIfNotNull(jsonObj, "is_in_person", this.isInPerson);
JsonUtils.addIfNotNull(jsonObj, "order", this.order);
JsonUtils.addIfNotNull(jsonObj, "embed_url_external_user_id", this.embedUrlExternalUserId);

JsonUtils.addIfNotNull(jsonObj, "redirect_url", this.redirectUrl);
JsonUtils.addIfNotNull(jsonObj, "declined_redirect_url", this.declinedRedirectUrl);
return jsonObj;
}

Expand Down
Loading

0 comments on commit 3921fe1

Please sign in to comment.