Skip to content

Commit

Permalink
[kbss-cvut/record-manager-ui#184] Implement detached import
Browse files Browse the repository at this point in the history
I.e. import that is fully implemented by external service. In this case database is modified by separate service.
  • Loading branch information
blcham committed Jul 21, 2024
1 parent f8b2dde commit 31be300
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ public RecordImportResult importRecordsJson(@RequestPart("file") MultipartFile f
}

@PostMapping(value = "/import/excel", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public RecordImportResult importRecordsExcel(@RequestPart("file") MultipartFile file,
@RequestParam(name = "phase", required = false) String phase) {
public RecordImportResult importRecordsExcel(
@RequestPart("file") MultipartFile file,
@RequestParam(name = "phase", required = false) String phase,
@RequestParam(name = "detached", required = false, defaultValue = "true") boolean detached) {

List<PatientRecord> records;

Expand All @@ -200,6 +202,22 @@ public RecordImportResult importRecordsExcel(@RequestPart("file") MultipartFile

HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);

if (detached) { // Implement variant where import is handled fully by external service
ResponseEntity<byte[]> responseEntity = restTemplate.postForEntity(
URI.create(excelImportServiceUrl),
requestEntity,
byte[].class
);

LOG.info("Import finished with status {}", responseEntity.getStatusCode());
if (responseEntity.getStatusCode() == HttpStatus.OK) {
byte[] responseBody = responseEntity.getBody();
LOG.debug("Response body length is {}", responseBody.length);
}

return new RecordImportResult();
}

ResponseEntity<List<PatientRecord>> responseEntity = restTemplate.exchange(
URI.create(excelImportServiceUrl),
HttpMethod.POST,
Expand Down

0 comments on commit 31be300

Please sign in to comment.