Merge branch 'master' into ja_20200206_multitenancy

This commit is contained in:
jamesagnew 2020-04-20 11:07:10 -04:00
commit 95b77af570
12 changed files with 297 additions and 92 deletions

View File

@ -0,0 +1,35 @@
package ca.uhn.fhir.rest.api;
/*-
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
/**
* Used by the client to indicate the cascade mode associated with a delete operation.
* <p>
* Note that this is a HAPI FHIR specific feature, and may not work on other platforms.
* </p>
*/
public enum DeleteCascadeModeEnum {
NONE,
DELETE
}

View File

@ -137,7 +137,7 @@ public class DateClientParam extends BaseClientParam implements IParam {
myPrefix = thePrefix;
this.previous = previous;
}
public DateWithPrefix(ParamPrefixEnum thePrefix) {
myPrefix = thePrefix;
}
@ -176,13 +176,27 @@ public class DateClientParam extends BaseClientParam implements IParam {
dt.setPrecision(TemporalPrecisionEnum.SECOND);
return constructCriterion(dt);
}
@Override
public IDateCriterion millis(Date theValue) {
DateTimeDt dt = new DateTimeDt(theValue);
dt.setPrecision(TemporalPrecisionEnum.MILLI);
return constructCriterion(dt);
}
@Override
public IDateCriterion millis(String theValue) {
DateTimeDt dt = new DateTimeDt(theValue);
dt.setPrecision(TemporalPrecisionEnum.MILLI);
return constructCriterion(dt);
}
private IDateCriterion constructCriterion(DateTimeDt dt) {
String valueAsString = dt.getValueAsString();
Criterion criterion = new Criterion(myPrefix, valueAsString);
if (previous != null) {
criterion.orCriterion = previous;
}
}
return criterion;
}
}
@ -199,8 +213,12 @@ public class DateClientParam extends BaseClientParam implements IParam {
IDateCriterion second(String theValue);
IDateCriterion millis(Date theValue);
IDateCriterion millis(String theValue);
}
public interface IDateCriterion extends ICriterion<DateClientParam> {
IDateSpecifier orAfter();

View File

@ -20,10 +20,14 @@ package ca.uhn.fhir.rest.gclient;
* #L%
*/
import ca.uhn.fhir.rest.api.DeleteCascadeModeEnum;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
public interface IDeleteTyped extends IClientExecutable<IDeleteTyped, IBaseOperationOutcome> {
// nothing for now
/**
* Delete cascade mode - Note that this is a HAPI FHIR specific feature and is not supported on all servers.
*/
IDeleteTyped cascade(DeleteCascadeModeEnum theDelete);
}

View File

@ -610,20 +610,34 @@ public class GenericClient extends BaseClient implements IGenericClient {
private IIdType myId;
private String myResourceType;
private String mySearchUrl;
private DeleteCascadeModeEnum myCascadeMode;
@Override
public IBaseOperationOutcome execute() {
Map<String, List<String>> additionalParams = new HashMap<>();
if (myCascadeMode != null) {
switch (myCascadeMode) {
case DELETE:
addParam(getParamMap(), Constants.PARAMETER_CASCADE_DELETE, Constants.CASCADE_DELETE);
break;
default:
case NONE:
break;
}
}
HttpDeleteClientInvocation invocation;
if (myId != null) {
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), myId);
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), myId, getParamMap());
} else if (myConditional) {
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), myResourceType, getParamMap());
} else {
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), mySearchUrl);
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), mySearchUrl, getParamMap());
}
OperationOutcomeResponseHandler binding = new OperationOutcomeResponseHandler();
Map<String, List<String>> params = new HashMap<String, List<String>>();
return invoke(params, binding, invocation);
return invoke(additionalParams, binding, invocation);
}
@Override
@ -687,6 +701,11 @@ public class GenericClient extends BaseClient implements IGenericClient {
return this;
}
@Override
public IDeleteTyped cascade(DeleteCascadeModeEnum theDelete) {
myCascadeMode = theDelete;
return this;
}
}
@SuppressWarnings({"rawtypes", "unchecked"})

