Skip to content

Commit

Permalink
JNG-5818 Add extensibility of export API
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcsakany committed Jul 2, 2024
1 parent ab22136 commit ca0f6a5
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,20 @@ public class {{ implClassName self }} implements {{ namedElementApiRestFqName se
java.io.File file = new java.io.File(tmpdir, java.util.UUID.randomUUID().toString() + ".xlsx");
file.deleteOnExit();

try(java.io.InputStream is = ((java.io.InputStream) result.get("output")); java.io.OutputStream os = new java.io.FileOutputStream(file)) {
java.util.Map<String, Object> exportResult = (java.util.Map<String, Object>) result.get("output");
java.io.InputStream exportStream = (java.io.InputStream) exportResult.get("stream");
String extension = (String) exportResult.get("extension");
String name = (String) exportResult.get("name");

try (java.io.InputStream is = exportStream; java.io.OutputStream os = new java.io.FileOutputStream(file)) {
is.transferTo(os);
} catch (java.io.IOException e) {
throw new java.lang.RuntimeException(e);
}

javax.ws.rs.core.Response.ResponseBuilder responseBuilder = javax.ws.rs.core.Response.ok(file, javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM)
.header("Access-Control-Expose-Headers", "Content-Disposition")
.header("Content-Disposition", "attachment; filename=\"" + file.getName() + "\"");
.header("Content-Disposition", "attachment; filename=\"" + name + "." + extension + "\"");
{{ else }}
javax.ws.rs.core.Response.ResponseBuilder responseBuilder = result != null && result.containsKey("{{ operation.output.name }}") ? javax.ws.rs.core.Response.ok(result.get("{{ operation.output.name }}")) : javax.ws.rs.core.Response.ok();
{{/ if }}
Expand Down

0 comments on commit ca0f6a5

Please sign in to comment.