Skip to content

Commit

Permalink
CSV Download endpoint edit
Browse files Browse the repository at this point in the history
  • Loading branch information
Utkarsh Shukla committed Aug 29, 2024
1 parent a1a28ac commit 7a68c3a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,25 +204,23 @@ class OpsmxAuditClientServiceController {
@PathVariable("type") String type,
@PathVariable("source") String source,
@RequestBody(required = false) Object data) {
//
Response response = opsmxAuditClientService.downloadCSVFile2(version, type, source, data)
// log.info("response for the system audit endpoint:" + response.getHeaders()+" with body:"+response.getBody())
// if (response.getBody()!= null) {
// InputStream inputStream = new ByteArrayInputStream(response.getBody().getBytes(StandardCharsets.UTF_8))
// try {
// byte[] csvFile = IOUtils.toByteArray(inputStream)
// HttpHeaders headers = new HttpHeaders()
// headers.setContentType(MediaType.parseMediaType("text/csv"));
// headers.add("Content-Disposition", response.getHeaders().stream().filter({ header -> header.getName().trim().equalsIgnoreCase("Content-Disposition") }).collect(Collectors.toList()).get(0).value)
// return ResponseEntity.ok().headers(headers).body(csvFile)
// } finally {
// if (inputStream != null) {
// inputStream.close()
// }
// }
// }
// return ResponseEntity.status(response.getStatus()).build()
return response;
log.info("response for the system audit endpoint:" + response.getHeaders())
if (response.getBody()!= null) {
InputStream inputStream = response.getBody().in()
try {
byte[] csvFile = IOUtils.toByteArray(inputStream)
HttpHeaders headers = new HttpHeaders()
headers.setContentType(MediaType.parseMediaType("text/csv"));
headers.add("Content-Disposition", response.getHeaders().stream().filter({ header -> header.getName().trim().equalsIgnoreCase("Content-Disposition") }).collect(Collectors.toList()).get(0).value)
return ResponseEntity.ok().headers(headers).body(csvFile)
} finally {
if (inputStream != null) {
inputStream.close()
}
}
}
return ResponseEntity.status(response.getStatus()).build()
}

@Operation(summary = "Endpoint for Delivery Insights controller to download csv file")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ interface OpsmxAuditClientService {
@Body Object data)

@POST("/auditclientservice/{version}/{type}/{source}/download")
Object downloadCSVFile2(@Path('version') String version,
Response downloadCSVFile2(@Path('version') String version,
@Path('type') String type,
@Path('source') String source,
@Body Object data)
Expand Down

0 comments on commit 7a68c3a

Please sign in to comment.