Fix build

This commit is contained in:
jamesagnew 2015-02-17 13:54:26 -05:00
parent 7e1f9cfdbf
commit 3631160269
22 changed files with 371 additions and 287 deletions

View File

@ -47,18 +47,25 @@ public abstract class BaseRuntimeChildDatatypeDefinition extends BaseRuntimeDecl
@Override @Override
public String getChildNameByDatatype(Class<? extends IBase> theDatatype) { public String getChildNameByDatatype(Class<? extends IBase> theDatatype) {
if (myDatatype.equals(theDatatype)) { Class<?> nextType = theDatatype;
while(nextType.equals(Object.class)==false) {
if (myDatatype.equals(nextType)) {
return getElementName(); return getElementName();
} }
nextType = nextType.getSuperclass();
}
return null; return null;
} }
@Override @Override
public BaseRuntimeElementDefinition<?> getChildElementDefinitionByDatatype(Class<? extends IBase> theDatatype) { public BaseRuntimeElementDefinition<?> getChildElementDefinitionByDatatype(Class<? extends IBase> theDatatype) {
Class<? extends IBase> datatype = theDatatype; Class<?> nextType = theDatatype;
if (myDatatype.equals(datatype)) { while(nextType.equals(Object.class)==false) {
if (myDatatype.equals(nextType)) {
return myElementDefinition; return myElementDefinition;
} }
nextType = nextType.getSuperclass();
}
return null; return null;
} }

View File

@ -178,4 +178,8 @@ public class RuntimeResourceDefinition extends BaseRuntimeElementCompositeDefini
return retVal; return retVal;
} }
public boolean isBundle() {
return "Bundle".equals(getName());
}
} }

View File

