Skip to content

Commit 0145bd0

Browse files
committed
aligning flow with the C# example
1 parent 36be53c commit 0145bd0

4 files changed

Lines changed: 44 additions & 33 deletions

File tree

src/main/java/com/docusign/controller/navigator/examples/Nav003BulkUploadDocumentsController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ public String postCompleteUpload(WorkArguments args, ModelMap model) throws Exce
7777
var accountId = session.getAccountId();
7878
var accessToken = user.getAccessToken();
7979

80-
NavigatorMethodsService.completeBulkUploadJob(accountId, accessToken, jobId);
80+
var completeUploadResult = NavigatorMethodsService.completeBulkUploadJob(accountId, accessToken, jobId);
8181

82+
var jsonAgreement = NavigatorMethodsService.serializeObjectToJson(completeUploadResult.bulkJob().orElseThrow());
8283
DoneExample.createDefault(getTextForCodeExampleByApiType().ExampleName)
8384
.withMessage(getTextForCodeExampleByApiType().AdditionalPage.get(1).ResultsPageText)
85+
.withJsonObject(jsonAgreement)
8486
.addToModel(model, config);
8587

8688
return DONE_EXAMPLE_PAGE;

src/main/java/com/docusign/controller/navigator/services/NavigatorMethodsService.java

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import com.docusign.iam.sdk.models.operations.UploadCompleteBulkJobResponse;
1010
import com.fasterxml.jackson.annotation.JsonInclude;
1111
import com.fasterxml.jackson.databind.ObjectMapper;
12+
import com.fasterxml.jackson.databind.SerializationFeature;
13+
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
1214
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
1315
import org.openapitools.jackson.nullable.JsonNullableModule;
1416

@@ -54,7 +56,9 @@ public static GetAgreementResponse getAgreement(String accountId, String accessT
5456
public static String serializeObjectToJson(Object data) throws Exception {
5557
var mapper = new ObjectMapper()
5658
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
59+
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
5760
.registerModule(new JavaTimeModule())
61+
.registerModule(new Jdk8Module())
5862
.registerModule(new JsonNullableModule());
5963

6064
return mapper.writeValueAsString(data);
@@ -110,11 +114,11 @@ public static void uploadDocumentsToJob(List<String> uploadUrls) throws Exceptio
110114
continue;
111115

112116
var docInfo = demoDocs.get(i);
113-
var bytes = loadClasspathResource(docInfo[0]);
117+
var bytes = loadClasspathResource(docInfo);
114118
if (bytes == null)
115119
continue;
116120

117-
uploadToBlobStorage(bytes, docInfo[1], docInfo[2], uploadUrl);
121+
uploadToBlobStorage(bytes, getContentType(docInfo), docInfo, uploadUrl);
118122
}
119123
}
120124

@@ -127,26 +131,49 @@ public static UploadCompleteBulkJobResponse completeBulkUploadJob(
127131
.uploadCompleteBulkJob(accountId, jobId);
128132
}
129133

130-
private static List<String[]> getAvailableDemoDocuments() {
131-
String[][] candidates = {
132-
{ "World_Wide_Corp_Battle_Plan_Trafalgar.docx",
133-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
134-
"World_Wide_Corp_Battle_Plan_Trafalgar.docx" },
135-
{ "World_Wide_Corp_lorem.pdf", "application/pdf", "World_Wide_Corp_lorem.pdf" },
136-
{ "doc_1.html", "text/html", "doc_1.html" },
137-
{ "Welcome.txt", "text/plain", "Welcome.txt" },
138-
{ "Id.jpg", "image/jpeg", "Id.jpg" },
134+
private static List<String> getAvailableDemoDocuments() {
135+
String[] candidates = {
136+
"World_Wide_Corp_Battle_Plan_Trafalgar.docx",
137+
"World_Wide_Corp_lorem.pdf",
138+
"doc_1.html",
139+
"Welcome.txt",
140+
"Id.jpg",
139141
};
140142

141-
var available = new ArrayList<String[]>();
143+
var available = new ArrayList<String>();
142144
for (var doc : candidates) {
143-
if (NavigatorMethodsService.class.getClassLoader().getResource(doc[0]) != null) {
145+
if (NavigatorMethodsService.class.getClassLoader().getResource(doc) != null) {
144146
available.add(doc);
145147
}
146148
}
147149
return available;
148150
}
149151

152+
private static String getContentType(String filename) {
153+
String extension = "";
154+
int lastDot = filename.lastIndexOf('.');
155+
156+
if (lastDot >= 0) {
157+
extension = filename.substring(lastDot).toLowerCase();
158+
}
159+
160+
switch (extension) {
161+
case ".docx":
162+
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
163+
case ".pdf":
164+
return "application/pdf";
165+
case ".html":
166+
return "text/html";
167+
case ".txt":
168+
return "text/plain";
169+
case ".jpg":
170+
case ".jpeg":
171+
return "image/jpeg";
172+
default:
173+
return "application/octet-stream";
174+
}
175+
}
176+
150177
private static byte[] loadClasspathResource(String resourcePath) {
151178
try (var stream = NavigatorMethodsService.class.getClassLoader().getResourceAsStream(resourcePath)) {
152179
if (stream == null)

src/main/webapp/WEB-INF/templates/views/pages/navigator/examples/nav003CompleteUpload.jsp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@
55

66
<h4>${example.getExampleName()}</h4>
77
<p>${example.getAdditionalPage().get(0).getResultsPageText()}</p>
8-
<c:if test="${showDoc}">
9-
<p><a target='_blank' href='${documentation}'>Documentation</a> about this example.</p>
10-
</c:if>
11-
12-
<jsp:include page="../../links_to_api_methods.jsp" />
13-
14-
<p>
15-
${viewSourceFile}
16-
</p>
178

189
<form class="eg" action="" method="post" data-busy="form">
1910
<input type="hidden" name="_csrf" value="${csrfToken}">

src/main/webapp/WEB-INF/templates/views/pages/navigator/examples/nav003UploadDocuments.jsp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@
55

66
<h4>${example.getExampleName()}</h4>
77
<p>${example.getResultsPageText()}</p>
8-
<c:if test="${showDoc}">
9-
<p><a target='_blank' href='${documentation}'>Documentation</a> about this example.</p>
10-
</c:if>
11-
12-
<jsp:include page="../../links_to_api_methods.jsp" />
13-
14-
<p>
15-
${viewSourceFile}
16-
</p>
17-
8+
189
<form class="eg" action="" method="post" data-busy="form">
1910
<input type="hidden" name="_csrf" value="${csrfToken}">
2011
<button type="submit" class="btn btn-docu">${launcherTexts.getContinueButton()}</button>

0 commit comments

Comments
 (0)