Skip to content

Commit ac3a325

Browse files
committed
updates for services
1 parent 8e48c82 commit ac3a325

File tree

2 files changed

+55
-61
lines changed

2 files changed

+55
-61
lines changed

src/main/java/com/docusign/controller/notary/examples/Neg004SendWithThirdPartyNotaryController.java

+26-25
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,30 @@
2020
@RequestMapping("/n004")
2121
public class Neg004SendWithThirdPartyNotaryController extends AbstractNotaryController {
2222

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-
}
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+
}
4849
}

src/main/java/com/docusign/controller/notary/services/SendWithThirdPartyNotaryService.java

+29-36
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,55 @@
11
package com.docusign.controller.notary.services;
22

3+
import com.docusign.common.WorkArguments;
4+
import com.docusign.controller.eSignature.examples.EnvelopeHelpers;
5+
import com.docusign.core.common.DocumentType;
36
import com.docusign.esign.api.EnvelopesApi;
47
import com.docusign.esign.model.*;
58
import com.docusign.webforms.client.ApiException;
9+
10+
import java.io.IOException;
611
import java.nio.charset.StandardCharsets;
712
import java.util.Collections;
813

914
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+
1019
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);
20+
EnvelopesApi envelopesApi, WorkArguments args)
21+
throws ApiException, com.docusign.esign.client.ApiException, IOException {
22+
EnvelopeDefinition envelopeDefinition = makeEnvelope(signerEmail, signerName, args);
1323

14-
EnvelopeSummary results = envelopesApi.createEnvelope(accountId, env);
15-
return results.getEnvelopeId();
24+
EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(accountId, envelopeDefinition);
25+
return envelopeSummary.getEnvelopeId();
1626
}
1727

18-
private static EnvelopeDefinition makeEnvelope(String signerEmail, String signerName, String envStatus) {
19-
EnvelopeDefinition env = new EnvelopeDefinition();
20-
env.setEmailSubject("Please sign this document set");
28+
private static EnvelopeDefinition makeEnvelope(String signerEmail, String signerName, WorkArguments args)
29+
throws IOException {
30+
EnvelopeDefinition envelopeDefinition = new EnvelopeDefinition();
31+
envelopeDefinition.setEmailSubject("Please sign this document set");
2132

22-
env.setDocuments(getDocuments(signerEmail, signerName));
33+
envelopeDefinition.setDocuments(getDocuments(signerEmail, signerName, args));
2334

2435
Recipients recipients = new Recipients();
2536
recipients.setSigners(getSigners(signerEmail, signerName));
2637
recipients.setNotaries(getNotaryRecipients());
2738

28-
env.setRecipients(recipients);
29-
env.setStatus(envStatus);
39+
envelopeDefinition.setRecipients(recipients);
40+
envelopeDefinition.setStatus("sent");
3041

31-
return env;
42+
return envelopeDefinition;
3243
}
3344

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-
}
45+
private static java.util.List<Document> getDocuments(String signerEmail, String signerName, WorkArguments args)
46+
throws IOException {
47+
byte[] htmlDoc = EnvelopeHelpers.createHtmlFromTemplateFile(HTML_DOCUMENT_FILE_NAME, "args", args)
48+
.getBytes(StandardCharsets.UTF_8);
49+
Document document = EnvelopeHelpers.createDocument(htmlDoc, HTML_DOCUMENT_NAME,
50+
DocumentType.HTML.getDefaultFileExtention(), "1");
4451

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);
52+
return Collections.singletonList(document);
6053
}
6154

6255
private static java.util.List<Signer> getSigners(String signerEmail, String signerName) {

0 commit comments

Comments
 (0)