99import com .docusign .iam .sdk .models .operations .UploadCompleteBulkJobResponse ;
1010import com .fasterxml .jackson .annotation .JsonInclude ;
1111import com .fasterxml .jackson .databind .ObjectMapper ;
12+ import com .fasterxml .jackson .databind .SerializationFeature ;
13+ import com .fasterxml .jackson .datatype .jdk8 .Jdk8Module ;
1214import com .fasterxml .jackson .datatype .jsr310 .JavaTimeModule ;
1315import 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 )
0 commit comments