Skip to content

Commit

Permalink
ALS-6511: Attempt to fix encoding issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Aug 14, 2024
1 parent 091eab0 commit 1be9246
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<AsyncResult>{

Expand All @@ -36,6 +37,12 @@ public void closeWriter() {
stream.closeWriter();
}

private MediaType responseType;

public MediaType getResponseType() {
return responseType;
}

public static enum Status{
SUCCESS {
@Override
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -55,6 +57,11 @@ public File getFile() {
return file;
}

@Override
public MediaType getResponseType() {
return MediaType.TEXT_PLAIN;
}

@Override
public void close() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -186,4 +187,9 @@ public void close() {
public File getFile() {
return file;
}

@Override
public MediaType getResponseType() {
return MediaType.APPLICATION_OCTET_STREAM;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,5 +15,7 @@ public interface ResultWriter {

File getFile();

MediaType getResponseType();

void close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 1be9246

Please sign in to comment.