View File

@ -65,18 +65,18 @@ public class DeleteMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
@Override
public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
IIdType idDt = (IIdType) theArgs[getIdParameterIndex()];
if (idDt == null) {
IIdType id = (IIdType) theArgs[getIdParameterIndex()];
if (id == null) {
throw new NullPointerException("ID can not be null");
}
if (idDt.hasResourceType() == false) {
idDt = idDt.withResourceType(getResourceName());
} else if (getResourceName().equals(idDt.getResourceType()) == false) {
throw new InvalidRequestException("ID parameter has the wrong resource type, expected '" + getResourceName() + "', found: " + idDt.getResourceType());
if (id.hasResourceType() == false) {
id = id.withResourceType(getResourceName());
} else if (getResourceName().equals(id.getResourceType()) == false) {
throw new InvalidRequestException("ID parameter has the wrong resource type, expected '" + getResourceName() + "', found: " + id.getResourceType());
}
HttpDeleteClientInvocation retVal = createDeleteInvocation(getContext(), idDt);
HttpDeleteClientInvocation retVal = createDeleteInvocation(getContext(), id, Collections.emptyMap());
for (int idx = 0; idx < theArgs.length; idx++) {
IParameter nextParam = getParameters().get(idx);
@ -86,9 +86,8 @@ public class DeleteMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
return retVal;
}
public static HttpDeleteClientInvocation createDeleteInvocation(FhirContext theContext, IIdType theId) {
HttpDeleteClientInvocation retVal = new HttpDeleteClientInvocation(theContext, theId);
return retVal;
public static HttpDeleteClientInvocation createDeleteInvocation(FhirContext theContext, IIdType theId, Map<String, List<String>> theAdditionalParams) {
return new HttpDeleteClientInvocation(theContext, theId, theAdditionalParams);
}
@ -97,13 +96,8 @@ public class DeleteMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
return null;
}
public static HttpDeleteClientInvocation createDeleteInvocation(FhirContext theContext, String theSearchUrl) {
HttpDeleteClientInvocation retVal = new HttpDeleteClientInvocation(theContext, theSearchUrl);
return retVal;
}
public static HttpDeleteClientInvocation createDeleteInvocation(FhirContext theContext, String theResourceType, Map<String, List<String>> theParams) {
return new HttpDeleteClientInvocation(theContext, theResourceType, theParams);
public static HttpDeleteClientInvocation createDeleteInvocation(FhirContext theContext, String theSearchUrl, Map<String, List<String>> theParams) {
return new HttpDeleteClientInvocation(theContext, theSearchUrl, theParams);
}
}

View File

@ -36,19 +36,15 @@ public class HttpDeleteClientInvocation extends BaseHttpClientInvocation {
private String myUrlPath;
private Map<String, List<String>> myParams;
public HttpDeleteClientInvocation(FhirContext theContext, IIdType theId) {
public HttpDeleteClientInvocation(FhirContext theContext, IIdType theId, Map<String, List<String>> theAdditionalParams) {
super(theContext);
myUrlPath = theId.toUnqualifiedVersionless().getValue();
myParams = theAdditionalParams;
}
public HttpDeleteClientInvocation(FhirContext theContext, String theSearchUrl) {
public HttpDeleteClientInvocation(FhirContext theContext, String theSearchUrl, Map<String, List<String>> theParams) {
super(theContext);
myUrlPath = theSearchUrl;
}
public HttpDeleteClientInvocation(FhirContext theContext, String theResourceType, Map<String, List<String>> theParams) {
super(theContext);
myUrlPath = theResourceType;
myParams = theParams;
}
@ -67,10 +63,4 @@ public class HttpDeleteClientInvocation extends BaseHttpClientInvocation {
return createHttpRequest(b.toString(), theEncoding, RequestTypeEnum.DELETE);
}
@Override
protected IHttpRequest createHttpRequest(String theUrl, EncodingEnum theEncoding, RequestTypeEnum theRequestType) {
// TODO Auto-generated method stub
return super.createHttpRequest(theUrl, theEncoding, theRequestType);
}
}

View File

@ -23,6 +23,7 @@ package ca.uhn.hapi.fhir.docs;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.PerformanceOptionsEnum;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.api.DeleteCascadeModeEnum;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.SearchStyleEnum;
import ca.uhn.fhir.rest.api.SummaryEnum;
@ -262,6 +263,19 @@ public class GenericClientExample {
.execute();
// END SNIPPET: deleteConditional
}
{
// START SNIPPET: deleteCascade
client.delete()
.resourceById(new IdType("Patient/123"))
.cascade(DeleteCascadeModeEnum.DELETE)
.execute();
client.delete()
.resourceConditionalByType("Patient")
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
.execute();
// END SNIPPET: deleteCascade
}
{
// START SNIPPET: search
Bundle response = client.search()

View File

@ -0,0 +1,5 @@
---
type: add
issue: 1798
title: New mthods have been added to DateClientParam allowing searching at MILLIS precision. Thanks to
David Gileadi for the pull request!

View File

@ -0,0 +1,4 @@
---
type: add
issue: 1804
title: Support for HAPI FHIR cascading deletes has been added to the Generic Client.

View File

@ -181,6 +181,14 @@ Conditional deletions are also possible, which is a form where instead of deleti
{{snippet:classpath:/ca/uhn/hapi/fhir/docs/GenericClientExample.java|deleteConditional}}
```
## Cascading Delete
The following snippet shows now to request a cascading delete. Note that this is a HAPI FHIR specific feature and is not supported on all servers.
```java
{{snippet:classpath:/ca/uhn/hapi/fhir/docs/GenericClientExample.java|deleteCascade}}
```
# Update - Instance
Updating a resource is similar to creating one, except that an ID must be supplied since you are updating a previously existing resource instance.

View File

@ -7,8 +7,13 @@ import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.parser.CustomTypeR4Test;
import ca.uhn.fhir.parser.CustomTypeR4Test.MyCustomPatient;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.api.DeleteCascadeModeEnum;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.*;
import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.PreferReturnEnum;
import ca.uhn.fhir.rest.api.SortOrderEnum;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException;
@ -31,6 +36,8 @@ import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicStatusLine;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.hl7.fhir.r4.model.*;
import org.hl7.fhir.r4.model.Bundle.BundleType;
@ -43,13 +50,24 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -115,7 +133,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -125,7 +143,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
pt.getText().setDivAsString("A PATIENT");
Binary bin = new Binary();
bin.setContent(ourCtx.newJsonParser().encodeResourceToString(pt).getBytes("UTF-8"));
bin.setContent(ourCtx.newJsonParser().encodeResourceToString(pt).getBytes(StandardCharsets.UTF_8));
bin.setContentType(Constants.CT_FHIR_JSON);
client.create().resource(bin).execute();
@ -139,7 +157,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
Binary output = ourCtx.newJsonParser().parseResource(Binary.class, extractBodyAsString(capt));
assertEquals(Constants.CT_FHIR_JSON, output.getContentType());
Patient outputPt = (Patient) ourCtx.newJsonParser().parseResource(new String(output.getContent(), "UTF-8"));
Patient outputPt = (Patient) ourCtx.newJsonParser().parseResource(new String(output.getContent(), StandardCharsets.UTF_8));
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">A PATIENT</div>", outputPt.getText().getDivAsString());
}
@ -158,7 +176,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -222,7 +240,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -262,9 +280,9 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
if (myAnswerCount++ == 0) {
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), StandardCharsets.UTF_8);
} else {
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
}
}
});
@ -311,7 +329,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
myAnswerCount++;
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
}
});
@ -332,6 +350,78 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(0).getURI().toASCIIString());
}
@Test
public void testDeleteCascade() throws Exception {
final IParser p = ourCtx.newXmlParser();
OperationOutcome oo = new OperationOutcome();
oo.getText().setDivAsString("FINAL VALUE");
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getAllHeaders()).thenAnswer(new Answer<Header[]>() {
@Override
public Header[] answer(InvocationOnMock theInvocation) {
return new Header[]{new BasicHeader(Constants.HEADER_LOCATION, "http://foo.com/base/Patient/222/_history/3")};
}
});
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
myAnswerCount++;
return new ReaderInputStream(new StringReader(p.encodeResourceToString(oo)), StandardCharsets.UTF_8);
}
});
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
IBaseOperationOutcome outcome;
// Regular delete
outcome = client
.delete()
.resourceById(new IdType("Patient/222"))
.execute();
assertNotNull(outcome);
assertEquals(1, capt.getAllValues().size());
assertEquals("http://example.com/fhir/Patient/222", capt.getAllValues().get(myAnswerCount - 1).getURI().toASCIIString());
assertEquals("DELETE", capt.getAllValues().get(myAnswerCount - 1).getMethod());
// NONE Cascading delete
outcome = client
.delete()
.resourceById(new IdType("Patient/222"))
.cascade(DeleteCascadeModeEnum.NONE)
.execute();
assertNotNull(outcome);
assertEquals(2, capt.getAllValues().size());
assertEquals("http://example.com/fhir/Patient/222", capt.getAllValues().get(myAnswerCount - 1).getURI().toASCIIString());
assertEquals("DELETE", capt.getAllValues().get(myAnswerCount - 1).getMethod());
// DELETE Cascading delete
outcome = client
.delete()
.resourceById(new IdType("Patient/222"))
.cascade(DeleteCascadeModeEnum.DELETE)
.execute();
assertNotNull(outcome);
assertEquals(myAnswerCount, capt.getAllValues().size());
assertEquals("http://example.com/fhir/Patient/222?" + Constants.PARAMETER_CASCADE_DELETE + "=" + Constants.CASCADE_DELETE, capt.getAllValues().get(myAnswerCount - 1).getURI().toASCIIString());
assertEquals("DELETE", capt.getAllValues().get(myAnswerCount - 1).getMethod());
// DELETE Cascading delete on search URL
outcome = client
.delete()
.resourceConditionalByUrl("Patient?identifier=sys|val")
.cascade(DeleteCascadeModeEnum.DELETE)
.execute();
assertNotNull(outcome);
assertEquals(myAnswerCount, capt.getAllValues().size());
assertEquals("http://example.com/fhir/Patient?identifier=sys%7Cval&" + Constants.PARAMETER_CASCADE_DELETE + "=" + Constants.CASCADE_DELETE, capt.getAllValues().get(myAnswerCount - 1).getURI().toASCIIString());
assertEquals("DELETE", capt.getAllValues().get(myAnswerCount - 1).getMethod());
}
@Test
public void testExplicitCustomTypeHistoryType() throws Exception {
final String respString = CustomTypeR4Test.createBundle(CustomTypeR4Test.createResource(false));
@ -342,7 +432,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -369,7 +459,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -414,7 +504,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -454,7 +544,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -499,7 +589,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
respString = p.encodeResourceToString(conf);
}
myCount++;
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -547,7 +637,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
respString = p.encodeResourceToString(conf);
}
myAnswerCount++;
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -587,7 +677,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenAnswer(t -> {
IParser p = ourCtx.newXmlParser();
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
});
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
@ -748,7 +838,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -792,7 +882,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -836,7 +926,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -879,7 +969,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", "text/html"));
when(myHttpResponse.getEntity().getContent()).thenAnswer(t -> new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8")));
when(myHttpResponse.getEntity().getContent()).thenAnswer(t -> new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8));
when(myHttpResponse.getAllHeaders()).thenReturn(new Header[]{
new BasicHeader("content-type", "text/html")
});
@ -914,7 +1004,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
Parameters inputParams = new Parameters();
inputParams.addParameter().setName("name").setValue(new BooleanType(true));
final byte[] respBytes = new byte[]{0,1,2,3,4,5,6,7,8,9,100};
final byte[] respBytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 100};
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
@ -959,7 +1049,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1013,7 +1103,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1052,7 +1142,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1091,7 +1181,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1129,7 +1219,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1167,7 +1257,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1205,7 +1295,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1252,7 +1342,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(encoded), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(encoded), StandardCharsets.UTF_8);
}
});
@ -1297,7 +1387,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(encoded), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(encoded), StandardCharsets.UTF_8);
}
});
@ -1326,7 +1416,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8));
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
@ -1355,7 +1445,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1386,7 +1476,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1433,6 +1523,8 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
DateTimeDt now = DateTimeDt.withCurrentTime();
String dateString = now.getValueAsString().substring(0, 10);
DateTimeDt nowWithMillis = new DateTimeDt(new Date(), TemporalPrecisionEnum.MILLI, TimeZone.getDefault());
client.search()
.forResource("Patient")
.where(Patient.BIRTHDATE.after().day(dateString))
@ -1505,6 +1597,24 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
assertEquals("http://example.com/fhir/Patient?birthdate=gt" + now.getValueAsString(), UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
client.search()
.forResource("Patient")
.where(Patient.BIRTHDATE.after().millis("2011-01-02T22:33:01.123Z"))
.returnBundle(Bundle.class)
.execute();
assertEquals("http://example.com/fhir/Patient?birthdate=gt2011-01-02T22:33:01.123Z", UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
client.search()
.forResource("Patient")
.where(Patient.BIRTHDATE.after().millis(nowWithMillis.getValue()))
.returnBundle(Bundle.class)
.execute();
assertEquals("http://example.com/fhir/Patient?birthdate=gt" + nowWithMillis.getValueAsString(), UrlUtil.unescape(capt.getAllValues().get(idx).getURI().toString()));
idx++;
client.search()
.forResource("Patient")
.where(Patient.BIRTHDATE.after().now())
@ -1735,12 +1845,12 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8));
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
HashMap<String, List<IQueryParameterType>> params = new HashMap<String, List<IQueryParameterType>>();
params.put("foo", Arrays.asList((IQueryParameterType) new DateParam("2001")));
params.put("foo", Arrays.asList(new DateParam("2001")));
Bundle response = client
.search()
.forResource(Patient.class)
@ -1783,7 +1893,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8));
// httpResponse = new BasicHttpResponse(statusline, catalog, locale)
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
@ -1834,7 +1944,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenAnswer(t -> {
IParser p = ourCtx.newXmlParser();
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
});
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
@ -1872,7 +1982,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1925,7 +2035,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenAnswer(t -> {
IParser p = ourCtx.newXmlParser();
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
});
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
@ -2004,7 +2114,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -2051,9 +2161,9 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
if (myAnswerCount++ == 0) {
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), StandardCharsets.UTF_8);
} else {
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
}
}
});
@ -2099,7 +2209,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
myAnswerCount++;
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
}
});
@ -2136,7 +2246,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -2173,7 +2283,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -2194,7 +2304,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -2229,7 +2339,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), StandardCharsets.UTF_8);
}
});
@ -2262,7 +2372,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -2300,7 +2410,7 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});

View File

@ -599,6 +599,10 @@
<id>augla</id>
<name>August Langhout</name>
</developer>
<developer>
<id>dgileadi</id>
<name>David Gileadi</name>
</developer>
</developers>
<licenses>