Skip to content

Commit 88b36ea

Browse files
authored
Merge pull request #152 from docusign/feature/added-notary-example
Added notary example
2 parents f323abe + f0fdf07 commit 88b36ea

File tree

8 files changed

+401
-104
lines changed

8 files changed

+401
-104
lines changed

src/main/java/com/docusign/common/ApiIndex.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public enum ApiIndex {
77
MONITOR("/pages/monitor/index", "", "/m001", "/m"),
88
ADMIN("/pages/admin/index", "/management", "/a001", "/a"),
99
CONNECT("/pages/connect/index", "", "/con001", "/con"),
10+
NOTARY("/pages/notary/index", "/restapi", "/n004", "/n"),
1011
WEBFORMS("/pages/webforms/index", "/restapi", "/web001", "/web");
1112

1213
private final String indexPath;
@@ -17,7 +18,8 @@ public enum ApiIndex {
1718

1819
private final String examplesPathCode;
1920

20-
ApiIndex(final String indexPath, final String baseUrlSuffix, final String firstExamplePath, final String examplesPathCode) {
21+
ApiIndex(final String indexPath, final String baseUrlSuffix, final String firstExamplePath,
22+
final String examplesPathCode) {
2123
this.indexPath = indexPath;
2224
this.baseUrlSuffix = baseUrlSuffix;
2325
this.firstExamplePath = firstExamplePath;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.docusign.controller.notary.examples;
2+
3+
import com.docusign.DSConfiguration;
4+
import com.docusign.core.controller.AbstractController;
5+
import com.docusign.core.model.Session;
6+
import com.docusign.core.model.User;
7+
import com.docusign.esign.api.EnvelopesApi;
8+
import com.docusign.esign.client.ApiClient;
9+
import com.docusign.esign.client.auth.OAuth;
10+
import org.springframework.http.HttpHeaders;
11+
import org.springframework.stereotype.Controller;
12+
13+
/**
14+
* Abstract base class for all controllers.
15+
*/
16+
@Controller
17+
public abstract class AbstractNotaryController extends AbstractController {
18+
19+
private static final String EXAMPLE_PAGES_PATH = "pages/notary/examples/";
20+
21+
protected Session session;
22+
23+
protected User user;
24+
25+
public AbstractNotaryController(DSConfiguration config, String exampleName, Session session, User user) {
26+
super(config, exampleName);
27+
this.session = session;
28+
this.user = user;
29+
}
30+
31+
/**
32+
* Creates new instance of the Rooms API client.
33+
*
34+
* @param basePath URL to eSignature REST API
35+
* @param userAccessToken user's access token
36+
* @return an instance of the {@link ApiClient}
37+
*/
38+
39+
//ds-snippet-start:Notary4Step2
40+
protected static ApiClient createApiClient(String basePath, String userAccessToken) {
41+
ApiClient apiClient = new ApiClient(basePath);
42+
apiClient.addDefaultHeader(HttpHeaders.AUTHORIZATION, BEARER_AUTHENTICATION + userAccessToken);
43+
apiClient.addAuthorization("docusignAccessCode", new OAuth());
44+
return apiClient;
45+
}
46+
//ds-snippet-end:Notary4Step2
47+
48+
/**
49+
* Creates a new instance of the eSignature EnvelopesApi. This method
50+
* creates an instance of the ApiClient class silently.
51+
*
52+
* @param basePath URL to eSignature REST API
53+
* @param userAccessToken user's access token
54+
* @return an instance of the {@link EnvelopesApi}
55+
*/
56+
protected EnvelopesApi createEnvelopesApi(String basePath, String userAccessToken) {
57+
ApiClient apiClient = createApiClient(basePath, userAccessToken);
58+
return new EnvelopesApi(apiClient);
59+
}
60+
61+
protected String getExamplePagesPath() {
62+
return AbstractNotaryController.EXAMPLE_PAGES_PATH;
63+
}
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.docusign.controller.notary.examples;
2+
3+
import java.io.IOException;
4+
5+
import javax.servlet.http.HttpServletResponse;
6+
7+
import org.springframework.stereotype.Controller;
8+
import org.springframework.ui.ModelMap;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import com.docusign.DSConfiguration;
11+
import com.docusign.common.WorkArguments;
12+
import com.docusign.core.model.DoneExample;
13+
import com.docusign.core.model.Session;
14+
import com.docusign.core.model.User;
15+
import com.docusign.esign.api.EnvelopesApi;
16+
import com.docusign.esign.client.ApiException;
17+
import com.docusign.controller.notary.services.SendWithThirdPartyNotaryService;
18+
19+
@Controller
20+
@RequestMapping("/n004")
21+
public class Neg004SendWithThirdPartyNotaryController extends AbstractNotaryController {
22+
23+
public Neg004SendWithThirdPartyNotaryController(DSConfiguration config, Session session, User user) {
24+
super(config, "n004", session, user);
25+
}
26+
27+
@Override
28+
protected Object doWork(
29+
WorkArguments args,
30+
ModelMap model,
31+
HttpServletResponse response)
32+
throws ApiException, IOException, com.docusign.webforms.client.ApiException {
33+
EnvelopesApi envelopesApi = createEnvelopesApi(session.getBasePath(), user.getAccessToken());
34+
35+
// Call the Examples API method to create and send an notary envelope via email
36+
var envelopeId = SendWithThirdPartyNotaryService.sendWithNotary(
37+
args.getSignerEmail(),
38+
args.getSignerName(),
39+
this.session.getAccountId(),
40+
envelopesApi,
41+
args);
42+
43+
DoneExample.createDefault(getTextForCodeExampleByApiType().ExampleName)
44+
.withMessage(getTextForCodeExampleByApiType().ResultsPageText
45+
.replaceFirst("\\{0}", envelopeId))
46+
.addToModel(model, config);
47+
return DONE_EXAMPLE_PAGE;
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package com.docusign.controller.notary.services;
2+
3+
import com.docusign.common.WorkArguments;
4+
import com.docusign.controller.eSignature.examples.EnvelopeHelpers;
5+
import com.docusign.core.common.DocumentType;
6+
import com.docusign.esign.api.EnvelopesApi;
7+
import com.docusign.esign.model.*;
8+
import com.docusign.webforms.client.ApiException;
9+
10+
import java.io.IOException;
11+
import java.nio.charset.StandardCharsets;
12+
import java.util.Collections;
13+
14+
public final class SendWithThirdPartyNotaryService {
15+
private static final String HTML_DOCUMENT_FILE_NAME = "order_form.html";
16+
17+
private static final String HTML_DOCUMENT_NAME = "Order form";
18+
19+
//ds-snippet-start:Notary4Step4
20+
public static String sendWithNotary(String signerEmail, String signerName, String accountId,
21+
EnvelopesApi envelopesApi, WorkArguments args)
22+
throws ApiException, com.docusign.esign.client.ApiException, IOException {
23+
EnvelopeDefinition envelopeDefinition = makeEnvelope(signerEmail, signerName, args);
24+
25+
EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(accountId, envelopeDefinition);
26+
return envelopeSummary.getEnvelopeId();
27+
}
28+
//ds-snippet-end:Notary4Step4
29+
30+
//ds-snippet-start:Notary4Step3
31+
private static EnvelopeDefinition makeEnvelope(String signerEmail, String signerName, WorkArguments args)
32+
throws IOException {
33+
EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition();
34+
envelopeDefinition.setEmailSubject("Please sign this document set");
35+
36+
envelopeDefinition.setDocuments(getDocuments(signerEmail, signerName, args));
37+
38+
Recipients recipients = new Recipients();
39+
recipients.setSigners(getSigners(signerEmail, signerName));
40+
recipients.setNotaries(getNotaryRecipients());
41+
42+
envelopeDefinition.setRecipients(recipients);
43+
envelopeDefinition.setStatus("sent");
44+
45+
return envelopeDefinition;
46+
}
47+
48+
private static java.util.List<Document> getDocuments(String signerEmail, String signerName, WorkArguments args)
49+
throws IOException {
50+
byte[] htmlDoc = EnvelopeHelpers.createHtmlFromTemplateFile(HTML_DOCUMENT_FILE_NAME, "args", args)
51+
.getBytes(StandardCharsets.UTF_8);
52+
Document document = EnvelopeHelpers.createDocument(htmlDoc, HTML_DOCUMENT_NAME,
53+
DocumentType.HTML.getDefaultFileExtention(), "1");
54+
55+
return Collections.singletonList(document);
56+
}
57+
58+
private static java.util.List<Signer> getSigners(String signerEmail, String signerName) {
59+
Signer signer = new Signer();
60+
signer.setClientUserId("1000");
61+
signer.setEmail(signerEmail);
62+
signer.setName(signerName);
63+
signer.setRecipientId("2");
64+
signer.setRoutingOrder("1");
65+
signer.setNotaryId("1");
66+
67+
SignHere signHere1 = new SignHere();
68+
signHere1.setDocumentId("1");
69+
signHere1.setXPosition("200");
70+
signHere1.setYPosition("235");
71+
signHere1.setPageNumber("1");
72+
73+
SignHere signHere2 = new SignHere();
74+
signHere2.setStampType("stamp");
75+
signHere2.setDocumentId("1");
76+
signHere2.setXPosition("200");
77+
signHere2.setYPosition("150");
78+
signHere2.setPageNumber("1");
79+
80+
Tabs signerTabs = new Tabs();
81+
signerTabs.setSignHereTabs(java.util.Arrays.asList(signHere1, signHere2));
82+
signer.setTabs(signerTabs);
83+
84+
return Collections.singletonList(signer);
85+
}
86+
87+
private static java.util.List<NotaryRecipient> getNotaryRecipients() {
88+
NotarySeal notarySealTabs = new NotarySeal();
89+
notarySealTabs.setXPosition("300");
90+
notarySealTabs.setYPosition("235");
91+
notarySealTabs.setDocumentId("1");
92+
notarySealTabs.setPageNumber("1");
93+
94+
SignHere notarySignHere = new SignHere();
95+
notarySignHere.setXPosition("300");
96+
notarySignHere.setYPosition("150");
97+
notarySignHere.setDocumentId("1");
98+
notarySignHere.setPageNumber("1");
99+
100+
Tabs notaryTabs = new Tabs();
101+
notaryTabs.setSignHereTabs(Collections.singletonList(notarySignHere));
102+
notaryTabs.setNotarySealTabs(Collections.singletonList(notarySealTabs));
103+
104+
NotaryRecipient notaryRecipient = new NotaryRecipient();
105+
notaryRecipient.setName("Notary");
106+
notaryRecipient.setRecipientId("1");
107+
notaryRecipient.setRoutingOrder("1");
108+
notaryRecipient.setTabs(notaryTabs);
109+
notaryRecipient.setNotaryType("remote");
110+
notaryRecipient.setNotarySourceType("thirdparty");
111+
notaryRecipient.setNotaryThirdPartyPartner("onenotary");
112+
113+
RecipientSignatureProvider signatureProvider = new RecipientSignatureProvider();
114+
signatureProvider.setSealDocumentsWithTabsOnly("false");
115+
signatureProvider.setSignatureProviderName("ds_authority_idv");
116+
signatureProvider.setSignatureProviderOptions(new RecipientSignatureProviderOptions());
117+
118+
notaryRecipient.setRecipientSignatureProviders(Collections.singletonList(signatureProvider));
119+
120+
return Collections.singletonList(notaryRecipient);
121+
}
122+
//ds-snippet-end:Notary4Step3
123+
}

src/main/java/com/docusign/core/model/ApiType.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public enum ApiType {
1717
"asset_group_account_read", "asset_group_account_clone_write", "asset_group_account_clone_read",
1818
"organization_sub_account_read", "organization_sub_account_write" }, "a"),
1919
WEBFORMS("WebForms API",
20-
new String[] { "signature", "webforms_read", "webforms_instance_read", "webforms_instance_write" }, "web");
20+
new String[] { "signature", "webforms_read", "webforms_instance_read", "webforms_instance_write" }, "web"),
21+
NOTARY("Notary API", new String[] { "signature" }, "n");
2122

2223
final String value;
2324

src/main/resources/public/assets/search.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
ADMIN: 'admin',
88
CONNECT: 'connect',
99
CONNECT: 'connect',
10-
WEBFORMS: 'webforms'
10+
WEBFORMS: 'webforms',
11+
NOTARY: 'notary'
1112
};
1213

1314
let processJSONData = function () {
@@ -129,6 +130,8 @@
129130
return "con";
130131
case API_TYPES.WEBFORMS:
131132
return "web";
133+
case API_TYPES.NOTARY:
134+
return "n";
132135
}
133136
}
134137

0 commit comments

Comments
 (0)