diff --git a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/AsyncResult.java b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/AsyncResult.java index 9f0e414e..7312b6f9 100644 --- a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/AsyncResult.java +++ b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/AsyncResult.java @@ -19,6 +19,7 @@ import edu.harvard.hms.dbmi.avillach.hpds.data.query.Query; import edu.harvard.hms.dbmi.avillach.hpds.data.query.ResultType; import edu.harvard.hms.dbmi.avillach.hpds.exception.NotEnoughMemoryException; +import org.springframework.http.MediaType; public class AsyncResult implements Runnable, Comparable{ @@ -36,6 +37,12 @@ public void closeWriter() { stream.closeWriter(); } + private MediaType responseType; + + public MediaType getResponseType() { + return responseType; + } + public static enum Status{ SUCCESS { @Override @@ -179,6 +186,7 @@ public AsyncResult(Query query, HpdsProcessor processor, ResultWriter writer) { this.query = query; this.processor = processor; this.headerRow = processor.getHeaderRow(query); + this.responseType = writer.getResponseType(); try { stream = new ResultStoreStream(headerRow, writer); } catch (IOException e) { diff --git a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/CsvWriter.java b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/CsvWriter.java index a615094e..3302d06e 100644 --- a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/CsvWriter.java +++ b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/CsvWriter.java @@ -1,5 +1,7 @@ package edu.harvard.hms.dbmi.avillach.hpds.processing.io; +import org.springframework.http.MediaType; + import java.io.File; import java.io.FileWriter; import java.io.IOException; @@ -55,6 +57,11 @@ public File getFile() { return file; } + @Override + public MediaType getResponseType() { + return MediaType.TEXT_PLAIN; + } + @Override public void close() { try { diff --git a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/PfbWriter.java b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/PfbWriter.java index 59a56057..1e97c766 100644 --- a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/PfbWriter.java +++ b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/PfbWriter.java @@ -11,6 +11,7 @@ import org.apache.avro.io.DatumWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.MediaType; import java.io.File; import java.io.IOException; @@ -186,4 +187,9 @@ public void close() { public File getFile() { return file; } + + @Override + public MediaType getResponseType() { + return MediaType.APPLICATION_OCTET_STREAM; + } } diff --git a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/ResultWriter.java b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/ResultWriter.java index 6f2f5d64..c0a81929 100644 --- a/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/ResultWriter.java +++ b/processing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/ResultWriter.java @@ -1,5 +1,7 @@ package edu.harvard.hms.dbmi.avillach.hpds.processing.io; +import org.springframework.http.MediaType; + import java.io.File; import java.io.IOException; import java.util.Collection; @@ -13,5 +15,7 @@ public interface ResultWriter { File getFile(); + MediaType getResponseType(); + void close(); } diff --git a/processing/src/test/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/PfbWriterTest.java b/processing/src/test/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/PfbWriterTest.java index 9861c1f3..7e18d1a7 100644 --- a/processing/src/test/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/PfbWriterTest.java +++ b/processing/src/test/java/edu/harvard/hms/dbmi/avillach/hpds/processing/io/PfbWriterTest.java @@ -24,7 +24,7 @@ public void writeValidPFB() { nullableList.add(List.of("Y")); pfbWriter.writeMultiValueEntity(List.of( nullableList, - List.of(List.of("456"), null ,List.of("N", "Y")), + List.of(List.of("456"), List.of("80") ,List.of("N", "Y")), List.of(List.of(), List.of("75"), List.of()) )); pfbWriter.writeMultiValueEntity(List.of( diff --git a/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/PicSureService.java b/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/PicSureService.java index 1feccc8e..ae4cca7c 100644 --- a/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/PicSureService.java +++ b/service/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/service/PicSureService.java @@ -13,6 +13,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.InputStreamResource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -229,8 +230,8 @@ public ResponseEntity queryResult(@PathVariable("resourceQueryId") UUID queryId, if (result.getStatus() == AsyncResult.Status.SUCCESS) { result.open(); return ResponseEntity.ok() - .contentType(MediaType.TEXT_PLAIN) - .body(result.readAllBytes()); + .contentType(result.getResponseType()) + .body(new InputStreamResource(result.getStream())); } else { return ResponseEntity.status(400).body("Status : " + result.getStatus().name()); }