@ -94,7 +94,11 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding<Obje
myResourceListCollectionType = collectionType; myResourceListCollectionType = collectionType;
} else if (IBaseResource.class.isAssignableFrom(methodReturnType)) { } else if (IBaseResource.class.isAssignableFrom(methodReturnType)) {
if (theConetxt.getResourceDefinition((Class<? extends IBaseResource>) methodReturnType).isBundle()) {
myMethodReturnType = MethodReturnTypeEnum.BUNDLE_RESOURCE;
}else {
myMethodReturnType = MethodReturnTypeEnum.RESOURCE; myMethodReturnType = MethodReturnTypeEnum.RESOURCE;
}
} else if (Bundle.class.isAssignableFrom(methodReturnType)) { } else if (Bundle.class.isAssignableFrom(methodReturnType)) {
myMethodReturnType = MethodReturnTypeEnum.BUNDLE; myMethodReturnType = MethodReturnTypeEnum.BUNDLE;
} else if (IBundleProvider.class.isAssignableFrom(methodReturnType)) { } else if (IBundleProvider.class.isAssignableFrom(methodReturnType)) {
@ -202,7 +206,7 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding<Obje
throw new IllegalStateException("Should not get here!"); throw new IllegalStateException("Should not get here!");
} }
public abstract IBundleProvider invokeServer(RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException; public abstract Object invokeServer(RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException;
@Override @Override
public void invokeServer(RestfulServer theServer, Request theRequest) throws BaseServerResponseException, IOException { public void invokeServer(RestfulServer theServer, Request theRequest) throws BaseServerResponseException, IOException {
@ -239,10 +243,16 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding<Obje
boolean respondGzip = theRequest.isRespondGzip(); boolean respondGzip = theRequest.isRespondGzip();
HttpServletResponse response = theRequest.getServletResponse(); HttpServletResponse response = theRequest.getServletResponse();
IBundleProvider result = invokeServer(theRequest, params); Object resultObj = invokeServer(theRequest, params);
switch (getReturnType()) { switch (getReturnType()) {
case BUNDLE: case BUNDLE:{
if (getMethodReturnType() == MethodReturnTypeEnum.BUNDLE_RESOURCE) {
IResource resource = (IResource) resultObj;
RestfulServer.streamResponseAsResource(theServer, response, resource, responseEncoding, prettyPrint, requestIsBrowser, narrativeMode, respondGzip, theRequest.getFhirServerBase());
break;
} else {
IBundleProvider result = (IBundleProvider) resultObj;
Bundle bundle = RestfulServer.createBundleFromBundleProvider(theServer, response, result, responseEncoding, theRequest.getFhirServerBase(), theRequest.getCompleteUrl(), prettyPrint, requestIsBrowser, narrativeMode, 0, count, null, getResponseBundleType()); Bundle bundle = RestfulServer.createBundleFromBundleProvider(theServer, response, result, responseEncoding, theRequest.getFhirServerBase(), theRequest.getCompleteUrl(), prettyPrint, requestIsBrowser, narrativeMode, 0, count, null, getResponseBundleType());
for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) { for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) {
@ -255,7 +265,10 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding<Obje
RestfulServer.streamResponseAsBundle(theServer, response, bundle, responseEncoding, theRequest.getFhirServerBase(), prettyPrint, narrativeMode, respondGzip); RestfulServer.streamResponseAsBundle(theServer, response, bundle, responseEncoding, theRequest.getFhirServerBase(), prettyPrint, narrativeMode, respondGzip);
break; break;
case RESOURCE: }
}
case RESOURCE:{
IBundleProvider result = (IBundleProvider) resultObj;
if (result.size() == 0) { if (result.size() == 0) {
throw new ResourceNotFoundException(theRequest.getId()); throw new ResourceNotFoundException(theRequest.getId());
} else if (result.size() > 1) { } else if (result.size() > 1) {
@ -276,6 +289,7 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding<Obje
break; break;
} }
} }
}
/** /**
* If the response is a bundle, this type will be placed in the root of the bundle (can be null) * If the response is a bundle, this type will be placed in the root of the bundle (can be null)
@ -295,7 +309,7 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding<Obje
} }
public enum MethodReturnTypeEnum { public enum MethodReturnTypeEnum {
BUNDLE, BUNDLE_PROVIDER, LIST_OF_RESOURCES, RESOURCE BUNDLE, BUNDLE_PROVIDER, LIST_OF_RESOURCES, RESOURCE, BUNDLE_RESOURCE
} }
public enum ReturnTypeEnum { public enum ReturnTypeEnum {

View File

@ -38,9 +38,11 @@ import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum;
import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.model.valueset.BundleTypeEnum;
import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.annotation.Transaction;
import ca.uhn.fhir.rest.annotation.TransactionParam; import ca.uhn.fhir.rest.annotation.TransactionParam;
import ca.uhn.fhir.rest.client.BaseHttpClientInvocation; import ca.uhn.fhir.rest.client.BaseHttpClientInvocation;
import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType; import ca.uhn.fhir.rest.method.SearchMethodBinding.RequestType;
import ca.uhn.fhir.rest.method.TransactionParamBinder.ParamStyle;
import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.RestfulServer;
@ -50,6 +52,7 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
public class TransactionMethodBinding extends BaseResourceReturningMethodBinding { public class TransactionMethodBinding extends BaseResourceReturningMethodBinding {
private int myTransactionParamIndex; private int myTransactionParamIndex;
private ParamStyle myTransactionParamStyle;
public TransactionMethodBinding(Method theMethod, FhirContext theConetxt, Object theProvider) { public TransactionMethodBinding(Method theMethod, FhirContext theConetxt, Object theProvider) {
super(null, theMethod, theConetxt, theProvider); super(null, theMethod, theConetxt, theProvider);
@ -58,7 +61,12 @@ public class TransactionMethodBinding extends BaseResourceReturningMethodBinding
int index = 0; int index = 0;
for (IParameter next : getParameters()) { for (IParameter next : getParameters()) {
if (next instanceof TransactionParamBinder) { if (next instanceof TransactionParamBinder) {
if (myTransactionParamIndex != -1) {
throw new ConfigurationException("Method '" + theMethod.getName() + "' in type " + theMethod.getDeclaringClass().getCanonicalName() + " has multiple parameters annotated with the @" + TransactionParam.class + " annotation, exactly one is required for @" + Transaction.class
+ " methods");
}
myTransactionParamIndex = index; myTransactionParamIndex = index;
myTransactionParamStyle = ((TransactionParamBinder) next).getParamStyle();
} }
index++; index++;
} }
@ -94,7 +102,20 @@ public class TransactionMethodBinding extends BaseResourceReturningMethodBinding
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public IBundleProvider invokeServer(RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException { public Object invokeServer(RequestDetails theRequest, Object[] theMethodParams) throws InvalidRequestException, InternalErrorException {
/*
* The design of HAPI's transaction method for DSTU1 support assumed that a
* transaction was just an update on a bunch of resources (because that's what
* it was), but in DSTU2 transaction has become much more broad, so we no longer
* hold the user's hand much here.
*/
if (myTransactionParamStyle == ParamStyle.RESOURCE_BUNDLE) {
// This is the DSTU2 style
Object response = invokeServerMethod(theMethodParams);
return response;
}
// Grab the IDs of all of the resources in the transaction // Grab the IDs of all of the resources in the transaction
List<IResource> resources; List<IResource> resources;
if (theMethodParams[myTransactionParamIndex] instanceof Bundle) { if (theMethodParams[myTransactionParamIndex] instanceof Bundle) {
@ -113,14 +134,10 @@ public class TransactionMethodBinding extends BaseResourceReturningMethodBinding
IBundleProvider retVal = toResourceList(response); IBundleProvider retVal = toResourceList(response);
/* /*
int offset = 0; * int offset = 0; if (retVal.size() != resources.size()) { if (retVal.size() > 0 && retVal.getResources(0,
if (retVal.size() != resources.size()) { * 1).get(0) instanceof OperationOutcome) { offset = 1; } else { throw new
if (retVal.size() > 0 && retVal.getResources(0, 1).get(0) instanceof OperationOutcome) { * InternalErrorException("Transaction bundle contained " + resources.size() +
offset = 1; * " entries, but server method response contained " + retVal.size() + " entries (must be the same)"); } }
} else {
throw new InternalErrorException("Transaction bundle contained " + resources.size() + " entries, but server method response contained " + retVal.size() + " entries (must be the same)");
}
}
*/ */
List<IResource> retResources = retVal.getResources(0, retVal.size()); List<IResource> retResources = retVal.getResources(0, retVal.size());
@ -141,17 +158,11 @@ public class TransactionMethodBinding extends BaseResourceReturningMethodBinding
} }
return retVal; return retVal;
} }
@Override @Override
protected Object parseRequestObject(Request theRequest) throws IOException { protected Object parseRequestObject(Request theRequest) throws IOException {
EncodingEnum encoding = RestfulServer.determineResponseEncoding(theRequest.getServletRequest()); return null; // This is parsed in TransactionParamBinder
IParser parser = encoding.newParser(getContext());
Bundle bundle = parser.parseBundle(theRequest.getServletRequest().getReader());
return bundle;
} }
@Override @Override

View File

@ -20,6 +20,8 @@ package ca.uhn.fhir.rest.method;
* #L% * #L%
*/ */
import java.io.BufferedReader;
import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
@ -35,20 +37,58 @@ import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.model.api.Bundle; import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.BundleEntry; import ca.uhn.fhir.model.api.BundleEntry;
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.annotation.TransactionParam; import ca.uhn.fhir.rest.annotation.TransactionParam;
import ca.uhn.fhir.rest.server.EncodingEnum;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
class TransactionParamBinder implements IParameter { class TransactionParamBinder implements IParameter {
private boolean myParamIsBundle;
private FhirContext myContext; private FhirContext myContext;
private boolean myParamIsResource; private ParamStyle myParamStyle;
private Class<? extends IBaseResource> myResourceBundleType;
public TransactionParamBinder(FhirContext theContext) { public TransactionParamBinder(FhirContext theContext) {
myContext = theContext; myContext = theContext;
} }
private String createParameterTypeError(Method theMethod) {
return "Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is annotated with @" + TransactionParam.class.getName() + " but is not of type List<" + IResource.class.getCanonicalName() + "> or Bundle";
}
@Override
public void initializeTypes(Method theMethod, Class<? extends Collection<?>> theOuterCollectionType, Class<? extends Collection<?>> theInnerCollectionType, Class<?> theParameterType) {
if (theOuterCollectionType != null) {
throw new ConfigurationException("Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is annotated with @" + TransactionParam.class.getName() + " but can not be a collection of collections");
}
if (theParameterType.equals(Bundle.class)) {
myParamStyle = ParamStyle.DSTU1_BUNDLE;
if (theInnerCollectionType != null) {
throw new ConfigurationException(createParameterTypeError(theMethod));
}
} else if (Modifier.isInterface(theParameterType.getModifiers()) == false && IBaseResource.class.isAssignableFrom(theParameterType)) {
@SuppressWarnings("unchecked")
Class<? extends IBaseResource> parameterType = (Class<? extends IBaseResource>) theParameterType;
RuntimeResourceDefinition def = myContext.getResourceDefinition(parameterType);
if ("Bundle".equals(def.getName())) {
myParamStyle = ParamStyle.RESOURCE_BUNDLE;
myResourceBundleType = parameterType;
} else {
throw new ConfigurationException(createParameterTypeError(theMethod));
}
} else {
if (theInnerCollectionType.equals(List.class) == false) {
throw new ConfigurationException(createParameterTypeError(theMethod));
}
if (theParameterType.equals(IResource.class) == false) {
throw new ConfigurationException(createParameterTypeError(theMethod));
}
myParamStyle = ParamStyle.RESOURCE_LIST;
}
}
@Override @Override
public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments) throws InternalErrorException { public void translateClientArgumentIntoQueryArgument(FhirContext theContext, Object theSourceClientArgument, Map<String, List<String>> theTargetQueryArguments) throws InternalErrorException {
// nothing // nothing
@ -57,54 +97,51 @@ class TransactionParamBinder implements IParameter {
@Override @Override
public Object translateQueryParametersIntoServerArgument(Request theRequest, Object theRequestContents) throws InternalErrorException, InvalidRequestException { public Object translateQueryParametersIntoServerArgument(Request theRequest, Object theRequestContents) throws InternalErrorException, InvalidRequestException {
Bundle resource = (Bundle) theRequestContents;
if (myParamIsBundle) { EncodingEnum encoding = RestfulServer.determineResponseEncoding(theRequest.getServletRequest());
return resource; IParser parser = encoding.newParser(myContext);
BufferedReader reader;
try {
reader = theRequest.getServletRequest().getReader();
} catch (IOException e) {
throw new InternalErrorException("Failed to read incoming payload", e);
} }
ArrayList<IResource> retVal = new ArrayList<IResource>(); switch (myParamStyle) {
for (BundleEntry next : resource.getEntries()) { case DSTU1_BUNDLE: {
Bundle bundle;
bundle = parser.parseBundle(reader);
return bundle;
}
case RESOURCE_LIST: {
Bundle bundle = parser.parseBundle(reader);
ArrayList<IResource> resourceList = new ArrayList<IResource>();
for (BundleEntry next : bundle.getEntries()) {
if (next.getResource() != null) { if (next.getResource() != null) {
retVal.add(next.getResource()); resourceList.add(next.getResource());
} }
} }
return resourceList;
}
case RESOURCE_BUNDLE:
return parser.parseResource(myResourceBundleType, reader);
}
return retVal; throw new IllegalStateException("Unknown type: " + myParamStyle); // should not happen
} }
@Override public ParamStyle getParamStyle() {
public void initializeTypes(Method theMethod, Class<? extends Collection<?>> theOuterCollectionType, Class<? extends Collection<?>> theInnerCollectionType, Class<?> theParameterType) { return myParamStyle;
if (theOuterCollectionType != null) {
throw new ConfigurationException("Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is annotated with @" + TransactionParam.class.getName() + " but can not be a collection of collections");
}
if (theParameterType.equals(Bundle.class)) {
myParamIsBundle=true;
if (theInnerCollectionType!=null) {
throw new ConfigurationException(createParameterTypeError(theMethod));
}
} else if (Modifier.isInterface(theParameterType.getModifiers()) == false && IBaseResource.class.isAssignableFrom(theParameterType)) {
@SuppressWarnings("unchecked")
Class<? extends IBaseResource> parameterType = (Class<? extends IBaseResource>) theParameterType;
RuntimeResourceDefinition def = myContext.getResourceDefinition(parameterType);
if ("Bundle".equals(def.getName())) {
myParamIsResource = true;
} else {
throw new ConfigurationException(createParameterTypeError(theMethod));
}
} else {
myParamIsBundle=false;
if (theInnerCollectionType.equals(List.class) == false) {
throw new ConfigurationException(createParameterTypeError(theMethod));
}
if (theParameterType.equals(IResource.class) == false) {
throw new ConfigurationException(createParameterTypeError(theMethod));
}
}
} }
private String createParameterTypeError(Method theMethod) { enum ParamStyle {
return "Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is annotated with @" + TransactionParam.class.getName() + " but is not of type List<" + IResource.class.getCanonicalName() /** Old style bundle (defined in hapi-fhir-base) */
+ "> or Bundle"; DSTU1_BUNDLE,
/** New style bundle (defined in hapi-fhir-structures-* as a resource definition itself */
RESOURCE_BUNDLE,
/** List of resources */
RESOURCE_LIST
} }
} }

View File

@ -41,179 +41,180 @@ public class TransactionWithBundleResourceParamTest {
} }
// private static CloseableHttpClient ourClient; private static CloseableHttpClient ourClient;
// private static FhirContext ourCtx = new FhirContext(); private static FhirContext ourCtx = new FhirContext();
// private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TransactionWithBundleResourceParamTest.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TransactionWithBundleResourceParamTest.class);
// private static int ourPort; private static int ourPort;
// private static boolean ourReturnOperationOutcome; private static boolean ourReturnOperationOutcome;
//
// private static Server ourServer; private static Server ourServer;
//
// @Before @Before
// public void before() { public void before() {
// ourReturnOperationOutcome = false; ourReturnOperationOutcome = false;
// } }
//
// @Test @Test
// public void testTransaction() throws Exception { public void testTransaction() throws Exception {
// Bundle b = new Bundle(); Bundle b = new Bundle();
// InstantDt nowInstant = InstantDt.withCurrentTime(); InstantDt nowInstant = InstantDt.withCurrentTime();
//
// Patient p1 = new Patient(); Patient p1 = new Patient();
// p1.addName().addFamily("Family1"); p1.addName().addFamily("Family1");
// Entry entry = b.addEntry(); Entry entry = b.addEntry();
// p1.getId().setValue("1"); p1.getId().setValue("1");
// entry.setResource(p1); entry.setResource(p1);
//
// Patient p2 = new Patient(); Patient p2 = new Patient();
// p2.addName().addFamily("Family2"); p2.addName().addFamily("Family2");
// entry = b.addEntry(); entry = b.addEntry();
// p2.getId().setValue("2"); p2.getId().setValue("2");
// entry.setResource(p2); entry.setResource(p2);
//
// Entry deletedEntry = b.addEntry(); Entry deletedEntry = b.addEntry();
// deletedEntry.getTransaction().setMethod(HTTPVerbEnum.DELETE); deletedEntry.getTransaction().setMethod(HTTPVerbEnum.DELETE);
// deletedEntry.getTransaction().setUrl("http://base.com/Patient/123"); deletedEntry.getTransaction().setUrl("http://base.com/Patient/123");
//
// String bundleString = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b); String bundleString = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
// ourLog.info(bundleString); ourLog.info(bundleString);
//
// HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/");
// httpPost.addHeader("Accept", Constants.CT_ATOM_XML + "; pretty=true"); httpPost.addHeader("Accept", Constants.CT_ATOM_XML + "; pretty=true");
// httpPost.setEntity(new StringEntity(bundleString, ContentType.create(Constants.CT_ATOM_XML, "UTF-8"))); httpPost.setEntity(new StringEntity(bundleString, ContentType.create(Constants.CT_ATOM_XML, "UTF-8")));
// HttpResponse status = ourClient.execute(httpPost); HttpResponse status = ourClient.execute(httpPost);
// String responseContent = IOUtils.toString(status.getEntity().getContent()); String responseContent = IOUtils.toString(status.getEntity().getContent());
// IOUtils.closeQuietly(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());
//
// assertEquals(200, status.getStatusLine().getStatusCode()); assertEquals(200, status.getStatusLine().getStatusCode());
//
// ourLog.info(responseContent); ourLog.info(responseContent);
//
// Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent); Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
// assertEquals(3, bundle.getEntry().size()); assertEquals(3, bundle.getEntry().size());
//
// Entry entry0 = bundle.getEntry().get(0); Entry entry0 = bundle.getEntry().get(0);
// assertEquals("http://localhost:" + ourPort + "/Patient/81/_history/91", entry0.getResource().getId().getValue()); assertEquals("Patient/81/_history/91", entry0.getTransactionResponse().getLocation());
//
// Entry entry1 = bundle.getEntry().get(1); Entry entry1 = bundle.getEntry().get(1);
// assertEquals("http://localhost:" + ourPort + "/Patient/82/_history/92", entry1.getResource().getId().getValue()); assertEquals( "Patient/82/_history/92", entry1.getTransactionResponse().getLocation());
//
// Entry entry2 = bundle.getEntry().get(2); Entry entry2 = bundle.getEntry().get(2);
// assertEquals("http://localhost:" + ourPort + "/Patient/3/_history/93", entry2.getResource().getId().getValue()); assertEquals("Patient/123/_history/93", entry2.getTransactionResponse().getLocation());
// } }
//
// @Test @Test
// public void testTransactionWithOperationOutcome() throws Exception { public void testTransactionWithOperationOutcome() throws Exception {
// ourReturnOperationOutcome = true; ourReturnOperationOutcome = true;
//
// Bundle b = new Bundle(); Bundle b = new Bundle();
// InstantDt nowInstant = InstantDt.withCurrentTime(); InstantDt nowInstant = InstantDt.withCurrentTime();
//
// Patient p1 = new Patient(); Patient p1 = new Patient();
// p1.addName().addFamily("Family1"); p1.addName().addFamily("Family1");
// Entry entry = b.addEntry(); Entry entry = b.addEntry();
// p1.getId().setValue("1"); p1.getId().setValue("1");
// entry.setResource(p1); entry.setResource(p1);
//
// Patient p2 = new Patient(); Patient p2 = new Patient();
// p2.addName().addFamily("Family2"); p2.addName().addFamily("Family2");
// entry = b.addEntry(); entry = b.addEntry();
// p2.getId().setValue("2"); p2.getId().setValue("2");
// entry.setResource(p2); entry.setResource(p2);
//
// Entry deletedEntry = b.addEntry(); Entry deletedEntry = b.addEntry();
// deletedEntry.getTransaction().setMethod(HTTPVerbEnum.DELETE); deletedEntry.getTransaction().setMethod(HTTPVerbEnum.DELETE);
// deletedEntry.getTransaction().setUrl(new IdDt("Patient/3")); deletedEntry.getTransaction().setUrl(new IdDt("Patient/3"));
//
// String bundleString = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b); String bundleString = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
// ourLog.info(bundleString); ourLog.info(bundleString);
//
// HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/"); String base = "http://localhost:" + ourPort + "/";
// httpPost.addHeader("Accept", Constants.CT_ATOM_XML + "; pretty=true"); HttpPost httpPost = new HttpPost(base);
// httpPost.setEntity(new StringEntity(bundleString, ContentType.create(Constants.CT_ATOM_XML, "UTF-8"))); httpPost.addHeader("Accept", Constants.CT_ATOM_XML + "; pretty=true");
// HttpResponse status = ourClient.execute(httpPost); httpPost.setEntity(new StringEntity(bundleString, ContentType.create(Constants.CT_ATOM_XML, "UTF-8")));
// String responseContent = IOUtils.toString(status.getEntity().getContent()); HttpResponse status = ourClient.execute(httpPost);
// IOUtils.closeQuietly(status.getEntity().getContent()); String responseContent = IOUtils.toString(status.getEntity().getContent());
// IOUtils.closeQuietly(status.getEntity().getContent());
// assertEquals(200, status.getStatusLine().getStatusCode());
// assertEquals(200, status.getStatusLine().getStatusCode());
// ourLog.info(responseContent);
// ourLog.info(responseContent);
// Bundle bundle = new FhirContext().newXmlParser().parseResource(Bundle.class, responseContent);
// assertEquals(4, bundle.getEntry().size()); Bundle bundle = new FhirContext().newXmlParser().parseResource(Bundle.class, responseContent);
// assertEquals(4, bundle.getEntry().size());
// assertEquals(OperationOutcome.class, bundle.getEntry().get(0).getResource().getClass());
// assertEquals(OperationOutcome.class, bundle.getEntry().get(0).getResource().getClass());
// Entry entry0 = bundle.getEntry().get(1);
// assertEquals("http://localhost:" + ourPort + "/Patient/81/_history/91", entry0.getResource().getId().getValue()); Entry entry0 = bundle.getEntry().get(1);
// assertEquals("Patient/81/_history/91", entry0.getTransactionResponse().getLocation());
// Entry entry1 = bundle.getEntry().get(2);
// assertEquals("http://localhost:" + ourPort + "/Patient/82/_history/92", entry1.getResource().getId().getValue()); Entry entry1 = bundle.getEntry().get(2);
// assertEquals("Patient/82/_history/92", entry1.getTransactionResponse().getLocation());
// Entry entry2 = bundle.getEntry().get(3);
// assertEquals("http://localhost:" + ourPort + "/Patient/3/_history/93", entry2.getResource().getId().getValue()); Entry entry2 = bundle.getEntry().get(3);
// } assertEquals( "Patient/3/_history/93", entry2.getTransactionResponse().getLocation());
// }
// @AfterClass
// public static void afterClass() throws Exception { @AfterClass
// ourServer.stop(); public static void afterClass() throws Exception {
// } ourServer.stop();
// }
// @BeforeClass
// public static void beforeClass() throws Exception { @BeforeClass
// ourPort = PortUtil.findFreePort(); public static void beforeClass() throws Exception {
// ourServer = new Server(ourPort); ourPort = PortUtil.findFreePort();
// ourServer = new Server(ourPort);
// DummyProvider patientProvider = new DummyProvider();
// RestfulServer server = new RestfulServer(); DummyProvider patientProvider = new DummyProvider();
// server.setProviders(patientProvider); RestfulServer server = new RestfulServer();
// server.setProviders(patientProvider);
// org.eclipse.jetty.servlet.ServletContextHandler proxyHandler = new org.eclipse.jetty.servlet.ServletContextHandler();
// proxyHandler.setContextPath("/"); org.eclipse.jetty.servlet.ServletContextHandler proxyHandler = new org.eclipse.jetty.servlet.ServletContextHandler();
// proxyHandler.setContextPath("/");
// ServletHolder handler = new ServletHolder();
// handler.setServlet(server); ServletHolder handler = new ServletHolder();
// proxyHandler.addServlet(handler, "/*"); handler.setServlet(server);
// proxyHandler.addServlet(handler, "/*");
// ourServer.setHandler(proxyHandler);
// ourServer.start(); ourServer.setHandler(proxyHandler);
// ourServer.start();
// PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
// HttpClientBuilder builder = HttpClientBuilder.create(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
// builder.setConnectionManager(connectionManager); HttpClientBuilder builder = HttpClientBuilder.create();
// ourClient = builder.build(); builder.setConnectionManager(connectionManager);
// ourClient = builder.build();
// }
// }
// /**
// * Created by dsotnikov on 2/25/2014. /**
// */ * Created by dsotnikov on 2/25/2014.
// public static class DummyProvider { */
// public static class DummyProvider {
// @Transaction
// public Bundle transaction(@TransactionParam Bundle theResources) { @Transaction
// Bundle retVal = new Bundle(); public Bundle transaction(@TransactionParam Bundle theResources) {
// Bundle retVal = new Bundle();
// if (ourReturnOperationOutcome) {
// OperationOutcome oo = new OperationOutcome(); if (ourReturnOperationOutcome) {
// oo.addIssue().setDetails("AAAAA"); OperationOutcome oo = new OperationOutcome();
// retVal.addEntry().setResource(oo); oo.addIssue().setDetails("AAAAA");
// } retVal.addEntry().setResource(oo);
// }
// int index = 1;
// for (Entry nextEntry : theResources.getEntry()) { int index = 1;
// String newId = "8" + Integer.toString(index); for (Entry nextEntry : theResources.getEntry()) {
// if (nextEntry.getTransaction().getMethodElement().getValueAsEnum() == HTTPVerbEnum.DELETE) { String newId = "8" + Integer.toString(index);
// newId = new IdDt(nextEntry.getTransaction().getUrlElement()).getIdPart(); if (nextEntry.getTransaction().getMethodElement().getValueAsEnum() == HTTPVerbEnum.DELETE) {
// } newId = new IdDt(nextEntry.getTransaction().getUrlElement()).getIdPart();
// IdDt newIdDt = (new IdDt("Patient", newId, "9" + Integer.toString(index))); }
// retVal.addEntry().getTransactionResponse().setLocation(newIdDt.getValue()); IdDt newIdDt = (new IdDt("Patient", newId, "9" + Integer.toString(index)));
// index++; retVal.addEntry().getTransactionResponse().setLocation(newIdDt.getValue());
// } index++;
// }
// return retVal;
// } return retVal;
// }
// }
}
} }

