diff --git a/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java b/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java index f29138fb..91163052 100644 --- a/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java +++ b/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java @@ -12,12 +12,13 @@ import cz.cvut.kbss.study.rest.util.RecordFilterMapper; import cz.cvut.kbss.study.rest.util.RestUtils; import cz.cvut.kbss.study.security.SecurityConstants; +import cz.cvut.kbss.study.service.ConfigReader; import cz.cvut.kbss.study.service.ExcelRecordConverter; import cz.cvut.kbss.study.service.PatientRecordService; +import cz.cvut.kbss.study.util.ConfigParam; import cz.cvut.kbss.study.util.Constants; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import org.apache.commons.collections4.EnumerationUtils; import org.springframework.context.ApplicationEventPublisher; import org.springframework.core.io.InputStreamResource; import org.springframework.data.domain.Page; @@ -25,9 +26,11 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; import java.io.InputStream; +import java.net.URI; import java.util.*; import java.util.stream.Stream; @@ -40,11 +43,15 @@ public class PatientRecordController extends BaseController { private final ApplicationEventPublisher eventPublisher; private final ExcelRecordConverter excelRecordConverter; + private final RestTemplate restTemplate; + private final ConfigReader configReader; - public PatientRecordController(PatientRecordService recordService, ApplicationEventPublisher eventPublisher, ExcelRecordConverter excelRecordConverter) { + public PatientRecordController(PatientRecordService recordService, ApplicationEventPublisher eventPublisher, ExcelRecordConverter excelRecordConverter, RestTemplate restTemplate, ConfigReader configReader) { this.recordService = recordService; this.eventPublisher = eventPublisher; this.excelRecordConverter = excelRecordConverter; + this.restTemplate = restTemplate; + this.configReader = configReader; } @PreAuthorize("hasRole('" + SecurityConstants.ROLE_ADMIN + "') or @securityUtils.isMemberOfInstitution(#institutionKey)") @@ -145,6 +152,24 @@ public ResponseEntity 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 params){ +// final Page result = recordService.findAllFull(RecordFilterMapper.constructRecordFilter(params), +// RestUtils.resolvePaging(params)); +// List records = result.getContent(); + List records = new ArrayList<>(); + String publishServiceUrl = configReader.getConfig(ConfigParam.PUBLISH_SERVICE_URL); + LOG.debug("Publishing records."); + RecordImportResult response = restTemplate.postForEntity(URI.create(publishServiceUrl), records, RecordImportResult.class).getBody(); + + LOG.debug("Publish server response: ", response); + return response; + } + @PostMapping(value = "/import", consumes = MediaType.APPLICATION_JSON_VALUE) public RecordImportResult importRecords(@RequestBody List records, @RequestParam(name = "phase", required = false) String phase) { diff --git a/src/main/java/cz/cvut/kbss/study/util/ConfigParam.java b/src/main/java/cz/cvut/kbss/study/util/ConfigParam.java index 9a9c3360..d7936b64 100644 --- a/src/main/java/cz/cvut/kbss/study/util/ConfigParam.java +++ b/src/main/java/cz/cvut/kbss/study/util/ConfigParam.java @@ -9,6 +9,8 @@ public enum ConfigParam { FORM_GEN_REPOSITORY_URL("formGenRepositoryUrl"), FORM_GEN_SERVICE_URL("formGenServiceUrl"), + PUBLISH_SERVICE_URL("publishServiceUrl"), + APP_CONTEXT("appContext"), SMTP_HOST("smtp.host"),