Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call onRecordUpdateServiceUrl if configured when record is updated. #57

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 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 @@ -12,22 +12,25 @@
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;
import org.springframework.http.*;
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;

Expand All @@ -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)")
Expand Down Expand Up @@ -171,6 +178,26 @@ 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 = 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;
}

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}")
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/cz/cvut/kbss/study/util/ConfigParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Loading