Skip to content

Commit

Permalink
Merge pull request #57 from kbss-cvut/feature/record-manager-ui-182-r…
Browse files Browse the repository at this point in the history
…ecord-update-event

 Call onRecordUpdateServiceUrl if configured when record is updated.
  • Loading branch information
blcham authored Jul 11, 2024
2 parents dcc2cab + f91a828 commit aaca505
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
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

0 comments on commit aaca505

Please sign in to comment.