summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java28
-rw-r--r--src/test/java/dev/dnpm/etl/processor/consent/GicsConsentServiceTest.java29
2 files changed, 36 insertions, 21 deletions
diff --git a/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java b/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java
index 7ffd3e0..a69ba53 100644
--- a/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java
+++ b/src/main/java/dev/dnpm/etl/processor/consent/GicsConsentService.java
@@ -5,10 +5,12 @@ import ca.uhn.fhir.parser.DataFormatException;
import dev.dnpm.etl.processor.config.AppFhirConfig;
import dev.dnpm.etl.processor.config.GIcsConfigProperties;
import java.net.URI;
+import java.net.URISyntaxException;
import java.util.Date;
import kotlin.random.Random;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
+import org.apache.hc.core5.net.URIBuilder;
import org.hl7.fhir.r4.model.*;
import org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent;
import org.jspecify.annotations.NonNull;
@@ -23,7 +25,6 @@ import org.springframework.retry.TerminatedRetryException;
import org.springframework.retry.support.RetryTemplate;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
-import org.springframework.web.util.UriComponentsBuilder;
/**
* Service to request Consent from remote gICS installation
@@ -112,12 +113,21 @@ public class GicsConsentService implements IConsentService {
return result;
}
- private URI endpointUri(String endpoint) {
- assert this.gIcsConfigProperties.getUri() != null;
- return UriComponentsBuilder.fromUriString(this.gIcsConfigProperties.getUri())
- .path(endpoint)
- .build()
- .toUri();
+ private URI endpointUri(String endpoint) throws URISyntaxException {
+ if (null == this.gIcsConfigProperties.getUri()) {
+ throw new URISyntaxException("null", "URI must not be null");
+ }
+ var gPasUrl1 = this.gIcsConfigProperties.getUri();
+ if (this.gIcsConfigProperties.getUri().lastIndexOf("/")
+ == this.gIcsConfigProperties.getUri().length() - 1) {
+ gPasUrl1 =
+ this.gIcsConfigProperties
+ .getUri()
+ .substring(0, this.gIcsConfigProperties.getUri().length() - 1);
+ }
+ var urlBuilder = new URIBuilder(new URI(gPasUrl1)).appendPath(endpoint);
+
+ return urlBuilder.build();
}
private HttpHeaders headersWithHttpBasicAuth() {
@@ -170,6 +180,10 @@ public class GicsConsentService implements IConsentService {
terminatedRetryException.getMessage());
log.error(msg);
return null;
+ } catch (URISyntaxException e) {
+ var msg = String.format("Invalid URI for consents status request: '%s", e.getMessage());
+ log.error(msg);
+ return null;
}
}
diff --git a/src/test/java/dev/dnpm/etl/processor/consent/GicsConsentServiceTest.java b/src/test/java/dev/dnpm/etl/processor/consent/GicsConsentServiceTest.java
index bbc53be..e450e4d 100644
--- a/src/test/java/dev/dnpm/etl/processor/consent/GicsConsentServiceTest.java
+++ b/src/test/java/dev/dnpm/etl/processor/consent/GicsConsentServiceTest.java
@@ -1,5 +1,6 @@
package dev.dnpm.etl.processor.consent;
+import static dev.dnpm.etl.processor.consent.GicsConsentService.IS_CONSENTED_ENDPOINT;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withServerError;
@@ -10,11 +11,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import dev.dnpm.etl.processor.config.AppConfiguration;
import dev.dnpm.etl.processor.config.AppFhirConfig;
import dev.dnpm.etl.processor.config.GIcsConfigProperties;
+import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.Date;
import java.util.Objects;
import org.apache.commons.io.IOUtils;
+import org.apache.hc.core5.net.URIBuilder;
import org.hl7.fhir.r4.model.*;
import org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity;
import org.hl7.fhir.r4.model.OperationOutcome.IssueType;
@@ -48,6 +51,10 @@ class GicsConsentServiceTest {
GicsConsentService gicsConsentService;
+ static URI expectedGicsConsentedEndpoint() throws Exception {
+ return new URIBuilder(URI.create(GICS_BASE_URI)).appendPath(IS_CONSENTED_ENDPOINT).build();
+ }
+
@BeforeEach
void setUp(
@Autowired AppFhirConfig appFhirConfig,
@@ -67,7 +74,7 @@ class GicsConsentServiceTest {
}
@Test
- void shouldReturnTtpBroadConsentStatus() {
+ void shouldReturnTtpBroadConsentStatus() throws Exception {
final Parameters consentedResponse =
new Parameters()
.addParameter(
@@ -76,10 +83,7 @@ class GicsConsentServiceTest {
.setValue(new BooleanType().setValue(true)));
mockRestServiceServer
- .expect(
- requestTo(
- "http://localhost:8090/ttp-fhir/fhir/gics"
- + GicsConsentService.IS_CONSENTED_ENDPOINT))
+ .expect(requestTo(expectedGicsConsentedEndpoint()))
.andRespond(
withSuccess(
appFhirConfig
@@ -93,7 +97,7 @@ class GicsConsentServiceTest {
}
@Test
- void shouldReturnRevokedConsent() {
+ void shouldReturnRevokedConsent() throws Exception {
final Parameters revokedResponse =
new Parameters()
.addParameter(
@@ -102,10 +106,7 @@ class GicsConsentServiceTest {
.setValue(new BooleanType().setValue(false)));
mockRestServiceServer
- .expect(
- requestTo(
- "http://localhost:8090/ttp-fhir/fhir/gics"
- + GicsConsentService.IS_CONSENTED_ENDPOINT))
+ .expect(requestTo(expectedGicsConsentedEndpoint()))
.andRespond(
withSuccess(
appFhirConfig.fhirContext().newJsonParser().encodeResourceToString(revokedResponse),
@@ -116,7 +117,7 @@ class GicsConsentServiceTest {
}
@Test
- void shouldReturnInvalidParameterResponse() {
+ void shouldReturnInvalidParameterResponse() throws Exception {
final OperationOutcome responseWithErrorOutcome =
new OperationOutcome()
.addIssue(
@@ -126,7 +127,7 @@ class GicsConsentServiceTest {
.setDiagnostics("Invalid policy parameter..."));
mockRestServiceServer
- .expect(requestTo(GICS_BASE_URI + GicsConsentService.IS_CONSENTED_ENDPOINT))
+ .expect(requestTo(expectedGicsConsentedEndpoint()))
.andRespond(
withSuccess(
appFhirConfig
@@ -140,9 +141,9 @@ class GicsConsentServiceTest {
}
@Test
- void shouldReturnRequestError() {
+ void shouldReturnRequestError() throws Exception {
mockRestServiceServer
- .expect(requestTo(GICS_BASE_URI + GicsConsentService.IS_CONSENTED_ENDPOINT))
+ .expect(requestTo(expectedGicsConsentedEndpoint()))
.andRespond(withServerError());
var consentStatus = gicsConsentService.getTtpBroadConsentStatus("123456");