Skip to content

Commit 3ae925d

Browse files
authored
Merge pull request #153 from docusign/fixes-for-java-examples
Fixes for file paths and monitor example
2 parents 88b36ea + 850e6e7 commit 3ae925d

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

src/main/java/com/docusign/controller/click/examples/ClickwrapHelper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class ClickwrapHelper {
2222
* @return the {@link Document} object
2323
* @throws IOException if document cannot be loaded due to some reason
2424
*/
25-
public static Document createDocumentFromFile(String fileName, String docName, Integer order) throws IOException {
26-
byte[] buffer = FileUtils.readFile(fileName);
25+
public Document createDocumentFromFile(String fileName, String docName, Integer order) throws IOException {
26+
byte[] buffer = new FileUtils().readFile(fileName);
2727
String extension = FilenameUtils.getExtension(fileName);
2828
return createDocument(buffer, docName, extension, order);
2929
}

src/main/java/com/docusign/controller/click/services/CreateClickwrapService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static ClickwrapRequest createClickwrapRequest(
1818
String documentName,
1919
Integer documentOrder
2020
) throws IOException {
21-
Document document = ClickwrapHelper.createDocumentFromFile(fileName, documentName, documentOrder);
21+
Document document = new ClickwrapHelper().createDocumentFromFile(fileName, documentName, documentOrder);
2222
DisplaySettings displaySettings = new DisplaySettings()
2323
.displayName("Terms of Service")
2424
.consentButtonText("I Agree")

src/main/java/com/docusign/controller/click/services/CreateNewVersionClickwrapService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static ClickwrapRequest createClickwrapRequest(
3333
Integer documentOrder,
3434
String clickwrapName
3535
) throws IOException {
36-
Document document = ClickwrapHelper.createDocumentFromFile(fileName, documentName, documentOrder);
36+
Document document = new ClickwrapHelper().createDocumentFromFile(fileName, documentName, documentOrder);
3737
DisplaySettings displaySettings = new DisplaySettings()
3838
.displayName(clickwrapName)
3939
.consentButtonText("I Agree")

src/main/java/com/docusign/controller/monitor/services/GetMonitoringDataService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public final class GetMonitoringDataService {
1515
public static JSONArray getMonitoringData(DataSetApi datasetApi) throws Exception {
1616
// Declare variables
1717
boolean complete = false;
18-
LocalDate cursorDate = LocalDate.now().minusYears(1);
18+
LocalDate cursorDate = LocalDate.now().minusDays(1);
1919
String cursorValue = cursorDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "T00:00:00Z";
2020
JSONArray monitoringData = new JSONArray();
2121

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.docusign.core.utils;
22

3-
import org.springframework.core.io.ClassPathResource;
43
import org.springframework.util.StreamUtils;
54

5+
import java.io.FileNotFoundException;
66
import java.io.IOException;
7+
import java.io.InputStream;
78

89
public class FileUtils {
910
/**
@@ -13,8 +14,12 @@ public class FileUtils {
1314
* @return the new byte array that has been loaded from the file
1415
* @throws IOException in case of I/O errors
1516
*/
16-
public static byte[] readFile(String path) throws IOException {
17-
ClassPathResource resource = new ClassPathResource(path);
18-
return StreamUtils.copyToByteArray(resource.getInputStream());
17+
public byte[] readFile(String path) throws IOException {
18+
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(path);
19+
if (inputStream == null) {
20+
throw new FileNotFoundException("File not found: " + path);
21+
}
22+
23+
return StreamUtils.copyToByteArray(inputStream);
1924
}
2025
}

src/test/java/tests/Click/CreateClickwrapTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void CreateClickwrapRequest_CorrectInputValues_ReturnsClickwrapRequest()
5555
String format = "modal";
5656
String documentDisplay = "document";
5757

58-
Document document = ClickwrapHelper.createDocumentFromFile(DOCUMENT_FILE_NAME, DOCUMENT_NAME, DOCUMENT_ORDER);
58+
Document document = new ClickwrapHelper().createDocumentFromFile(DOCUMENT_FILE_NAME, DOCUMENT_NAME, DOCUMENT_ORDER);
5959
DisplaySettings displaySettings = new DisplaySettings()
6060
.displayName(displayName)
6161
.consentButtonText(consentButtonText)

0 commit comments

Comments
 (0)