View File

@ -18,13 +18,15 @@ package ca.uhn.fhir.model.dev.composite;
import java.net.URI; import java.net.URI;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.*; import java.util.*;
import ca.uhn.fhir.model.api.*; import ca.uhn.fhir.model.api.*;
import ca.uhn.fhir.model.primitive.*; import ca.uhn.fhir.model.primitive.*;
import ca.uhn.fhir.model.api.annotation.*; import ca.uhn.fhir.model.api.annotation.*;
import ca.uhn.fhir.model.base.composite.*; import ca.uhn.fhir.model.base.composite.*;
import ca.uhn.fhir.model.dev.valueset.AddressUseEnum; import ca.uhn.fhir.model.dev.valueset.AddressUseEnum;
import ca.uhn.fhir.model.dev.valueset.AggregationModeEnum; import ca.uhn.fhir.model.dev.valueset.AggregationModeEnum;
import ca.uhn.fhir.model.dev.valueset.BindingConformanceEnum; import ca.uhn.fhir.model.dev.valueset.BindingConformanceEnum;
@ -354,7 +356,7 @@ public class AttachmentDt
* An alternative location where the data can be accessed * An alternative location where the data can be accessed
* </p> * </p>
*/ */
public URI getUrl() { public String getUrl() {
return getUrlElement().getValue(); return getUrlElement().getValue();
} }

