Skip to content

Commit

Permalink
feat: Support sign template and new sign status (#1197)
Browse files Browse the repository at this point in the history
  • Loading branch information
congminh1254 authored Aug 29, 2023
1 parent d291878 commit e37c0dc
Show file tree
Hide file tree
Showing 12 changed files with 1,040 additions and 25 deletions.
51 changes: 51 additions & 0 deletions doc/sign_templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Sign Templates
==================

Box Sign enables you to create templates so you can automatically add the same fields and formatting to requests for signature. With templates, you don't need to repetitively add the same fields to each request every time you send a new document for signature.

Making and testing a template takes a few minutes, but when done it makes working with Box Sign easier and faster.

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Get all Sign Templates](#get-all-sign-templates)
- [Get Sign Template by ID](#get-sign-template-by-id)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Get All Sign Templates
------------------------

Calling the static [`getAll(BoxAPIConnection api)`][get-all-sign-templates]
will return an iterable that will page through all the Sign Templates.

The static
[`getAll(BoxAPIConnection api, int limit)`][get-all-sign-templates-with-limit]
method offers `limit` parameter. The `limit` parameter specifies the maximum number of items to be returned in a single response.

<!-- sample get_sign_templates -->
```java
Iterable<BoxSignTemplate.Info> signTemplates = BoxSignTemplate.getAll(api);
for (BoxSignTemplate.Info signTemplateInfo : signTemplates) {
// Do something with each `signTemplateInfo`.
}
```

[get-all-sign-templates]: http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxSignTemplate.html#getAll-com.box.sdk.BoxAPIConnection-
[get-all-sign-templates-with-limit]: http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxSignTemplate.html#getAll-com.box.sdk.BoxAPIConnection-int-

Get Sign Template by ID
------------------------

Calling [`getInfo()`][get-sign-template-by-id] will return a [`BoxSignTemplate.Info`][box-sign-template-info] object
containing information about the Sign Template.


<!-- sample get_sign_templates_id -->
```java
BoxSignTemplate signTemplate = new BoxSignTemplate(api, id);
BoxSignTemplate.Info signTemplateInfo = signTemplate.getInfo();
```

[get-sign-template-by-id]:http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxSignTemplate.html#getInfo-
[box-sign-template-info]:http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxSignTemplate.Info.html
71 changes: 50 additions & 21 deletions src/main/java/com/box/sdk/BoxSignRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,17 @@ public enum BoxSignRequestStatus {
/**
* Expired status.
*/
Expired("expired");
Expired("expired"),

/**
* Finalizing status.
*/
Finalizing("finalizing"),

/**
* Error finalizing status.
*/
ErrorFinalizing("error_finalizing");

private final String jsonValue;

Expand All @@ -308,26 +318,32 @@ public enum BoxSignRequestStatus {
}

static BoxSignRequestStatus fromJSONString(String jsonValue) {
if ("converting".equals(jsonValue)) {
return Converting;
} else if ("created".equals(jsonValue)) {
return Created;
} else if ("sent".equals(jsonValue)) {
return Sent;
} else if ("viewed".equals(jsonValue)) {
return Viewed;
} else if ("signed".equals(jsonValue)) {
return Signed;
} else if ("cancelled".equals(jsonValue)) {
return Cancelled;
} else if ("declined".equals(jsonValue)) {
return Declined;
} else if ("error_converting".equals(jsonValue)) {
return ErrorConverting;
} else if ("error_sending".equals(jsonValue)) {
return ErrorSending;
} else if ("expired".equals(jsonValue)) {
return Expired;
switch (jsonValue) {
case "converting":
return Converting;
case "created":
return Created;
case "sent":
return Sent;
case "viewed":
return Viewed;
case "signed":
return Signed;
case "cancelled":
return Cancelled;
case "declined":
return Declined;
case "error_converting":
return ErrorConverting;
case "error_sending":
return ErrorSending;
case "expired":
return Expired;
case "finalizing":
return Finalizing;
case "error_finalizing":
return ErrorFinalizing;
default:
}
throw new IllegalArgumentException("The provided JSON value isn't a valid BoxSignRequestStatus value.");
}
Expand Down Expand Up @@ -359,6 +375,7 @@ public class Info extends BoxResource.Info {
private Date autoExpireAt;
private String redirectUrl;
private String declinedRedirectUrl;
private String templateId;

/**
* Constructs an empty Info object.
Expand Down Expand Up @@ -578,6 +595,15 @@ public String getDeclinedRedirectUrl() {
return this.declinedRedirectUrl;
}

/**
* Gets the id of the template that was used to create this sign request.
*
* @return sign template id.
*/
public String getTemplateId() {
return this.templateId;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -680,6 +706,9 @@ void parseJSONMember(JsonObject.Member member) {
case "declined_redirect_url":
this.declinedRedirectUrl = value.asString();
break;
case "template_id":
this.templateId = value.asString();
break;
default:
}
} catch (Exception e) {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/box/sdk/BoxSignRequestCreateParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class BoxSignRequestCreateParams {
private String externalId;
private String redirectUrl;
private String declinedRedirectUrl;
private String templateId;

/**
* Gets the flag indicating if the sender should be taken into the builder flow to prepare the document.
Expand Down Expand Up @@ -296,6 +297,26 @@ public BoxSignRequestCreateParams setDeclinedRedirectUrl(String declinedRedirect
return this;
}

/**
* Gets the Sign Template ID of the Sign Request.
*
* @return template id.
*/
public String getTemplateId() {
return this.templateId;
}

/**
* Sets the Sign Template ID will be use to create the sign request.
*
* @param templateId for this sign request.
* @return this BoxSignRequestCreateParams object for chaining.
*/
public BoxSignRequestCreateParams setTemplateId(String templateId) {
this.templateId = templateId;
return this;
}

/**
* Used to append BoxSignRequestCreateParams to request.
*
Expand All @@ -315,6 +336,7 @@ public void appendParamsAsJson(JsonObject requestJSON) {
JsonUtils.addIfNotNull(requestJSON, "external_id", this.externalId);
JsonUtils.addIfNotNull(requestJSON, "redirect_url", this.redirectUrl);
JsonUtils.addIfNotNull(requestJSON, "declined_redirect_url", this.declinedRedirectUrl);
JsonUtils.addIfNotNull(requestJSON, "template_id", this.templateId);

if (this.prefillTags != null) {
JsonArray prefillTagsJSON = new JsonArray();
Expand Down
Loading

0 comments on commit e37c0dc

Please sign in to comment.