diff --git a/.gitignore b/.gitignore
index 2a64f04d425..3f1190ec6c7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@ Servers/
*.log*
nohup.out
.DS_Store
+*.orig
# Vagrant stuff.
.vagrant
diff --git a/examples/src/main/java/example/GenericClientExample.java b/examples/src/main/java/example/GenericClientExample.java
index 1c0b4de6569..135253caf6e 100644
--- a/examples/src/main/java/example/GenericClientExample.java
+++ b/examples/src/main/java/example/GenericClientExample.java
@@ -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
diff --git a/hapi-fhir-android/pom.xml b/hapi-fhir-android/pom.xml
index 5ec4621fa18..906337f3cd4 100644
--- a/hapi-fhir-android/pom.xml
+++ b/hapi-fhir-android/pom.xml
@@ -63,20 +63,22 @@
org.slf4j
slf4j-android
${slf4j_version}
- provided
-
-
+
+ org.slf4j
+ slf4j-api
+ ${slf4j_version}
+ test
+
commons-io
commons-io
${commons_io_version}
+ test
-
+
javax.servlet
javax.servlet-api
@@ -135,11 +137,10 @@
true
-
+
commons-codec:commons-codec
- commons-io:commons-io
ca.uhn.hapi.fhir:hapi-fhir-base
ca.uhn.hapi.fhir:hapi-fhir-structures-dstu
ca.uhn.hapi.fhir:hapi-fhir-structures-dstu2
@@ -148,7 +149,7 @@
javax.xml.stream:stax-api
javax.servlet:javax.servlet-api
org.codehaus.woodstox:stax2-api
-
+
org.apache.commons:*
org.apache.httpcomponents:*
org.glassfish:javax.json
@@ -179,7 +180,7 @@
-
+
DIST
@@ -208,5 +209,5 @@
-
+
diff --git a/hapi-fhir-android/src/main/java/ca/uhn/fhir/android/AndroidLoader.java b/hapi-fhir-android/src/main/java/ca/uhn/fhir/android/AndroidLoader.java
new file mode 100644
index 00000000000..f7e1b685601
--- /dev/null
+++ b/hapi-fhir-android/src/main/java/ca/uhn/fhir/android/AndroidLoader.java
@@ -0,0 +1,14 @@
+package ca.uhn.fhir.android;
+
+import ca.uhn.fhir.context.FhirContext;
+
+public class AndroidLoader {
+
+ public static void main(String[] theArgs) {
+ FhirContext ctx = FhirContext.forDstu2();
+ ctx.newJsonParser();
+ ctx.newXmlParser();
+ ctx.newRestfulGenericClient("");
+ }
+
+}
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java
index d9c574f2675..00765a8ce83 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildChoiceDefinition.java
@@ -85,29 +85,34 @@ public class RuntimeChildChoiceDefinition extends BaseRuntimeDeclaredChildDefini
for (Class extends IBase> next : myChoiceTypes) {
String elementName;
- String alternateElementName = null;
BaseRuntimeElementDefinition> nextDef;
if (IBaseResource.class.isAssignableFrom(next)) {
elementName = getElementName() + StringUtils.capitalize(next.getSimpleName());
- alternateElementName = getElementName() + "Reference";
List> types = new ArrayList>();
types.add((Class extends IBaseResource>) next);
nextDef = new RuntimeResourceReferenceDefinition(elementName, types);
nextDef.sealAndInitialize(theContext, theClassToElementDefinitions);
+
+ myNameToChildDefinition.put(getElementName() + "Reference", nextDef);
+ myNameToChildDefinition.put(getElementName() + "Resource", nextDef);
+
} else {
nextDef = theClassToElementDefinitions.get(next);
elementName = getElementName() + StringUtils.capitalize(nextDef.getName());
}
myNameToChildDefinition.put(elementName, nextDef);
- if (alternateElementName != null) {
- myNameToChildDefinition.put(alternateElementName, nextDef);
- }
if (IBaseResource.class.isAssignableFrom(next)) {
Class extends IBase> refType = theContext.getVersion().getResourceReferenceType();
myDatatypeToElementDefinition.put(refType, nextDef);
- alternateElementName = getElementName() + "Reference";
+
+ String alternateElementName;
+ if (theContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU1)) {
+ alternateElementName = getElementName() + "Resource";
+ } else {
+ alternateElementName = getElementName() + "Reference";
+ }
myDatatypeToElementName.put(refType, alternateElementName);
}
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java
index 0beae3a5f75..95418e9832c 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/RuntimeChildUndeclaredExtensionDefinition.java
@@ -38,6 +38,8 @@ import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildDefinition {
+ private static final String VALUE_REFERENCE = "valueReference";
+ private static final String VALUE_RESOURCE = "valueResource";
private Map> myAttributeNameToDefinition;
private Map, String> myDatatypeToAttributeName;
private Map, BaseRuntimeElementDefinition>> myDatatypeToDefinition;
@@ -53,7 +55,7 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
public List getValues(Object theTarget) {
ExtensionDt target = (ExtensionDt) theTarget;
if (target.getValue() != null) {
- return Collections.singletonList((IBase)target.getValue());
+ return Collections.singletonList((IBase) target.getValue());
}
ArrayList retVal = new ArrayList(target.getUndeclaredExtensions());
return retVal;
@@ -118,10 +120,10 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
for (BaseRuntimeElementDefinition> next : theClassToElementDefinitions.values()) {
if (next instanceof IRuntimeDatatypeDefinition) {
-// if (next.getName().equals("CodeableConcept")) {
-// System.out.println();
-// }
-
+ // if (next.getName().equals("CodeableConcept")) {
+ // System.out.println();
+ // }
+
if (!((IRuntimeDatatypeDefinition) next).isSpecialization()) {
String attrName = createExtensionChildName(next);
datatypeAttributeNameToDefinition.put(attrName, next);
@@ -142,22 +144,29 @@ public class RuntimeChildUndeclaredExtensionDefinition extends BaseRuntimeChildD
}
/*
- * Resource reference - The correct name is 'valueReference', but
- * we allow for valueResource because some incorrect parsers may use this
+ * Resource reference - The correct name is 'valueReference' in DSTU2 and 'valueResource' in DSTU1
*/
- addReferenceBinding(theContext, theClassToElementDefinitions, "valueResource");
- addReferenceBinding(theContext, theClassToElementDefinitions, "valueReference");
+ addReferenceBinding(theContext, theClassToElementDefinitions, VALUE_RESOURCE);
+ addReferenceBinding(theContext, theClassToElementDefinitions, VALUE_REFERENCE);
}
private void addReferenceBinding(FhirContext theContext, Map, BaseRuntimeElementDefinition>> theClassToElementDefinitions, String value) {
- myDatatypeToAttributeName.put(theContext.getVersion().getResourceReferenceType(), value);
List> types = new ArrayList>();
types.add(IBaseResource.class);
RuntimeResourceReferenceDefinition def = new RuntimeResourceReferenceDefinition(value, types);
def.sealAndInitialize(theContext, theClassToElementDefinitions);
+
myAttributeNameToDefinition.put(value, def);
- myDatatypeToDefinition.put(BaseResourceReferenceDt.class, def);
- myDatatypeToDefinition.put(theContext.getVersion().getResourceReferenceType(), def);
+ /*
+ * Resource reference - The correct name is 'valueReference' in DSTU2 and 'valueResource' in DSTU1
+ */
+ boolean dstu1 = (theContext.getVersion().getVersion().equals(FhirVersionEnum.DSTU1));
+ if ((dstu1 && (value != VALUE_REFERENCE)) || (!dstu1 && (value != VALUE_RESOURCE))) {
+ myDatatypeToAttributeName.put(theContext.getVersion().getResourceReferenceType(), value);
+ myDatatypeToDefinition.put(BaseResourceReferenceDt.class, def);
+ myDatatypeToDefinition.put(theContext.getVersion().getResourceReferenceType(), def);
+ }
+
}
public static String createExtensionChildName(BaseRuntimeElementDefinition> next) {
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Bundle.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Bundle.java
index a57b1f79c96..285307e5adc 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Bundle.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/Bundle.java
@@ -293,6 +293,7 @@ public class Bundle extends BaseBundle /* implements IElement */{
return myLinkSelf;
}
+ /*
public InstantDt getPublished() {
InstantDt retVal = (InstantDt) getResourceMetadata().get(ResourceMetadataKeyEnum.PUBLISHED);
if (retVal == null) {
@@ -301,6 +302,7 @@ public class Bundle extends BaseBundle /* implements IElement */{
}
return retVal;
}
+ */
/**
* Retrieves a resource from a bundle given its logical ID.
@@ -394,9 +396,11 @@ public class Bundle extends BaseBundle /* implements IElement */{
myCategories = theCategories;
}
+ /*
public void setPublished(InstantDt thePublished) {
getResourceMetadata().put(ResourceMetadataKeyEnum.PUBLISHED, thePublished);
}
+ /*
public void setType(BoundCodeDt theType) {
myType = theType;
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java
index e8e7917b247..212e6234e07 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnum.java
@@ -20,7 +20,7 @@ package ca.uhn.fhir.model.api;
* #L%
*/
-import static org.apache.commons.lang3.StringUtils.isNotBlank;
+import static org.apache.commons.lang3.StringUtils.*;
import java.util.ArrayList;
import java.util.Collections;
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java
index a5ac3b2a5ca..d446148bf6b 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java
@@ -95,19 +95,20 @@ import ca.uhn.fhir.model.base.composite.BaseCodingDt;
import ca.uhn.fhir.model.base.composite.BaseContainedDt;
import ca.uhn.fhir.model.base.composite.BaseNarrativeDt;
import ca.uhn.fhir.model.base.composite.BaseResourceReferenceDt;
+import ca.uhn.fhir.model.primitive.CodeDt;
import ca.uhn.fhir.model.primitive.DecimalDt;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.model.primitive.IntegerDt;
import ca.uhn.fhir.model.primitive.StringDt;
+import ca.uhn.fhir.model.primitive.UriDt;
import ca.uhn.fhir.model.primitive.XhtmlDt;
import ca.uhn.fhir.narrative.INarrativeGenerator;
import ca.uhn.fhir.util.ElementUtil;
import ca.uhn.fhir.util.UrlUtil;
/**
- * This class is the FHIR JSON parser/encoder. Users should not interact with this class directly, but should use
- * {@link FhirContext#newJsonParser()} to get an instance.
+ * This class is the FHIR JSON parser/encoder. Users should not interact with this class directly, but should use {@link FhirContext#newJsonParser()} to get an instance.
*/
public class JsonParser extends BaseParser implements IParser {
@@ -196,7 +197,6 @@ public class JsonParser extends BaseParser implements IParser {
writeTagWithTextNode(eventWriter, "title", theBundle.getTitle());
writeTagWithTextNode(eventWriter, "id", theBundle.getBundleId());
writeOptionalTagWithTextNode(eventWriter, "updated", theBundle.getUpdated());
- writeOptionalTagWithTextNode(eventWriter, "published", theBundle.getPublished());
boolean linkStarted = false;
linkStarted = writeAtomLinkInDstu1Format(eventWriter, "self", theBundle.getLinkSelf(), linkStarted);
@@ -353,7 +353,8 @@ public class JsonParser extends BaseParser implements IParser {
theEventWriter.writeEnd();
}
- private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonGenerator theWriter, IBase theNextValue, BaseRuntimeElementDefinition> theChildDef, String theChildName, boolean theIsSubElementWithinResource) throws IOException {
+ private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonGenerator theWriter, IBase theNextValue,
+ BaseRuntimeElementDefinition> theChildDef, String theChildName, boolean theContainedResource) throws IOException {
switch (theChildDef.getChildType()) {
case ID_DATATYPE: {
@@ -414,7 +415,7 @@ public class JsonParser extends BaseParser implements IParser {
if (theNextValue instanceof IBaseExtension) {
theWriter.write("url", ((IBaseExtension>) theNextValue).getUrl());
}
- encodeCompositeElementToStreamWriter(theResDef, theResource, theNextValue, theWriter, childCompositeDef, theIsSubElementWithinResource);
+ encodeCompositeElementToStreamWriter(theResDef, theResource, theNextValue, theWriter, childCompositeDef, theContainedResource);
theWriter.writeEnd();
break;
}
@@ -488,7 +489,8 @@ public class JsonParser extends BaseParser implements IParser {
}
- private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theNextValue, JsonGenerator theEventWriter, List extends BaseRuntimeChildDefinition> theChildren, boolean theIsSubElementWithinResource) throws IOException {
+ private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theNextValue, JsonGenerator theEventWriter,
+ List extends BaseRuntimeChildDefinition> theChildren, boolean theContainedResource) throws IOException {
for (BaseRuntimeChildDefinition nextChild : theChildren) {
if (nextChild.getElementName().equals("extension") || nextChild.getElementName().equals("modifierExtension")) {
continue;
@@ -507,15 +509,15 @@ public class JsonParser extends BaseParser implements IParser {
RuntimeChildNarrativeDefinition child = (RuntimeChildNarrativeDefinition) nextChild;
String childName = nextChild.getChildNameByDatatype(child.getDatatype());
BaseRuntimeElementDefinition> type = child.getChildByName(childName);
- encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, narr, type, childName, theIsSubElementWithinResource);
+ encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, narr, type, childName, theContainedResource);
continue;
}
}
} else if (nextChild instanceof RuntimeChildContainedResources) {
- if (theIsSubElementWithinResource == false) {
+ if (theContainedResource == false) {
String childName = nextChild.getValidChildNames().iterator().next();
BaseRuntimeElementDefinition> child = nextChild.getChildByName(childName);
- encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, null, child, childName, theIsSubElementWithinResource);
+ encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, null, child, childName, theContainedResource);
}
continue;
}
@@ -535,7 +537,7 @@ public class JsonParser extends BaseParser implements IParser {
for (IBase nextValue : values) {
if (nextValue == null || nextValue.isEmpty()) {
if (nextValue instanceof BaseContainedDt) {
- if (theIsSubElementWithinResource || getContainedResources().isEmpty()) {
+ if (theContainedResource || getContainedResources().isEmpty()) {
continue;
}
} else {
@@ -551,7 +553,7 @@ public class JsonParser extends BaseParser implements IParser {
}
boolean primitive = childDef.getChildType() == ChildTypeEnum.PRIMITIVE_DATATYPE;
- if ((childDef.getChildType() == ChildTypeEnum.CONTAINED_RESOURCES||childDef.getChildType()==ChildTypeEnum.CONTAINED_RESOURCE_LIST) && theIsSubElementWithinResource) {
+ if ((childDef.getChildType() == ChildTypeEnum.CONTAINED_RESOURCES||childDef.getChildType()==ChildTypeEnum.CONTAINED_RESOURCE_LIST) && theContainedResource) {
continue;
}
@@ -573,15 +575,15 @@ public class JsonParser extends BaseParser implements IParser {
if (nextChild.getMax() > 1 || nextChild.getMax() == Child.MAX_UNLIMITED) {
theEventWriter.writeStartArray(childName);
inArray = true;
- encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, null, theIsSubElementWithinResource);
- } else if (nextChild instanceof RuntimeChildNarrativeDefinition && theIsSubElementWithinResource) {
+ encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, null, theContainedResource);
+ } else if (nextChild instanceof RuntimeChildNarrativeDefinition && theContainedResource) {
// suppress narratives from contained resources
} else {
- encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, childName, theIsSubElementWithinResource);
+ encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, childName, theContainedResource);
}
currentChildName = childName;
} else {
- encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, null, theIsSubElementWithinResource);
+ encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, null, theContainedResource);
}
if (primitive) {
@@ -655,13 +657,15 @@ public class JsonParser extends BaseParser implements IParser {
}
}
- private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theNextValue, JsonGenerator theEventWriter, BaseRuntimeElementCompositeDefinition> resDef, boolean theIsSubElementWithinResource) throws IOException, DataFormatException {
+ private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, IBase theNextValue, JsonGenerator theEventWriter,
+ BaseRuntimeElementCompositeDefinition> resDef, boolean theContainedResource) throws IOException, DataFormatException {
extractAndWriteExtensionsAsDirectChild(theNextValue, theEventWriter, resDef, theResDef, theResource, null);
- encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theNextValue, theEventWriter, resDef.getExtensions(), theIsSubElementWithinResource);
- encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theNextValue, theEventWriter, resDef.getChildren(), theIsSubElementWithinResource);
+ encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theNextValue, theEventWriter, resDef.getExtensions(), theContainedResource);
+ encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theNextValue, theEventWriter, resDef.getChildren(), theContainedResource);
}
- private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonGenerator theEventWriter, String theObjectNameOrNull, boolean theContainedResource) throws IOException {
+ private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDef, IBaseResource theResource, JsonGenerator theEventWriter, String theObjectNameOrNull, boolean theContainedResource)
+ throws IOException {
String resourceId = null;
if (theResource instanceof IResource) {
IResource res = (IResource) theResource;
@@ -702,20 +706,22 @@ public class JsonParser extends BaseParser implements IParser {
if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1) && theResource instanceof IResource) {
IResource resource = (IResource) theResource;
+ // Object securityLabelRawObj =
+ List securityLabels = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.SECURITY_LABELS);
+ List profiles = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.PROFILES);
+ TagList tags = ResourceMetadataKeyEnum.TAG_LIST.get(resource);
InstantDt updated = (InstantDt) resource.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED);
IdDt resourceId = resource.getId();
String versionIdPart = resourceId.getVersionIdPart();
if (isBlank(versionIdPart)) {
versionIdPart = ResourceMetadataKeyEnum.VERSION.get(resource);
}
- List securityLabels = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.SECURITY_LABELS);
- List profiles = extractMetadataListNotNull(resource, ResourceMetadataKeyEnum.PROFILES);
- TagList tags = ResourceMetadataKeyEnum.TAG_LIST.get(resource);
+
if (ElementUtil.isEmpty(versionIdPart, updated, securityLabels, profiles) == false) {
theEventWriter.writeStartObject("meta");
- writeOptionalTagWithTextNode(theEventWriter, "versionId", resource.getId().getVersionIdPart());
- writeOptionalTagWithTextNode(theEventWriter, "lastUpdated", ResourceMetadataKeyEnum.UPDATED.get(resource));
+ writeOptionalTagWithTextNode(theEventWriter, "versionId", versionIdPart);
+ writeOptionalTagWithTextNode(theEventWriter, "lastUpdated", updated);
if (profiles != null && profiles.isEmpty() == false) {
theEventWriter.writeStartArray("profile");
@@ -1175,31 +1181,30 @@ public class JsonParser extends BaseParser implements IParser {
}
}
- private void parseExtensionInDstu2Style(boolean theModifier, ParserState> theState, String theParentExtensionUrl, String theExtensionUrl, JsonArray theValues) {
- String extUrl = UrlUtil.constructAbsoluteUrl(theParentExtensionUrl, theExtensionUrl);
- theState.enteringNewElementExtension(null, extUrl, theModifier);
-
- for (int extIdx = 0; extIdx < theValues.size(); extIdx++) {
- JsonObject nextExt = theValues.getJsonObject(extIdx);
- for (String nextKey : nextExt.keySet()) {
- // if (nextKey.startsWith("value") && nextKey.length() > 5 &&
- // myContext.getRuntimeChildUndeclaredExtensionDefinition().getChildByName(nextKey) != null) {
- JsonValue jsonVal = nextExt.get(nextKey);
- if (jsonVal.getValueType() == ValueType.ARRAY) {
- /*
- * Extension children which are arrays are sub-extensions. Any other value type should be treated as
- * a value.
- */
- JsonArray arrayValue = (JsonArray) jsonVal;
- parseExtensionInDstu2Style(theModifier, theState, extUrl, nextKey, arrayValue);
- } else {
- parseChildren(theState, nextKey, jsonVal, null, null);
- }
- }
- }
-
- theState.endingElement();
- }
+ // private void parseExtensionInDstu2Style(boolean theModifier, ParserState> theState, String theParentExtensionUrl, String theExtensionUrl, JsonArray theValues) {
+ // String extUrl = UrlUtil.constructAbsoluteUrl(theParentExtensionUrl, theExtensionUrl);
+ // theState.enteringNewElementExtension(null, extUrl, theModifier);
+ //
+ // for (int extIdx = 0; extIdx < theValues.size(); extIdx++) {
+ // JsonObject nextExt = theValues.getJsonObject(extIdx);
+ // for (String nextKey : nextExt.keySet()) {
+ // // if (nextKey.startsWith("value") && nextKey.length() > 5 &&
+ // // myContext.getRuntimeChildUndeclaredExtensionDefinition().getChildByName(nextKey) != null) {
+ // JsonValue jsonVal = nextExt.get(nextKey);
+ // if (jsonVal.getValueType() == ValueType.ARRAY) {
+ // /*
+ // * Extension children which are arrays are sub-extensions. Any other value type should be treated as a value.
+ // */
+ // JsonArray arrayValue = (JsonArray) jsonVal;
+ // parseExtensionInDstu2Style(theModifier, theState, extUrl, nextKey, arrayValue);
+ // } else {
+ // parseChildren(theState, nextKey, jsonVal, null, null);
+ // }
+ // }
+ // }
+ //
+ // theState.endingElement();
+ // }
@Override
public T doParseResource(Class theResourceType, Reader theReader) {
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java
index 9e6fd5ef497..52d365804b8 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java
@@ -683,8 +683,6 @@ class ParserState {
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
if ("entry".equals(theLocalPart) && verifyNamespace(XmlParser.ATOM_NS, theNamespaceURI)) {
push(new AtomEntryState(myInstance, myResourceType));
- } else if (theLocalPart.equals("published")) {
- push(new AtomPrimitiveState(myInstance.getPublished()));
} else if (theLocalPart.equals("title")) {
push(new AtomPrimitiveState(myInstance.getTitle()));
} else if ("id".equals(theLocalPart)) {
@@ -900,7 +898,7 @@ class ParserState {
if (myInstance instanceof IIdentifiableElement) {
((IIdentifiableElement) myInstance).setElementSpecificId((theValue));
} else {
- ((IResource)myInstance).setId(new IdDt(theValue));
+ ((IResource) myInstance).setId(new IdDt(theValue));
}
} else if ("contentType".equals(theName)) {
myInstance.setContentType(theValue);
@@ -1393,7 +1391,7 @@ class ParserState {
res.getId().setValue('#' + res.getId().getIdPart());
}
}
-
+
IBaseResource preResCurrentElement = getPreResourceState().getCurrentElement();
RuntimeResourceDefinition def = myContext.getResourceDefinition(preResCurrentElement);
def.getChildByName("contained").getMutator().addValue(preResCurrentElement, res);
@@ -1496,6 +1494,7 @@ class ParserState {
private class ElementCompositeState extends BaseState {
private BaseRuntimeElementCompositeDefinition> myDefinition;
+
public BaseRuntimeElementCompositeDefinition> getDefinition() {
return myDefinition;
}
@@ -1623,8 +1622,8 @@ class ParserState {
ParserState.PreResourceStateHapi state = new PreResourceStateHapi(myInstance, child.getMutator(), null);
push(state);
} else {
- ParserState.PreResourceStateHl7Org state = new PreResourceStateHl7Org(myInstance, child.getMutator(), null);
- push(state);
+ ParserState.PreResourceStateHl7Org state = new PreResourceStateHl7Org(myInstance, child.getMutator(), null);
+ push(state);
}
return;
}
@@ -1729,10 +1728,9 @@ class ParserState {
}
-
private class SecurityLabelElementStateHapi extends ElementCompositeState {
- public SecurityLabelElementStateHapi(ParserState.PreResourceState thePreResourceState,BaseRuntimeElementCompositeDefinition> theDef, BaseCodingDt codingDt) {
+ public SecurityLabelElementStateHapi(ParserState.PreResourceState thePreResourceState, BaseRuntimeElementCompositeDefinition> theDef, BaseCodingDt codingDt) {
super(thePreResourceState, theDef, codingDt);
}
@@ -1741,7 +1739,6 @@ class ParserState {
pop();
}
-
}
private class MetaElementState extends BaseState {
@@ -1761,8 +1758,8 @@ class ParserState {
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
if (theLocalPart.equals("versionId")) {
push(new MetaVersionElementState(getPreResourceState(), myMap));
-// } else if (theLocalPart.equals("profile")) {
-//
+ // } else if (theLocalPart.equals("profile")) {
+ //
} else if (theLocalPart.equals("lastUpdated")) {
InstantDt updated = new InstantDt();
push(new PrimitiveState(getPreResourceState(), updated));
@@ -1774,7 +1771,7 @@ class ParserState {
securityLabels = new ArrayList();
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);
@@ -1903,33 +1900,30 @@ class ParserState {
if (myEntry == null) {
myObject = (T) getCurrentElement();
}
-
+
IResource nextResource = (IResource) getCurrentElement();
String version = ResourceMetadataKeyEnum.VERSION.get(nextResource);
String resourceName = myContext.getResourceDefinition(nextResource).getName();
String bundleIdPart = nextResource.getId().getIdPart();
if (isNotBlank(bundleIdPart)) {
-// if (isNotBlank(entryBaseUrl)) {
-// nextResource.setId(new IdDt(entryBaseUrl, resourceName, bundleIdPart, version));
-// } else {
- nextResource.setId(new IdDt(null, resourceName, bundleIdPart, version));
-// }
+ // if (isNotBlank(entryBaseUrl)) {
+ // nextResource.setId(new IdDt(entryBaseUrl, resourceName, bundleIdPart, version));
+ // } else {
+ nextResource.setId(new IdDt(null, resourceName, bundleIdPart, version));
+ // }
}
-
}
-
-
@Override
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
super.enteringNewElement(theNamespaceURI, theLocalPart);
if (myEntry != null) {
myEntry.setResource((IResource) getCurrentElement());
}
- if (myMutator != null) {
- myMutator.addValue(myTarget, getCurrentElement());
- }
+ if (myMutator != null) {
+ myMutator.addValue(myTarget, getCurrentElement());
+ }
}
}
@@ -1956,13 +1950,15 @@ class ParserState {
if (myTarget == null) {
myObject = (T) getCurrentElement();
}
-
+
if (getCurrentElement() instanceof IDomainResource) {
IDomainResource elem = (IDomainResource) getCurrentElement();
String resourceName = myContext.getResourceDefinition(elem).getName();
String versionId = elem.getMeta().getVersionId();
- if (StringUtils.isNotBlank(versionId)) {
- elem.getIdElement().setValue(resourceName + "/" + elem.getId().getIdPart() + "/_history/" + versionId);
+ if (StringUtils.isBlank(elem.getId().getIdPart())) {
+ // Resource has no ID
+ } else if (StringUtils.isNotBlank(versionId)) {
+ elem.getIdElement().setValue(resourceName + "/" + elem.getId().getIdPart() + "/_history/" + versionId);
} else {
elem.getIdElement().setValue(resourceName + "/" + elem.getId().getIdPart());
}
@@ -2063,12 +2059,12 @@ class ParserState {
@Override
public void wereBack() {
final boolean bundle = "Bundle".equals(myContext.getResourceDefinition(myInstance).getName());
-
+
FhirTerser terser = myContext.newTerser();
terser.visit(myInstance, new IModelVisitor() {
@Override
- public void acceptElement(IBase theElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition) {
+ public void acceptElement(IBase theElement, List thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition) {
if (theElement instanceof BaseResourceReferenceDt) {
BaseResourceReferenceDt nextRef = (BaseResourceReferenceDt) theElement;
String ref = nextRef.getReference().getValue();
@@ -2082,7 +2078,7 @@ class ParserState {
}
}
}
- }else if (theElement instanceof IReference) {
+ } else if (theElement instanceof IReference) {
IReference nextRef = (IReference) theElement;
String ref = nextRef.getReference().getValue();
if (isNotBlank(ref)) {
@@ -2099,8 +2095,8 @@ class ParserState {
}
@Override
- public void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition, ExtensionDt theNextExt) {
- acceptElement(theNextExt.getValue(), null, null);
+ public void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, List thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition, ExtensionDt theNextExt) {
+ acceptElement(theNextExt.getValue(), null, null, null);
}
});
@@ -2132,7 +2128,7 @@ class ParserState {
}
}
-
+
}
}
@@ -2547,13 +2543,12 @@ class ParserState {
// TODO: this is not very efficient
String value = getDt().getValueAsString();
myHl7OrgDatatype.setValueAsString(value);
-
+
super.doPop();
}
-
-
+
}
-
+
private class XhtmlState extends BaseState {
private int myDepth;
private XhtmlDt myDt;
@@ -2583,7 +2578,7 @@ class ParserState {
protected void doPop() {
pop();
}
-
+
@Override
public void endingElement() throws DataFormatException {
if (myJsonMode) {
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java
index e513f6035f9..7f304958395 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java
@@ -271,7 +271,6 @@ public class XmlParser extends BaseParser implements IParser {
}
writeOptionalTagWithTextNode(eventWriter, "updated", theBundle.getUpdated());
- writeOptionalTagWithTextNode(eventWriter, "published", theBundle.getPublished());
if (StringUtils.isNotBlank(theBundle.getAuthorName().getValue())) {
eventWriter.writeStartElement("author");
@@ -804,6 +803,7 @@ public class XmlParser extends BaseParser implements IParser {
if (updated != null) {
writeOptionalTagWithValue(theEventWriter, "lastUpdated", updated.getValueAsString());
}
+
for (IdDt profile : profiles) {
theEventWriter.writeStartElement("profile");
theEventWriter.writeAttribute("value", profile.getValue());
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/MethodOutcome.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/MethodOutcome.java
index 63e58755f95..70cf63a0f84 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/MethodOutcome.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/MethodOutcome.java
@@ -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() {
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java
index c2a595f64b6..f3d0a392719 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/client/GenericClient.java
@@ -20,8 +20,7 @@ package ca.uhn.fhir.rest.client;
* #L%
*/
-import static org.apache.commons.lang3.StringUtils.isBlank;
-import static org.apache.commons.lang3.StringUtils.isNotBlank;
+import static org.apache.commons.lang3.StringUtils.*;
import java.io.IOException;
import java.io.Reader;
@@ -1413,7 +1412,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
+ "the bundle return type for the client by adding \".returnBundle(org.hl7.fhir.instance.model.Bundle.class)\" to your search method call before the \".execute()\" method");
}
- IClientResponseHandler binding;
+ IClientResponseHandler extends IBase> binding;
if (myReturnBundleType != null) {
binding = new ResourceResponseHandler(myReturnBundleType, null);
} else {
@@ -1581,8 +1580,8 @@ public class GenericClient extends BaseClient implements IGenericClient {
myBundle = theResources;
}
- public TransactionExecutable(List theResources) {
- myResources = theResources;
+ public TransactionExecutable(List extends IBaseResource> theResources) {
+ myResources = new ArrayList(theResources);
}
public TransactionExecutable(IBaseBundle theBundle) {
@@ -1619,7 +1618,7 @@ public class GenericClient extends BaseClient implements IGenericClient {
}
@Override
- public ITransactionTyped> withResources(List theResources) {
+ public ITransactionTyped> withResources(List extends IBaseResource> theResources) {
Validate.notNull(theResources, "theResources must not be null");
return new TransactionExecutable>(theResources);
}
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/ITransaction.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/ITransaction.java
index cbed783919a..4ffa1ef4dfe 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/ITransaction.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/ITransaction.java
@@ -32,7 +32,7 @@ public interface ITransaction {
/**
* Use a list of resources as the transaction input
*/
- ITransactionTyped> withResources(List theResources);
+ ITransactionTyped> withResources(List extends IBaseResource> theResources);
/**
* Use a DSTU1 Bundle (Atom) as the transaction input
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseResourceReturningMethodBinding.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseResourceReturningMethodBinding.java
index aa86fdc744d..b1580912fd2 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseResourceReturningMethodBinding.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseResourceReturningMethodBinding.java
@@ -279,7 +279,7 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding includes = getRequestIncludesFromParams(params);
@@ -312,7 +312,7 @@ abstract class BaseResourceReturningMethodBinding extends BaseMethodBinding resourceType) {
- this.myDeclaredResourceType = resourceType;
- }
-
@Override
- public String toString() {
- return getMethod().toString();
+ protected boolean isAddContentLocationHeader() {
+ return false;
}
private List processWhitelistAndBlacklist(List theQualifiedNames, Set theQualifierWhitelist, Set theQualifierBlacklist) {
@@ -313,6 +314,15 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding {
return retVal;
}
+ public void setResourceType(Class extends IResource> resourceType) {
+ this.myDeclaredResourceType = resourceType;
+ }
+
+ @Override
+ public String toString() {
+ return getMethod().toString();
+ }
+
public static BaseHttpClientInvocation createSearchInvocation(FhirContext theContext, String theResourceName, Map> theParameters, IdDt theId, String theCompartmentName,
SearchStyleEnum theSearchStyle) {
SearchStyleEnum searchStyle = theSearchStyle;
@@ -473,9 +483,4 @@ public class SearchMethodBinding extends BaseResourceReturningMethodBinding {
}
- @Override
- protected BundleTypeEnum getResponseBundleType() {
- return BundleTypeEnum.SEARCHSET;
- }
-
}
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Dstu1BundleFactory.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Dstu1BundleFactory.java
index f27e6c5bc39..9bd60ec57c6 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Dstu1BundleFactory.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Dstu1BundleFactory.java
@@ -203,8 +203,6 @@ public class Dstu1BundleFactory implements IVersionSpecificBundleFactory {
addResourcesToBundle(new ArrayList(resourceList), theBundleType, theServerBase, theServer.getBundleInclusionRule(), theIncludes);
addRootPropertiesToBundle(null, theServerBase, theCompleteUrl, theResult.size(), theBundleType);
- myBundle.setPublished(theResult.getPublished());
-
if (theServer.getPagingProvider() != null) {
int limit;
limit = theLimit != null ? theLimit : theServer.getPagingProvider().getDefaultPageSize();
@@ -232,10 +230,6 @@ public class Dstu1BundleFactory implements IVersionSpecificBundleFactory {
myBundle.getBundleId().setValue(UUID.randomUUID().toString());
}
- if (myBundle.getPublished().isEmpty()) {
- myBundle.getPublished().setToCurrentTimeInLocalTimeZone();
- }
-
if (myBundle.getLinkBase().isEmpty()) {
myBundle.getLinkBase().setValue(theServerBase);
}
@@ -269,7 +263,6 @@ public class Dstu1BundleFactory implements IVersionSpecificBundleFactory {
myBundle.getAuthorName().setValue(theAuthor);
myBundle.getBundleId().setValue(UUID.randomUUID().toString());
- myBundle.getPublished().setToCurrentTimeInLocalTimeZone();
myBundle.getLinkBase().setValue(theServerBase);
myBundle.getLinkSelf().setValue(theCompleteUrl);
myBundle.getType().setValueAsEnum(theBundleType);
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/IncomingRequestAddressStrategy.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/IncomingRequestAddressStrategy.java
index 6bcdacd5b22..793e80e23bd 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/IncomingRequestAddressStrategy.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/IncomingRequestAddressStrategy.java
@@ -30,10 +30,19 @@ import org.apache.commons.lang3.StringUtils;
*/
public class IncomingRequestAddressStrategy implements IServerAddressStrategy {
+ private String myServletPath;
+
@Override
public String determineServerBase(ServletContext theServletContext, HttpServletRequest theRequest) {
String requestFullPath = StringUtils.defaultString(theRequest.getRequestURI());
- String servletPath = StringUtils.defaultString(theRequest.getServletPath());
+
+ String servletPath;
+ if (myServletPath != null) {
+ servletPath = myServletPath;
+ } else {
+ servletPath = StringUtils.defaultString(theRequest.getServletPath());
+ }
+
StringBuffer requestUrl = theRequest.getRequestURL();
String servletContextPath = "";
if (theServletContext != null) {
@@ -48,7 +57,9 @@ public class IncomingRequestAddressStrategy implements IServerAddressStrategy {
}
int startOfPath = requestUrl.indexOf("//");
- if (startOfPath != -1 && (startOfPath + 2) < requestUrl.length()) {
+ int requestUrlLength = requestUrl.length();
+
+ if (startOfPath != -1 && (startOfPath + 2) < requestUrlLength) {
startOfPath = requestUrl.indexOf("/", startOfPath + 2);
}
if (startOfPath == -1) {
@@ -56,9 +67,9 @@ public class IncomingRequestAddressStrategy implements IServerAddressStrategy {
}
int contextIndex;
- if (servletPath.length() == 0) {
+ if (servletPath.length() == 0 || servletPath.equals("/")) {
if (requestPath.length() == 0) {
- contextIndex = requestUrl.length();
+ contextIndex = requestUrlLength;
} else {
contextIndex = requestUrl.indexOf(requestPath, startOfPath);
}
@@ -68,8 +79,30 @@ public class IncomingRequestAddressStrategy implements IServerAddressStrategy {
String fhirServerBase;
int length = contextIndex + servletPath.length();
+ if (length > requestUrlLength) {
+ length = requestUrlLength;
+ }
fhirServerBase = requestUrl.substring(0, length);
return fhirServerBase;
}
+ /**
+ * If set to a non-null value (default is null
), this address strategy assumes that the FHIR endpoint is deployed to the given servlet path within the context. This is useful in some
+ * deployments where it isn't obvious to the servlet which part of the path is actually the root path to reach the servlet.
+ *
+ * Example values could be:
+ *
+ * - null
+ * - /
+ * - /base
+ *
+ *
+ *
+ * Wildcards are not supported!
+ *
+ */
+ public void setServletPath(String theServletPath) {
+ myServletPath = theServletPath;
+ }
+
}
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java
index 557a2d10b3e..5580492d90f 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java
@@ -490,7 +490,7 @@ public class RestfulServer extends HttpServlet {
return;
}
}
- RestfulServerUtils.streamResponseAsResource(this, theResponse, (IResource) resBundle, responseEncoding, prettyPrint, requestIsBrowser, narrativeMode, Constants.STATUS_HTTP_200_OK, theRequest.isRespondGzip(), theRequest.getFhirServerBase());
+ RestfulServerUtils.streamResponseAsResource(this, theResponse, (IResource) resBundle, responseEncoding, prettyPrint, requestIsBrowser, narrativeMode, Constants.STATUS_HTTP_200_OK, theRequest.isRespondGzip(), theRequest.getFhirServerBase(), false);
}
}
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java
index 26daa5255cd..87df3587f3d 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServerUtils.java
@@ -76,10 +76,10 @@ public class RestfulServerUtils {
}
public static void streamResponseAsResource(RestfulServer theServer, HttpServletResponse theHttpResponse, IBaseResource theResource, EncodingEnum theResponseEncoding, boolean thePrettyPrint,
- boolean theRequestIsBrowser, RestfulServer.NarrativeModeEnum theNarrativeMode, int stausCode, boolean theRespondGzip, String theServerBase) throws IOException {
+ boolean theRequestIsBrowser, RestfulServer.NarrativeModeEnum theNarrativeMode, int stausCode, boolean theRespondGzip, String theServerBase, boolean theAddContentLocationHeader) throws IOException {
theHttpResponse.setStatus(stausCode);
- if (theResource.getId() != null && theResource.getId().hasIdPart() && isNotBlank(theServerBase)) {
+ if (theAddContentLocationHeader && theResource.getId() != null && theResource.getId().hasIdPart() && isNotBlank(theServerBase)) {
String resName = theServer.getFhirContext().getResourceDefinition(theResource).getName();
IIdType fullId = theResource.getId().withServerBase(theServerBase, resName);
theHttpResponse.addHeader(Constants.HEADER_CONTENT_LOCATION, fullId.getValue());
@@ -413,12 +413,12 @@ public class RestfulServerUtils {
}
}
- public static void streamResponseAsResource(RestfulServer theServer, HttpServletResponse theHttpResponse, IBaseResource theResource, EncodingEnum theResponseEncoding, boolean thePrettyPrint,
- boolean theRequestIsBrowser, RestfulServer.NarrativeModeEnum theNarrativeMode, boolean theRespondGzip, String theServerBase) throws IOException {
- int stausCode = 200;
- RestfulServerUtils.streamResponseAsResource(theServer, theHttpResponse, theResource, theResponseEncoding, thePrettyPrint, theRequestIsBrowser, theNarrativeMode, stausCode, theRespondGzip,
- theServerBase);
- }
+// public static void streamResponseAsResource(RestfulServer theServer, HttpServletResponse theHttpResponse, IResource theResource, EncodingEnum theResponseEncoding, boolean thePrettyPrint,
+// boolean theRequestIsBrowser, RestfulServer.NarrativeModeEnum theNarrativeMode, boolean theRespondGzip, String theServerBase) throws IOException {
+// int stausCode = 200;
+// RestfulServerUtils.streamResponseAsResource(theServer, theHttpResponse, theResource, theResponseEncoding, thePrettyPrint, theRequestIsBrowser, theNarrativeMode, stausCode, theRespondGzip,
+// theServerBase);
+// }
public static void validateResourceListNotNull(List extends IBaseResource> theResourceList) {
if (theResourceList == null) {
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptor.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptor.java
index a8987477d3c..8737104ff11 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptor.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptor.java
@@ -129,7 +129,7 @@ public class ExceptionHandlingInterceptor extends InterceptorAdapter {
boolean requestIsBrowser = RestfulServer.requestIsBrowser(theRequest);
String fhirServerBase = ((Request) theRequestDetails).getFhirServerBase();
RestfulServerUtils.streamResponseAsResource(theRequestDetails.getServer(), theResponse, oo, RestfulServerUtils.determineResponseEncodingNoDefault(theRequest), true, requestIsBrowser,
- NarrativeModeEnum.NORMAL, statusCode, false, fhirServerBase);
+ NarrativeModeEnum.NORMAL, statusCode, false, fhirServerBase, false);
// theResponse.setStatus(statusCode);
// theRequestDetails.getServer().addHeadersToResponse(theResponse);
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptor.java.orig b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptor.java.orig
deleted file mode 100644
index 9e81a04ae44..00000000000
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptor.java.orig
+++ /dev/null
@@ -1,172 +0,0 @@
-package ca.uhn.fhir.rest.server.interceptor;
-
-/*
- * #%L
- * HAPI FHIR - Core Library
- * %%
- * Copyright (C) 2014 - 2015 University Health Network
- * %%
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * #L%
- */
-
-import static org.apache.commons.lang3.StringUtils.isNotBlank;
-
-import java.io.IOException;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.lang3.exception.ExceptionUtils;
-
-import ca.uhn.fhir.context.FhirContext;
-import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
-import ca.uhn.fhir.model.base.resource.BaseOperationOutcome.BaseIssue;
-import ca.uhn.fhir.rest.method.Request;
-import ca.uhn.fhir.rest.method.RequestDetails;
-import ca.uhn.fhir.rest.server.Constants;
-import ca.uhn.fhir.rest.server.RestfulServer;
-import ca.uhn.fhir.rest.server.RestfulServer.NarrativeModeEnum;
-import ca.uhn.fhir.rest.server.RestfulServerUtils;
-import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
-import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
-
-public class ExceptionHandlingInterceptor extends InterceptorAdapter {
-
- private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExceptionHandlingInterceptor.class);
- private Class>[] myReturnStackTracesForExceptionTypes;
-
- /**
- * If any server methods throw an exception which extends any of the given exception types, the exception
- * stack trace will be returned to the user. This can be useful for helping to diagnose issues, but may
- * not be desirable for production situations.
- *
- * @param theExceptionTypes The exception types for which to return the stack trace to the user.
- * @return Returns an instance of this interceptor, to allow for easy method chaining.
- */
- public ExceptionHandlingInterceptor setReturnStackTracesForExceptionTypes(Class>... theExceptionTypes) {
- myReturnStackTracesForExceptionTypes = theExceptionTypes;
- return this;
- }
-
- @Override
-<<<<<<< HEAD
- public boolean handleException(RequestDetails theRequestDetails, Throwable theException, HttpServletRequest theRequest, HttpServletResponse theResponse) throws ServletException, IOException {
-=======
- public boolean handleException(RestfulServer theRestfulServer, RequestDetails theRequestDetails, Throwable theException, HttpServletRequest theRequest, HttpServletResponse theResponse) throws ServletException, IOException {
- ourLog.error("AA", theException);
->>>>>>> 5956ab75fd9186ccc8b9836b60bc421b19d3d288
- BaseOperationOutcome oo = null;
- int statusCode = Constants.STATUS_HTTP_500_INTERNAL_ERROR;
-
- FhirContext ctx = theRestfulServer.getFhirContext();
-
- if (theException instanceof BaseServerResponseException) {
- oo = ((BaseServerResponseException) theException).getOperationOutcome();
- statusCode = ((BaseServerResponseException) theException).getStatusCode();
- }
-
- /*
- * Generate an OperationOutcome to return, unless the exception throw by the resource provider had one
- */
- if (oo == null) {
- try {
- oo = (BaseOperationOutcome) ctx.getResourceDefinition("OperationOutcome").getImplementingClass().newInstance();
- } catch (Exception e1) {
- ourLog.error("Failed to instantiate OperationOutcome resource instance", e1);
- throw new ServletException("Failed to instantiate OperationOutcome resource instance", e1);
- }
-
- BaseIssue issue = oo.addIssue();
- issue.getSeverityElement().setValue("error");
- if (theException instanceof InternalErrorException) {
- ourLog.error("Failure during REST processing", theException);
- populateDetails(theException, issue);
- } else if (theException instanceof BaseServerResponseException) {
- ourLog.warn("Failure during REST processing: {}", theException);
- BaseServerResponseException baseServerResponseException = (BaseServerResponseException) theException;
- statusCode = baseServerResponseException.getStatusCode();
- populateDetails(theException, issue);
- if (baseServerResponseException.getAdditionalMessages() != null) {
- for (String next : baseServerResponseException.getAdditionalMessages()) {
- BaseIssue issue2 = oo.addIssue();
- issue2.getSeverityElement().setValue("error");
- issue2.setDetails(next);
- }
- }
- } else {
- ourLog.error("Failure during REST processing: " + theException.toString(), theException);
- populateDetails(theException, issue);
- statusCode = Constants.STATUS_HTTP_500_INTERNAL_ERROR;
- }
- } else {
- ourLog.error("Unknown error during processing", theException);
- }
-
- // Add headers associated with the specific error code
- if (theException instanceof BaseServerResponseException) {
- Map additional = ((BaseServerResponseException) theException).getAssociatedHeaders();
- if (additional != null) {
- for (Entry next : additional.entrySet()) {
- if (isNotBlank(next.getKey()) && next.getValue() != null) {
- String nextKey = next.getKey();
- for (String nextValue : next.getValue()) {
- theResponse.addHeader(nextKey, nextValue);
- }
- }
- }
- }
- }
-
- boolean requestIsBrowser = RestfulServer.requestIsBrowser(theRequest);
- String fhirServerBase = theRestfulServer.getServerBaseForRequest(theRequest);
-
- RestfulServerUtils.streamResponseAsResource(theRestfulServer, theResponse, oo, RestfulServerUtils.determineResponseEncodingNoDefault(theRequest), true, requestIsBrowser,
- NarrativeModeEnum.NORMAL, statusCode, false, fhirServerBase);
-
-<<<<<<< HEAD
-// theResponse.setStatus(statusCode);
-// theRequestDetails.getServer().addHeadersToResponse(theResponse);
-// theResponse.setContentType("text/plain");
-// theResponse.setCharacterEncoding("UTF-8");
-// theResponse.getWriter().append(theException.getMessage());
-// theResponse.getWriter().close();
-=======
- theResponse.setStatus(statusCode);
- theRestfulServer.addHeadersToResponse(theResponse);
- theResponse.setContentType("text/plain");
- theResponse.setCharacterEncoding("UTF-8");
- theResponse.getWriter().append(theException.getMessage());
- theResponse.getWriter().close();
->>>>>>> 5956ab75fd9186ccc8b9836b60bc421b19d3d288
-
- return false;
- }
-
- private void populateDetails(Throwable theException, BaseIssue issue) {
- if (myReturnStackTracesForExceptionTypes != null) {
- for (Class> next : myReturnStackTracesForExceptionTypes) {
- if (next.isAssignableFrom(theException.getClass())) {
- issue.getDetailsElement().setValue(theException.getMessage() + "\n\n" + ExceptionUtils.getStackTrace(theException));
- return;
- }
- }
- }
-
- issue.getDetailsElement().setValue(theException.getMessage());
- }
-
-}
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java
index f3d5a40984c..ee43923212b 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java
@@ -61,7 +61,7 @@ public class FhirTerser {
if (theElement instanceof ISupportsUndeclaredExtensions) {
ISupportsUndeclaredExtensions containingElement = (ISupportsUndeclaredExtensions) theElement;
for (ExtensionDt nextExt : containingElement.getUndeclaredExtensions()) {
- theCallback.acceptUndeclaredExtension(containingElement, theChildDefinition, theDefinition, nextExt);
+ theCallback.acceptUndeclaredExtension(containingElement, null, theChildDefinition, theDefinition, nextExt);
addUndeclaredExtensions(nextExt, theDefinition, theChildDefinition, theCallback);
}
}
@@ -90,10 +90,10 @@ public class FhirTerser {
public List getAllPopulatedChildElementsOfType(IBaseResource theResource, final Class theType) {
final ArrayList retVal = new ArrayList();
BaseRuntimeElementCompositeDefinition> def = myContext.getResourceDefinition(theResource);
- visit(theResource, null, def, new IModelVisitor() {
+ visit(theResource, null, null, def, new IModelVisitor() {
@SuppressWarnings("unchecked")
@Override
- public void acceptElement(IBase theElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition) {
+ public void acceptElement(IBase theElement, List thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition) {
if (theElement == null || theElement.isEmpty()) {
return;
}
@@ -105,7 +105,8 @@ public class FhirTerser {
@SuppressWarnings("unchecked")
@Override
- public void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition, ExtensionDt theNextExt) {
+ public void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, List thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition,
+ ExtensionDt theNextExt) {
if (theType.isAssignableFrom(theNextExt.getClass())) {
retVal.add((T) theNextExt);
}
@@ -117,39 +118,34 @@ public class FhirTerser {
return retVal;
}
- public List getAllResourceReferences(final IBaseResource theResource) {
- final ArrayList retVal = new ArrayList();
- BaseRuntimeElementCompositeDefinition> def = myContext.getResourceDefinition(theResource);
- visit(theResource, null, def, new IModelVisitor() {
- @Override
- public void acceptElement(IBase theElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition) {
- if (theElement == null || theElement.isEmpty()) {
- return;
- }
- String name = null;
- if (theChildDefinition != null) {
- name = theChildDefinition.getElementName();
- }
- if (BaseResourceReferenceDt.class.isAssignableFrom(theElement.getClass())) {
- retVal.add(new ResourceReferenceInfo(theResource, name, (BaseResourceReferenceDt) theElement));
- }
- }
+ public List getAllResourceReferences(final IBaseResource theResource) {
+ final ArrayList retVal = new ArrayList();
+ BaseRuntimeElementCompositeDefinition> def = myContext.getResourceDefinition(theResource);
+ visit(theResource, null, null, def, new IModelVisitor() {
+ @SuppressWarnings("unchecked")
+ @Override
+ public void acceptElement(IBase theElement, List thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition) {
+ if (theElement == null || theElement.isEmpty()) {
+ return;
+ }
+ if (BaseResourceReferenceDt.class.isAssignableFrom(theElement.getClass())) {
+ retVal.add(new ResourceReferenceInfo(theResource, thePathToElement, (BaseResourceReferenceDt)theElement));
+ }
+ }
- @Override
- public void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition, ExtensionDt theNextExt) {
- String name = null;
- if (theChildDefinition != null) {
- name = theChildDefinition.getElementName();
- }
- if (theNextExt.getValue() != null && BaseResourceReferenceDt.class.isAssignableFrom(theNextExt.getValue().getClass())) {
- retVal.add(new ResourceReferenceInfo(theResource, name, (BaseResourceReferenceDt) theNextExt.getValue()));
- }
- }
- });
- return retVal;
- }
+ @SuppressWarnings("unchecked")
+ @Override
+ public void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, List thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition,
+ ExtensionDt theNextExt) {
+ if (theNextExt.getValue() != null && BaseResourceReferenceDt.class.isAssignableFrom(theNextExt.getValue().getClass())) {
+ retVal.add(new ResourceReferenceInfo(theResource, thePathToElement, (BaseResourceReferenceDt)theNextExt.getValue()));
+ }
+ }
+ });
+ return retVal;
+ }
- private BaseRuntimeChildDefinition getDefinition(BaseRuntimeElementCompositeDefinition> theCurrentDef, List theSubList) {
+ private BaseRuntimeChildDefinition getDefinition(BaseRuntimeElementCompositeDefinition> theCurrentDef, List theSubList) {
BaseRuntimeChildDefinition nextDef = theCurrentDef.getChildByNameOrThrowDataFormatException(theSubList.get(0));
if (theSubList.size() == 1) {
@@ -222,8 +218,19 @@ public class FhirTerser {
}
- private void visit(IBase theElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition, IModelVisitor theCallback) {
- theCallback.acceptElement(theElement, theChildDefinition, theDefinition);
+ private List addNameToList(List theCurrentList, BaseRuntimeChildDefinition theChildDefinition) {
+ if (theChildDefinition == null)
+ return null;
+ if (theCurrentList== null || theCurrentList.isEmpty())
+ return new ArrayList(Arrays.asList(theChildDefinition.getElementName()));
+ List newList = new ArrayList(theCurrentList);
+ newList.add(theChildDefinition.getElementName());
+ return newList;
+ }
+
+ private void visit(IBase theElement, List thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition, IModelVisitor theCallback) {
+ List pathToElement = addNameToList(thePathToElement, theChildDefinition);
+ theCallback.acceptElement(theElement, pathToElement, theChildDefinition, theDefinition);
addUndeclaredExtensions(theElement, theDefinition, theChildDefinition, theCallback);
// if (theElement.isEmpty()) {
@@ -243,7 +250,7 @@ public class FhirTerser {
IBaseResource theResource = resRefDt.getResource();
if (theResource.getId() == null || theResource.getId().isEmpty() || theResource.getId().isLocal()) {
BaseRuntimeElementCompositeDefinition> def = myContext.getResourceDefinition(theResource);
- visit(theResource, null, def, theCallback);
+ visit(theResource, pathToElement, null, def, theCallback);
}
}
break;
@@ -285,9 +292,9 @@ public class FhirTerser {
if (nextChild instanceof RuntimeChildDirectResource) {
// Don't descend into embedded resources
- theCallback.acceptElement(nextValue, nextChild, childElementDef);
+ theCallback.acceptElement(nextValue, null, nextChild, childElementDef);
} else {
- visit(nextValue, nextChild, childElementDef, theCallback);
+ visit(nextValue, pathToElement, nextChild, childElementDef, theCallback);
}
}
}
@@ -298,7 +305,7 @@ public class FhirTerser {
BaseContainedDt value = (BaseContainedDt) theElement;
for (IResource next : value.getContainedResources()) {
BaseRuntimeElementCompositeDefinition> def = myContext.getResourceDefinition(next);
- visit(next, null, def, theCallback);
+ visit(next, pathToElement, null, def, theCallback);
}
break;
}
@@ -309,7 +316,7 @@ public class FhirTerser {
case CONTAINED_RESOURCE_LIST:
if (theElement != null) {
BaseRuntimeElementDefinition> def = myContext.getElementDefinition(theElement.getClass());
- visit(theElement, null, def, theCallback);
+ visit(theElement, pathToElement, null, def, theCallback);
}
break;
}
@@ -454,7 +461,7 @@ public class FhirTerser {
*/
public void visit(IBaseResource theResource, IModelVisitor theVisitor) {
BaseRuntimeElementCompositeDefinition> def = myContext.getResourceDefinition(theResource);
- visit(theResource, null, def, theVisitor);
+ visit(theResource, null, null, def, theVisitor);
}
/**
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/IModelVisitor.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/IModelVisitor.java
index f183f8ee4d4..518080aab93 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/IModelVisitor.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/IModelVisitor.java
@@ -28,6 +28,8 @@ import ca.uhn.fhir.context.BaseRuntimeElementDefinition;
import ca.uhn.fhir.model.api.ExtensionDt;
import ca.uhn.fhir.model.api.ISupportsUndeclaredExtensions;
+import java.util.List;
+
/**
* @see FhirTerser#visit(IBaseResource, IModelVisitor)
*/
@@ -39,7 +41,7 @@ public interface IModelVisitor {
* @param theChildDefinition May be null if this is a root element
* @param theDefinition
*/
- void acceptElement(IBase theElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition);
+ void acceptElement(IBase theElement, List thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition);
/**
*
@@ -48,7 +50,7 @@ public interface IModelVisitor {
* @param theDefinition
* @param theNextExt
*/
- void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition, ExtensionDt theNextExt);
+ void acceptUndeclaredExtension(ISupportsUndeclaredExtensions theContainingElement, List thePathToElement, BaseRuntimeChildDefinition theChildDefinition, BaseRuntimeElementDefinition> theDefinition, ExtensionDt theNextExt);
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java
index 1c634d695fa..fd50f9f5a81 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ResourceReferenceInfo.java
@@ -28,58 +28,71 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hl7.fhir.instance.model.IBaseResource;
+import java.util.Iterator;
+import java.util.List;
import java.util.Set;
/**
* Created by Bill de Beaubien on 2/26/2015.
*/
public class ResourceReferenceInfo {
- private String myOwningResource;
- private String myName;
- private BaseResourceReferenceDt myResource;
+ private String myOwningResource;
+ private String myName;
+ private BaseResourceReferenceDt myResource;
- public ResourceReferenceInfo(IBaseResource theOwningResource, String theName, BaseResourceReferenceDt theResource) {
- myOwningResource = theOwningResource.getClass().getAnnotation(ResourceDef.class).name();
- myName = theName;
- myResource = theResource;
- }
+ public ResourceReferenceInfo(IBaseResource theOwningResource, List thePathToElement, BaseResourceReferenceDt theResource) {
+ myOwningResource = theOwningResource.getClass().getAnnotation(ResourceDef.class).name();
+ myResource = theResource;
+ if (thePathToElement != null && !thePathToElement.isEmpty()) {
+ StringBuilder sb = new StringBuilder();
+ thePathToElement.iterator();
+ for (Iterator iterator = thePathToElement.iterator(); iterator.hasNext(); ) {
+ sb.append(iterator.next());
+ if (iterator.hasNext())
+ sb.append(".");
+ }
+ myName = sb.toString();
+ } else {
+ myName = null;
+ }
+ }
- @Override
- public String toString() {
- ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
- b.append("name", myName);
- b.append("resource", myResource.getReference());
- return b.build();
- }
+ @Override
+ public String toString() {
+ ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
+ b.append("name", myName);
+ b.append("resource", myResource.getReference());
+ return b.build();
+ }
- public String getName() {
- return myName;
- }
+ public String getName() {
+ return myName;
+ }
- public BaseResourceReferenceDt getResourceReference() {
- return myResource;
- }
+ public BaseResourceReferenceDt getResourceReference() {
+ return myResource;
+ }
- public boolean matchesIncludeSet(Set theIncludes) {
- if (theIncludes == null)
- return false;
- for (Include include : theIncludes) {
- if (matchesInclude(include))
- return true;
- }
- return false;
- }
+ public boolean matchesIncludeSet(Set theIncludes) {
+ if (theIncludes == null)
+ return false;
+ for (Include include : theIncludes) {
+ if (matchesInclude(include))
+ return true;
+ }
+ return false;
+ }
- public boolean matchesInclude(Include theInclude) {
- if (theInclude.getValue().equals("*")) {
- return true;
- }
- if (theInclude.getValue().indexOf(':') != -1) {
- // DSTU2 style
- return (theInclude.getValue().equals(myOwningResource + ':' + myName));
- } else {
- // DSTU1 style
- return (theInclude.getValue().equals(myOwningResource + '.' + myName));
- }
- }
+ public boolean matchesInclude(Include theInclude) {
+ if (theInclude.getValue().equals("*")) {
+ return true;
+ }
+ if (theInclude.getValue().indexOf(':') != -1) {
+ // DSTU2 style
+ return (theInclude.getValue().equals(myOwningResource + ':' + myName));
+ } else {
+ // DSTU1 style
+ return (theInclude.getValue().equals(myOwningResource + '.' + myName));
+ }
+ }
}
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java
index 6f9b45405c2..b4a58ff2c61 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirDao.java
@@ -20,8 +20,7 @@ package ca.uhn.fhir.jpa.dao;
* #L%
*/
-import static org.apache.commons.lang3.StringUtils.isBlank;
-import static org.apache.commons.lang3.StringUtils.isNotBlank;
+import static org.apache.commons.lang3.StringUtils.*;
import java.io.UnsupportedEncodingException;
import java.net.URI;
@@ -444,12 +443,12 @@ public abstract class BaseFhirDao implements IDao {
}
@Override
- public List getResources(final int theFromIndex, final int theToIndex) {
+ public List getResources(final int theFromIndex, final int theToIndex) {
final StopWatch timer = new StopWatch();
TransactionTemplate template = new TransactionTemplate(myPlatformTransactionManager);
- return template.execute(new TransactionCallback>() {
+ return template.execute(new TransactionCallback>() {
@Override
- public List doInTransaction(TransactionStatus theStatus) {
+ public List doInTransaction(TransactionStatus theStatus) {
List resEntities = Lists.newArrayList();
List tupleSubList = tuples.subList(theFromIndex, theToIndex);
@@ -471,7 +470,7 @@ public abstract class BaseFhirDao implements IDao {
resEntities = resEntities.subList(0, limit);
}
- ArrayList retVal = new ArrayList();
+ ArrayList retVal = new ArrayList();
for (BaseHasResource next : resEntities) {
RuntimeResourceDefinition type;
try {
@@ -514,7 +513,7 @@ public abstract class BaseFhirDao implements IDao {
return true;
}
- protected List loadResourcesById(Set theIncludePids) {
+ protected List loadResourcesById(Set theIncludePids) {
Set pids = new HashSet();
for (IdDt next : theIncludePids) {
if (next.isIdPartValidLong()) {
@@ -528,6 +527,10 @@ public abstract class BaseFhirDao implements IDao {
}
}
+ if (pids.isEmpty()) {
+ return new ArrayList();
+ }
+
CriteriaBuilder builder = myEntityManager.getCriteriaBuilder();
CriteriaQuery cq = builder.createQuery(ResourceTable.class);
Root from = cq.from(ResourceTable.class);
@@ -538,7 +541,7 @@ public abstract class BaseFhirDao implements IDao {
// }
TypedQuery q = myEntityManager.createQuery(cq);
- ArrayList retVal = new ArrayList();
+ ArrayList retVal = new ArrayList();
for (ResourceTable next : q.getResultList()) {
IResource resource = (IResource) toResource(next);
retVal.add(resource);
diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java
index 935df209c6d..b530d8901e3 100644
--- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java
+++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java
@@ -20,8 +20,7 @@ package ca.uhn.fhir.jpa.dao;
* #L%
*/
-import static org.apache.commons.lang3.StringUtils.isBlank;
-import static org.apache.commons.lang3.StringUtils.isNotBlank;
+import static org.apache.commons.lang3.StringUtils.*;
import java.math.BigDecimal;
import java.util.ArrayList;
@@ -660,12 +659,12 @@ public abstract class BaseFhirResourceDao extends BaseFhirD
return new HashSet(q.getResultList());
}
- private List addResourcesAsIncludesById(List theListToPopulate, Set includePids, List resources) {
+ private List addResourcesAsIncludesById(List theListToPopulate, Set includePids, List resources) {
if (!includePids.isEmpty()) {
ourLog.info("Loading {} included resources", includePids.size());
resources = loadResourcesById(includePids);
- for (IResource next : resources) {
- ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put(next, BundleEntrySearchModeEnum.INCLUDE);
+ for (IBaseResource next : resources) {
+ ResourceMetadataKeyEnum.ENTRY_SEARCH_MODE.put((IResource) next, BundleEntrySearchModeEnum.INCLUDE);
}
theListToPopulate.addAll(resources);
}
@@ -1000,7 +999,7 @@ public abstract class BaseFhirResourceDao extends BaseFhirD
return tags;
}
- protected abstract List