From 3921fe1a4a6249146a8dd2f22e15801846bc073b Mon Sep 17 00:00:00 2001 From: Minh Nguyen Cong Date: Fri, 26 Aug 2022 10:53:00 +0200 Subject: [PATCH] feat: Add `redirect_url` and `declined_redirect_url` to Sign Request (#1089) * feat: Add `redirect_url` and `declined_redirect_url` to Sign Request --- src/main/java/com/box/sdk/BoxSignRequest.java | 166 +++++++++++------- .../box/sdk/BoxSignRequestCreateParams.java | 44 +++++ .../com/box/sdk/BoxSignRequestSigner.java | 116 +++++++++--- .../BoxSignRequest/CancelSignRequest200.json | 6 +- .../BoxSignRequest/CreateSignRequest200.json | 6 +- .../BoxSignRequest/GetAllSignRequests200.json | 6 +- .../BoxSignRequest/GetSignRequest200.json | 6 +- .../java/com/box/sdk/BoxSignRequestTest.java | 28 ++- 8 files changed, 287 insertions(+), 91 deletions(-) diff --git a/src/main/java/com/box/sdk/BoxSignRequest.java b/src/main/java/com/box/sdk/BoxSignRequest.java index 8a58e0447..eeb1e93bc 100644 --- a/src/main/java/com/box/sdk/BoxSignRequest.java +++ b/src/main/java/com/box/sdk/BoxSignRequest.java @@ -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. @@ -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} */ @@ -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 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 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 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 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 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 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); diff --git a/src/main/java/com/box/sdk/BoxSignRequestCreateParams.java b/src/main/java/com/box/sdk/BoxSignRequestCreateParams.java index 6d331f64b..f0cf8d1df 100644 --- a/src/main/java/com/box/sdk/BoxSignRequestCreateParams.java +++ b/src/main/java/com/box/sdk/BoxSignRequestCreateParams.java @@ -23,6 +23,8 @@ public class BoxSignRequestCreateParams { private List 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. @@ -254,6 +256,46 @@ public BoxSignRequestCreateParams setPrefillTags(List 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. * @@ -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(); diff --git a/src/main/java/com/box/sdk/BoxSignRequestSigner.java b/src/main/java/com/box/sdk/BoxSignRequestSigner.java index bda8eb663..1052ceb01 100644 --- a/src/main/java/com/box/sdk/BoxSignRequestSigner.java +++ b/src/main/java/com/box/sdk/BoxSignRequestSigner.java @@ -23,6 +23,8 @@ public class BoxSignRequestSigner extends BoxJSONObject { private BoxSignerDecision signerDecision; private List inputs; private String embedUrl; + private String redirectUrl; + private String declinedRedirectUrl; private BoxAPIConnection api; /** @@ -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} */ @@ -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 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 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); @@ -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; } diff --git a/src/test/Fixtures/BoxSignRequest/CancelSignRequest200.json b/src/test/Fixtures/BoxSignRequest/CancelSignRequest200.json index 8e0b32790..5a5f8260b 100644 --- a/src/test/Fixtures/BoxSignRequest/CancelSignRequest200.json +++ b/src/test/Fixtures/BoxSignRequest/CancelSignRequest200.json @@ -30,7 +30,9 @@ "content_type": "checkbox" } ], - "embed_url": "https://example.com" + "embed_url": "https://example.com", + "redirect_url": "https://box.com/redirect_url_signer_1", + "declined_redirect_url": "https://box.com/declined_redirect_url_signer_1" } ], "source_files": [ @@ -69,6 +71,8 @@ "type": "sign-request", "id": "12345", "prepare_url": "https://prepareurl.com", + "redirect_url": "https://box.com/redirect_url", + "declined_redirect_url": "https://box.com/declined_redirect_url", "signing_log": { "id": "12345", "etag": "1", diff --git a/src/test/Fixtures/BoxSignRequest/CreateSignRequest200.json b/src/test/Fixtures/BoxSignRequest/CreateSignRequest200.json index e0cf43d5a..c72feb8e4 100644 --- a/src/test/Fixtures/BoxSignRequest/CreateSignRequest200.json +++ b/src/test/Fixtures/BoxSignRequest/CreateSignRequest200.json @@ -30,7 +30,9 @@ "content_type": "checkbox" } ], - "embed_url": "https://example.com" + "embed_url": "https://example.com", + "redirect_url": "https://box.com/redirect_url_signer_1", + "declined_redirect_url": "https://box.com/declined_redirect_url_signer_1" } ], "source_files": [ @@ -69,6 +71,8 @@ "type": "sign-request", "id": "12345", "prepare_url": "https://prepareurl.com", + "redirect_url": "https://box.com/redirect_url", + "declined_redirect_url": "https://box.com/declined_redirect_url", "signing_log": { "id": "12345", "etag": "1", diff --git a/src/test/Fixtures/BoxSignRequest/GetAllSignRequests200.json b/src/test/Fixtures/BoxSignRequest/GetAllSignRequests200.json index 84970ce58..fc989f016 100644 --- a/src/test/Fixtures/BoxSignRequest/GetAllSignRequests200.json +++ b/src/test/Fixtures/BoxSignRequest/GetAllSignRequests200.json @@ -52,7 +52,9 @@ "content_type": "date" } ], - "embed_url": "https://example.com" + "embed_url": "https://example.com", + "redirect_url": "https://box.com/redirect_url_signer_1", + "declined_redirect_url": "https://box.com/declined_redirect_url_signer_1" } ], "source_files": [ @@ -91,6 +93,8 @@ "type": "sign-request", "id": "12345", "prepare_url": "https://prepareurl.com", + "redirect_url": "https://box.com/redirect_url", + "declined_redirect_url": "https://box.com/declined_redirect_url", "signing_log": { "id": "12345", "etag": "1", diff --git a/src/test/Fixtures/BoxSignRequest/GetSignRequest200.json b/src/test/Fixtures/BoxSignRequest/GetSignRequest200.json index 14e2edee4..67d308656 100644 --- a/src/test/Fixtures/BoxSignRequest/GetSignRequest200.json +++ b/src/test/Fixtures/BoxSignRequest/GetSignRequest200.json @@ -48,7 +48,9 @@ "content_type": "date" } ], - "embed_url": "https://example.com" + "embed_url": "https://example.com", + "redirect_url": "https://box.com/redirect_url_signer_1", + "declined_redirect_url": "https://box.com/declined_redirect_url_signer_1" } ], "source_files": [ @@ -87,6 +89,8 @@ "type": "sign-request", "id": "12345", "prepare_url": "https://prepareurl.com", + "redirect_url": "https://box.com/redirect_url", + "declined_redirect_url": "https://box.com/declined_redirect_url", "signing_log": { "id": "12345", "etag": "1", diff --git a/src/test/java/com/box/sdk/BoxSignRequestTest.java b/src/test/java/com/box/sdk/BoxSignRequestTest.java index 6a3cabb32..225ed6a79 100644 --- a/src/test/java/com/box/sdk/BoxSignRequestTest.java +++ b/src/test/java/com/box/sdk/BoxSignRequestTest.java @@ -42,6 +42,11 @@ public void createSignRequestSucceeds() throws IOException { final BoxSignRequestInputContentType contentType = BoxSignRequestInputContentType.Checkbox; final String prepareUrl = "https://prepareurl.com"; + final String redirectUrl = "https://box.com/redirect_url"; + final String declinedRedirectUrl = "https://box.com/declined_redirect_url"; + + final String signerRedirectUrl = "https://box.com/redirect_url_signer_1"; + final String signerDeclinedRedirectUrl = "https://box.com/declined_redirect_url_signer_1"; String result = TestUtils.getFixture("BoxSignRequest/CreateSignRequest200"); @@ -65,8 +70,12 @@ public void createSignRequestSucceeds() throws IOException { BoxFile.Info fileInfo = signRequestInfo.getSourceFiles().get(0); BoxSignRequestSigner signer = signRequestInfo.getSigners().get(0); BoxSignerInput input = signer.getInputs().get(0); + assertEquals(signerRedirectUrl, signer.getRedirectUrl()); + assertEquals(signerDeclinedRedirectUrl, signer.getDeclinedRedirectUrl()); assertEquals(prepareUrl, signRequestInfo.getPrepareUrl()); + assertEquals(redirectUrl, signRequestInfo.getRedirectUrl()); + assertEquals(declinedRedirectUrl, signRequestInfo.getDeclinedRedirectUrl()); assertEquals(fileId, fileInfo.getID()); assertEquals(fileName, fileInfo.getName()); assertEquals(signerEmail, signer.getEmail()); @@ -83,6 +92,11 @@ public void getSignRequestInfoSucceeds() throws IOException { BoxSignRequestInputContentType contentType = BoxSignRequestInputContentType.Checkbox; final String prepareUrl = "https://prepareurl.com"; + final String redirectUrl = "https://box.com/redirect_url"; + final String declinedRedirectUrl = "https://box.com/declined_redirect_url"; + + final String signerRedirectUrl = "https://box.com/redirect_url_signer_1"; + final String signerDeclinedRedirectUrl = "https://box.com/declined_redirect_url_signer_1"; final String requestUrl = "/2.0/sign_requests/" + signRequestId; @@ -99,9 +113,12 @@ public void getSignRequestInfoSucceeds() throws IOException { BoxFile.Info fileInfo = signRequestInfo.getSourceFiles().get(0); BoxSignRequestSigner signer = signRequestInfo.getSigners().get(0); BoxSignerInput input = signer.getInputs().get(0); - + assertEquals(signerRedirectUrl, signer.getRedirectUrl()); + assertEquals(signerDeclinedRedirectUrl, signer.getDeclinedRedirectUrl()); assertEquals(prepareUrl, signRequestInfo.getPrepareUrl()); + assertEquals(redirectUrl, signRequestInfo.getRedirectUrl()); + assertEquals(declinedRedirectUrl, signRequestInfo.getDeclinedRedirectUrl()); assertEquals(fileId, fileInfo.getID()); assertEquals(fileName, fileInfo.getName()); assertEquals(signerEmail, signer.getEmail()); @@ -118,6 +135,11 @@ public void getAllSignRequestsSucceeds() throws IOException { final BoxSignRequestInputContentType contentType = BoxSignRequestInputContentType.Checkbox; final String prepareUrl = "https://prepareurl.com"; + final String redirectUrl = "https://box.com/redirect_url"; + final String declinedRedirectUrl = "https://box.com/declined_redirect_url"; + + final String signerRedirectUrl = "https://box.com/redirect_url_signer_1"; + final String signerDeclinedRedirectUrl = "https://box.com/declined_redirect_url_signer_1"; final String requestUrl = "/2.0/sign_requests"; @@ -134,8 +156,12 @@ public void getAllSignRequestsSucceeds() throws IOException { BoxFile.Info fileInfo = firstSignRequest.getSourceFiles().get(0); BoxSignRequestSigner signer = firstSignRequest.getSigners().get(0); BoxSignerInput input = signer.getInputs().get(0); + assertEquals(signerRedirectUrl, signer.getRedirectUrl()); + assertEquals(signerDeclinedRedirectUrl, signer.getDeclinedRedirectUrl()); assertEquals(prepareUrl, firstSignRequest.getPrepareUrl()); + assertEquals(redirectUrl, firstSignRequest.getRedirectUrl()); + assertEquals(declinedRedirectUrl, firstSignRequest.getDeclinedRedirectUrl()); assertEquals(fileId, fileInfo.getID()); assertEquals(fileName, fileInfo.getName()); assertEquals(signerEmail, signer.getEmail());