View File

@ -18,13 +18,15 @@ package ca.uhn.fhir.model.dev.composite;
import java.net.URI; import java.net.URI;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.*; import java.util.*;
import ca.uhn.fhir.model.api.*; import ca.uhn.fhir.model.api.*;
import ca.uhn.fhir.model.primitive.*; import ca.uhn.fhir.model.primitive.*;
import ca.uhn.fhir.model.api.annotation.*; import ca.uhn.fhir.model.api.annotation.*;
import ca.uhn.fhir.model.base.composite.*; import ca.uhn.fhir.model.base.composite.*;
import ca.uhn.fhir.model.dev.valueset.AddressUseEnum; import ca.uhn.fhir.model.dev.valueset.AddressUseEnum;
import ca.uhn.fhir.model.dev.valueset.AggregationModeEnum; import ca.uhn.fhir.model.dev.valueset.AggregationModeEnum;
import ca.uhn.fhir.model.dev.valueset.BindingConformanceEnum; import ca.uhn.fhir.model.dev.valueset.BindingConformanceEnum;
@ -180,7 +182,7 @@ public class CodingDt
* The identification of the code system that defines the meaning of the symbol in the code. * The identification of the code system that defines the meaning of the symbol in the code.
* </p> * </p>
*/ */
public URI getSystem() { public String getSystem() {
return getSystemElement().getValue(); return getSystemElement().getValue();
} }

