|
4 | 4 | import com.docusign.esign.model.*; |
5 | 5 |
|
6 | 6 | import java.io.IOException; |
| 7 | +import java.nio.charset.StandardCharsets; |
7 | 8 | import java.util.Arrays; |
8 | 9 | import java.util.Collections; |
9 | 10 |
|
| 11 | +import org.apache.commons.io.FilenameUtils; |
| 12 | +import org.springframework.core.io.ClassPathResource; |
| 13 | +import org.springframework.util.StreamUtils; |
| 14 | + |
10 | 15 | public final class SetDocumentVisibilityService { |
11 | 16 | //ds-snippet-start:eSign40Step3 |
12 | 17 | public static EnvelopeDefinition makeEnvelope( |
@@ -37,6 +42,10 @@ public static EnvelopeDefinition makeEnvelope( |
37 | 42 | envelopeDefinition.setRecipients(recipients); |
38 | 43 |
|
39 | 44 | envelopeDefinition.setDocuments(Arrays.asList(prepareDocumentsForSending( |
| 45 | + signerEmail, |
| 46 | + signerName, |
| 47 | + ccEmail, |
| 48 | + ccName, |
40 | 49 | documentFileNamePDF, |
41 | 50 | documentFileNameDOCX, |
42 | 51 | documentFileNameHTML))); |
@@ -73,12 +82,26 @@ private static Signer[] prepareSigners( |
73 | 82 | } |
74 | 83 |
|
75 | 84 | private static Document[] prepareDocumentsForSending( |
| 85 | + String signerEmail, |
| 86 | + String signerName, |
| 87 | + String ccEmail, |
| 88 | + String ccName, |
76 | 89 | String documentFileNamePDF, |
77 | 90 | String documentFileNameDOCX, |
78 | 91 | String documentFileNameHTML) throws IOException { |
79 | | - Document documentHTML = EnvelopeHelpers.createDocumentFromFile( |
80 | | - documentFileNameHTML, |
| 92 | + ClassPathResource resource = new ClassPathResource(documentFileNameHTML); |
| 93 | + String documentHTMLContentsString = StreamUtils.copyToString(resource.getInputStream(), StandardCharsets.UTF_8); |
| 94 | + documentHTMLContentsString = documentHTMLContentsString.replace("{USER_EMAIL}", signerEmail); |
| 95 | + documentHTMLContentsString = documentHTMLContentsString.replace("{USER_FULLNAME}", signerName); |
| 96 | + documentHTMLContentsString = documentHTMLContentsString.replace("{CC_EMAIL}", ccEmail); |
| 97 | + documentHTMLContentsString = documentHTMLContentsString.replace("{CC_NAME}", ccName); |
| 98 | + byte[] documentHTMLContentsBytes = documentHTMLContentsString.getBytes(StandardCharsets.UTF_8); |
| 99 | + String extension = FilenameUtils.getExtension(documentFileNameHTML); |
| 100 | + |
| 101 | + Document documentHTML = EnvelopeHelpers.createDocument( |
| 102 | + documentHTMLContentsBytes, |
81 | 103 | "Order acknowledgement", |
| 104 | + extension, |
82 | 105 | "1"); |
83 | 106 |
|
84 | 107 | Document documentDOCX = EnvelopeHelpers.createDocumentFromFile( |
|
0 commit comments