From 6761b69558fbe1231ede069f56e74428b757fb1c Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Thu, 11 Jul 2024 19:20:26 +0200 Subject: [PATCH 1/2] [Fix partially kbss-cvut/record-manager-ui#182] Call onRecordUpdateServiceUrl if configured when record is updated. --- .../study/rest/PatientRecordController.java | 28 +++++++++++++++++-- .../cz/cvut/kbss/study/util/ConfigParam.java | 2 ++ 2 files changed, 28 insertions(+), 2 deletions(-) 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..7f4a512c 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)") @@ -171,6 +178,23 @@ public void updateRecord(@PathVariable("key") String key, @RequestBody PatientRe if (LOG.isTraceEnabled()) { LOG.trace("Patient record {} successfully updated.", record); } + + onUpdateRecord(record.getUri()); + } + + private void onUpdateRecord(URI uri){ + Objects.nonNull(uri); + String onRecordUpdateServiceUrl = configReader.getConfig(ConfigParam.ON_UPDATE_RECORD_SERVICE_URL); + if(onRecordUpdateServiceUrl == null || onRecordUpdateServiceUrl.isBlank()) { + LOG.debug("No onRecordUpdateServiceUrl service url provided, noop."); + return; + } + + LOG.debug("calling onRecordUpdateServiceUrl: {} with parameter {}", onRecordUpdateServiceUrl, uri); + String requestUrl = UriComponentsBuilder.fromHttpUrl(onRecordUpdateServiceUrl) + .queryParam("record", uri) + .toUriString(); + restTemplate.getForObject(requestUrl,String.class); } @DeleteMapping(value = "/{key}") 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..9cb58769 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"), + ON_UPDATE_RECORD_SERVICE_URL("onRecordUpdateServiceUrl"), + APP_CONTEXT("appContext"), SMTP_HOST("smtp.host"), From f91a828728d94672373d53f4255e57e92da79a1c Mon Sep 17 00:00:00 2001 From: Bogdan Kostov Date: Thu, 11 Jul 2024 19:53:44 +0200 Subject: [PATCH 2/2] [Fix partially kbss-cvut/record-manager-ui#182] Fix failing test --- .../cz/cvut/kbss/study/rest/PatientRecordController.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 7f4a512c..987c4b56 100644 --- a/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java +++ b/src/main/java/cz/cvut/kbss/study/rest/PatientRecordController.java @@ -184,7 +184,10 @@ public void updateRecord(@PathVariable("key") String key, @RequestBody PatientRe private void onUpdateRecord(URI uri){ Objects.nonNull(uri); - String onRecordUpdateServiceUrl = configReader.getConfig(ConfigParam.ON_UPDATE_RECORD_SERVICE_URL); + String onRecordUpdateServiceUrl = Optional.ofNullable(configReader) + .map(r -> r.getConfig(ConfigParam.ON_UPDATE_RECORD_SERVICE_URL)) + .orElse(null); + if(onRecordUpdateServiceUrl == null || onRecordUpdateServiceUrl.isBlank()) { LOG.debug("No onRecordUpdateServiceUrl service url provided, noop."); return;