View File

@ -18,13 +18,15 @@ package ca.uhn.fhir.model.dev.composite;
import java.net.URI; import java.net.URI;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.*; import java.util.*;
import ca.uhn.fhir.model.api.*; import ca.uhn.fhir.model.api.*;
import ca.uhn.fhir.model.primitive.*; import ca.uhn.fhir.model.primitive.*;
import ca.uhn.fhir.model.api.annotation.*; import ca.uhn.fhir.model.api.annotation.*;
import ca.uhn.fhir.model.base.composite.*; import ca.uhn.fhir.model.base.composite.*;
import ca.uhn.fhir.model.dev.valueset.AddressUseEnum; import ca.uhn.fhir.model.dev.valueset.AddressUseEnum;
import ca.uhn.fhir.model.dev.valueset.AggregationModeEnum; import ca.uhn.fhir.model.dev.valueset.AggregationModeEnum;
import ca.uhn.fhir.model.dev.valueset.BindingConformanceEnum; import ca.uhn.fhir.model.dev.valueset.BindingConformanceEnum;
@ -2207,7 +2209,7 @@ public class ElementDefinitionDt
* Identifies a profile structure that SHALL hold for resources or datatypes referenced as the type of this element. Can be a local reference - to another structure in this profile, or a reference to a structure in another profile * Identifies a profile structure that SHALL hold for resources or datatypes referenced as the type of this element. Can be a local reference - to another structure in this profile, or a reference to a structure in another profile
* </p> * </p>
*/ */
public URI getProfile() { public String getProfile() {
return getProfileElement().getValue(); return getProfileElement().getValue();
} }

