More test fixes

This commit is contained in:
jamesagnew 2016-04-17 20:57:27 -04:00
parent 12a66a9438
commit 59c44a3b0b
5 changed files with 24 additions and 35 deletions

View File

@ -12,6 +12,7 @@ import javax.servlet.http.HttpServletResponse;
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.api.Include;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
@ -1111,40 +1112,13 @@ public class TagMethodProvider
//START SNIPPET: transaction
@Transaction
public List<IResource> transaction(@TransactionParam List<IResource> theResources) {
// theResources will contain a complete bundle of all resources to persist
// in a single transaction
for (IResource next : theResources) {
InstantDt deleted = (InstantDt) next.getResourceMetadata().get(ResourceMetadataKeyEnum.DELETED_AT);
if (deleted != null && deleted.isEmpty() == false) {
// delete this resource
} else {
// create or update this resource
}
public Bundle transaction(@TransactionParam Bundle theInput) {
for (BundleEntry nextEntry : theInput.getEntries()) {
// Process entry
}
// According to the specification, a bundle must be returned. This bundle will contain
// all of the created/updated/deleted resources, including their new/updated identities.
//
// The returned list must be the exact same size as the list of resources
// passed in, and it is acceptable to return the same list instance that was
// passed in.
List<IResource> retVal = new ArrayList<IResource>(theResources);
for (IResource next : theResources) {
/*
* Populate each returned resource with the new ID for that resource,
* including the new version if the server supports versioning.
*/
IdDt newId = new IdDt("Patient", "1", "2");
next.setId(newId);
}
// If wanted, you may optionally also return an OperationOutcome resource
// If present, the OperationOutcome must come first in the returned list.
OperationOutcome oo = new OperationOutcome();
oo.addIssue().setSeverity(IssueSeverityEnum.INFORMATION).setDiagnostics("Completed successfully");
retVal.add(0, oo);
Bundle retVal = new Bundle();
// Populate return bundle
return retVal;
}
//END SNIPPET: transaction

View File

@ -70,7 +70,6 @@ import ca.uhn.fhir.util.TestUtil;
//@formatter:off
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes= {TestDstu2Config.class/*, ca.uhn.fhir.jpa.config.WebsocketDstu2Config.class*/ })
@DirtiesContext
//@formatter:on
public abstract class BaseJpaDstu2Test extends BaseJpaTest {

View File

@ -46,7 +46,6 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.PlatformTransactionManager;
@ -80,7 +79,6 @@ import ca.uhn.fhir.util.TestUtil;
//@formatter:off
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes= {TestDstu3Config.class})
@DirtiesContext
//@formatter:on
public abstract class BaseJpaDstu3Test extends BaseJpaTest {

View File

@ -37,6 +37,7 @@ import ca.uhn.fhir.model.dstu2.resource.ValueSet.CodeSystemConcept;
import ca.uhn.fhir.model.dstu2.resource.ValueSet.ComposeIncludeConcept;
import ca.uhn.fhir.model.primitive.CodeDt;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.parser.LenientErrorHandler;
import ca.uhn.fhir.tinder.TinderStructuresMojo.ValueSetFileDefinition;
import ca.uhn.fhir.tinder.model.ValueSetTm;
import ca.uhn.fhir.tinder.parser.ResourceGeneratorUsingSpreadsheet;
@ -92,6 +93,7 @@ public class ValueSetGenerator {
public void parse() throws FileNotFoundException, IOException {
FhirContext ctx = "dstu".equals(myVersion) ? FhirContext.forDstu1() : FhirContext.forDstu2();
IParser newXmlParser = ctx.newXmlParser();
newXmlParser.setParserErrorHandler(new LenientErrorHandler(false));
ourLog.info("Parsing built-in ValueSets");
String version = myVersion;

View File

@ -1254,6 +1254,22 @@
parameter may be of type List&lt;IResource&gt; or Bundle.
</p>
<p>
In terms of actually implementing the method, unfortunately there is only so much help
HAPI will give you. One might expect HAPI to automatically delegate the individual
operations in the transaction to other methods on the server but at this point it
does not do that. There is a lot that transaction needs to handle
(making everything atomic, replacing placeholder IDs across multiple resources
which may even be circular, handling operations in the right order) and
so far we have not found a way for the framework to do this in a generic way.
</p>
<p>
What it comes down to is the fact that transaction is a tricky thing to implement.
For what it's worth, you could look at our JPA module's "transaction" method in
<a href="https://github.com/jamesagnew/hapi-fhir/blob/master/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3.java">our source repository</a>
to see how we implemented transaction in the JPA server.
</p>
<p>
Example URL to invoke this method:
<br />