Skip to content

Commit e37c0dc

Browse files
authored
feat: Support sign template and new sign status (#1197)
1 parent d291878 commit e37c0dc

12 files changed

Lines changed: 1040 additions & 25 deletions

doc/sign_templates.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Sign Templates
2+
==================
3+
4+
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.
5+
6+
Making and testing a template takes a few minutes, but when done it makes working with Box Sign easier and faster.
7+
8+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
9+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
10+
11+
- [Get all Sign Templates](#get-all-sign-templates)
12+
- [Get Sign Template by ID](#get-sign-template-by-id)
13+
14+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
15+
16+
Get All Sign Templates
17+
------------------------
18+
19+
Calling the static [`getAll(BoxAPIConnection api)`][get-all-sign-templates]
20+
will return an iterable that will page through all the Sign Templates.
21+
22+
The static
23+
[`getAll(BoxAPIConnection api, int limit)`][get-all-sign-templates-with-limit]
24+
method offers `limit` parameter. The `limit` parameter specifies the maximum number of items to be returned in a single response.
25+
26+
<!-- sample get_sign_templates -->
27+
```java
28+
Iterable<BoxSignTemplate.Info> signTemplates = BoxSignTemplate.getAll(api);
29+
for (BoxSignTemplate.Info signTemplateInfo : signTemplates) {
30+
// Do something with each `signTemplateInfo`.
31+
}
32+
```
33+
34+
[get-all-sign-templates]: http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxSignTemplate.html#getAll-com.box.sdk.BoxAPIConnection-
35+
[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-
36+
37+
Get Sign Template by ID
38+
------------------------
39+
40+
Calling [`getInfo()`][get-sign-template-by-id] will return a [`BoxSignTemplate.Info`][box-sign-template-info] object
41+
containing information about the Sign Template.
42+
43+
44+
<!-- sample get_sign_templates_id -->
45+
```java
46+
BoxSignTemplate signTemplate = new BoxSignTemplate(api, id);
47+
BoxSignTemplate.Info signTemplateInfo = signTemplate.getInfo();
48+
```
49+
50+
[get-sign-template-by-id]:http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxSignTemplate.html#getInfo-
51+
[box-sign-template-info]:http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxSignTemplate.Info.html

src/main/java/com/box/sdk/BoxSignRequest.java

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,17 @@ public enum BoxSignRequestStatus {
299299
/**
300300
* Expired status.
301301
*/
302-
Expired("expired");
302+
Expired("expired"),
303+
304+
/**
305+
* Finalizing status.
306+
*/
307+
Finalizing("finalizing"),
308+
309+
/**
310+
* Error finalizing status.
311+
*/
312+
ErrorFinalizing("error_finalizing");
303313

304314
private final String jsonValue;
305315

@@ -308,26 +318,32 @@ public enum BoxSignRequestStatus {
308318
}
309319

310320
static BoxSignRequestStatus fromJSONString(String jsonValue) {
311-
if ("converting".equals(jsonValue)) {
312-
return Converting;
313-
} else if ("created".equals(jsonValue)) {
314-
return Created;
315-
} else if ("sent".equals(jsonValue)) {
316-
return Sent;
317-
} else if ("viewed".equals(jsonValue)) {
318-
return Viewed;
319-
} else if ("signed".equals(jsonValue)) {
320-
return Signed;
321-
} else if ("cancelled".equals(jsonValue)) {
322-
return Cancelled;
323-
} else if ("declined".equals(jsonValue)) {
324-
return Declined;
325-
} else if ("error_converting".equals(jsonValue)) {
326-
return ErrorConverting;
327-
} else if ("error_sending".equals(jsonValue)) {
328-
return ErrorSending;
329-
} else if ("expired".equals(jsonValue)) {
330-
return Expired;
321+
switch (jsonValue) {
322+
case "converting":
323+
return Converting;
324+
case "created":
325+
return Created;
326+
case "sent":
327+
return Sent;
328+
case "viewed":
329+
return Viewed;
330+
case "signed":
331+
return Signed;
332+
case "cancelled":
333+
return Cancelled;
334+
case "declined":
335+
return Declined;
336+
case "error_converting":
337+
return ErrorConverting;
338+
case "error_sending":
339+
return ErrorSending;
340+
case "expired":
341+
return Expired;
342+
case "finalizing":
343+
return Finalizing;
344+
case "error_finalizing":
345+
return ErrorFinalizing;
346+
default:
331347
}
332348
throw new IllegalArgumentException("The provided JSON value isn't a valid BoxSignRequestStatus value.");
333349
}
@@ -359,6 +375,7 @@ public class Info extends BoxResource.Info {
359375
private Date autoExpireAt;
360376
private String redirectUrl;
361377
private String declinedRedirectUrl;
378+
private String templateId;
362379

363380
/**
364381
* Constructs an empty Info object.
@@ -578,6 +595,15 @@ public String getDeclinedRedirectUrl() {
578595
return this.declinedRedirectUrl;
579596
}
580597

598+
/**
599+
* Gets the id of the template that was used to create this sign request.
600+
*
601+
* @return sign template id.
602+
*/
603+
public String getTemplateId() {
604+
return this.templateId;
605+
}
606+
581607
/**
582608
* {@inheritDoc}
583609
*/
@@ -680,6 +706,9 @@ void parseJSONMember(JsonObject.Member member) {
680706
case "declined_redirect_url":
681707
this.declinedRedirectUrl = value.asString();
682708
break;
709+
case "template_id":
710+
this.templateId = value.asString();
711+
break;
683712
default:
684713
}
685714
} catch (Exception e) {

src/main/java/com/box/sdk/BoxSignRequestCreateParams.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class BoxSignRequestCreateParams {
2525
private String externalId;
2626
private String redirectUrl;
2727
private String declinedRedirectUrl;
28+
private String templateId;
2829

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

300+
/**
301+
* Gets the Sign Template ID of the Sign Request.
302+
*
303+
* @return template id.
304+
*/
305+
public String getTemplateId() {
306+
return this.templateId;
307+
}
308+
309+
/**
310+
* Sets the Sign Template ID will be use to create the sign request.
311+
*
312+
* @param templateId for this sign request.
313+
* @return this BoxSignRequestCreateParams object for chaining.
314+
*/
315+
public BoxSignRequestCreateParams setTemplateId(String templateId) {
316+
this.templateId = templateId;
317+
return this;
318+
}
319+
299320
/**
300321
* Used to append BoxSignRequestCreateParams to request.
301322
*
@@ -315,6 +336,7 @@ public void appendParamsAsJson(JsonObject requestJSON) {
315336
JsonUtils.addIfNotNull(requestJSON, "external_id", this.externalId);
316337
JsonUtils.addIfNotNull(requestJSON, "redirect_url", this.redirectUrl);
317338
JsonUtils.addIfNotNull(requestJSON, "declined_redirect_url", this.declinedRedirectUrl);
339+
JsonUtils.addIfNotNull(requestJSON, "template_id", this.templateId);
318340

319341
if (this.prefillTags != null) {
320342
JsonArray prefillTagsJSON = new JsonArray();

0 commit comments

Comments
 (0)