View File

@ -18,13 +18,15 @@ package ca.uhn.fhir.model.dev.composite;
import java.net.URI; import java.net.URI;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.*; import java.util.*;
import ca.uhn.fhir.model.api.*; import ca.uhn.fhir.model.api.*;
import ca.uhn.fhir.model.primitive.*; import ca.uhn.fhir.model.primitive.*;
import ca.uhn.fhir.model.api.annotation.*; import ca.uhn.fhir.model.api.annotation.*;
import ca.uhn.fhir.model.base.composite.*; import ca.uhn.fhir.model.base.composite.*;
import ca.uhn.fhir.model.dev.valueset.AddressUseEnum; import ca.uhn.fhir.model.dev.valueset.AddressUseEnum;
import ca.uhn.fhir.model.dev.valueset.AggregationModeEnum; import ca.uhn.fhir.model.dev.valueset.AggregationModeEnum;
import ca.uhn.fhir.model.dev.valueset.BindingConformanceEnum; import ca.uhn.fhir.model.dev.valueset.BindingConformanceEnum;
@ -312,7 +314,7 @@ public class IdentifierDt
* Establishes the namespace in which set of possible id values is unique. * Establishes the namespace in which set of possible id values is unique.
* </p> * </p>
*/ */
public URI getSystem() { public String getSystem() {
return getSystemElement().getValue(); return getSystemElement().getValue();
} }

