Skip to content

Commit 8e48c82

Browse files
committed
preparing a base for the example
1 parent f323abe commit 8e48c82

File tree

8 files changed

+402
-104
lines changed

8 files changed

+402
-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", "/n001", "/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,62 @@
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+
protected static ApiClient createApiClient(String basePath, String userAccessToken) {
40+
ApiClient apiClient = new ApiClient(basePath);
41+
apiClient.addDefaultHeader(HttpHeaders.AUTHORIZATION, BEARER_AUTHENTICATION + userAccessToken);
42+
apiClient.addAuthorization("docusignAccessCode", new OAuth());
43+
return apiClient;
44+
}
45+
46+
/**
47+
* Creates a new instance of the eSignature EnvelopesApi. This method
48+
* creates an instance of the ApiClient class silently.
49+
*
50+
* @param basePath URL to eSignature REST API
51+
* @param userAccessToken user's access token
52+
* @return an instance of the {@link EnvelopesApi}
53+
*/
54+
protected EnvelopesApi createEnvelopesApi(String basePath, String userAccessToken) {
55+
ApiClient apiClient = createApiClient(basePath, userAccessToken);
56+
return new EnvelopesApi(apiClient);
57+
}
58+
59+
protected String getExamplePagesPath() {
60+
return AbstractNotaryController.EXAMPLE_PAGES_PATH;
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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) throws ApiException, IOException, com.docusign.webforms.client.ApiException {
32+
EnvelopesApi envelopesApi = createEnvelopesApi(session.getBasePath(), user.getAccessToken());
33+
34+
// Call the Examples API method to create and send an notary envelope via email
35+
var envelopeId = SendWithThirdPartyNotaryService.sendWithNotary(
36+
args.getSignerEmail(),
37+
args.getSignerName(),
38+
this.session.getAccountId(),
39+
envelopesApi,
40+
args.getStatus());
41+
42+
DoneExample.createDefault(getTextForCodeExampleByApiType().ExampleName)
43+
.withMessage(getTextForCodeExampleByApiType().ResultsPageText
44+
.replaceFirst("\\{0}", envelopeId))
45+
.addToModel(model, config);
46+
return DONE_EXAMPLE_PAGE;
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package com.docusign.controller.notary.services;
2+
3+
import com.docusign.esign.api.EnvelopesApi;
4+
import com.docusign.esign.model.*;
5+
import com.docusign.webforms.client.ApiException;
6+
import java.nio.charset.StandardCharsets;
7+
import java.util.Collections;
8+
9+
public final class SendWithThirdPartyNotaryService {
10+
public static String sendWithNotary(String signerEmail, String signerName, String accountId,
11+
EnvelopesApi envelopesApi, String envStatus) throws ApiException, com.docusign.esign.client.ApiException {
12+
EnvelopeDefinition env = makeEnvelope(signerEmail, signerName, envStatus);
13+
14+
EnvelopeSummary results = envelopesApi.createEnvelope(accountId, env);
15+
return results.getEnvelopeId();
16+
}
17+
18+
private static EnvelopeDefinition makeEnvelope(String signerEmail, String signerName, String envStatus) {
19+
EnvelopeDefinition env = new EnvelopeDefinition();
20+
env.setEmailSubject("Please sign this document set");
21+
22+
env.setDocuments(getDocuments(signerEmail, signerName));
23+
24+
Recipients recipients = new Recipients();
25+
recipients.setSigners(getSigners(signerEmail, signerName));
26+
recipients.setNotaries(getNotaryRecipients());
27+
28+
env.setRecipients(recipients);
29+
env.setStatus(envStatus);
30+
31+
return env;
32+
}
33+
34+
private static java.util.List<Document> getDocuments(String signerEmail, String signerName) {
35+
Document doc1 = new Document();
36+
String b64 = java.util.Base64.getEncoder().encodeToString(getDocumentExample(signerEmail, signerName));
37+
doc1.setDocumentBase64(b64);
38+
doc1.setName("Order acknowledgement");
39+
doc1.setFileExtension("html");
40+
doc1.setDocumentId("1");
41+
42+
return Collections.singletonList(doc1);
43+
}
44+
45+
private static byte[] getDocumentExample(String signerEmail, String signerName) {
46+
String document = "<!DOCTYPE html>\n"
47+
+ "<html>\n"
48+
+ " <head>\n"
49+
+ " <meta charset=\"UTF-8\">\n"
50+
+ " </head>\n"
51+
+ " <body style=\"font-family:sans-serif;margin-left:2em;\">\n"
52+
+ " <h1 style=\"font-family: 'Trebuchet MS', Helvetica, sans-serif; color: darkblue;margin-bottom: 0;\">World Wide Corp</h1>\n"
53+
+ " <h2 style=\"font-family: 'Trebuchet MS', Helvetica, sans-serif; margin-top: 0px;margin-bottom: 3.5em;font-size: 1em; color: darkblue;\">Order Processing Division</h2>\n"
54+
+ " <h4>Ordered by " + signerName + "</h4>\n"
55+
+ " <p>Email: " + signerEmail + "</p>\n"
56+
+ " <h3>Agreed: <span style=\"color:white;\">**signature_1**/</span></h3>\n"
57+
+ " </body>\n"
58+
+ "</html>";
59+
return document.getBytes(StandardCharsets.UTF_8);
60+
}
61+
62+
private static java.util.List<Signer> getSigners(String signerEmail, String signerName) {
63+
Signer signer = new Signer();
64+
signer.setClientUserId("1000");
65+
signer.setEmail(signerEmail);
66+
signer.setName(signerName);
67+
signer.setRecipientId("2");
68+
signer.setRoutingOrder("1");
69+
signer.setNotaryId("1");
70+
71+
SignHere signHere1 = new SignHere();
72+
signHere1.setDocumentId("1");
73+
signHere1.setXPosition("200");
74+
signHere1.setYPosition("235");
75+
signHere1.setPageNumber("1");
76+
77+
SignHere signHere2 = new SignHere();
78+
signHere2.setStampType("stamp");
79+
signHere2.setDocumentId("1");
80+
signHere2.setXPosition("200");
81+
signHere2.setYPosition("150");
82+
signHere2.setPageNumber("1");
83+
84+
Tabs signerTabs = new Tabs();
85+
signerTabs.setSignHereTabs(java.util.Arrays.asList(signHere1, signHere2));
86+
signer.setTabs(signerTabs);
87+
88+
return Collections.singletonList(signer);
89+
}
90+
91+
private static java.util.List<NotaryRecipient> getNotaryRecipients() {
92+
NotarySeal notarySealTabs = new NotarySeal();
93+
notarySealTabs.setXPosition("300");
94+
notarySealTabs.setYPosition("235");
95+
notarySealTabs.setDocumentId("1");
96+
notarySealTabs.setPageNumber("1");
97+
98+
SignHere notarySignHere = new SignHere();
99+
notarySignHere.setXPosition("300");
100+
notarySignHere.setYPosition("150");
101+
notarySignHere.setDocumentId("1");
102+
notarySignHere.setPageNumber("1");
103+
104+
Tabs notaryTabs = new Tabs();
105+
notaryTabs.setSignHereTabs(Collections.singletonList(notarySignHere));
106+
notaryTabs.setNotarySealTabs(Collections.singletonList(notarySealTabs));
107+
108+
NotaryRecipient notaryRecipient = new NotaryRecipient();
109+
notaryRecipient.setEmail("");
110+
notaryRecipient.setName("Notary");
111+
notaryRecipient.setRecipientId("1");
112+
notaryRecipient.setRoutingOrder("1");
113+
notaryRecipient.setTabs(notaryTabs);
114+
notaryRecipient.setNotaryType("remote");
115+
notaryRecipient.setNotarySourceType("thirdparty");
116+
notaryRecipient.setNotaryThirdPartyPartner("onenotary");
117+
118+
RecipientSignatureProvider signatureProvider = new RecipientSignatureProvider();
119+
signatureProvider.setSealDocumentsWithTabsOnly("false");
120+
signatureProvider.setSignatureProviderName("ds_authority_idv");
121+
signatureProvider.setSignatureProviderOptions(new RecipientSignatureProviderOptions());
122+
123+
notaryRecipient.setRecipientSignatureProviders(Collections.singletonList(signatureProvider));
124+
125+
return Collections.singletonList(notaryRecipient);
126+
}
127+
}

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)