Skip to content

Commit

Permalink
patch java API client for /api/v1/admin/usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed May 9, 2024
1 parent 00a9e17 commit b79defd
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
43 changes: 43 additions & 0 deletions tools/AdminResourceApi.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
diff --git a/vcell-restclient/src/main/java/org/vcell/restclient/api/AdminResourceApi.java b/vcell-restclient/src/main/java/org/vcell/restclient/api/AdminResourceApi.java
index 376df77e9..be5b616c3 100644
--- a/vcell-restclient/src/main/java/org/vcell/restclient/api/AdminResourceApi.java
+++ b/vcell-restclient/src/main/java/org/vcell/restclient/api/AdminResourceApi.java
@@ -17,17 +17,12 @@ import org.vcell.restclient.ApiException;
import org.vcell.restclient.ApiResponse;
import org.vcell.restclient.Pair;

-import java.io.File;
+import java.io.*;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

-import java.io.InputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.File;
-import java.io.IOException;
-import java.io.OutputStream;
import java.net.http.HttpRequest;
import java.nio.channels.Channels;
import java.nio.channels.Pipe;
@@ -111,10 +106,16 @@ public class AdminResourceApi {
if (localVarResponse.statusCode()/ 100 != 2) {
throw getApiException("getUsage", localVarResponse);
}
+ // Create a temporary file to store the PDF
+ File tempFile = File.createTempFile("usage_summary", ".pdf");
+ try (OutputStream out = new FileOutputStream(tempFile)) {
+ // Write the response body to the file
+ localVarResponse.body().transferTo(out);
+ }
return new ApiResponse<File>(
- localVarResponse.statusCode(),
- localVarResponse.headers().map(),
- localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<File>() {}) // closes the InputStream
+ localVarResponse.statusCode(),
+ localVarResponse.headers().map(),
+ tempFile
);
} finally {
}
9 changes: 9 additions & 0 deletions tools/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ docker run --rm -v ${parentDir}:/vcell \
-o /vcell/vcell-restclient \
-c /vcell/tools/java-config.yaml

# Apply the patch to AdminResourceApi.java to treat getUsage() as a PDF file rather than a JSON file
pushd "${parentDir}" || { echo "Failed to change directory to ${parentDir}"; exit 1; }
if ! git apply "${scriptDir}/AdminResourceApi.patch"; then
echo "Failed to apply AdminResourceApi.patch"
exit 1
fi
popd || { echo "Failed to return to the previous directory"; exit 1; }


docker run --rm -v ${parentDir}:/vcell \
${generatorCliImage} generate \
-g python \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@
import org.vcell.restclient.ApiResponse;
import org.vcell.restclient.Pair;

import java.io.File;
import java.io.*;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.http.HttpRequest;
import java.nio.channels.Channels;
import java.nio.channels.Pipe;
Expand Down Expand Up @@ -111,10 +106,16 @@ public ApiResponse<File> getUsageWithHttpInfo() throws ApiException {
if (localVarResponse.statusCode()/ 100 != 2) {
throw getApiException("getUsage", localVarResponse);
}
// Create a temporary file to store the PDF
File tempFile = File.createTempFile("usage_summary", ".pdf");
try (OutputStream out = new FileOutputStream(tempFile)) {
// Write the response body to the file
localVarResponse.body().transferTo(out);
}
return new ApiResponse<File>(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<File>() {}) // closes the InputStream
localVarResponse.statusCode(),
localVarResponse.headers().map(),
tempFile
);
} finally {
}
Expand Down

0 comments on commit b79defd

Please sign in to comment.