View File

@ -18,13 +18,15 @@ package ca.uhn.fhir.model.dev.composite;
import java.net.URI; import java.net.URI;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.util.*; import java.util.*;
import ca.uhn.fhir.model.api.*; import ca.uhn.fhir.model.api.*;
import ca.uhn.fhir.model.primitive.*; import ca.uhn.fhir.model.primitive.*;
import ca.uhn.fhir.model.api.annotation.*; import ca.uhn.fhir.model.api.annotation.*;
import ca.uhn.fhir.model.base.composite.*; import ca.uhn.fhir.model.base.composite.*;
import ca.uhn.fhir.model.dev.valueset.AddressUseEnum; import ca.uhn.fhir.model.dev.valueset.AddressUseEnum;
import ca.uhn.fhir.model.dev.valueset.AggregationModeEnum; import ca.uhn.fhir.model.dev.valueset.AggregationModeEnum;
import ca.uhn.fhir.model.dev.valueset.BindingConformanceEnum; import ca.uhn.fhir.model.dev.valueset.BindingConformanceEnum;
@ -428,7 +430,7 @@ public class QuantityDt
* The identification of the system that provides the coded form of the unit * The identification of the system that provides the coded form of the unit
* </p> * </p>
*/ */
public URI getSystem() { public String getSystem() {
return getSystemElement().getValue(); return getSystemElement().getValue();
} }

View File

@ -2084,7 +2084,7 @@ public class Conformance extends BaseResource implements ca.uhn.fhir.model.base.
* A base URL for the implementation. This forms the base for REST interfaces as well as the mailbox and document interfaces. * A base URL for the implementation. This forms the base for REST interfaces as well as the mailbox and document interfaces.
* </p> * </p>
*/ */
public URI getUrl() { public String getUrl() {
return getUrlElement().getValue(); return getUrlElement().getValue();
} }
@ -3994,7 +3994,7 @@ public class Conformance extends BaseResource implements ca.uhn.fhir.model.base.
* A formal reference to where this parameter was first defined, so that a client can be confident of the meaning of the search parameter * A formal reference to where this parameter was first defined, so that a client can be confident of the meaning of the search parameter
* </p> * </p>
*/ */
public URI getDefinition() { public String getDefinition() {
return getDefinitionElement().getValue(); return getDefinitionElement().getValue();
} }
@ -4707,7 +4707,7 @@ public class Conformance extends BaseResource implements ca.uhn.fhir.model.base.
* An address to which messages and/or replies are to be sent. * An address to which messages and/or replies are to be sent.
* </p> * </p>
*/ */
public URI getEndpoint() { public String getEndpoint() {
return getEndpointElement().getValue(); return getEndpointElement().getValue();
} }

View File

@ -2106,7 +2106,7 @@ public class DataElement
* A URI that identifies the specification that this mapping is expressed to * A URI that identifies the specification that this mapping is expressed to
* </p> * </p>
*/ */
public URI getUri() { public String getUri() {
return getUriElement().getValue(); return getUriElement().getValue();
} }

View File

@ -621,7 +621,7 @@ public class OperationDefinition
* The identifier that is used to identify this operation definition when it is referenced in a specification, model, design or an instance (should be globally unique OID, UUID, or URI) * The identifier that is used to identify this operation definition when it is referenced in a specification, model, design or an instance (should be globally unique OID, UUID, or URI)
* </p> * </p>
*/ */
public URI getIdentifier() { public String getIdentifier() {
return getIdentifierElement().getValue(); return getIdentifierElement().getValue();
} }

