Update to the latest upstream.

This commit is contained in:
mochaholic 2015-04-09 07:25:09 -06:00
parent e4b5943314
commit 3003b5e17b
10 changed files with 96 additions and 77 deletions

View File

@ -74,30 +74,30 @@ public class GenericClientExample {
// END SNIPPET: create
}
{
Patient patient = new Patient();
// START SNIPPET: createConditional
// One form
MethodOutcome outcome = client.create()
.resource(patient)
.conditionalByUrl("Patient?identifier=system%7C00001")
.execute();
Patient patient = new Patient();
// START SNIPPET: createConditional
// One form
MethodOutcome outcome = client.create()
.resource(patient)
.conditionalByUrl("Patient?identifier=system%7C00001")
.execute();
// Another form
MethodOutcome outcome2 = client.create()
.resource(patient)
.conditional()
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
.execute();
// This will return true if the server responded with an HTTP 201 created,
// otherwise it will return null.
Boolean created = outcome.getCreated();
// The ID of the created, or the pre-existing resource
IdDt id = outcome.getId();
// END SNIPPET: createConditional
// Another form
MethodOutcome outcome2 = client.create()
.resource(patient)
.conditional()
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
.execute();
// This will return true if the server responded with an HTTP 201 created,
// otherwise it will return null.
Boolean created = outcome.getCreated();
// The ID of the created, or the pre-existing resource
IdDt id = outcome.getId();
// END SNIPPET: createConditional
}
{
{
// START SNIPPET: update
Patient patient = new Patient();
// ..populate the patient object..
@ -125,21 +125,21 @@ public class GenericClientExample {
// END SNIPPET: update
}
{
Patient patient = new Patient();
// START SNIPPET: updateConditional
client.update()
.resource(patient)
.conditionalByUrl("Patient?identifier=system%7C00001")
.execute();
client.update()
.resource(patient)
.conditional()
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
.execute();
// END SNIPPET: updateConditional
Patient patient = new Patient();
// START SNIPPET: updateConditional
client.update()
.resource(patient)
.conditionalByUrl("Patient?identifier=system%7C00001")
.execute();
client.update()
.resource(patient)
.conditional()
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
.execute();
// END SNIPPET: updateConditional
}
{
{
// START SNIPPET: etagupdate
// First, let's retrive the latest version of a resource
// from the server
@ -176,26 +176,26 @@ public class GenericClientExample {
}
{
// START SNIPPET: delete
BaseOperationOutcome resp = client.delete().resourceById(new IdDt("Patient", "1234")).execute();
BaseOperationOutcome resp = client.delete().resourceById(new IdDt("Patient", "1234")).execute();
// outcome may be null if the server didn't return one
if (resp != null) {
OperationOutcome outcome = (OperationOutcome) resp;
if (resp != null) {
OperationOutcome outcome = (OperationOutcome) resp;
System.out.println(outcome.getIssueFirstRep().getDetailsElement().getValue());
}
// END SNIPPET: delete
}
{
// START SNIPPET: deleteConditional
client.delete()
.resourceConditionalByUrl("Patient?identifier=system%7C00001")
.execute();
client.delete()
.resourceConditionalByType("Patient")
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
.execute();
// END SNIPPET: deleteConditional
{
// START SNIPPET: deleteConditional
client.delete()
.resourceConditionalByUrl("Patient?identifier=system%7C00001")
.execute();
client.delete()
.resourceConditionalByType("Patient")
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
.execute();
// END SNIPPET: deleteConditional
}
{
// START SNIPPET: search

View File

@ -1676,7 +1676,7 @@ class ParserState<T> {
private class SecurityLabelElementStateHapi extends ElementCompositeState {
public SecurityLabelElementStateHapi(ParserState<T>.PreResourceState thePreResourceState,BaseRuntimeElementCompositeDefinition<?> theDef, BaseCodingDt codingDt) {
public SecurityLabelElementStateHapi(ParserState<T>.PreResourceState thePreResourceState, BaseRuntimeElementCompositeDefinition<?> theDef, BaseCodingDt codingDt) {
super(thePreResourceState, theDef, codingDt);
}
@ -1718,7 +1718,7 @@ class ParserState<T> {
securityLabels = new ArrayList<BaseCodingDt>();
myMap.put(ResourceMetadataKeyEnum.SECURITY_LABELS, securityLabels);
}
BaseCodingDt securityLabel= myContext.getVersion().newCodingDt();
BaseCodingDt securityLabel = myContext.getVersion().newCodingDt();
BaseRuntimeElementCompositeDefinition<?> codinfDef = (BaseRuntimeElementCompositeDefinition<?>) myContext.getElementDefinition(securityLabel.getClass());
push(new SecurityLabelElementStateHapi(getPreResourceState(), codinfDef, securityLabel));
securityLabels.add(securityLabel);

View File

@ -135,7 +135,7 @@ public class MethodOutcome {
}
/**
* This will be set to {@link Boolean#TRUE} for instance of MethodOutcome which are
* This will be set to {@link Boolean#TRUE} for instance of MethodOutcome which are
* returned to client instances, if the server has responded with an HTTP 201 Created.
*/
public Boolean getCreated() {

View File

@ -280,9 +280,9 @@ abstract class BaseOutcomeReturningMethodBinding extends BaseMethodBinding<Metho
} else {
retVal = parser.parseResource(requestReader);
}
retVal.setId(theRequest.getId());
return retVal;
}

View File

@ -39,9 +39,11 @@
</bean>
</property>
</bean>
<bean id="myTxManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="myEntityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="myTxManager" />
</beans>

View File

@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
@ -167,10 +168,15 @@ public class TestRestfulServer extends RestfulServer {
* Do some fancy logging to create a nice access log that has details
* about each incoming request.
*/
LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
List<IServerInterceptor> interceptorBeans = myAppCtx.getBean("myServerInterceptors", List.class);
for (IServerInterceptor interceptor : interceptorBeans)
this.registerInterceptor(interceptor);
/*LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
loggingInterceptor.setLoggerName("fhirtest.access");
loggingInterceptor.setMessageFormat("Path[${servletPath}] Source[${requestHeader.x-forwarded-for}] Operation[${operationType} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}]");
this.registerInterceptor(loggingInterceptor);
*/
}

View File

@ -21,4 +21,13 @@
</bean>
<tx:annotation-driven transaction-manager="myTxManager" />
<util:list id="myServerInterceptors">
<ref bean="myLoggingInterceptor"/>
</util:list>
<bean id="myLoggingInterceptor" class="ca.uhn.fhir.rest.server.interceptor.LoggingInterceptor">
<property name="loggerName" value="fhirtest.access"/>
<property name="messageFormat"
value="Path[${servletPath}] Source[${requestHeader.x-forwarded-for}] Operation[${operationType} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}]"/>
</bean>
</beans>

View File

@ -132,7 +132,7 @@ public class GenericClientTest {
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getAllHeaders()).thenReturn(new Header[] { new BasicHeader(Constants.HEADER_LOCATION, "/Patient/44/_history/22") });
when(myHttpResponse.getAllHeaders()).thenReturn(new Header[]{new BasicHeader(Constants.HEADER_LOCATION, "/Patient/44/_history/22")});
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
@ -141,14 +141,14 @@ public class GenericClientTest {
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK"));
MethodOutcome resp = client.create().resource(ourCtx.newXmlParser().encodeResourceToString(p1)).execute();
assertTrue(resp.getCreated());
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
resp = client.create().resource(ourCtx.newXmlParser().encodeResourceToString(p1)).execute();
assertNull(resp.getCreated());
}
@Test
public void testCreateWithStringAutoDetectsEncoding() throws Exception {

View File

@ -105,7 +105,7 @@ public class FhirDstu2 implements IFhirVersion {
public Class<? extends BaseContainedDt> getContainedType() {
return ContainedDt.class;
}
@Override
public BaseCodingDt newCodingDt() {
return new CodingDt();

View File

@ -165,8 +165,10 @@
<h4>Search - Using HTTP POST</h4>
<p>
The FHIR specification allows the use of an HTTP POST to transmit a search to a server instead of using
an HTTP GET. With this style of search, the search parameters are included in the request body instead
The FHIR specification allows the use of an HTTP POST to transmit a search to a server instead of
using
an HTTP GET. With this style of search, the search parameters are included in the request body
instead
of the request URL, which can be useful if you need to transmit a search with a large number
of parameters.
</p>
@ -176,7 +178,7 @@
case the client automatically switches to POST.
</p>
<p>
An alternate form of the search URL (using a URL ending with <code>_search</code>) was also
An alternate form of the search URL (using a URL ending with<code>_search</code>) was also
supported in FHIR DSTU1. This form is no longer valid in FHIR DSTU2, but HAPI retains support
for using this form in order to interoperate with servers which use it.
</p>
@ -211,18 +213,18 @@
<param name="file"
value="examples/src/main/java/example/GenericClientExample.java" />
</macro>
<h4>Conditional Creates</h4>
<p>
FHIR also specifies a type of update called "conditional create", where
a set of search parameters are provided and a new resource is only
created if no existing resource matches those parameters. See the
FHIR specification for more information on conditional creation.
created if no existing resource matches those parameters. See the
FHIR specification for more information on conditional creation.
</p>
<macro name="snippet">
<param name="id" value="updateConditional" />
<param name="id" value="updateConditional"/>
<param name="file"
value="examples/src/main/java/example/GenericClientExample.java" />
value="examples/src/main/java/example/GenericClientExample.java"/>
</macro>
</subsection>
@ -276,7 +278,7 @@
</macro>
<h4>Conditional Deletes</h4>
<p>
Conditional deletions are also possible, which is a form where
Conditional deletions are also possible, which is a form where
instead of deleting a resource using its logical ID, you specify
a set of search criteria and a single resource is deleted if
it matches that criteria. Note that this is not a mechanism
@ -284,9 +286,9 @@
on conditional deletes and how they are used.
</p>
<macro name="snippet">
<param name="id" value="deleteConditional" />
<param name="id" value="deleteConditional"/>
<param name="file"
value="examples/src/main/java/example/GenericClientExample.java" />
value="examples/src/main/java/example/GenericClientExample.java"/>
</macro>
</subsection>
@ -305,19 +307,19 @@
<param name="file"
value="examples/src/main/java/example/GenericClientExample.java" />
</macro>
<h4>Conditional Updates</h4>
<p>
FHIR also specifies a type of update called "conditional updates", where
insetad of using the logical ID of a resource to update, a set of
search parameters is provided. If a single resource matches that set of
parameters, that resource is updated. See the FHIR specification for
parameters, that resource is updated. See the FHIR specification for
information on how conditional updates work.
</p>
<macro name="snippet">
<param name="id" value="updateConditional" />
<param name="id" value="updateConditional"/>
<param name="file"
value="examples/src/main/java/example/GenericClientExample.java" />
value="examples/src/main/java/example/GenericClientExample.java"/>
</macro>
<h4>ETags and Resource Contention</h4>