Work on operation support in client
This commit is contained in:
parent
533339c92c
commit
b68d07b546
|
@ -3,6 +3,8 @@ package example;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.omg.Dynamic.Parameter;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
|
@ -12,11 +14,17 @@ import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum;
|
|||
import ca.uhn.fhir.model.dstu2.resource.Observation;
|
||||
import ca.uhn.fhir.model.dstu2.resource.OperationOutcome;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Organization;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Parameters;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu2.resource.ValueSet;
|
||||
import ca.uhn.fhir.model.primitive.CodeDt;
|
||||
import ca.uhn.fhir.model.primitive.DateDt;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.client.IGenericClient;
|
||||
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
|
||||
import ca.uhn.fhir.rest.method.SearchStyleEnum;
|
||||
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
|
||||
|
||||
|
@ -359,7 +367,28 @@ public class GenericClientExample {
|
|||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
fluentSearch();
|
||||
operation();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void operation() {
|
||||
// START SNIPPET: operation
|
||||
// Create a client to talk to the HeathIntersections server
|
||||
FhirContext ctx = FhirContext.forDstu2();
|
||||
IGenericClient client = ctx.newRestfulGenericClient("http://fhir-dev.healthintersections.com.au/open");
|
||||
client.registerInterceptor(new LoggingInterceptor(true));
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setName("start").setValue(new DateDt("2001-01-01"));
|
||||
inParams.addParameter().setName("end").setValue(new DateDt("2015-03-01"));
|
||||
|
||||
Parameters outParams = client
|
||||
.operation()
|
||||
.ofInstance(new IdDt("Patient", "1"))
|
||||
.named("$everything")
|
||||
.withParameters(inParams)
|
||||
.execute();
|
||||
// END SNIPPET: operation
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<configuration scan="true" scanPeriod="30 seconds">
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>INFO</level>
|
||||
</filter>
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} [%file:%line] %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
|
@ -51,11 +51,13 @@ import javax.json.stream.JsonParsingException;
|
|||
|
||||
import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
||||
import ca.uhn.fhir.model.primitive.*;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.hl7.fhir.instance.model.IBase;
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.IPrimitiveType;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBooleanDatatype;
|
||||
import org.hl7.fhir.instance.model.api.IBaseDatatype;
|
||||
|
@ -92,7 +94,6 @@ import ca.uhn.fhir.model.api.annotation.Child;
|
|||
import ca.uhn.fhir.model.base.composite.BaseContainedDt;
|
||||
import ca.uhn.fhir.model.base.composite.BaseNarrativeDt;
|
||||
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
|
||||
import ca.uhn.fhir.model.base.resource.BaseBinary;
|
||||
import ca.uhn.fhir.model.primitive.DecimalDt;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.IntegerDt;
|
||||
|
@ -693,8 +694,8 @@ public class JsonParser extends BaseParser implements IParser {
|
|||
}
|
||||
}
|
||||
|
||||
if (theResource instanceof BaseBinary) {
|
||||
BaseBinary bin = (BaseBinary) theResource;
|
||||
if (theResource instanceof IBaseBinary) {
|
||||
IBaseBinary bin = (IBaseBinary) theResource;
|
||||
theEventWriter.write("contentType", bin.getContentType());
|
||||
theEventWriter.write("content", bin.getContentAsBase64());
|
||||
} else {
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.hl7.fhir.instance.model.IBase;
|
|||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.ICompositeType;
|
||||
import org.hl7.fhir.instance.model.IPrimitiveType;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
import org.hl7.fhir.instance.model.api.IBaseDatatype;
|
||||
import org.hl7.fhir.instance.model.api.IBaseElement;
|
||||
|
@ -74,7 +75,6 @@ import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
|||
import ca.uhn.fhir.model.api.Tag;
|
||||
import ca.uhn.fhir.model.api.TagList;
|
||||
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
|
||||
import ca.uhn.fhir.model.base.resource.BaseBinary;
|
||||
import ca.uhn.fhir.model.base.resource.ResourceMetadataMap;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
|
@ -886,10 +886,10 @@ class ParserState<T> {
|
|||
private static final int SUBSTATE_CONTENT = 2;
|
||||
private static final int SUBSTATE_CT = 1;
|
||||
private String myData;
|
||||
private BaseBinary myInstance;
|
||||
private IBaseBinary myInstance;
|
||||
private int mySubState = 0;
|
||||
|
||||
public BinaryResourceStateForDstu1(PreResourceState thePreResourceState, BaseBinary theInstance) {
|
||||
public BinaryResourceStateForDstu1(PreResourceState thePreResourceState, IBaseBinary theInstance) {
|
||||
super(thePreResourceState);
|
||||
myInstance = theInstance;
|
||||
}
|
||||
|
@ -900,7 +900,7 @@ class ParserState<T> {
|
|||
if (myInstance instanceof IIdentifiableElement) {
|
||||
((IIdentifiableElement) myInstance).setElementSpecificId((theValue));
|
||||
} else {
|
||||
(myInstance).setId(new IdDt(theValue));
|
||||
((IResource)myInstance).setId(new IdDt(theValue));
|
||||
}
|
||||
} else if ("contentType".equals(theName)) {
|
||||
myInstance.setContentType(theValue);
|
||||
|
@ -1923,7 +1923,7 @@ class ParserState<T> {
|
|||
|
||||
String resourceName = def.getName();
|
||||
if ("Binary".equals(resourceName) && myContext.getVersion().getVersion() == FhirVersionEnum.DSTU1) {
|
||||
push(new BinaryResourceStateForDstu1(getRootPreResourceState(), (BaseBinary) myInstance));
|
||||
push(new BinaryResourceStateForDstu1(getRootPreResourceState(), (IBaseBinary) myInstance));
|
||||
} else if (myInstance instanceof IResource) {
|
||||
push(new ResourceStateHapi(getRootPreResourceState(), def, (IResource) myInstance));
|
||||
} else {
|
||||
|
|
|
@ -49,6 +49,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.hl7.fhir.instance.model.IBase;
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.IPrimitiveType;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
import org.hl7.fhir.instance.model.api.IBaseDatatype;
|
||||
import org.hl7.fhir.instance.model.api.IBaseExtension;
|
||||
|
@ -79,7 +80,6 @@ import ca.uhn.fhir.model.base.composite.BaseCodingDt;
|
|||
import ca.uhn.fhir.model.base.composite.BaseContainedDt;
|
||||
import ca.uhn.fhir.model.base.composite.BaseNarrativeDt;
|
||||
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
|
||||
import ca.uhn.fhir.model.base.resource.BaseBinary;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
|
@ -766,8 +766,8 @@ public class XmlParser extends BaseParser implements IParser {
|
|||
theEventWriter.writeEndElement();
|
||||
}
|
||||
|
||||
if (theResource instanceof BaseBinary) {
|
||||
BaseBinary bin = (BaseBinary) theResource;
|
||||
if (theResource instanceof IBaseBinary) {
|
||||
IBaseBinary bin = (IBaseBinary) theResource;
|
||||
writeOptionalTagWithValue(theEventWriter, "contentType", bin.getContentType());
|
||||
writeOptionalTagWithValue(theEventWriter, "content", bin.getContentAsBase64());
|
||||
} else {
|
||||
|
@ -781,8 +781,8 @@ public class XmlParser extends BaseParser implements IParser {
|
|||
theEventWriter.writeAttribute("id", theResourceId);
|
||||
}
|
||||
|
||||
if (theResource instanceof BaseBinary) {
|
||||
BaseBinary bin = (BaseBinary) theResource;
|
||||
if (theResource instanceof IBaseBinary) {
|
||||
IBaseBinary bin = (IBaseBinary) theResource;
|
||||
if (bin.getContentType() != null) {
|
||||
theEventWriter.writeAttribute("contentType", bin.getContentType());
|
||||
}
|
||||
|
|
|
@ -20,8 +20,7 @@ package ca.uhn.fhir.rest.client;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
@ -39,6 +38,7 @@ import org.apache.http.client.HttpClient;
|
|||
import org.apache.http.client.methods.HttpRequestBase;
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBundle;
|
||||
import org.hl7.fhir.instance.model.api.IBaseParameters;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
|
@ -76,6 +76,9 @@ import ca.uhn.fhir.rest.gclient.IHistory;
|
|||
import ca.uhn.fhir.rest.gclient.IHistoryTyped;
|
||||
import ca.uhn.fhir.rest.gclient.IHistoryUntyped;
|
||||
import ca.uhn.fhir.rest.gclient.IOperation;
|
||||
import ca.uhn.fhir.rest.gclient.IOperationUnnamed;
|
||||
import ca.uhn.fhir.rest.gclient.IOperationUntyped;
|
||||
import ca.uhn.fhir.rest.gclient.IOperationUntypedWithInput;
|
||||
import ca.uhn.fhir.rest.gclient.IParam;
|
||||
import ca.uhn.fhir.rest.gclient.IQuery;
|
||||
import ca.uhn.fhir.rest.gclient.IRead;
|
||||
|
@ -95,9 +98,11 @@ import ca.uhn.fhir.rest.method.DeleteMethodBinding;
|
|||
import ca.uhn.fhir.rest.method.HistoryMethodBinding;
|
||||
import ca.uhn.fhir.rest.method.HttpDeleteClientInvocation;
|
||||
import ca.uhn.fhir.rest.method.HttpGetClientInvocation;
|
||||
import ca.uhn.fhir.rest.method.HttpPostClientInvocation;
|
||||
import ca.uhn.fhir.rest.method.HttpSimpleGetClientInvocation;
|
||||
import ca.uhn.fhir.rest.method.IClientResponseHandler;
|
||||
import ca.uhn.fhir.rest.method.MethodUtil;
|
||||
import ca.uhn.fhir.rest.method.OperationMethodBinding;
|
||||
import ca.uhn.fhir.rest.method.ReadMethodBinding;
|
||||
import ca.uhn.fhir.rest.method.SearchMethodBinding;
|
||||
import ca.uhn.fhir.rest.method.SearchStyleEnum;
|
||||
|
@ -117,6 +122,72 @@ import ca.uhn.fhir.util.ICallable;
|
|||
*/
|
||||
public class GenericClient extends BaseClient implements IGenericClient {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class OperationInternal extends BaseClientExecutable implements IOperation, IOperationUnnamed, IOperationUntyped, IOperationUntypedWithInput {
|
||||
|
||||
private IdDt myId;
|
||||
private Class<? extends IBaseResource> myType;
|
||||
private IBaseParameters myParameters;
|
||||
private String myOperationName;
|
||||
|
||||
@Override
|
||||
public IOperationUnnamed ofServer() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IOperationUnnamed ofType(Class<? extends IBaseResource> theResourceType) {
|
||||
myType = theResourceType;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IOperationUnnamed ofInstance(IdDt theId) {
|
||||
myId = theId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@Override
|
||||
public IOperationUntypedWithInput withParameters(IBaseParameters theParameters) {
|
||||
Validate.notNull(theParameters, "theParameters can not be null");
|
||||
myParameters = theParameters;
|
||||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Object execute() {
|
||||
String resourceName;
|
||||
String id;
|
||||
if (myType != null) {
|
||||
resourceName = myContext.getResourceDefinition(myType).getName();
|
||||
id = null;
|
||||
} else if (myId != null) {
|
||||
resourceName = myId.getResourceType();
|
||||
id = myId.getIdPart();
|
||||
} else {
|
||||
resourceName = null;
|
||||
id = null;
|
||||
}
|
||||
|
||||
HttpPostClientInvocation invocation = OperationMethodBinding.createOperationInvocation(myContext, resourceName, id, myOperationName, myParameters);
|
||||
|
||||
IClientResponseHandler handler;
|
||||
handler = new ResourceResponseHandler(myParameters.getClass(), null);
|
||||
|
||||
return invoke(null, handler, invocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IOperationUntyped named(String theName) {
|
||||
Validate.notBlank(theName, "theName can not be null");
|
||||
myOperationName =theName;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final String I18N_CANNOT_DETEMINE_RESOURCE_TYPE = "ca.uhn.fhir.rest.client.GenericClient.cannotDetermineResourceTypeFromUri";
|
||||
|
||||
private static final String I18N_INCOMPLETE_URI_FOR_READ = "ca.uhn.fhir.rest.client.GenericClient.incompleteUriForRead";
|
||||
|
@ -340,8 +411,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
|
||||
@Override
|
||||
public IOperation operation() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return new OperationInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,9 +34,7 @@ import ca.uhn.fhir.model.primitive.IdDt;
|
|||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.client.api.IRestfulClient;
|
||||
import ca.uhn.fhir.rest.gclient.IClientExecutable;
|
||||
import ca.uhn.fhir.rest.gclient.ICreate;
|
||||
import ca.uhn.fhir.rest.gclient.ICreateTyped;
|
||||
import ca.uhn.fhir.rest.gclient.IDelete;
|
||||
import ca.uhn.fhir.rest.gclient.IGetPage;
|
||||
import ca.uhn.fhir.rest.gclient.IGetTags;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ca.uhn.fhir.rest.gclient;
|
||||
|
||||
public interface IOperation {
|
||||
public interface IOperation extends IBaseOn<IOperationUnnamed> {
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package ca.uhn.fhir.rest.gclient;
|
||||
|
||||
|
||||
public interface IOperationUnnamed {
|
||||
|
||||
IOperationUntyped named(String theName);
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package ca.uhn.fhir.rest.gclient;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseParameters;
|
||||
|
||||
public interface IOperationUntyped {
|
||||
|
||||
<T extends IBaseParameters> IOperationUntypedWithInput<T> withParameters(T theParameters);
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package ca.uhn.fhir.rest.gclient;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseParameters;
|
||||
|
||||
public interface IOperationUntypedWithInput<T extends IBaseParameters> extends IClientExecutable<IOperationUntypedWithInput<T>, T> {
|
||||
|
||||
}
|
|
@ -20,10 +20,6 @@ package ca.uhn.fhir.rest.method;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -36,16 +32,14 @@ import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|||
import org.apache.http.client.methods.HttpRequestBase;
|
||||
import org.apache.http.entity.AbstractHttpEntity;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.TagList;
|
||||
import ca.uhn.fhir.model.base.resource.BaseBinary;
|
||||
import ca.uhn.fhir.model.valueset.BundleTypeEnum;
|
||||
import ca.uhn.fhir.parser.DataFormatException;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
|
@ -69,7 +63,7 @@ abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvoca
|
|||
private Map<String, List<String>> myIfNoneExistParams;
|
||||
private String myIfNoneExistString;
|
||||
private Map<String, List<String>> myParams;
|
||||
private final IResource myResource;
|
||||
private final IBaseResource myResource;
|
||||
private final List<IResource> myResources;
|
||||
private final TagList myTagList;
|
||||
private final String myUrlPath;
|
||||
|
@ -85,7 +79,7 @@ abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvoca
|
|||
myBundleType = null;
|
||||
}
|
||||
|
||||
public BaseHttpClientInvocationWithContents(FhirContext theContext, IResource theResource, Map<String, List<String>> theParams, String... theUrlPath) {
|
||||
public BaseHttpClientInvocationWithContents(FhirContext theContext, IBaseResource theResource, Map<String, List<String>> theParams, String... theUrlPath) {
|
||||
myContext = theContext;
|
||||
myResource = theResource;
|
||||
myTagList = null;
|
||||
|
@ -98,7 +92,7 @@ abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvoca
|
|||
myBundleType = null;
|
||||
}
|
||||
|
||||
public BaseHttpClientInvocationWithContents(FhirContext theContext, IResource theResource, String theUrlPath) {
|
||||
public BaseHttpClientInvocationWithContents(FhirContext theContext, IBaseResource theResource, String theUrlPath) {
|
||||
super();
|
||||
myContext = theContext;
|
||||
myResource = theResource;
|
||||
|
@ -209,8 +203,8 @@ abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvoca
|
|||
|
||||
appendExtraParamsWithQuestionMark(theExtraParams, url, url.indexOf("?") == -1);
|
||||
|
||||
if (myResource != null && BaseBinary.class.isAssignableFrom(myResource.getClass())) {
|
||||
BaseBinary binary = (BaseBinary) myResource;
|
||||
if (myResource != null && IBaseBinary.class.isAssignableFrom(myResource.getClass())) {
|
||||
IBaseBinary binary = (IBaseBinary) myResource;
|
||||
|
||||
/*
|
||||
* Note: Be careful about changing which constructor we use for ByteArrayEntity,
|
||||
|
|
|
@ -26,11 +26,11 @@ import java.lang.reflect.Modifier;
|
|||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
|
||||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.base.resource.BaseBinary;
|
||||
import ca.uhn.fhir.rest.annotation.ResourceParam;
|
||||
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
|
||||
import ca.uhn.fhir.rest.param.ResourceParameter;
|
||||
|
@ -64,7 +64,7 @@ abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOu
|
|||
providerResourceType = ((IResourceProvider) theProvider).getResourceType();
|
||||
}
|
||||
|
||||
if (BaseBinary.class.isAssignableFrom(providerResourceType)) {
|
||||
if (IBaseBinary.class.isAssignableFrom(providerResourceType)) {
|
||||
myBinary = true;
|
||||
}
|
||||
|
||||
|
@ -99,11 +99,11 @@ abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOu
|
|||
String ct = theRequest.getServletRequest().getHeader(Constants.HEADER_CONTENT_TYPE);
|
||||
byte[] contents = IOUtils.toByteArray(theRequest.getServletRequest().getInputStream());
|
||||
|
||||
BaseBinary binary = (BaseBinary) getContext().getResourceDefinition("Binary").newInstance();
|
||||
IBaseBinary binary = (IBaseBinary) getContext().getResourceDefinition("Binary").newInstance();
|
||||
binary.setContentType(ct);
|
||||
binary.setContent(contents);
|
||||
|
||||
return binary;
|
||||
return (IResource) binary;
|
||||
} else {
|
||||
return super.parseIncomingServerResource(theRequest);
|
||||
}
|
||||
|
|
|
@ -96,6 +96,11 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding {
|
|||
return myResourceOperationType;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BundleTypeEnum getResponseBundleType() {
|
||||
return BundleTypeEnum.HISTORY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnTypeEnum getReturnType() {
|
||||
return ReturnTypeEnum.BUNDLE;
|
||||
|
@ -106,110 +111,6 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding {
|
|||
return mySystemOperationType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
|
||||
IdDt id = null;
|
||||
String resourceName = myResourceName;
|
||||
if (myIdParamIndex != null) {
|
||||
id = (IdDt) theArgs[myIdParamIndex];
|
||||
if (id == null || isBlank(id.getValue())) {
|
||||
throw new NullPointerException("ID can not be null");
|
||||
}
|
||||
}
|
||||
|
||||
String historyId = id != null ? id.getIdPart() : null;
|
||||
HttpGetClientInvocation retVal = createHistoryInvocation(resourceName, historyId, null, null);
|
||||
|
||||
if (theArgs != null) {
|
||||
for (int idx = 0; idx < theArgs.length; idx++) {
|
||||
IParameter nextParam = getParameters().get(idx);
|
||||
nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], retVal.getParameters());
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BundleTypeEnum getResponseBundleType() {
|
||||
return BundleTypeEnum.HISTORY;
|
||||
}
|
||||
|
||||
public static HttpGetClientInvocation createHistoryInvocation(String theResourceName, String theId, BaseDateTimeDt theSince, Integer theLimit) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
if (theResourceName != null) {
|
||||
b.append(theResourceName);
|
||||
if (isNotBlank(theId)) {
|
||||
b.append('/');
|
||||
b.append(theId);
|
||||
}
|
||||
}
|
||||
if (b.length() > 0) {
|
||||
b.append('/');
|
||||
}
|
||||
b.append(Constants.PARAM_HISTORY);
|
||||
|
||||
boolean haveParam = false;
|
||||
if (theSince != null && !theSince.isEmpty()) {
|
||||
haveParam = true;
|
||||
b.append('?').append(Constants.PARAM_SINCE).append('=').append(theSince.getValueAsString());
|
||||
}
|
||||
if (theLimit != null) {
|
||||
b.append(haveParam ? '&' : '?');
|
||||
b.append(Constants.PARAM_COUNT).append('=').append(theLimit);
|
||||
}
|
||||
|
||||
HttpGetClientInvocation retVal = new HttpGetClientInvocation(b.toString());
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBundleProvider invokeServer(RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException {
|
||||
if (myIdParamIndex != null) {
|
||||
theMethodParams[myIdParamIndex] = theRequest.getId();
|
||||
}
|
||||
|
||||
Object response = invokeServerMethod(theMethodParams);
|
||||
|
||||
final IBundleProvider resources = toResourceList(response);
|
||||
|
||||
/*
|
||||
* We wrap the response so we can verify that it has the ID and version set,
|
||||
* as is the contract for history
|
||||
*/
|
||||
return new IBundleProvider() {
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return resources.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IResource> getResources(int theFromIndex, int theToIndex) {
|
||||
List<IResource> retVal = resources.getResources(theFromIndex, theToIndex);
|
||||
int index = theFromIndex;
|
||||
for (IResource nextResource : retVal) {
|
||||
if (nextResource.getId() == null || isBlank(nextResource.getId().getIdPart())) {
|
||||
throw new InternalErrorException("Server provided resource at index " + index + " with no ID set (using IResource#setId(IdDt))");
|
||||
}
|
||||
if (isBlank(nextResource.getId().getVersionIdPart())) {
|
||||
IdDt versionId = (IdDt) ResourceMetadataKeyEnum.VERSION_ID.get(nextResource);
|
||||
if (versionId == null || versionId.isEmpty()) {
|
||||
throw new InternalErrorException("Server provided resource at index " + index + " with no Version ID set (using IResource#setId(IdDt))");
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstantDt getPublished() {
|
||||
return resources.getPublished();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// ObjectUtils.equals is replaced by a JDK7 method..
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
|
@ -239,6 +140,105 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
|
||||
IdDt id = null;
|
||||
String resourceName = myResourceName;
|
||||
if (myIdParamIndex != null) {
|
||||
id = (IdDt) theArgs[myIdParamIndex];
|
||||
if (id == null || isBlank(id.getValue())) {
|
||||
throw new NullPointerException("ID can not be null");
|
||||
}
|
||||
}
|
||||
|
||||
String historyId = id != null ? id.getIdPart() : null;
|
||||
HttpGetClientInvocation retVal = createHistoryInvocation(resourceName, historyId, null, null);
|
||||
|
||||
if (theArgs != null) {
|
||||
for (int idx = 0; idx < theArgs.length; idx++) {
|
||||
IParameter nextParam = getParameters().get(idx);
|
||||
nextParam.translateClientArgumentIntoQueryArgument(getContext(), theArgs[idx], retVal.getParameters());
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBundleProvider invokeServer(RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException {
|
||||
if (myIdParamIndex != null) {
|
||||
theMethodParams[myIdParamIndex] = theRequest.getId();
|
||||
}
|
||||
|
||||
Object response = invokeServerMethod(theMethodParams);
|
||||
|
||||
final IBundleProvider resources = toResourceList(response);
|
||||
|
||||
/*
|
||||
* We wrap the response so we can verify that it has the ID and version set,
|
||||
* as is the contract for history
|
||||
*/
|
||||
return new IBundleProvider() {
|
||||
|
||||
@Override
|
||||
public InstantDt getPublished() {
|
||||
return resources.getPublished();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IResource> getResources(int theFromIndex, int theToIndex) {
|
||||
List<IResource> retVal = resources.getResources(theFromIndex, theToIndex);
|
||||
int index = theFromIndex;
|
||||
for (IResource nextResource : retVal) {
|
||||
if (nextResource.getId() == null || isBlank(nextResource.getId().getIdPart())) {
|
||||
throw new InternalErrorException("Server provided resource at index " + index + " with no ID set (using IResource#setId(IdDt))");
|
||||
}
|
||||
if (isBlank(nextResource.getId().getVersionIdPart())) {
|
||||
IdDt versionId = (IdDt) ResourceMetadataKeyEnum.VERSION_ID.get(nextResource);
|
||||
if (versionId == null || versionId.isEmpty()) {
|
||||
throw new InternalErrorException("Server provided resource at index " + index + " with no Version ID set (using IResource#setId(IdDt))");
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return resources.size();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static HttpGetClientInvocation createHistoryInvocation(String theResourceName, String theId, BaseDateTimeDt theSince, Integer theLimit) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
if (theResourceName != null) {
|
||||
b.append(theResourceName);
|
||||
if (isNotBlank(theId)) {
|
||||
b.append('/');
|
||||
b.append(theId);
|
||||
}
|
||||
}
|
||||
if (b.length() > 0) {
|
||||
b.append('/');
|
||||
}
|
||||
b.append(Constants.PARAM_HISTORY);
|
||||
|
||||
boolean haveParam = false;
|
||||
if (theSince != null && !theSince.isEmpty()) {
|
||||
haveParam = true;
|
||||
b.append('?').append(Constants.PARAM_SINCE).append('=').append(theSince.getValueAsString());
|
||||
}
|
||||
if (theLimit != null) {
|
||||
b.append(haveParam ? '&' : '?');
|
||||
b.append(Constants.PARAM_COUNT).append('=').append(theLimit);
|
||||
}
|
||||
|
||||
HttpGetClientInvocation retVal = new HttpGetClientInvocation(b.toString());
|
||||
return retVal;
|
||||
}
|
||||
|
||||
private static Class<? extends IBaseResource> toReturnType(Method theMethod, Object theProvider) {
|
||||
if (theProvider instanceof IResourceProvider) {
|
||||
return ((IResourceProvider) theProvider).getResourceType();
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.Map;
|
|||
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.AbstractHttpEntity;
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
|
@ -35,7 +36,7 @@ import ca.uhn.fhir.model.valueset.BundleTypeEnum;
|
|||
public class HttpPostClientInvocation extends BaseHttpClientInvocationWithContents {
|
||||
|
||||
|
||||
public HttpPostClientInvocation(FhirContext theContext, IResource theResource, String theUrlExtension) {
|
||||
public HttpPostClientInvocation(FhirContext theContext, IBaseResource theResource, String theUrlExtension) {
|
||||
super(theContext, theResource, theUrlExtension);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package ca.uhn.fhir.rest.method;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.*;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseParameters;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
|
||||
public class OperationMethodBinding {
|
||||
|
||||
public static HttpPostClientInvocation createOperationInvocation(FhirContext theContext, String theResourceName, String theId, String theOperationName, IBaseParameters theInput) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
if (theResourceName != null) {
|
||||
b.append(theResourceName);
|
||||
if (isNotBlank(theId)) {
|
||||
b.append('/');
|
||||
b.append(theId);
|
||||
}
|
||||
}
|
||||
if (b.length() > 0) {
|
||||
b.append('/');
|
||||
}
|
||||
if (!theOperationName.startsWith("$")) {
|
||||
b.append("$");
|
||||
}
|
||||
b.append(theOperationName);
|
||||
|
||||
return new HttpPostClientInvocation(theContext, theInput, b.toString());
|
||||
}
|
||||
|
||||
}
|
|
@ -32,12 +32,12 @@ import org.apache.commons.io.IOUtils;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
|
||||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.base.resource.BaseBinary;
|
||||
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum;
|
||||
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
|
@ -174,19 +174,19 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding implem
|
|||
public Object invokeClient(String theResponseMimeType, InputStream theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException, BaseServerResponseException {
|
||||
byte[] contents = IOUtils.toByteArray(theResponseReader);
|
||||
|
||||
BaseBinary resource = (BaseBinary) getContext().getResourceDefinition("Binary").newInstance();
|
||||
IBaseBinary resource = (IBaseBinary) getContext().getResourceDefinition("Binary").newInstance();
|
||||
resource.setContentType(theResponseMimeType);
|
||||
resource.setContent(contents);
|
||||
|
||||
switch (getMethodReturnType()) {
|
||||
case BUNDLE:
|
||||
return Bundle.withSingleResource(resource);
|
||||
return Bundle.withSingleResource((IResource) resource);
|
||||
case LIST_OF_RESOURCES:
|
||||
return Collections.singletonList(resource);
|
||||
case RESOURCE:
|
||||
return resource;
|
||||
case BUNDLE_PROVIDER:
|
||||
return new SimpleBundleProvider(resource);
|
||||
return new SimpleBundleProvider((IResource) resource);
|
||||
}
|
||||
|
||||
throw new IllegalStateException("" + getMethodReturnType()); // should not happen
|
||||
|
|
|
@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.client.utils.DateUtils;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
|
@ -26,7 +27,6 @@ import ca.uhn.fhir.model.api.IResource;
|
|||
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
||||
import ca.uhn.fhir.model.api.Tag;
|
||||
import ca.uhn.fhir.model.api.TagList;
|
||||
import ca.uhn.fhir.model.base.resource.BaseBinary;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
|
@ -73,8 +73,8 @@ public class RestfulServerUtils {
|
|||
}
|
||||
}
|
||||
|
||||
if (theResource instanceof BaseBinary && theResponseEncoding == null) {
|
||||
BaseBinary bin = (BaseBinary) theResource;
|
||||
if (theResource instanceof IBaseBinary && theResponseEncoding == null) {
|
||||
IBaseBinary bin = (IBaseBinary) theResource;
|
||||
if (isNotBlank(bin.getContentType())) {
|
||||
theHttpResponse.setContentType(bin.getContentType());
|
||||
} else {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package ca.uhn.fhir.model.base.resource;
|
||||
package org.hl7.fhir.instance.model.api;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
|
@ -20,9 +20,9 @@ package ca.uhn.fhir.model.base.resource;
|
|||
* #L%
|
||||
*/
|
||||
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
|
||||
public interface BaseBinary extends IResource {
|
||||
public interface IBaseBinary extends IBaseResource {
|
||||
|
||||
byte[] getContent();
|
||||
|
||||
|
@ -30,9 +30,9 @@ public interface BaseBinary extends IResource {
|
|||
|
||||
String getContentType();
|
||||
|
||||
BaseBinary setContent(byte[] theContent);
|
||||
IBaseBinary setContent(byte[] theContent);
|
||||
|
||||
BaseBinary setContentAsBase64(String theContent);
|
||||
IBaseBinary setContentAsBase64(String theContent);
|
||||
|
||||
BaseBinary setContentType(String theContentType);
|
||||
IBaseBinary setContentType(String theContentType);
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package org.hl7.fhir.instance.model.api;
|
||||
|
||||
import org.hl7.fhir.instance.model.IBaseResource;
|
||||
|
||||
public interface IBaseParameters extends IBaseResource {
|
||||
|
||||
}
|
|
@ -27,7 +27,7 @@
|
|||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
|
||||
<attributes>
|
||||
<attribute name="owner.project.facets" value="java"/>
|
||||
</attributes>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<installed facet="jst.utility" version="1.0"/>
|
||||
<installed facet="java" version="1.7"/>
|
||||
<installed facet="java" version="1.6"/>
|
||||
</faceted-project>
|
||||
|
|
|
@ -23,17 +23,18 @@ package ca.uhn.fhir.model.dev.resource;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
import ca.uhn.fhir.model.api.IElement;
|
||||
import ca.uhn.fhir.model.api.annotation.Child;
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.model.base.resource.BaseBinary;
|
||||
import ca.uhn.fhir.model.primitive.Base64BinaryDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.util.ElementUtil;
|
||||
|
||||
@ResourceDef(name = "Binary", profile = "http://hl7.org/fhir/profiles/Binary", id = "binary")
|
||||
public class Binary extends BaseResource implements BaseBinary {
|
||||
public class Binary extends BaseResource implements IBaseBinary {
|
||||
|
||||
@Child(name = "content", order = 1)
|
||||
private Base64BinaryDt myContent = new Base64BinaryDt();
|
||||
|
|
|
@ -23,18 +23,18 @@ package ca.uhn.fhir.model.dstu.resource;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
import ca.uhn.fhir.model.api.IElement;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.annotation.Child;
|
||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||
import ca.uhn.fhir.model.base.resource.BaseBinary;
|
||||
import ca.uhn.fhir.model.primitive.Base64BinaryDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.util.ElementUtil;
|
||||
|
||||
@ResourceDef(name = "Binary", profile = "http://hl7.org/fhir/profiles/Binary", id = "binary")
|
||||
public class Binary extends BaseResource implements BaseBinary {
|
||||
public class Binary extends BaseResource implements IBaseBinary {
|
||||
|
||||
@Child(name = "content", order = 1)
|
||||
private Base64BinaryDt myContent = new Base64BinaryDt();
|
||||
|
|
|
@ -4,12 +4,12 @@ import static org.junit.Assert.*;
|
|||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
import org.junit.Test;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.base.resource.BaseBinary;
|
||||
import ca.uhn.fhir.model.dstu2.resource.Binary;
|
||||
|
||||
public class ModelInstantiationTest {
|
||||
|
@ -18,7 +18,7 @@ public class ModelInstantiationTest {
|
|||
|
||||
@Test
|
||||
public void testBinaryIsBaseBinary() {
|
||||
assertTrue(BaseBinary.class.isAssignableFrom(Binary.class));
|
||||
assertTrue(IBaseBinary.class.isAssignableFrom(Binary.class));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -38,6 +38,7 @@ import ca.uhn.fhir.model.dstu2.resource.Parameters;
|
|||
import ca.uhn.fhir.model.dstu2.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.rest.server.EncodingEnum;
|
||||
|
||||
|
@ -93,7 +94,8 @@ public class GenericClientTestDstu2 {
|
|||
@Override
|
||||
public InputStream answer(InvocationOnMock theInvocation) throws Throwable {
|
||||
return new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"));
|
||||
}});
|
||||
}
|
||||
});
|
||||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
|
@ -134,7 +136,6 @@ public class GenericClientTestDstu2 {
|
|||
idx++;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSearchByString() throws Exception {
|
||||
String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
|
||||
|
@ -160,29 +161,42 @@ public class GenericClientTestDstu2 {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testOperationWithListOfParameters() throws Exception {
|
||||
public void testOperationWithListOfParameterResponse() throws Exception {
|
||||
IParser p = ourCtx.newXmlParser();
|
||||
|
||||
Parameters inParams = new Parameters();
|
||||
inParams.addParameter().setValue(new StringDt("STRINGVALIN1"));
|
||||
inParams.addParameter().setValue(new StringDt("STRINGVALIN2"));
|
||||
String reqString = ourCtx.newXmlParser().encodeResourceToString(inParams);
|
||||
String reqString = p.encodeResourceToString(inParams);
|
||||
|
||||
Parameters outParams = new Parameters();
|
||||
outParams.addParameter().setValue(new StringDt("STRINGVALOUT1"));
|
||||
outParams.addParameter().setValue(new StringDt("STRINGVALOUT2"));
|
||||
final String respString = ourCtx.newXmlParser().encodeResourceToString(outParams);
|
||||
final String respString = p.encodeResourceToString(outParams);
|
||||
|
||||
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.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
||||
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) throws Throwable {
|
||||
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8")); }});
|
||||
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
|
||||
}
|
||||
});
|
||||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
// client.operation().onServer().withParameters(inParams);
|
||||
int idx = 0;
|
||||
|
||||
Parameters resp = client.operation().ofServer().named("$SOMEOPERATION").withParameters(inParams).execute();
|
||||
assertEquals(respString, p.encodeResourceToString(resp));
|
||||
assertEquals(1, capt.getAllValues().get(idx).getHeaders(Constants.HEADER_CONTENT_TYPE).length);
|
||||
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(idx).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
|
||||
assertEquals(extractBody(capt, idx), reqString);
|
||||
assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
|
||||
idx++;
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -39,11 +39,12 @@ import org.hl7.fhir.instance.model.annotations.SearchParamDefinition;
|
|||
import org.hl7.fhir.instance.model.annotations.Block;
|
||||
import org.hl7.fhir.instance.model.annotations.Child;
|
||||
import org.hl7.fhir.instance.model.annotations.Description;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
/**
|
||||
* A binary resource can contain any content, whether text, image, pdf, zip archive, etc.
|
||||
*/
|
||||
@ResourceDef(name="Binary", profile="http://hl7.org/fhir/Profile/Binary")
|
||||
public class Binary extends Resource {
|
||||
public class Binary extends Resource implements IBaseBinary {
|
||||
|
||||
/**
|
||||
* MimeType of the binary content represented as a standard MimeType (BCP 13).
|
||||
|
@ -212,5 +213,20 @@ public class Binary extends Resource {
|
|||
@SearchParamDefinition(name="contenttype", path="Binary.contentType", description="MimeType of the binary content", type="token" )
|
||||
public static final String SP_CONTENTTYPE = "contenttype";
|
||||
|
||||
@Override
|
||||
public String getContentAsBase64() {
|
||||
return getContentElement().getValueAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Binary setContentAsBase64(String theContent) {
|
||||
if (theContent != null) {
|
||||
getContentElement().setValueAsString(theContent);
|
||||
} else {
|
||||
setContent(null);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package ca.uhn.fhir.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.hl7.fhir.instance.model.Address;
|
||||
import org.hl7.fhir.instance.model.BackboneElement;
|
||||
import org.hl7.fhir.instance.model.Base;
|
||||
import org.hl7.fhir.instance.model.Binary;
|
||||
import org.hl7.fhir.instance.model.BooleanType;
|
||||
import org.hl7.fhir.instance.model.Bundle;
|
||||
import org.hl7.fhir.instance.model.Coding;
|
||||
|
@ -19,6 +18,7 @@ import org.hl7.fhir.instance.model.ICompositeType;
|
|||
import org.hl7.fhir.instance.model.IPrimitiveType;
|
||||
import org.hl7.fhir.instance.model.IdType;
|
||||
import org.hl7.fhir.instance.model.Identifier;
|
||||
import org.hl7.fhir.instance.model.Identifier.IdentifierUseEnumFactory;
|
||||
import org.hl7.fhir.instance.model.IntegerType;
|
||||
import org.hl7.fhir.instance.model.Meta;
|
||||
import org.hl7.fhir.instance.model.Narrative;
|
||||
|
@ -27,11 +27,11 @@ import org.hl7.fhir.instance.model.Reference;
|
|||
import org.hl7.fhir.instance.model.Resource;
|
||||
import org.hl7.fhir.instance.model.Timing;
|
||||
import org.hl7.fhir.instance.model.Type;
|
||||
import org.hl7.fhir.instance.model.Identifier.IdentifierUseEnumFactory;
|
||||
import org.hl7.fhir.instance.model.annotations.Block;
|
||||
import org.hl7.fhir.instance.model.annotations.Child;
|
||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
import org.hl7.fhir.instance.model.api.IBackboneElement;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBinary;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBooleanDatatype;
|
||||
import org.hl7.fhir.instance.model.api.IBaseBundle;
|
||||
import org.hl7.fhir.instance.model.api.IBaseDatatype;
|
||||
|
@ -49,8 +49,7 @@ import org.hl7.fhir.instance.model.api.IReference;
|
|||
import org.junit.Test;
|
||||
|
||||
public class ModelInheritanceTest {
|
||||
|
||||
/**
|
||||
/*
|
||||
* <pre>
|
||||
* Other changes:
|
||||
*
|
||||
|
@ -71,11 +70,6 @@ public class ModelInheritanceTest {
|
|||
* </pre>
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testType() {
|
||||
assertTrue(IBaseDatatype.class.isAssignableFrom(Type.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* This one should apply to all composite types
|
||||
*/
|
||||
|
@ -84,76 +78,6 @@ public class ModelInheritanceTest {
|
|||
assertTrue(ICompositeType.class.isAssignableFrom(Address.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBase() {
|
||||
assertTrue(IBase.class.isAssignableFrom(Base.class));
|
||||
}
|
||||
|
||||
public void testIdentifierUse() throws Exception {
|
||||
Child child = Identifier.class.getField("use").getAnnotation(Child.class);
|
||||
assertEquals(IdentifierUseEnumFactory.class, child.enumFactory());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Should be "implements IBaseExtension<Extension>"
|
||||
*/
|
||||
@Test
|
||||
public void testExtension() {
|
||||
assertTrue(IBaseExtension.class.isAssignableFrom(Extension.class));
|
||||
assertTrue(IBaseHasExtensions.class.isAssignableFrom(Extension.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNarrative() {
|
||||
assertTrue(INarrative.class.isAssignableFrom(Narrative.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBooleanType() {
|
||||
assertTrue(IBaseBooleanDatatype.class.isAssignableFrom(BooleanType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecimalType() {
|
||||
assertTrue(IBaseDecimalDatatype.class.isAssignableFrom(DecimalType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegerType() {
|
||||
assertTrue(IBaseIntegerDatatype.class.isAssignableFrom(IntegerType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveType() {
|
||||
assertTrue(IPrimitiveType.class.isAssignableFrom(PrimitiveType.class));
|
||||
assertTrue(IBaseHasExtensions.class.isAssignableFrom(PrimitiveType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResource() {
|
||||
assertTrue(IAnyResource.class.isAssignableFrom(Resource.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBundle() {
|
||||
assertTrue(IBaseBundle.class.isAssignableFrom(Bundle.class));
|
||||
}
|
||||
|
||||
public void testIdType() {
|
||||
assertTrue(IIdType.class.isAssignableFrom(IdType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReference() {
|
||||
assertTrue(IReference.class.isAssignableFrom(Reference.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMeta() {
|
||||
assertTrue(IMetaType.class.isAssignableFrom(Meta.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBackboneElement() {
|
||||
assertTrue(IBackboneElement.class.isAssignableFrom(BackboneElement.class));
|
||||
|
@ -162,8 +86,36 @@ public class ModelInheritanceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testElement() {
|
||||
assertTrue(IBaseHasExtensions.class.isAssignableFrom(Element.class));
|
||||
public void testBase() {
|
||||
assertTrue(IBase.class.isAssignableFrom(Base.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBinary() {
|
||||
assertTrue(IBaseBinary.class.isAssignableFrom(Binary.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBooleanType() {
|
||||
assertTrue(IBaseBooleanDatatype.class.isAssignableFrom(BooleanType.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBundle() {
|
||||
assertTrue(IBaseBundle.class.isAssignableFrom(Bundle.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCoding() {
|
||||
assertTrue(ICoding.class.isAssignableFrom(Coding.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecimalType() {
|
||||
assertTrue(IBaseDecimalDatatype.class.isAssignableFrom(DecimalType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -173,8 +125,57 @@ public class ModelInheritanceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCoding() {
|
||||
assertTrue(ICoding.class.isAssignableFrom(Coding.class));
|
||||
public void testElement() {
|
||||
assertTrue(IBaseHasExtensions.class.isAssignableFrom(Element.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Should be "implements IBaseExtension<Extension>"
|
||||
*/
|
||||
@Test
|
||||
public void testExtension() {
|
||||
assertTrue(IBaseExtension.class.isAssignableFrom(Extension.class));
|
||||
assertTrue(IBaseHasExtensions.class.isAssignableFrom(Extension.class));
|
||||
}
|
||||
|
||||
public void testIdentifierUse() throws Exception {
|
||||
Child child = Identifier.class.getField("use").getAnnotation(Child.class);
|
||||
assertEquals(IdentifierUseEnumFactory.class, child.enumFactory());
|
||||
}
|
||||
|
||||
public void testIdType() {
|
||||
assertTrue(IIdType.class.isAssignableFrom(IdType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegerType() {
|
||||
assertTrue(IBaseIntegerDatatype.class.isAssignableFrom(IntegerType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMeta() {
|
||||
assertTrue(IMetaType.class.isAssignableFrom(Meta.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNarrative() {
|
||||
assertTrue(INarrative.class.isAssignableFrom(Narrative.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrimitiveType() {
|
||||
assertTrue(IPrimitiveType.class.isAssignableFrom(PrimitiveType.class));
|
||||
assertTrue(IBaseHasExtensions.class.isAssignableFrom(PrimitiveType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReference() {
|
||||
assertTrue(IReference.class.isAssignableFrom(Reference.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResource() {
|
||||
assertTrue(IAnyResource.class.isAssignableFrom(Resource.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -183,4 +184,9 @@ public class ModelInheritanceTest {
|
|||
assertNotNull(Timing.TimingRepeatComponent.class.getAnnotation(Block.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testType() {
|
||||
assertTrue(IBaseDatatype.class.isAssignableFrom(Type.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,11 +41,8 @@ import ${import};
|
|||
@ResourceDef(name="${elementName}", profile="${profile}", id="${id}")
|
||||
public class ${className} extends ca.uhn.fhir.model.${version}.resource.BaseResource
|
||||
implements #{if}( ${className}=="OperationOutcome" || ${className}=="Conformance" || ${className}=="SecurityEvent" ) ca.uhn.fhir.model.base.resource.Base${className} #{else} IResource #{end}
|
||||
#if ( ${className} == "Bundle" )
|
||||
, org.hl7.fhir.instance.model.api.IBaseBundle
|
||||
#end
|
||||
#if ( ${className}=="Binary" )
|
||||
, ca.uhn.fhir.model.base.resource.Base${className}
|
||||
#if ( ${className} == "Bundle" || ${className} == "Parameters" || ${className} == "Binary" )
|
||||
, org.hl7.fhir.instance.model.api.IBase${className}
|
||||
#end
|
||||
{
|
||||
|
||||
|
|
Loading…
Reference in New Issue