Skip to content

Commit 0a21d3e

Browse files
committed
Merge branch 'feature/document-generation-example'
2 parents 1ce94d0 + 782866c commit 0a21d3e

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

‎src/main/java/com/docusign/controller/eSignature/services/DocumentGenerationService.java‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,27 @@ public String generateDocument(
5252
EnvelopesApi envelopesApi,
5353
TemplatesApi templatesApi
5454
) throws ApiException, IOException {
55+
// Step 2a start
5556
TemplateSummary template = templatesApi.createTemplate(accountId, makeTemplate());
5657
String templateId = template.getTemplateId();
58+
// Step 2a end
5759

60+
// Step 3a start
5861
templatesApi.updateDocument(accountId, templateId, DEFAULT_ID, addDocumentTemplate(offerDocDocx));
62+
// Step 3a end
63+
64+
// Step 4a start
5965
templatesApi.createTabs(accountId, templateId, DEFAULT_ID, prepareTabs());
66+
// Step 4a end
6067

68+
// Step 5a start
6169
EnvelopeSummary envelopeSummary = envelopesApi.createEnvelope(
6270
accountId,
6371
makeEnvelope(candidateEmail, candidateName, template.getTemplateId()));
6472
String envelopeId = envelopeSummary.getEnvelopeId();
73+
// Step 5a end
6574

75+
// Step 6 start
6676
DocGenFormFieldResponse formFieldResponse = envelopesApi.getEnvelopeDocGenFormFields(accountId, envelopeId);
6777
String documentId = "";
6878
if (!formFieldResponse.getDocGenFormFields().isEmpty()) {
@@ -71,7 +81,8 @@ public String generateDocument(
7181
documentId = docGenFormFields.getDocumentId();
7282
}
7383
}
74-
84+
// Step 6 end
85+
// Step 7a start
7586
DocGenFormFieldRequest formFields = getFormFields(
7687
documentId,
7788
candidateName,
@@ -81,15 +92,18 @@ public String generateDocument(
8192
startDate);
8293

8394
envelopesApi.updateEnvelopeDocGenFormFields(accountId, envelopeId, formFields);
95+
// Step 7a end
8496

97+
// Step 8 start
8598
Envelope envelope = new Envelope();
8699
envelope.setStatus(EnvelopeHelpers.ENVELOPE_STATUS_SENT);
87100

88101
EnvelopeUpdateSummary envelopeUpdateSummary = envelopesApi.update(accountId, envelopeId, envelope);
89-
102+
// Step 8 end
90103
return envelopeUpdateSummary.getEnvelopeId();
91104
}
92105

106+
// Step 4b start
93107
private TemplateTabs prepareTabs() {
94108
SignHere signHere = createSignHere();
95109
DateSigned dateSigned = createDateSigned();
@@ -121,7 +135,9 @@ public static DateSigned createDateSigned() {
121135

122136
return dateSigned;
123137
}
138+
// Step 4b end
124139

140+
// Step 7b start
125141
private DocGenFormFieldRequest getFormFields(
126142
String documentId,
127143
String candidateName,
@@ -163,7 +179,9 @@ private DocGenFormFieldRequest getFormFields(
163179

164180
return docGenFormFieldRequest;
165181
}
182+
// Step 7b end
166183

184+
// Step 5b start
167185
private EnvelopeDefinition makeEnvelope(String candidateEmail, String candidateName, String templateId) {
168186
TemplateRole signerRole = new TemplateRole();
169187
signerRole.setName(candidateName);
@@ -177,7 +195,9 @@ private EnvelopeDefinition makeEnvelope(String candidateEmail, String candidateN
177195

178196
return envelopeDefinition;
179197
}
198+
// Step 5b end
180199

200+
// Step 2b start
181201
private EnvelopeTemplate makeTemplate() {
182202
Signer signer = new Signer();
183203
signer.setRoleName(EnvelopeHelpers.SIGNER_ROLE_NAME);
@@ -196,7 +216,9 @@ private EnvelopeTemplate makeTemplate() {
196216

197217
return template;
198218
}
219+
// Step 2b end
199220

221+
// Step 3b start
200222
private static EnvelopeDefinition addDocumentTemplate(String offerDocDocx) throws IOException {
201223
String documentName = "OfferLetterDemo.docx";
202224
Document document = EnvelopeHelpers.createDocumentFromFile(offerDocDocx, documentName,DEFAULT_ID);
@@ -208,4 +230,5 @@ private static EnvelopeDefinition addDocumentTemplate(String offerDocDocx) throw
208230

209231
return envelopeDefinition;
210232
}
233+
// Step 3b stop
211234
}

0 commit comments

Comments
 (0)