View File

@ -538,7 +538,7 @@ public class Profile
* The URL at which this profile is (or will be) published, and which is used to reference this profile in extension urls and tag values in operational FHIR systems * The URL at which this profile is (or will be) published, and which is used to reference this profile in extension urls and tag values in operational FHIR systems
* </p> * </p>
*/ */
public URI getUrl() { public String getUrl() {
return getUrlElement().getValue(); return getUrlElement().getValue();
} }
@ -1470,7 +1470,7 @@ public class Profile
* The structure that is the base on which this set of constraints is derived from. * The structure that is the base on which this set of constraints is derived from.
* </p> * </p>
*/ */
public URI getBase() { public String getBase() {
return getBaseElement().getValue(); return getBaseElement().getValue();
} }
@ -1709,7 +1709,7 @@ public class Profile
* A URI that identifies the specification that this mapping is expressed to * A URI that identifies the specification that this mapping is expressed to
* </p> * </p>
*/ */
public URI getUri() { public String getUri() {
return getUriElement().getValue(); return getUriElement().getValue();
} }

View File

@ -502,7 +502,7 @@ public class ValueSet
* The identifier that is used to identify this value set when it is referenced in a specification, model, design or an instance (should be globally unique OID, UUID, or URI) * The identifier that is used to identify this value set when it is referenced in a specification, model, design or an instance (should be globally unique OID, UUID, or URI)
* </p> * </p>
*/ */
public URI getIdentifier() { public String getIdentifier() {
return getIdentifierElement().getValue(); return getIdentifierElement().getValue();
} }
@ -1533,7 +1533,7 @@ public class ValueSet
* *
* </p> * </p>
*/ */
public URI getSystem() { public String getSystem() {
return getSystemElement().getValue(); return getSystemElement().getValue();
} }
@ -2724,7 +2724,7 @@ public class ValueSet
* The code system from which the selected codes come from * The code system from which the selected codes come from
* </p> * </p>
*/ */
public URI getSystem() { public String getSystem() {
return getSystemElement().getValue(); return getSystemElement().getValue();
} }
@ -3719,7 +3719,7 @@ public class ValueSet
* The system in which the code for this item in the expansion is defined * The system in which the code for this item in the expansion is defined
* </p> * </p>
*/ */
public URI getSystem() { public String getSystem() {
return getSystemElement().getValue(); return getSystemElement().getValue();
} }

View File

@ -356,7 +356,7 @@ public class AttachmentDt
* An alternative location where the data can be accessed * An alternative location where the data can be accessed
* </p> * </p>
*/ */
public URI getUrl() { public String getUrl() {
return getUrlElement().getValue(); return getUrlElement().getValue();
} }

View File

@ -182,7 +182,7 @@ public class CodingDt
* The identification of the code system that defines the meaning of the symbol in the code. * The identification of the code system that defines the meaning of the symbol in the code.
* </p> * </p>
*/ */
public URI getSystem() { public String getSystem() {
return getSystemElement().getValue(); return getSystemElement().getValue();
} }

View File

@ -2209,7 +2209,7 @@ public class ElementDefinitionDt
* Identifies a profile structure that SHALL hold for resources or datatypes referenced as the type of this element. Can be a local reference - to another structure in this profile, or a reference to a structure in another profile * Identifies a profile structure that SHALL hold for resources or datatypes referenced as the type of this element. Can be a local reference - to another structure in this profile, or a reference to a structure in another profile
* </p> * </p>
*/ */
public URI getProfile() { public String getProfile() {
return getProfileElement().getValue(); return getProfileElement().getValue();
} }

View File

@ -313,7 +313,7 @@ public class IdentifierDt
* Establishes the namespace in which set of possible id values is unique. * Establishes the namespace in which set of possible id values is unique.
* </p> * </p>
*/ */
public URI getSystem() { public String getSystem() {
return getSystemElement().getValue(); return getSystemElement().getValue();
} }

View File

@ -429,7 +429,7 @@ public class QuantityDt
* The identification of the system that provides the coded form of the unit * The identification of the system that provides the coded form of the unit
* </p> * </p>
*/ */
public URI getSystem() { public String getSystem() {
return getSystemElement().getValue(); return getSystemElement().getValue();
} }

View File

@ -502,7 +502,7 @@ public class ValueSet
* The identifier that is used to identify this value set when it is referenced in a specification, model, design or an instance (should be globally unique OID, UUID, or URI) * The identifier that is used to identify this value set when it is referenced in a specification, model, design or an instance (should be globally unique OID, UUID, or URI)
* </p> * </p>
*/ */
public URI getIdentifier() { public String getIdentifier() {
return getIdentifierElement().getValue(); return getIdentifierElement().getValue();
} }
@ -1533,7 +1533,7 @@ public class ValueSet
* *
* </p> * </p>
*/ */
public URI getSystem() { public String getSystem() {
return getSystemElement().getValue(); return getSystemElement().getValue();
} }
@ -2724,7 +2724,7 @@ public class ValueSet
* The code system from which the selected codes come from * The code system from which the selected codes come from
* </p> * </p>
*/ */
public URI getSystem() { public String getSystem() {
return getSystemElement().getValue(); return getSystemElement().getValue();
} }
@ -3719,7 +3719,7 @@ public class ValueSet
* The system in which the code for this item in the expansion is defined * The system in which the code for this item in the expansion is defined
* </p> * </p>
*/ */
public URI getSystem() { public String getSystem() {
return getSystemElement().getValue(); return getSystemElement().getValue();
} }