Get transaction working in server

This commit is contained in:
jamesagnew 2014-05-23 18:29:32 -04:00
parent 03bf040ef9
commit de3fbc9023
50 changed files with 615 additions and 304 deletions

View File

@ -236,4 +236,21 @@ public class IdDt extends BasePrimitive<String> {
return myValue;
}
/**
* Returns <code>true</code> if the unqualified ID is a valid {@link Long} value (in other
* words, it consists only of digits)
*/
public boolean isValidLong() {
String id = getUnqualifiedId();
if (StringUtils.isBlank(id)) {
return false;
}
for (int i = 0; i < id.length(); i++) {
if (Character.isDigit(id.charAt(i)) == false) {
return false;
}
}
return true;
}
}

View File

@ -100,11 +100,11 @@ public abstract class BaseClient {
return myUrlBase;
}
<T> T invokeClient(IClientResponseHandler<T> binding, BaseClientInvocation clientInvocation) {
<T> T invokeClient(IClientResponseHandler<T> binding, BaseHttpClientInvocation clientInvocation) {
return invokeClient(binding, clientInvocation, false);
}
<T> T invokeClient(IClientResponseHandler<T> binding, BaseClientInvocation clientInvocation, boolean theLogRequestAndResponse) {
<T> T invokeClient(IClientResponseHandler<T> binding, BaseHttpClientInvocation clientInvocation, boolean theLogRequestAndResponse) {
// TODO: handle non 2xx status codes by throwing the correct exception,
// and ensure it's passed upwards
HttpRequestBase httpRequest;

View File

@ -33,7 +33,7 @@ import org.apache.http.message.BasicHeader;
import ca.uhn.fhir.rest.server.EncodingEnum;
public abstract class BaseClientInvocation {
public abstract class BaseHttpClientInvocation {
private List<Header> myHeaders;

View File

@ -72,7 +72,7 @@ public class ClientInvocationHandler extends BaseClient implements InvocationHan
BaseMethodBinding<?> binding = myBindings.get(theMethod);
if (binding != null) {
BaseClientInvocation clientInvocation = binding.invokeClient(theArgs);
BaseHttpClientInvocation clientInvocation = binding.invokeClient(theArgs);
return invokeClient(binding, clientInvocation);
}

View File

@ -54,6 +54,8 @@ import ca.uhn.fhir.rest.method.ConformanceMethodBinding;
import ca.uhn.fhir.rest.method.CreateMethodBinding;
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.IClientResponseHandler;
import ca.uhn.fhir.rest.method.ReadMethodBinding;
import ca.uhn.fhir.rest.method.SearchMethodBinding;
@ -79,7 +81,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
@Override
public Conformance conformance() {
GetClientInvocation invocation = ConformanceMethodBinding.createConformanceInvocation();
HttpGetClientInvocation invocation = ConformanceMethodBinding.createConformanceInvocation();
if (isKeepResponses()) {
myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
}
@ -91,7 +93,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
@Override
public MethodOutcome create(IResource theResource) {
BaseClientInvocation invocation = CreateMethodBinding.createCreateInvocation(theResource, myContext);
BaseHttpClientInvocation invocation = CreateMethodBinding.createCreateInvocation(theResource, myContext);
if (isKeepResponses()) {
myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
}
@ -108,7 +110,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
@Override
public MethodOutcome delete(final Class<? extends IResource> theType, IdDt theId) {
DeleteClientInvocation invocation = DeleteMethodBinding.createDeleteInvocation(toResourceName(theType), theId);
HttpDeleteClientInvocation invocation = DeleteMethodBinding.createDeleteInvocation(toResourceName(theType), theId);
if (isKeepResponses()) {
myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
}
@ -130,7 +132,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
@Override
public <T extends IResource> Bundle history(final Class<T> theType, IdDt theIdDt) {
GetClientInvocation invocation = HistoryMethodBinding.createHistoryInvocation(toResourceName(theType), theIdDt);
HttpGetClientInvocation invocation = HistoryMethodBinding.createHistoryInvocation(toResourceName(theType), theIdDt);
if (isKeepResponses()) {
myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
}
@ -148,7 +150,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
@Override
public <T extends IResource> T read(final Class<T> theType, IdDt theId) {
GetClientInvocation invocation = ReadMethodBinding.createReadInvocation(theId, toResourceName(theType));
HttpGetClientInvocation invocation = ReadMethodBinding.createReadInvocation(theId, toResourceName(theType));
if (isKeepResponses()) {
myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
}
@ -182,7 +184,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
params.put(nextEntry.getKey()+qualifier, valueList);
}
GetClientInvocation invocation = SearchMethodBinding.createSearchInvocation(toResourceName(theType), params);
HttpGetClientInvocation invocation = SearchMethodBinding.createSearchInvocation(toResourceName(theType), params);
if (isKeepResponses()) {
myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
}
@ -201,7 +203,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
@Override
public MethodOutcome update(IdDt theIdDt, IResource theResource) {
BaseClientInvocation invocation = UpdateMethodBinding.createUpdateInvocation(theResource, theIdDt, null, myContext);
BaseHttpClientInvocation invocation = UpdateMethodBinding.createUpdateInvocation(theResource, theIdDt, null, myContext);
if (isKeepResponses()) {
myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
}
@ -221,7 +223,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
@Override
public MethodOutcome validate(IResource theResource) {
BaseClientInvocation invocation = ValidateMethodBinding.createValidateInvocation(theResource, null, myContext);
BaseHttpClientInvocation invocation = ValidateMethodBinding.createValidateInvocation(theResource, null, myContext);
if (isKeepResponses()) {
myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
}
@ -236,7 +238,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
@Override
public <T extends IResource> T vread(final Class<T> theType, IdDt theId, IdDt theVersionId) {
GetClientInvocation invocation = ReadMethodBinding.createVReadInvocation(theId, theVersionId, toResourceName(theType));
HttpGetClientInvocation invocation = ReadMethodBinding.createVReadInvocation(theId, theVersionId, toResourceName(theType));
if (isKeepResponses()) {
myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
}
@ -383,7 +385,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
addParam(params, Constants.PARAM_COUNT, Integer.toString(myParamLimit));
}
GetClientInvocation invocation = new GetClientInvocation(params, myResourceName);
HttpGetClientInvocation invocation = new HttpGetClientInvocation(params, myResourceName);
if (isKeepResponses()) {
myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
}

View File

@ -39,8 +39,7 @@ import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.PostClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType;
import ca.uhn.fhir.rest.param.IParameter;
import ca.uhn.fhir.rest.param.ParameterUtil;
@ -119,8 +118,8 @@ public abstract class BaseAddOrDeleteTagsMethodBinding extends BaseMethodBinding
protected abstract boolean isDelete();
@Override
public BaseClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
PostClientInvocation retVal;
public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
HttpPostClientInvocation retVal;
IdDt id = (IdDt) theArgs[myIdParamIndex];
if (id == null || id.isEmpty()) {
@ -139,15 +138,15 @@ public abstract class BaseAddOrDeleteTagsMethodBinding extends BaseMethodBinding
if (isDelete()) {
if (versionId != null) {
retVal = new PostClientInvocation(getContext(), tagList, getResourceName(), id.getValue(), Constants.PARAM_HISTORY, versionId.getValue(), Constants.PARAM_TAGS, Constants.PARAM_DELETE);
retVal = new HttpPostClientInvocation(getContext(), tagList, getResourceName(), id.getValue(), Constants.PARAM_HISTORY, versionId.getValue(), Constants.PARAM_TAGS, Constants.PARAM_DELETE);
} else {
retVal = new PostClientInvocation(getContext(), tagList, getResourceName(), id.getValue(), Constants.PARAM_TAGS, Constants.PARAM_DELETE);
retVal = new HttpPostClientInvocation(getContext(), tagList, getResourceName(), id.getValue(), Constants.PARAM_TAGS, Constants.PARAM_DELETE);
}
} else {
if (versionId != null) {
retVal = new PostClientInvocation(getContext(), tagList, getResourceName(), id.getValue(), Constants.PARAM_HISTORY, versionId.getValue(), Constants.PARAM_TAGS);
retVal = new HttpPostClientInvocation(getContext(), tagList, getResourceName(), id.getValue(), Constants.PARAM_HISTORY, versionId.getValue(), Constants.PARAM_TAGS);
} else {
retVal = new PostClientInvocation(getContext(), tagList, getResourceName(), id.getValue(), Constants.PARAM_TAGS);
retVal = new HttpPostClientInvocation(getContext(), tagList, getResourceName(), id.getValue(), Constants.PARAM_TAGS);
}
}
for (int idx = 0; idx < theArgs.length; idx++) {

View File

@ -1,4 +1,4 @@
package ca.uhn.fhir.rest.client;
package ca.uhn.fhir.rest.method;
/*
* #%L
@ -29,29 +29,34 @@ import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
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.parser.DataFormatException;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.RestfulServer.NarrativeModeEnum;
public abstract class BaseClientInvocationWithContents extends BaseClientInvocation {
public abstract class BaseHttpClientInvocationWithContents extends BaseHttpClientInvocation {
private final FhirContext myContext;
private final IResource myResource;
private final String myUrlExtension;
private final TagList myTagList;
private final List<IResource> myResources;
public BaseClientInvocationWithContents(FhirContext theContext, IResource theResource, String theUrlExtension) {
public BaseHttpClientInvocationWithContents(FhirContext theContext, IResource theResource, String theUrlExtension) {
super();
myContext = theContext;
myResource = theResource;
myUrlExtension = theUrlExtension;
myTagList = null;
myResources=null;
}
public BaseClientInvocationWithContents(FhirContext theContext, TagList theTagList, String... theUrlExtension) {
public BaseHttpClientInvocationWithContents(FhirContext theContext, TagList theTagList, String... theUrlExtension) {
super();
if (theTagList == null) {
throw new NullPointerException("Tag list must not be null");
@ -60,10 +65,19 @@ public abstract class BaseClientInvocationWithContents extends BaseClientInvocat
myResource = null;
myContext = theContext;
myTagList = theTagList;
myResources=null;
myUrlExtension = StringUtils.join(theUrlExtension, '/');
}
public BaseHttpClientInvocationWithContents(FhirContext theContext, List<IResource> theResources) {
myContext=theContext;
myResource=null;
myTagList=null;
myUrlExtension=null;
myResources = theResources;
}
@Override
public HttpRequestBase asHttpRequest(String theUrlBase, Map<String, List<String>> theExtraParams, EncodingEnum theEncoding) throws DataFormatException {
StringBuilder b = new StringBuilder();
@ -88,6 +102,9 @@ public abstract class BaseClientInvocationWithContents extends BaseClientInvocat
String contents;
if (myTagList != null) {
contents = parser.encodeTagListToString(myTagList);
} else if (myResources != null) {
Bundle bundle = BaseResourceReturningMethodBinding.createBundleFromResourceList(myContext, "", myResources, theEncoding, theUrlBase, "", false, NarrativeModeEnum.NORMAL);
contents = parser.encodeBundleToString(bundle);
} else {
contents = parser.encodeResourceToString(myResource);
}

View File

@ -60,7 +60,7 @@ import ca.uhn.fhir.rest.annotation.Transaction;
import ca.uhn.fhir.rest.annotation.Update;
import ca.uhn.fhir.rest.annotation.Validate;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.client.exceptions.NonFhirResponseException;
import ca.uhn.fhir.rest.param.IParameter;
import ca.uhn.fhir.rest.param.ParameterUtil;
@ -118,7 +118,7 @@ public abstract class BaseMethodBinding<T> implements IClientResponseHandler<T>
public abstract RestfulOperationSystemEnum getSystemOperationType();
public abstract BaseClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException;
public abstract BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException;
public abstract void invokeServer(RestfulServer theServer, Request theRequest, HttpServletResponse theResponse) throws BaseServerResponseException, IOException;

View File

@ -47,7 +47,7 @@ import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.EncodingEnum;
@ -334,7 +334,7 @@ public abstract class BaseOutcomeReturningMethodBinding extends BaseMethodBindin
return false;
}
protected abstract BaseClientInvocation createClientInvocation(Object[] theArgs, IResource resource);
protected abstract BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource resource);
/**
* For servers, this method will match only incoming requests that match the

View File

@ -31,7 +31,7 @@ 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.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.param.IParameter;
import ca.uhn.fhir.rest.param.ResourceParameter;
import ca.uhn.fhir.rest.server.Constants;
@ -88,13 +88,13 @@ abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOu
}
@Override
public BaseClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
IResource resource = (IResource) theArgs[myResourceParameterIndex];
if (resource == null) {
throw new NullPointerException("Resource can not be null");
}
BaseClientInvocation retVal = createClientInvocation(theArgs, resource);
BaseHttpClientInvocation retVal = createClientInvocation(theArgs, resource);
TagList list = (TagList) resource.getResourceMetadata().get(ResourceMetadataKeyEnum.TAG_LIST);
if (list != null) {

View File

@ -209,7 +209,7 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding<Obje
if (uaHeader != null && uaHeader.contains("Mozilla")) {
requestIsBrowser = true;
}
Object requestObject = parseRequestObject(theRequest);
// Method params
@ -237,8 +237,8 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding<Obje
}
}
/**
* Subclasses may override
/**
* Subclasses may override
*/
protected Object parseRequestObject(@SuppressWarnings("unused") Request theRequest) {
return null;
@ -264,7 +264,7 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding<Obje
throw new InternalErrorException("Found an object of type '" + retValObj.getClass().getCanonicalName() + "' in resource metadata for key " + theKey.name() + " - Expected " + IdDt.class.getCanonicalName());
}
private InstantDt getInstantFromMetadataOrNullIfNone(Map<ResourceMetadataKeyEnum, Object> theResourceMetadata, ResourceMetadataKeyEnum theKey) {
private static InstantDt getInstantFromMetadataOrNullIfNone(Map<ResourceMetadataKeyEnum, Object> theResourceMetadata, ResourceMetadataKeyEnum theKey) {
Object retValObj = theResourceMetadata.get(theKey);
if (retValObj == null) {
return null;
@ -280,7 +280,7 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding<Obje
throw new InternalErrorException("Found an object of type '" + retValObj.getClass().getCanonicalName() + "' in resource metadata for key " + theKey.name() + " - Expected " + InstantDt.class.getCanonicalName());
}
private TagList getTagListFromMetadataOrNullIfNone(Map<ResourceMetadataKeyEnum, Object> theResourceMetadata, ResourceMetadataKeyEnum theKey) {
private static TagList getTagListFromMetadataOrNullIfNone(Map<ResourceMetadataKeyEnum, Object> theResourceMetadata, ResourceMetadataKeyEnum theKey) {
Object retValObj = theResourceMetadata.get(theKey);
if (retValObj == null) {
return null;
@ -326,8 +326,26 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding<Obje
theServer.addHeadersToResponse(theHttpResponse);
Bundle bundle = createBundleFromResourceList(getContext(), getClass().getCanonicalName(), theResult, theResponseEncoding, theServerBase, theCompleteUrl, thePrettyPrint, theNarrativeMode);
PrintWriter writer = theHttpResponse.getWriter();
try {
if (theNarrativeMode == NarrativeModeEnum.ONLY) {
for (IResource next : theResult) {
writer.append(next.getText().getDiv().getValueAsString());
writer.append("<hr/>");
}
} else {
getNewParser(theResponseEncoding, thePrettyPrint, theNarrativeMode).encodeBundleToWriter(bundle, writer);
}
} finally {
writer.close();
}
}
public static Bundle createBundleFromResourceList(FhirContext theContext, String theAuthor, List<IResource> theResult, EncodingEnum theResponseEncoding, String theServerBase, String theCompleteUrl, boolean thePrettyPrint, NarrativeModeEnum theNarrativeMode) {
Bundle bundle = new Bundle();
bundle.getAuthorName().setValue(getClass().getCanonicalName());
bundle.getAuthorName().setValue(theAuthor);
bundle.getBundleId().setValue(UUID.randomUUID().toString());
bundle.getPublished().setToCurrentTimeInLocalTimeZone();
bundle.getLinkBase().setValue(theServerBase);
@ -347,7 +365,7 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding<Obje
}
}
RuntimeResourceDefinition def = getContext().getResourceDefinition(next);
RuntimeResourceDefinition def = theContext.getResourceDefinition(next);
if (next.getId() != null && StringUtils.isNotBlank(next.getId().getValue())) {
entry.getId().setValue(next.getId().getValue());
@ -355,28 +373,22 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding<Obje
StringBuilder b = new StringBuilder();
b.append(theServerBase);
b.append('/');
if (b.charAt(b.length()-1) != '/') {
b.append('/');
}
b.append(def.getName());
b.append('/');
String resId = next.getId().getValue();
String resId = next.getId().getUnqualifiedId();
b.append(resId);
/*
* If this is a history operation, we add the version of the
* resource to the self link to indicate the version
*/
if (getResourceOperationType() == RestfulOperationTypeEnum.HISTORY_INSTANCE || getResourceOperationType() == RestfulOperationTypeEnum.HISTORY_TYPE || getSystemOperationType() == RestfulOperationSystemEnum.HISTORY_SYSTEM) {
IdDt versionId = getIdFromMetadataOrNullIfNone(next.getResourceMetadata(), ResourceMetadataKeyEnum.VERSION_ID);
if (versionId != null) {
b.append('/');
b.append(Constants.PARAM_HISTORY);
b.append('/');
b.append(versionId.getValue());
} else {
throw new InternalErrorException("Server did not provide a VERSION_ID in the resource metadata for resource with ID " + resId);
}
IdDt versionId = getIdFromMetadataOrNullIfNone(next.getResourceMetadata(), ResourceMetadataKeyEnum.VERSION_ID);
if (versionId != null) {
b.append('/');
b.append(Constants.PARAM_HISTORY);
b.append('/');
b.append(versionId.getValue());
}
InstantDt published = getInstantFromMetadataOrNullIfNone(next.getResourceMetadata(), ResourceMetadataKeyEnum.PUBLISHED);
if (published == null) {
entry.getPublished().setToCurrentTimeInLocalTimeZone();
@ -418,20 +430,7 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding<Obje
}
bundle.getTotalResults().setValue(theResult.size());
PrintWriter writer = theHttpResponse.getWriter();
try {
if (theNarrativeMode == NarrativeModeEnum.ONLY) {
for (IResource next : theResult) {
writer.append(next.getText().getDiv().getValueAsString());
writer.append("<hr/>");
}
} else {
getNewParser(theResponseEncoding, thePrettyPrint, theNarrativeMode).encodeBundleToWriter(bundle, writer);
}
} finally {
writer.close();
}
return bundle;
}
private void streamResponseAsResource(RestfulServer theServer, HttpServletResponse theHttpResponse, IResource theResource, EncodingEnum theResponseEncoding, boolean thePrettyPrint, boolean theRequestIsBrowser, NarrativeModeEnum theNarrativeMode) throws IOException {

View File

@ -30,7 +30,6 @@ import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.resource.Conformance;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum;
import ca.uhn.fhir.rest.client.GetClientInvocation;
import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType;
import ca.uhn.fhir.rest.param.IParameter;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
@ -53,8 +52,8 @@ public class ConformanceMethodBinding extends BaseResourceReturningMethodBinding
}
@Override
public GetClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
GetClientInvocation retVal = createConformanceInvocation();
public HttpGetClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
HttpGetClientInvocation retVal = createConformanceInvocation();
if (theArgs != null) {
for (int idx = 0; idx < theArgs.length; idx++) {
@ -66,8 +65,8 @@ public class ConformanceMethodBinding extends BaseResourceReturningMethodBinding
return retVal;
}
public static GetClientInvocation createConformanceInvocation() {
return new GetClientInvocation("metadata");
public static HttpGetClientInvocation createConformanceInvocation() {
return new HttpGetClientInvocation("metadata");
}
@Override

View File

@ -30,8 +30,7 @@ import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum;
import ca.uhn.fhir.rest.annotation.Create;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.PostClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType;
import ca.uhn.fhir.rest.param.IParameter;
@ -57,10 +56,10 @@ public class CreateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
}
@Override
protected BaseClientInvocation createClientInvocation(Object[] theArgs, IResource resource) {
protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource resource) {
FhirContext context = getContext();
BaseClientInvocation retVal = createCreateInvocation(resource, context);
BaseHttpClientInvocation retVal = createCreateInvocation(resource, context);
if (theArgs != null) {
for (int idx = 0; idx < theArgs.length; idx++) {
@ -72,14 +71,14 @@ public class CreateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
return retVal;
}
public static PostClientInvocation createCreateInvocation(IResource resource, FhirContext context) {
public static HttpPostClientInvocation createCreateInvocation(IResource resource, FhirContext context) {
RuntimeResourceDefinition def = context.getResourceDefinition(resource);
String resourceName = def.getName();
StringBuilder urlExtension = new StringBuilder();
urlExtension.append(resourceName);
return new PostClientInvocation(context, resource, urlExtension.toString());
return new HttpPostClientInvocation(context, resource, urlExtension.toString());
}
@Override

View File

@ -34,9 +34,7 @@ import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.Delete;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.VersionIdParam;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.DeleteClientInvocation;
import ca.uhn.fhir.rest.client.PostClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType;
import ca.uhn.fhir.rest.param.IParameter;
import ca.uhn.fhir.rest.param.ParameterUtil;
@ -106,11 +104,11 @@ public class DeleteMethodBinding extends BaseOutcomeReturningMethodBinding {
}
@Override
protected BaseClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) {
protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) {
StringBuilder urlExtension = new StringBuilder();
urlExtension.append(getContext().getResourceDefinition(theResource).getName());
return new PostClientInvocation(getContext(), theResource, urlExtension.toString());
return new HttpPostClientInvocation(getContext(), theResource, urlExtension.toString());
}
@Override
@ -119,14 +117,14 @@ public class DeleteMethodBinding extends BaseOutcomeReturningMethodBinding {
}
@Override
public BaseClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
IdDt idDt = (IdDt) theArgs[myIdParameterIndex];
if (idDt == null) {
throw new NullPointerException("ID can not be null");
}
String resourceName = getResourceName();
DeleteClientInvocation retVal = createDeleteInvocation(resourceName, idDt);
HttpDeleteClientInvocation retVal = createDeleteInvocation(resourceName, idDt);
for (int idx = 0; idx < theArgs.length; idx++) {
IParameter nextParam = getParameters().get(idx);
@ -136,9 +134,9 @@ public class DeleteMethodBinding extends BaseOutcomeReturningMethodBinding {
return retVal;
}
public static DeleteClientInvocation createDeleteInvocation(String theResourceName, IdDt idDt) {
public static HttpDeleteClientInvocation createDeleteInvocation(String theResourceName, IdDt idDt) {
String id = idDt.getValue();
DeleteClientInvocation retVal = new DeleteClientInvocation(theResourceName, id);
HttpDeleteClientInvocation retVal = new HttpDeleteClientInvocation(theResourceName, id);
return retVal;
}

View File

@ -39,8 +39,7 @@ import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.annotation.GetTags;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.GetClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType;
import ca.uhn.fhir.rest.param.IParameter;
import ca.uhn.fhir.rest.param.ParameterUtil;
@ -107,8 +106,8 @@ public class GetTagsMethodBinding extends BaseMethodBinding<TagList> {
}
@Override
public BaseClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
GetClientInvocation retVal;
public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
HttpGetClientInvocation retVal;
IdDt id = null;
IdDt versionId = null;
@ -122,15 +121,15 @@ public class GetTagsMethodBinding extends BaseMethodBinding<TagList> {
if (myType != IResource.class) {
if (id != null) {
if (versionId != null) {
retVal = new GetClientInvocation(getResourceName(), id.getValue(), Constants.PARAM_HISTORY, versionId.getValue(), Constants.PARAM_TAGS);
retVal = new HttpGetClientInvocation(getResourceName(), id.getValue(), Constants.PARAM_HISTORY, versionId.getValue(), Constants.PARAM_TAGS);
} else {
retVal = new GetClientInvocation(getResourceName(), id.getValue(), Constants.PARAM_TAGS);
retVal = new HttpGetClientInvocation(getResourceName(), id.getValue(), Constants.PARAM_TAGS);
}
} else {
retVal = new GetClientInvocation(getResourceName(), Constants.PARAM_TAGS);
retVal = new HttpGetClientInvocation(getResourceName(), Constants.PARAM_TAGS);
}
} else {
retVal = new GetClientInvocation(Constants.PARAM_TAGS);
retVal = new HttpGetClientInvocation(Constants.PARAM_TAGS);
}
if (theArgs != null) {

View File

@ -34,8 +34,7 @@ import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.History;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.GetClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.param.IParameter;
import ca.uhn.fhir.rest.param.ParameterUtil;
import ca.uhn.fhir.rest.server.Constants;
@ -103,7 +102,7 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding {
}
@Override
public BaseClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
IdDt id = null;
String resourceName = myResourceName;
if (myIdParamIndex != null) {
@ -113,7 +112,7 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding {
}
}
GetClientInvocation retVal = createHistoryInvocation(resourceName, id);
HttpGetClientInvocation retVal = createHistoryInvocation(resourceName, id);
if (theArgs != null) {
for (int idx = 0; idx < theArgs.length; idx++) {
@ -125,7 +124,7 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding {
return retVal;
}
public static GetClientInvocation createHistoryInvocation(String theResourceName, IdDt theId) {
public static HttpGetClientInvocation createHistoryInvocation(String theResourceName, IdDt theId) {
StringBuilder b = new StringBuilder();
if (theResourceName != null) {
b.append(theResourceName);
@ -138,7 +137,7 @@ public class HistoryMethodBinding extends BaseResourceReturningMethodBinding {
b.append('/');
}
b.append(Constants.PARAM_HISTORY);
GetClientInvocation retVal = new GetClientInvocation(b.toString());
HttpGetClientInvocation retVal = new HttpGetClientInvocation(b.toString());
return retVal;
}

View File

@ -1,4 +1,4 @@
package ca.uhn.fhir.rest.client;
package ca.uhn.fhir.rest.method;
/*
* #%L
@ -27,13 +27,14 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpRequestBase;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.server.EncodingEnum;
public class DeleteClientInvocation extends BaseClientInvocation {
public class HttpDeleteClientInvocation extends BaseHttpClientInvocation {
private String myUrlPath;
public DeleteClientInvocation(String... theUrlFragments) {
public HttpDeleteClientInvocation(String... theUrlFragments) {
super();
myUrlPath = StringUtils.join(theUrlFragments, '/');
}

View File

@ -1,4 +1,4 @@
package ca.uhn.fhir.rest.client;
package ca.uhn.fhir.rest.method;
/*
* #%L
@ -32,24 +32,25 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;
import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.server.EncodingEnum;
public class GetClientInvocation extends BaseClientInvocation {
public class HttpGetClientInvocation extends BaseHttpClientInvocation {
private final Map<String, List<String>> myParameters;
private final String myUrlPath;
public GetClientInvocation(Map<String, List<String>> theParameters, String... theUrlFragments) {
public HttpGetClientInvocation(Map<String, List<String>> theParameters, String... theUrlFragments) {
myParameters = theParameters;
myUrlPath = StringUtils.join(theUrlFragments, '/');
}
public GetClientInvocation(String theUrlPath) {
public HttpGetClientInvocation(String theUrlPath) {
myParameters = new HashMap<String, List<String>>();
myUrlPath = theUrlPath;
}
public GetClientInvocation(String... theUrlFragments) {
public HttpGetClientInvocation(String... theUrlFragments) {
myParameters = new HashMap<String, List<String>>();
myUrlPath = StringUtils.join(theUrlFragments, '/');
}

View File

@ -1,4 +1,4 @@
package ca.uhn.fhir.rest.client;
package ca.uhn.fhir.rest.method;
/*
* #%L
@ -20,6 +20,8 @@ package ca.uhn.fhir.rest.client;
* #L%
*/
import java.util.List;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
@ -27,18 +29,23 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.TagList;
public class PostClientInvocation extends BaseClientInvocationWithContents {
public class HttpPostClientInvocation extends BaseHttpClientInvocationWithContents {
public PostClientInvocation(FhirContext theContext, IResource theResource, String theUrlExtension) {
public HttpPostClientInvocation(FhirContext theContext, IResource theResource, String theUrlExtension) {
super(theContext, theResource, theUrlExtension);
}
public PostClientInvocation(FhirContext theContext, TagList theTagList, String... theUrlExtension) {
public HttpPostClientInvocation(FhirContext theContext, TagList theTagList, String... theUrlExtension) {
super(theContext, theTagList, theUrlExtension);
}
public HttpPostClientInvocation(FhirContext theContext, List<IResource> theResources) {
super(theContext, theResources);
}
@Override
protected HttpPost createRequest(String url, StringEntity theEntity) {
HttpPost retVal = new HttpPost(url);

View File

@ -1,4 +1,4 @@
package ca.uhn.fhir.rest.client;
package ca.uhn.fhir.rest.method;
/*
* #%L
@ -27,9 +27,9 @@ import org.apache.http.entity.StringEntity;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
public class PutClientInvocation extends BaseClientInvocationWithContents {
public class HttpPutClientInvocation extends BaseHttpClientInvocationWithContents {
public PutClientInvocation(FhirContext theContext, IResource theResource, String theUrlExtension) {
public HttpPutClientInvocation(FhirContext theContext, IResource theResource, String theUrlExtension) {
super(theContext, theResource, theUrlExtension);
}

View File

@ -32,7 +32,6 @@ import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.client.GetClientInvocation;
import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType;
import ca.uhn.fhir.rest.param.IParameter;
import ca.uhn.fhir.rest.param.ParameterUtil;
@ -119,8 +118,8 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding {
}
@Override
public GetClientInvocation invokeClient(Object[] theArgs) {
GetClientInvocation retVal;
public HttpGetClientInvocation invokeClient(Object[] theArgs) {
HttpGetClientInvocation retVal;
IdDt id = ((IdDt) theArgs[myIdIndex]);
if (myVersionIdIndex == null) {
String resourceName = getResourceName();
@ -139,12 +138,12 @@ public class ReadMethodBinding extends BaseResourceReturningMethodBinding {
return retVal;
}
public static GetClientInvocation createVReadInvocation(IdDt theId, IdDt vid, String resourceName) {
return new GetClientInvocation(resourceName, theId.getUnqualifiedId(), Constants.URL_TOKEN_HISTORY, vid.getUnqualifiedId());
public static HttpGetClientInvocation createVReadInvocation(IdDt theId, IdDt vid, String resourceName) {
return new HttpGetClientInvocation(resourceName, theId.getUnqualifiedId(), Constants.URL_TOKEN_HISTORY, vid.getUnqualifiedId());
}
public static GetClientInvocation createReadInvocation(IdDt theId, String resourceName) {
return new GetClientInvocation(resourceName, theId.getUnqualifiedId());
public static HttpGetClientInvocation createReadInvocation(IdDt theId, String resourceName) {
return new HttpGetClientInvocation(resourceName, theId.getUnqualifiedId());
}
@Override

View File

@ -34,7 +34,6 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum;
import ca.uhn.fhir.rest.client.GetClientInvocation;
import ca.uhn.fhir.rest.param.BaseQueryParameter;
import ca.uhn.fhir.rest.param.IParameter;
import ca.uhn.fhir.rest.server.Constants;
@ -76,7 +75,7 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding {
}
@Override
public GetClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
public HttpGetClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
assert (myQueryName == null || ((theArgs != null ? theArgs.length : 0) == getParameters().size())) : "Wrong number of arguments: " + (theArgs != null ? theArgs.length : "null");
Map<String, List<String>> queryStringArgs = new LinkedHashMap<String, List<String>>();
@ -86,7 +85,7 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding {
}
String resourceName = getResourceName();
GetClientInvocation retVal = createSearchInvocation(resourceName, queryStringArgs);
HttpGetClientInvocation retVal = createSearchInvocation(resourceName, queryStringArgs);
if (theArgs != null) {
for (int idx = 0; idx < theArgs.length; idx++) {
@ -98,8 +97,8 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding {
return retVal;
}
public static GetClientInvocation createSearchInvocation(String theResourceName, Map<String, List<String>> theParameters) {
return new GetClientInvocation(theParameters, theResourceName);
public static HttpGetClientInvocation createSearchInvocation(String theResourceName, Map<String, List<String>> theParameters) {
return new HttpGetClientInvocation(theParameters, theResourceName);
}
@Override

View File

@ -28,12 +28,13 @@ import java.util.List;
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.BundleEntry;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.annotation.TransactionParam;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType;
import ca.uhn.fhir.rest.param.TransactionParameter;
import ca.uhn.fhir.rest.param.IParameter;
@ -108,9 +109,11 @@ public class TransactionMethodBinding extends BaseResourceReturningMethodBinding
}
@Override
public BaseClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
// TODO Auto-generated method stub
return null;
public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
List<IResource> resources = (List<IResource>) theArgs[myResourceParameterIndex];
FhirContext context = getContext();
return new HttpPostClientInvocation(context, resources);
}
}

View File

@ -37,8 +37,7 @@ import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Update;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.PutClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType;
import ca.uhn.fhir.rest.param.IParameter;
import ca.uhn.fhir.rest.param.ParameterUtil;
@ -97,7 +96,7 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
}
@Override
protected BaseClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) {
protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) {
IdDt idDt = (IdDt) theArgs[myIdParameterIndex];
if (idDt == null) {
throw new NullPointerException("ID can not be null");
@ -109,7 +108,7 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
}
FhirContext context = getContext();
PutClientInvocation retVal = createUpdateInvocation(theResource, idDt, versionIdDt, context);
HttpPutClientInvocation retVal = createUpdateInvocation(theResource, idDt, versionIdDt, context);
for (int idx = 0; idx < theArgs.length; idx++) {
IParameter nextParam = getParameters().get(idx);
@ -119,14 +118,14 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
return retVal;
}
public static PutClientInvocation createUpdateInvocation(IResource theResource, IdDt idDt, IdDt versionIdDt, FhirContext context) {
public static HttpPutClientInvocation createUpdateInvocation(IResource theResource, IdDt idDt, IdDt versionIdDt, FhirContext context) {
String id = idDt.getValue();
String resourceName = context.getResourceDefinition(theResource).getName();
StringBuilder urlExtension = new StringBuilder();
urlExtension.append(resourceName);
urlExtension.append('/');
urlExtension.append(id);
PutClientInvocation retVal = new PutClientInvocation(context, theResource, urlExtension.toString());
HttpPutClientInvocation retVal = new HttpPutClientInvocation(context, theResource, urlExtension.toString());
if (versionIdDt != null) {
String versionId = versionIdDt.getValue();

View File

@ -30,8 +30,7 @@ import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.Validate;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.PostClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType;
import ca.uhn.fhir.rest.param.IParameter;
import ca.uhn.fhir.rest.param.ParameterUtil;
@ -65,7 +64,7 @@ public class ValidateMethodBinding extends BaseOutcomeReturningMethodBindingWith
}
@Override
protected BaseClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) {
protected BaseHttpClientInvocation createClientInvocation(Object[] theArgs, IResource theResource) {
FhirContext context = getContext();
IdDt idDt=null;
@ -73,7 +72,7 @@ public class ValidateMethodBinding extends BaseOutcomeReturningMethodBindingWith
idDt = (IdDt) theArgs[myIdParameterIndex];
}
PostClientInvocation retVal = createValidateInvocation(theResource, idDt, context);
HttpPostClientInvocation retVal = createValidateInvocation(theResource, idDt, context);
for (int idx = 0; idx < theArgs.length; idx++) {
IParameter nextParam = getParameters().get(idx);
@ -83,7 +82,7 @@ public class ValidateMethodBinding extends BaseOutcomeReturningMethodBindingWith
return retVal;
}
public static PostClientInvocation createValidateInvocation(IResource theResource, IdDt theId, FhirContext theContext) {
public static HttpPostClientInvocation createValidateInvocation(IResource theResource, IdDt theId, FhirContext theContext) {
StringBuilder urlExtension = new StringBuilder();
urlExtension.append(theContext.getResourceDefinition(theResource).getName());
urlExtension.append('/');
@ -95,7 +94,7 @@ public class ValidateMethodBinding extends BaseOutcomeReturningMethodBindingWith
urlExtension.append(id);
}
// TODO: is post correct here?
PostClientInvocation retVal = new PostClientInvocation(theContext, theResource, urlExtension.toString());
HttpPostClientInvocation retVal = new HttpPostClientInvocation(theContext, theResource, urlExtension.toString());
return retVal;
}

View File

@ -30,7 +30,7 @@ import org.apache.commons.lang3.StringUtils;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.dstu.valueset.SearchParamTypeEnum;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.QualifiedParamList;
import ca.uhn.fhir.rest.method.Request;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
@ -55,7 +55,7 @@ public abstract class BaseQueryParameter implements IParameter {
public abstract SearchParamTypeEnum getParamType();
@Override
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseClientInvocation theClientInvocation) throws InternalErrorException {
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseHttpClientInvocation theClientInvocation) throws InternalErrorException {
if (theSourceClientArgument == null) {
if (isRequired()) {
throw new NullPointerException("SearchParameter '" + getName() + "' is required and may not be null");

View File

@ -33,7 +33,7 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.primitive.IntegerDt;
import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.rest.annotation.Since;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.Request;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
@ -44,7 +44,7 @@ public class CountParameter implements IParameter {
private Class<?> myType;
@Override
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseClientInvocation theClientInvocation) throws InternalErrorException {
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseHttpClientInvocation theClientInvocation) throws InternalErrorException {
if (theSourceClientArgument != null) {
IntegerDt since = ParameterUtil.toInteger(theSourceClientArgument);
if (since.isEmpty() == false) {

View File

@ -27,7 +27,7 @@ import java.util.Map;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.Request;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
@ -35,7 +35,7 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
public interface IParameter {
void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseClientInvocation theClientInvocation) throws InternalErrorException;
void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseHttpClientInvocation theClientInvocation) throws InternalErrorException;
/**
* This <b>server method</b> method takes the data received by the server in an incoming request, and translates that data into a single argument for a server method invocation. Note that all

View File

@ -26,7 +26,7 @@ import java.util.List;
import java.util.Map;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.Request;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -34,7 +34,7 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
class NullParameter implements IParameter {
@Override
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseClientInvocation theClientInvocation) throws InternalErrorException {
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseHttpClientInvocation theClientInvocation) throws InternalErrorException {
//nothing
}

View File

@ -27,7 +27,7 @@ import java.util.Map;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.Request;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -41,7 +41,7 @@ public class ResourceParameter implements IParameter {
}
@Override
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseClientInvocation theClientInvocation) throws InternalErrorException {
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseHttpClientInvocation theClientInvocation) throws InternalErrorException {
// TODO Auto-generated method stub
}

View File

@ -26,7 +26,7 @@ import java.util.List;
import java.util.Map;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.Request;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -35,7 +35,7 @@ class ServerBaseParameter implements IParameter {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerBaseParameter.class);
@Override
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseClientInvocation theClientInvocation) throws InternalErrorException {
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseHttpClientInvocation theClientInvocation) throws InternalErrorException {
/*
* Does nothing, since we just ignore serverbase arguments
*/

View File

@ -26,7 +26,7 @@ import java.util.List;
import java.util.Map;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.Request;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -35,7 +35,7 @@ class ServletRequestParameter implements IParameter {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServletRequestParameter.class);
@Override
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseClientInvocation theClientInvocation) throws InternalErrorException {
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseHttpClientInvocation theClientInvocation) throws InternalErrorException {
/*
* Does nothing, since we just ignore HttpServletRequest arguments
*/

View File

@ -26,7 +26,7 @@ import java.util.List;
import java.util.Map;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.Request;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -35,7 +35,7 @@ class ServletResponseParameter implements IParameter {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServletResponseParameter.class);
@Override
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseClientInvocation theClientInvocation) throws InternalErrorException {
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseHttpClientInvocation theClientInvocation) throws InternalErrorException {
/*
* Does nothing, since we just ignore HttpServletResponse arguments
*/

View File

@ -33,7 +33,7 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.parser.DataFormatException;
import ca.uhn.fhir.rest.annotation.Since;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.Request;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
@ -44,7 +44,7 @@ public class SinceParameter implements IParameter {
private Class<?> myType;
@Override
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseClientInvocation theClientInvocation) throws InternalErrorException {
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseHttpClientInvocation theClientInvocation) throws InternalErrorException {
if (theSourceClientArgument != null) {
InstantDt since = ParameterUtil.toInstant(theSourceClientArgument);
if (since.isEmpty() == false) {

View File

@ -33,7 +33,7 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.annotation.Sort;
import ca.uhn.fhir.rest.api.SortOrderEnum;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.Request;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
@ -42,7 +42,7 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
public class SortParameter implements IParameter {
@Override
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseClientInvocation theClientInvocation) throws InternalErrorException {
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseHttpClientInvocation theClientInvocation) throws InternalErrorException {
SortSpec ss = (SortSpec) theSourceClientArgument;
while (ss != null) {
String name;

View File

@ -32,7 +32,7 @@ import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.BundleEntry;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.annotation.TransactionParam;
import ca.uhn.fhir.rest.client.BaseClientInvocation;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.Request;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -43,7 +43,7 @@ public class TransactionParameter implements IParameter {
}
@Override
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseClientInvocation theClientInvocation) throws InternalErrorException {
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments, BaseHttpClientInvocation theClientInvocation) throws InternalErrorException {
// TODO Auto-generated method stub
}

View File

@ -323,6 +323,42 @@ public class XmlParserTest {
}
}
@Test
public void testEncodePrettyPrint() throws DataFormatException {
Patient patient = new Patient();
patient.getText().getDiv().setValueAsString("<div>\n <i> hello </i>\n</div>");
patient.addName().addFamily("Family").addGiven("Given");
//@formatter:off
String encoded = new FhirContext().newXmlParser().setPrettyPrint(false).encodeResourceToString(patient);
ourLog.info(encoded);
String expected = "<Patient xmlns=\"http://hl7.org/fhir\"><text><div xmlns=\"http://www.w3.org/1999/xhtml\">\n" +
" <i> hello </i>\n" +
"</div></text><name><family value=\"Family\"/><given value=\"Given\"/></name></Patient>";
assertEquals(expected, encoded);
encoded = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient);
ourLog.info(encoded);
expected = "<Patient xmlns=\"http://hl7.org/fhir\">\n"
+ " <text>\n"
+ " <div xmlns=\"http://www.w3.org/1999/xhtml\">\n"
+ " <i> hello </i>\n"
+ "</div>\n"
+ " </text>\n"
+ " <name>\n"
+ " <family value=\"Family\"/>\n"
+ " <given value=\"Given\"/>\n"
+ " </name>\n"
+ "</Patient>";
//@formatter:on
// Whitespace should be preserved and not reformatted in narrative blocks
assertEquals(expected, encoded);
}
@Test
public void testEncodeResourceRef() throws DataFormatException {

View File

@ -0,0 +1,108 @@
package ca.uhn.fhir.rest.client;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.io.input.ReaderInputStream;
import org.apache.http.HttpResponse;
import org.apache.http.ProtocolVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicStatusLine;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
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.dstu.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu.resource.Conformance;
import ca.uhn.fhir.model.dstu.resource.Observation;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.Transaction;
import ca.uhn.fhir.rest.annotation.TransactionParam;
import ca.uhn.fhir.rest.client.api.IBasicClient;
import ca.uhn.fhir.rest.server.Constants;
public class TransactionClientTest {
private FhirContext ctx;
private HttpClient httpClient;
private HttpResponse httpResponse;
// atom-document-large.xml
@Before
public void before() {
ctx = new FhirContext(Patient.class, Conformance.class);
httpClient = mock(HttpClient.class, new ReturnsDeepStubs());
ctx.getRestfulClientFactory().setHttpClient(httpClient);
httpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
}
@Test
public void testSimpleTransaction() throws Exception {
Patient patient = new Patient();
patient.setId(new IdDt("Patient/testPersistWithSimpleLinkP01"));
patient.addIdentifier("urn:system", "testPersistWithSimpleLinkP01");
patient.addName().addFamily("Tester").addGiven("Joe");
Observation obs = new Observation();
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO01");
obs.setSubject(new ResourceReferenceDt("Patient/testPersistWithSimpleLinkP01"));
List<IResource> resources = Arrays.asList((IResource)patient, obs);
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(createBundle()), Charset.forName("UTF-8")));
client.searchWithParam(resources);
assertEquals(HttpPost.class, capt.getValue().getClass());
HttpPost get = (HttpPost) capt.getValue();
assertEquals("http://foo/", get.getURI().toString());
Bundle bundle = ctx.newXmlParser().parseBundle(new InputStreamReader(get.getEntity().getContent()));
ourLog.info(ctx.newXmlParser().setPrettyPrint(true).encodeBundleToString(bundle));
assertEquals(2, bundle.size());
assertEquals("Patient/testPersistWithSimpleLinkP01", bundle.getEntries().get(0).getId().getValue());
assertEquals("http://foo/Patient/testPersistWithSimpleLinkP01", bundle.getEntries().get(0).getLinkSelf().getValue());
assertTrue(bundle.getEntries().get(1).getId().isEmpty());
}
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TransactionClientTest.class);
private String createBundle() {
return ctx.newXmlParser().encodeBundleToString(new Bundle());
}
private interface IClient extends IBasicClient {
@Transaction
public List<IResource> searchWithParam(@TransactionParam List<IResource> theResources);
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**/*.java" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry including="**/*.java" kind="src" path="src/test/java"/>
<classpathentry excluding="**/*.java" kind="src" path="src/test/resources"/>
<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
<classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
<classpathentry exported="true" kind="var" path="M2_REPO/javax/activation/activation/1.1/activation-1.1.jar" sourcepath="M2_REPO/javax/activation/activation/1.1/activation-1.1-sources.jar"/>

View File

@ -4,6 +4,7 @@ import static org.apache.commons.lang3.StringUtils.*;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -19,6 +20,7 @@ import ca.uhn.fhir.context.ConfigurationException;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.jpa.entity.ResourceHistoryTable;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamDate;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamNumber;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
@ -47,7 +49,7 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.util.FhirTerser;
public abstract class BaseFhirDao {
private FhirContext myContext=new FhirContext();
private FhirContext myContext = new FhirContext();
@PersistenceContext(name = "FHIR_UT", type = PersistenceContextType.TRANSACTION, unitName = "FHIR_UT")
private EntityManager myEntityManager;
@Autowired
@ -58,10 +60,87 @@ public abstract class BaseFhirDao {
public FhirContext getContext() {
return myContext;
}
public void setContext(FhirContext theContext) {
myContext = theContext;
}
protected ResourceTable updateEntity(final IResource theResource, ResourceTable entity, boolean theUpdateHistory) {
if (entity.getPublished() == null) {
entity.setPublished(new Date());
}
if (theUpdateHistory) {
final ResourceHistoryTable historyEntry = entity.toHistory(getContext());
myEntityManager.persist(historyEntry);
}
entity.setVersion(entity.getVersion()+1);
final List<ResourceIndexedSearchParamString> stringParams = extractSearchParamStrings(entity, theResource);
final List<ResourceIndexedSearchParamToken> tokenParams = extractSearchParamTokens(entity, theResource);
final List<ResourceIndexedSearchParamNumber> numberParams = extractSearchParamNumber(entity, theResource);
final List<ResourceIndexedSearchParamDate> dateParams = extractSearchParamDates(entity, theResource);
final List<ResourceLink> links = extractResourceLinks(entity, theResource);
populateResourceIntoEntity(theResource, entity);
entity.setUpdated(new Date());
if (entity.getId() == null) {
myEntityManager.persist(entity);
} else {
entity = myEntityManager.merge(entity);
}
if (entity.isParamsStringPopulated()) {
for (ResourceIndexedSearchParamString next : entity.getParamsString()) {
myEntityManager.remove(next);
}
}
for (ResourceIndexedSearchParamString next : stringParams) {
myEntityManager.persist(next);
}
if (entity.isParamsTokenPopulated()) {
for (ResourceIndexedSearchParamToken next : entity.getParamsToken()) {
myEntityManager.remove(next);
}
}
for (ResourceIndexedSearchParamToken next : tokenParams) {
myEntityManager.persist(next);
}
if (entity.isParamsNumberPopulated()) {
for (ResourceIndexedSearchParamNumber next : entity.getParamsNumber()) {
myEntityManager.remove(next);
}
}
for (ResourceIndexedSearchParamNumber next : numberParams) {
myEntityManager.persist(next);
}
if (entity.isParamsDatePopulated()) {
for (ResourceIndexedSearchParamDate next : entity.getParamsDate()) {
myEntityManager.remove(next);
}
}
for (ResourceIndexedSearchParamDate next : dateParams) {
myEntityManager.persist(next);
}
if (entity.isHasLinks()) {
for (ResourceLink next : entity.getResourceLinks()) {
myEntityManager.remove(next);
}
}
for (ResourceLink next : links) {
myEntityManager.persist(next);
}
return entity;
}
protected List<ResourceLink> extractResourceLinks(ResourceTable theEntity, IResource theResource) {
ArrayList<ResourceLink> retVal = new ArrayList<ResourceLink>();
@ -211,7 +290,8 @@ public abstract class BaseFhirDao {
if (nextObject instanceof QuantityDt) {
QuantityDt nextValue = (QuantityDt) nextObject;
ResourceIndexedSearchParamNumber nextEntity = new ResourceIndexedSearchParamNumber(resourceName, nextValue.getValue().getValue(), nextValue.getSystem().getValueAsString(), nextValue.getUnits().getValue());
ResourceIndexedSearchParamNumber nextEntity = new ResourceIndexedSearchParamNumber(resourceName, nextValue.getValue().getValue(), nextValue.getSystem().getValueAsString(),
nextValue.getUnits().getValue());
nextEntity.setResource(theEntity);
retVal.add(nextEntity);
} else {
@ -294,7 +374,8 @@ public abstract class BaseFhirDao {
} else if (nextObject instanceof ContactDt) {
ContactDt nextContact = (ContactDt) nextObject;
if (nextContact.getValue().isEmpty() == false) {
ResourceIndexedSearchParamString nextEntity = new ResourceIndexedSearchParamString(resourceName, normalizeString(nextContact.getValue().getValueAsString()), nextContact.getValue().getValueAsString());
ResourceIndexedSearchParamString nextEntity = new ResourceIndexedSearchParamString(resourceName, normalizeString(nextContact.getValue().getValueAsString()), nextContact
.getValue().getValueAsString());
nextEntity.setResource(theEntity);
retVal.add(nextEntity);
}
@ -311,7 +392,7 @@ public abstract class BaseFhirDao {
return retVal;
}
protected List<ResourceIndexedSearchParamToken> extractSearchParamTokens(ResourceTable theEntity, IResource theResource) {
ArrayList<ResourceIndexedSearchParamToken> retVal = new ArrayList<ResourceIndexedSearchParamToken>();
@ -377,7 +458,7 @@ public abstract class BaseFhirDao {
return retVal;
}
protected IFhirResourceDao<? extends IResource> getDao(Class<? extends IResource> theType) {
protected IFhirResourceDao<? extends IResource> getDao(Class<? extends IResource> theType) {
if (myResourceTypeToDao == null) {
myResourceTypeToDao = new HashMap<>();
for (IFhirResourceDao<?> next : myResourceDaos) {
@ -403,6 +484,8 @@ public abstract class BaseFhirDao {
}
protected void populateResourceIntoEntity(IResource theResource, ResourceTable theEntity) {
theEntity.setResourceType(toResourceName(theResource));
theEntity.setResource(getContext().newJsonParser().encodeResourceToString(theResource));
theEntity.setEncoding(EncodingEnum.JSON);
@ -427,5 +510,4 @@ public abstract class BaseFhirDao {
return myContext.getResourceDefinition(theResource).getName();
}
}

View File

@ -64,6 +64,7 @@ import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.QualifiedDateParam;
import ca.uhn.fhir.rest.param.ReferenceParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements IFhirResourceDao<T> {
@ -80,7 +81,7 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
@Override
public MethodOutcome create(T theResource) {
public MethodOutcome create(final T theResource) {
final ResourceTable entity = toEntity(theResource);
@ -88,13 +89,13 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
entity.setUpdated(entity.getPublished());
entity.setResourceType(toResourceName(theResource));
final List<ResourceIndexedSearchParamString> stringParams = extractSearchParamStrings(entity, theResource);
final List<ResourceIndexedSearchParamToken> tokenParams = extractSearchParamTokens(entity, theResource);
final List<ResourceIndexedSearchParamNumber> numberParams = extractSearchParamNumber(entity, theResource);
final List<ResourceIndexedSearchParamDate> dateParams = extractSearchParamDates(entity, theResource);
final List<ResourceLink> links = extractResourceLinks(entity, theResource);
// final List<ResourceIndexedSearchParamString> stringParams = extractSearchParamStrings(entity, theResource);
// final List<ResourceIndexedSearchParamToken> tokenParams = extractSearchParamTokens(entity, theResource);
// final List<ResourceIndexedSearchParamNumber> numberParams = extractSearchParamNumber(entity, theResource);
// final List<ResourceIndexedSearchParamDate> dateParams = extractSearchParamDates(entity, theResource);
// final List<ResourceLink> links = extractResourceLinks(entity, theResource);
ourLog.info("Saving links: {}", links);
// ourLog.info("Saving links: {}", links);
TransactionTemplate template = new TransactionTemplate(myPlatformTransactionManager);
template.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW);
@ -102,22 +103,23 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
template.execute(new TransactionCallback<ResourceTable>() {
@Override
public ResourceTable doInTransaction(TransactionStatus theStatus) {
myEntityManager.persist(entity);
for (ResourceIndexedSearchParamString next : stringParams) {
myEntityManager.persist(next);
}
for (ResourceIndexedSearchParamToken next : tokenParams) {
myEntityManager.persist(next);
}
for (ResourceIndexedSearchParamNumber next : numberParams) {
myEntityManager.persist(next);
}
for (ResourceIndexedSearchParamDate next : dateParams) {
myEntityManager.persist(next);
}
for (ResourceLink next : links) {
myEntityManager.persist(next);
}
// myEntityManager.persist(entity);
// for (ResourceIndexedSearchParamString next : stringParams) {
// myEntityManager.persist(next);
// }
// for (ResourceIndexedSearchParamToken next : tokenParams) {
// myEntityManager.persist(next);
// }
// for (ResourceIndexedSearchParamNumber next : numberParams) {
// myEntityManager.persist(next);
// }
// for (ResourceIndexedSearchParamDate next : dateParams) {
// myEntityManager.persist(next);
// }
// for (ResourceLink next : links) {
// myEntityManager.persist(next);
// }
updateEntity(theResource, entity,false);
return entity;
}
});
@ -126,7 +128,6 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
return outcome;
}
public Class<T> getResourceType() {
return myResourceType;
}
@ -303,84 +304,27 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
myResourceType = (Class<T>) theTableType;
}
@Transactional(propagation = Propagation.SUPPORTS)
@Transactional(propagation = Propagation.REQUIRED)
@Override
public MethodOutcome update(final T theResource, final IdDt theId) {
TransactionTemplate template = new TransactionTemplate(myPlatformTransactionManager);
ResourceTable savedEntity = template.execute(new TransactionCallback<ResourceTable>() {
@Override
public ResourceTable doInTransaction(TransactionStatus theStatus) {
// TransactionTemplate template = new TransactionTemplate(myPlatformTransactionManager);
// ResourceTable savedEntity = template.execute(new TransactionCallback<ResourceTable>() {
// @Override
// public ResourceTable doInTransaction(TransactionStatus theStatus) {
// final ResourceTable entity = readEntity(theId);
// return updateEntity(theResource, entity,true);
// }
// });
final ResourceTable entity = readEntity(theId);
entity.setUpdated(entity.getPublished());
final ResourceHistoryTable historyEntry = entity.toHistory(getContext());
final List<ResourceIndexedSearchParamString> stringParams = extractSearchParamStrings(entity, theResource);
final List<ResourceIndexedSearchParamToken> tokenParams = extractSearchParamTokens(entity, theResource);
final List<ResourceIndexedSearchParamNumber> numberParams = extractSearchParamNumber(entity, theResource);
final List<ResourceIndexedSearchParamDate> dateParams = extractSearchParamDates(entity, theResource);
final List<ResourceLink> links = extractResourceLinks(entity, theResource);
populateResourceIntoEntity(theResource, entity);
myEntityManager.persist(historyEntry);
entity.setUpdated(new Date());
myEntityManager.persist(entity);
if (entity.isParamsStringPopulated()) {
for (ResourceIndexedSearchParamString next : entity.getParamsString()) {
myEntityManager.remove(next);
}
}
for (ResourceIndexedSearchParamString next : stringParams) {
myEntityManager.persist(next);
}
if (entity.isParamsTokenPopulated()) {
for (ResourceIndexedSearchParamToken next : entity.getParamsToken()) {
myEntityManager.remove(next);
}
}
for (ResourceIndexedSearchParamToken next : tokenParams) {
myEntityManager.persist(next);
}
if (entity.isParamsNumberPopulated()) {
for (ResourceIndexedSearchParamNumber next : entity.getParamsNumber()) {
myEntityManager.remove(next);
}
}
for (ResourceIndexedSearchParamNumber next : numberParams) {
myEntityManager.persist(next);
}
if (entity.isParamsDatePopulated()) {
for (ResourceIndexedSearchParamDate next : entity.getParamsDate()) {
myEntityManager.remove(next);
}
}
for (ResourceIndexedSearchParamDate next : dateParams) {
myEntityManager.persist(next);
}
if (entity.isHasLinks()) {
for (ResourceLink next : entity.getResourceLinks()) {
myEntityManager.remove(next);
}
}
for (ResourceLink next : links) {
myEntityManager.persist(next);
}
return entity;
}
});
final ResourceTable entity = readEntity(theId);
ResourceTable savedEntity = updateEntity(theResource, entity,true);
return toMethodOutcome(savedEntity);
}
private Set<Long> addPredicateDate(Set<Long> thePids, List<IQueryParameterType> theOrParams) {
if (theOrParams == null || theOrParams.isEmpty()) {
return thePids;
@ -710,8 +654,6 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
return new HashSet<Long>(q.getResultList());
}
private ResourceTable readEntity(IdDt theId) {
ResourceTable entity = myEntityManager.find(ResourceTable.class, theId.asLong());
if (entity == null) {
@ -720,11 +662,10 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
return entity;
}
private MethodOutcome toMethodOutcome(final ResourceTable entity) {
MethodOutcome outcome = new MethodOutcome();
outcome.setId(new IdDt(entity.getResourceType() + '/' + entity.getId()));
outcome.setVersionId(entity.getVersion());
outcome.setId(new IdDt(entity.getResourceType() + '/' + entity.getId() + '/' + Constants.PARAM_HISTORY + '/' + entity.getVersion()));
outcome.setVersionId(new IdDt(entity.getVersion()));
return outcome;
}
@ -759,11 +700,10 @@ public class FhirResourceDao<T extends IResource> extends BaseFhirDao implements
protected IFhirResourceDao<? extends IResource> getDao(Class<? extends IResource> theType) {
if (theType.equals(myResourceType)) {
return this;
}
}
return super.getDao(theType);
}
private T toResource(BaseHasResource theEntity) {
String resourceText = theEntity.getResource();
IParser parser = theEntity.getEncoding().newParser(getContext());

View File

@ -15,6 +15,11 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamDate;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamNumber;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString;
import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamToken;
import ca.uhn.fhir.jpa.entity.ResourceLink;
import ca.uhn.fhir.jpa.entity.ResourceTable;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
@ -35,13 +40,13 @@ public class FhirSystemDao extends BaseFhirDao implements IFhirSystemDao {
ourLog.info("Beginning transaction with {} resources", theResources.size());
FhirTerser terser = myContext.newTerser();
Map<IdDt, IdDt> idConversions = new HashMap<>();
List<ResourceTable> persistedResources = new ArrayList<>();
for (IResource nextResource : theResources) {
IdDt nextId = nextResource.getId();
if (isBlank(nextId.getUnqualifiedId())) {
continue;
if (nextId == null) {
nextId = new IdDt();
}
String resourceName = toResourceName(nextResource);
@ -52,19 +57,28 @@ public class FhirSystemDao extends BaseFhirDao implements IFhirSystemDao {
// nextResource.getResourceId().getResourceType());
// }
ResourceTable entity = myEntityManager.find(ResourceTable.class, nextId.asLong());
ResourceTable entity;
if (nextId.isEmpty()) {
entity = null;
} else if (!nextId.isValidLong()) {
entity = null;
} else {
entity = myEntityManager.find(ResourceTable.class, nextId.asLong());
}
if (entity == null) {
entity = toEntity(nextResource);
myEntityManager.persist(entity);
myEntityManager.flush();
}
idConversions.put(nextId, new IdDt(resourceName + '/' + entity.getId()));
persistedResources.add(entity);
}
for (IResource nextResource : theResources) {
List<ResourceReferenceDt> allRefs = terser.getAllPopulatedChildElementsOfType(nextResource, ResourceReferenceDt.class);
List<ResourceReferenceDt> allRefs = terser.getAllPopulatedChildElementsOfType(nextResource, ResourceReferenceDt.class);
for (ResourceReferenceDt nextRef : allRefs) {
IdDt nextId = nextRef.getResourceId();
if (idConversions.containsKey(nextId)) {
@ -74,8 +88,13 @@ public class FhirSystemDao extends BaseFhirDao implements IFhirSystemDao {
}
}
}
for (int i = 0; i < theResources.size(); i++) {
IResource resource = theResources.get(i);
ResourceTable table = persistedResources.get(i);
updateEntity(resource, table, table.getId() != null);
}
return null;
}

View File

@ -3,16 +3,12 @@ package ca.uhn.fhir.jpa.entity;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.Lob;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Fetch;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.rest.server.EncodingEnum;
@ -55,7 +51,7 @@ public abstract class BaseHasResource {
return new InstantDt(myUpdated);
}
public abstract IdDt getVersion();
public abstract long getVersion();
public void setEncoding(EncodingEnum theEncoding) {
myEncoding = theEncoding;

View File

@ -14,6 +14,7 @@ import javax.persistence.Table;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
@Entity
@ -32,7 +33,7 @@ public class ResourceHistoryTable extends BaseHasResource implements Serializabl
@Override
public IdDt getIdDt() {
return new IdDt(myPk.getId());
return new IdDt(myPk.getResourceType() + '/' + myPk.getId() + '/' + Constants.PARAM_HISTORY + '/' + myPk.getVersion());
}
public ResourceHistoryTablePk getPk() {
@ -56,8 +57,8 @@ public class ResourceHistoryTable extends BaseHasResource implements Serializabl
}
@Override
public IdDt getVersion() {
return new IdDt(myPk.getVersion());
public long getVersion() {
return myPk.getVersion();
}
public void setPk(ResourceHistoryTablePk thePk) {

View File

@ -16,7 +16,7 @@ public class ResourceHistoryTablePk implements Serializable {
@Column(name="RES_TYPE", length=30, nullable=false)
private String myResourceType;
@Column(name="VERSION")
@Column(name="VERSION", nullable=false)
private Long myVersion;
public Long getId() {

View File

@ -19,6 +19,7 @@ import javax.persistence.Version;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.server.Constants;
@Entity
@Table(name = "HFJ_RESOURCE", uniqueConstraints = {})
@ -72,7 +73,7 @@ public class ResourceTable extends BaseHasResource implements Serializable {
@Version()
@Column(name = "RES_VER")
private Long myVersion;
private long myVersion;
public void addTag(String theTerm, String theLabel, String theScheme) {
for (ResourceTag next : getTags()) {
@ -84,7 +85,7 @@ public class ResourceTable extends BaseHasResource implements Serializable {
}
public IdDt getIdDt() {
return new IdDt(myId);
return new IdDt(myResourceType + '/' + myId + '/' + Constants.PARAM_HISTORY + '/' + myVersion);
}
public Long getId() {
@ -137,8 +138,8 @@ public class ResourceTable extends BaseHasResource implements Serializable {
return myTags;
}
public IdDt getVersion() {
return new IdDt(myVersion);
public long getVersion() {
return myVersion;
}
public boolean isHasLinks() {
@ -201,8 +202,8 @@ public class ResourceTable extends BaseHasResource implements Serializable {
myResourceType = theResourceType;
}
public void setVersion(IdDt theVersion) {
myVersion = theVersion.asLong();
public void setVersion(long theVersion) {
myVersion = theVersion;
}
public ResourceHistoryTable toHistory(FhirContext theCtx) {

View File

@ -454,6 +454,8 @@ public class FhirResourceDaoTest {
assertNotNull(outcome.getId());
assertFalse(outcome.getId().isEmpty());
assertEquals("1", outcome.getId().getUnqualifiedVersionId());
Date now = new Date();
Patient retrieved = ourPatientDao.read(outcome.getId());
InstantDt published = (InstantDt) retrieved.getResourceMetadata().get(ResourceMetadataKeyEnum.PUBLISHED);
@ -465,12 +467,17 @@ public class FhirResourceDaoTest {
retrieved.getIdentifierFirstRep().setValue("002");
MethodOutcome outcome2 = ourPatientDao.update(retrieved, outcome.getId());
assertEquals(outcome.getId(), outcome2.getId());
assertEquals(outcome.getId().getUnqualifiedId(), outcome2.getId().getUnqualifiedId());
assertNotEquals(outcome.getId().getUnqualifiedVersionId(), outcome2.getId().getUnqualifiedVersionId());
assertNotEquals(outcome.getVersionId(), outcome2.getVersionId());
assertEquals("2", outcome2.getId().getUnqualifiedVersionId());
Date now2 = new Date();
Patient retrieved2 = ourPatientDao.read(outcome.getId());
assertEquals("2", retrieved2.getId().getUnqualifiedVersionId());
assertEquals("002", retrieved2.getIdentifierFirstRep().getValue().getValue());
InstantDt published2 = (InstantDt) retrieved2.getResourceMetadata().get(ResourceMetadataKeyEnum.PUBLISHED);
InstantDt updated2 = (InstantDt) retrieved2.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED);

View File

@ -0,0 +1,82 @@
package ca.uhn.fhir.jpa.dao;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu.resource.Device;
import ca.uhn.fhir.model.dstu.resource.DiagnosticReport;
import ca.uhn.fhir.model.dstu.resource.Location;
import ca.uhn.fhir.model.dstu.resource.Observation;
import ca.uhn.fhir.model.dstu.resource.Organization;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
public class FhirSystemDaoTest {
private static ClassPathXmlApplicationContext ourCtx;
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoTest.class);
private static IFhirResourceDao<Observation> ourObservationDao;
private static IFhirResourceDao<Patient> ourPatientDao;
private static IFhirResourceDao<Device> ourDeviceDao;
private static IFhirResourceDao<DiagnosticReport> ourDiagnosticReportDao;
private static IFhirResourceDao<Organization> ourOrganizationDao;
private static IFhirResourceDao<Location> ourLocationDao;
private static Date ourTestStarted;
private static IFhirSystemDao ourSystemDao;
@Test
public void testPersistWithSimpleLink() {
Patient patient = new Patient();
patient.setId(new IdDt("Patient/testPersistWithSimpleLinkP01"));
patient.addIdentifier("urn:system", "testPersistWithSimpleLinkP01");
patient.addName().addFamily("Tester").addGiven("Joe");
Observation obs = new Observation();
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO01");
obs.setSubject(new ResourceReferenceDt("Patient/testPersistWithSimpleLinkP01"));
List<IResource> response = ourSystemDao.transaction(Arrays.asList((IResource)patient, obs));
List<Observation> obsResults = ourObservationDao.search(Observation.SP_NAME, new IdentifierDt("urn:system","testPersistWithSimpleLinkO01"));
assertEquals(1, obsResults.size());
List<Patient> patResults = ourPatientDao.search(Patient.SP_IDENTIFIER, new IdentifierDt("urn:system","testPersistWithSimpleLinkP01"));
assertEquals(1, obsResults.size());
IdDt patientId = patResults.get(0).getId();
ResourceReferenceDt subject = obs.getSubject();
assertEquals(patientId.getUnqualifiedId(), subject.getResourceId().getUnqualifiedId());
}
@AfterClass
public static void afterClass() {
ourCtx.close();
}
@SuppressWarnings("unchecked")
@BeforeClass
public static void beforeClass() {
ourTestStarted = new Date();
ourCtx = new ClassPathXmlApplicationContext("fhir-jpabase-spring-test-config.xml");
ourPatientDao = ourCtx.getBean("myPatientDao", IFhirResourceDao.class);
ourObservationDao = ourCtx.getBean("myObservationDao", IFhirResourceDao.class);
ourDiagnosticReportDao = ourCtx.getBean("myDiagnosticReportDao", IFhirResourceDao.class);
ourDeviceDao = ourCtx.getBean("myDeviceDao", IFhirResourceDao.class);
ourOrganizationDao = ourCtx.getBean("myOrganizationDao", IFhirResourceDao.class);
ourLocationDao = ourCtx.getBean("myLocationDao", IFhirResourceDao.class);
ourSystemDao = ourCtx.getBean("mySystemDao", IFhirSystemDao.class);
}
}

View File

@ -13,6 +13,9 @@
<context:annotation-config />
<context:mbean-server />
<bean id="mySystemDao" class="ca.uhn.fhir.jpa.dao.FhirSystemDao">
</bean>
<bean id="myDiagnosticReportDao" class="ca.uhn.fhir.jpa.dao.FhirResourceDao">
<property name="resourceType" value="ca.uhn.fhir.model.dstu.resource.DiagnosticReport"/>
</bean>

View File

@ -12,7 +12,7 @@
<artifactId>hapi-fhir-jpaserver-test</artifactId>
<packaging>jar</packaging>
<name>HAPI FHIR JPA Server - Tester</name>
<name>HAPI FHIR JPA Server - Test Project</name>
<dependencies>
<dependency>