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

issue #3501 - apply fix for #2965 more universally #3506

Merged
merged 3 commits into from
Mar 30, 2022
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
11 changes: 9 additions & 2 deletions fhir-client/src/main/java/com/ibm/fhir/client/FHIRClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2016, 2021
* (C) Copyright IBM Corp. 2016, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -8,12 +8,13 @@

import java.security.KeyStore;

import jakarta.json.JsonObject;
import javax.ws.rs.client.WebTarget;

import com.ibm.fhir.model.resource.Bundle;
import com.ibm.fhir.model.resource.Resource;

import jakarta.json.JsonObject;

/**
* This interface provides a client API for invoking the FHIR Server's REST API.
*/
Expand Down Expand Up @@ -126,6 +127,12 @@ public interface FHIRClient {
*/
public static final String PROPNAME_TENANT_ID = "fhirclient.tenant.id";

/**
* Returns the default FHIR base URL that is configured for this client instance
* @return the FHIR base URL with scheme, host, and path
*/
String getDefaultBaseUrl();

/**
* Returns a JAX-RS 2.0 WebTarget object associated with the REST API endpoint.
* @return a WebTarget instance that can be used to invoke REST APIs.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Copyright IBM Corp. 2016, 2021
* (C) Copyright IBM Corp. 2016, 2022
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -819,6 +819,11 @@ private Builder addRequestHeaders(Builder builder, FHIRRequestHeader[] headers)
return builder;
}

@Override
public String getDefaultBaseUrl() {
return baseEndpointURL;
}

@Override
public WebTarget getWebTarget() throws Exception {
return client.target(getBaseEndpointURL());
Expand Down Expand Up @@ -973,7 +978,7 @@ private void setClientProperties(Properties clientProperties) {
this.clientProperties = clientProperties;
}

private String getBaseEndpointURL() {
public String getBaseEndpointURL() {
return baseEndpointURL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,15 @@ public Resource insert(Resource resource, List<ExtractedParameterValue> paramet
* @param conn
* @param parameterDao
* @param ifNoneMatch 0 for conditional create-on-update behavior; otherwise null
* @param resourcePayloadKey
* @param outInteractionStatus
* @param outIfNoneMatchVersion
* @return the resource_id for the entry we created
* @throws Exception
*/
public long storeResource(String tablePrefix, List<ExtractedParameterValue> parameters,
public long storeResource(String tablePrefix, List<ExtractedParameterValue> parameters,
String p_logical_id, InputStream p_payload, Timestamp p_last_updated, boolean p_is_deleted,
String p_source_key, Integer p_version, String p_parameterHashB64, Connection conn,
String p_source_key, Integer p_version, String p_parameterHashB64, Connection conn,
ParameterDAO parameterDao, Integer ifNoneMatch, String resourcePayloadKey,
AtomicInteger outInteractionStatus, AtomicInteger outIfNoneMatchVersion) throws Exception {

Expand Down Expand Up @@ -452,7 +455,7 @@ public long storeResource(String tablePrefix, List<ExtractedParameterValue> para
stmt.setLong(1, v_resource_id);
stmt.setLong(2, v_logical_resource_id);
stmt.setInt(3, p_version);

if (p_payload != null) {
stmt.setBinaryStream(4, p_payload);
} else {
Expand Down Expand Up @@ -521,7 +524,7 @@ identityCache, getResourceReferenceDAO(), getTransactionData())) {

// Finally, write a record to RESOURCE_CHANGE_LOG which records each event
// related to resources changes (issue-1955)
String changeType = p_is_deleted ? "D" : v_new_resource ? "C" : "U";
String changeType = p_is_deleted ? "D" : v_new_resource ? "C" : "U";
String INSERT_CHANGE_LOG = "INSERT INTO resource_change_log(resource_id, change_tstamp, resource_type_id, logical_resource_id, version_id, change_type)"
+ " VALUES (?,?,?,?,?,?)";
try (PreparedStatement ps = conn.prepareStatement(INSERT_CHANGE_LOG)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
import com.ibm.fhir.search.context.FHIRSearchContext;

/**
* This testng test class contains methods that test the parsing of the search result _type parameter in the
* SearchUtil class.
* Test the parsing of the search result _type parameter in the SearchUtil class.
*/
public class TypeParameterParseTest extends BaseSearchTest {

Expand Down Expand Up @@ -75,7 +74,6 @@ public void testTypeNonSystemSearch_strict() throws Exception {
} catch(Exception ex) {
isExceptionThrown = true;
assertEquals(ex.getMessage(), "_type parameter is only supported for whole-system search");

}
assertTrue(isExceptionThrown);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
package com.ibm.fhir.server.test;

import static com.ibm.fhir.model.type.String.string;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.fail;
Expand All @@ -32,6 +32,7 @@
import com.ibm.fhir.model.format.Format;
import com.ibm.fhir.model.generator.FHIRGenerator;
import com.ibm.fhir.model.resource.Bundle;
import com.ibm.fhir.model.resource.Bundle.Entry;
import com.ibm.fhir.model.resource.CapabilityStatement;
import com.ibm.fhir.model.resource.Immunization;
import com.ibm.fhir.model.resource.Observation;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void testMetadataAPI() throws FHIRPathException, FHIRValidationException
CapabilityStatement conf = response.readEntity(CapabilityStatement.class);
assertNotNull(conf);
assertNotNull(conf.getFormat());
assertEquals(6, conf.getFormat().size());
assertEquals(conf.getFormat().size(), 6);
assertNotNull(conf.getVersion());
assertNotNull(conf.getName());

Expand Down Expand Up @@ -160,12 +161,12 @@ public void testMetadataAPI_XML() {
WebTarget target = getWebTarget();
Response response = target.path("metadata").request(FHIRMediaType.APPLICATION_FHIR_XML).get();
assertResponse(response, Response.Status.OK.getStatusCode());
assertEquals(FHIRMediaType.APPLICATION_FHIR_XML_TYPE, response.getMediaType());
assertEquals(response.getMediaType(), FHIRMediaType.APPLICATION_FHIR_XML_TYPE);

CapabilityStatement conf = response.readEntity(CapabilityStatement.class);
assertNotNull(conf);
assertNotNull(conf.getFormat());
assertEquals(6, conf.getFormat().size());
assertEquals(conf.getFormat().size(), 6);
assertNotNull(conf.getVersion());
assertNotNull(conf.getName());
}
Expand All @@ -180,12 +181,12 @@ public void testMetadataAPI_validFhirVersion() {
Collections.singletonMap(FHIRMediaType.FHIR_VERSION_PARAMETER, "4.0"));
Response response = target.path("metadata").request(mediaType).get();
assertResponse(response, Response.Status.OK.getStatusCode());
assertEquals(mediaType, response.getMediaType());
assertEquals(response.getMediaType(), mediaType);

CapabilityStatement conf = response.readEntity(CapabilityStatement.class);
assertNotNull(conf);
assertNotNull(conf.getFormat());
assertEquals(6, conf.getFormat().size());
assertEquals(conf.getFormat().size(), 6);
assertNotNull(conf.getVersion());
assertNotNull(conf.getName());
}
Expand Down Expand Up @@ -554,22 +555,26 @@ public void testUpdateObservation() throws Exception {
}

/**
* Tests the retrieval of the history for a previously saved and updated
* patient.
* Tests the retrieval of the history for a previously saved and updated patient.
*/
@Test(groups = { "server-basic" }, dependsOnMethods = { "testCreatePatient", "testUpdatePatient" })
public void testHistoryPatient() {
WebTarget target = getWebTarget();

// Call the 'history' API to retrieve both the original and updated versions of
// the patient.
// Call the 'history' API to retrieve both the original and updated versions of the patient.
String targetPath = "Patient/" + savedCreatedPatient.getId() + "/_history";
Response response = target.path(targetPath).request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
assertResponse(response, Response.Status.OK.getStatusCode());

Bundle resources = response.readEntity(Bundle.class);
assertNotNull(resources);
assertEquals(2, resources.getEntry().size());
assertEquals(resources.getEntry().size(), 2);

for (Entry entry : resources.getEntry()) {
String fullUrl = entry.getFullUrl().getValue();
assertEquals(fullUrl, getRestBaseURL() + "/Patient/" + savedCreatedPatient.getId());
}

Patient updatedPatient = (Patient) resources.getEntry().get(0).getResource();
Patient originalPatient = (Patient) resources.getEntry().get(1).getResource();
// Make sure patient ids are equal, and versionIds are NOT equal.
Expand All @@ -583,22 +588,26 @@ public void testHistoryPatient() {
}

/**
* Tests the retrieval of the history for a previously saved and updated
* observation.
* Tests the retrieval of the history for a previously saved and updated observation.
*/
@Test(groups = { "server-basic" }, dependsOnMethods = { "testCreateObservation", "testUpdateObservation" })
public void testHistoryObservation() {
WebTarget target = getWebTarget();

// Call the 'history' API to retrieve both the original and updated versions of
// the observation.
// Call the 'history' API to retrieve both the original and updated versions of the observation.
String targetPath = "Observation/" + savedCreatedObservation.getId() + "/_history";
Response response = target.path(targetPath).request(FHIRMediaType.APPLICATION_FHIR_JSON).get();
assertResponse(response, Response.Status.OK.getStatusCode());

Bundle resources = response.readEntity(Bundle.class);
assertNotNull(resources);
assertEquals(2, resources.getEntry().size());
assertEquals(resources.getEntry().size(), 2);

for (Entry entry : resources.getEntry()) {
String fullUrl = entry.getFullUrl().getValue();
assertEquals(fullUrl, getRestBaseURL() + "/Observation/" + savedCreatedObservation.getId());
}

Observation updatedObservation = (Observation) resources.getEntry().get(0).getResource();
Observation originalObservation = (Observation) resources.getEntry().get(1).getResource();
// Make sure observation ids are equal, and versionIds are NOT equal.
Expand Down Expand Up @@ -728,6 +737,6 @@ public void testSearchObservation() {
assertResponse(response, Response.Status.OK.getStatusCode());
Bundle bundle = response.readEntity(Bundle.class);
assertNotNull(bundle);
assertEquals(1, bundle.getEntry().size());
assertEquals(bundle.getEntry().size(), 1);
}
}
Loading