Skip to content

Commit

Permalink
[Fix partially kbss-cvut/record-manager-ui#180] Add publish rest api
Browse files Browse the repository at this point in the history
  • Loading branch information
kostobog authored and blcham committed Jul 22, 2024
1 parent c9e9b44 commit 84c127c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,32 @@ public ResponseEntity<String> createRecord(@RequestBody PatientRecord record) {
return new ResponseEntity<>(headers, HttpStatus.CREATED);
}

@PreAuthorize(
"hasRole('" + SecurityConstants.ROLE_ADMIN + "') or @securityUtils.isMemberOfInstitution(#institutionKey)")
@PostMapping(value = "/publish", produces = {MediaType.APPLICATION_JSON_VALUE})
public RecordImportResult publishRecords(
@RequestParam(name = "institution", required = false) String institutionKey,
@RequestParam(required = false) MultiValueMap<String, String> params){
String onPublishRecordsServiceUrl = configReader.getConfig(ConfigParam.ON_PUBLISH_RECORDS_SERVICE_URL);
if(onPublishRecordsServiceUrl == null || onPublishRecordsServiceUrl.isBlank()) {
LOG.info("No publish service url provided, noop.");
RecordImportResult result = new RecordImportResult(0);
result.addError("Cannot publish completed records. Publish server not configured.");
return result;
}

// TODO fetch records completed records
// final Page<PatientRecord> result = recordService.findAllFull(RecordFilterMapper.constructRecordFilter(params),
// RestUtils.resolvePaging(params));
// List<PatientRecord> records = result.getContent();
List<PatientRecord> records = new ArrayList<>();
LOG.debug("Publishing records.");
RecordImportResult response = restTemplate.postForEntity(URI.create(onPublishRecordsServiceUrl), records, RecordImportResult.class).getBody();

LOG.debug("Publish server response: ", response);
return response;
}

@PostMapping(value = "/import/json", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public RecordImportResult importRecordsJson(@RequestPart("file") MultipartFile file,
@RequestParam(name = "phase", required = false) String phase) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cz/cvut/kbss/study/util/ConfigParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum ConfigParam {
FORM_GEN_SERVICE_URL("formGenServiceUrl"),

ON_UPDATE_RECORD_SERVICE_URL("onRecordUpdateServiceUrl"),
ON_PUBLISH_RECORDS_SERVICE_URL("onPublishRecordsServiceUrl"),
EXCEL_IMPORT_SERVICE_URL("excelImportServiceUrl"),

APP_CONTEXT("appContext"),
Expand Down

0 comments on commit 84c127c

Please sign in to comment.