Skip to content

Commit

Permalink
More work on tester
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesagnew committed Jul 11, 2014
1 parent 0a7f7d0 commit a2a1035
Show file tree
Hide file tree
Showing 25 changed files with 573 additions and 143 deletions.
9 changes: 9 additions & 0 deletions hapi-fhir-base/src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@
<action type="fix">
Server now automatically compresses responses if the client indicates support
</action>
<action type="fix">
Server failed to support optional parameters when type is String and :exact qualifier is used
</action>
<action type="fix">
Read method in client correctly populated resource ID in returned object
</action>
<action type="add">
Support added for deleted-entry by/name, by/email, and comment from Tombstones spec
</action>
</release>
</body>
</document>
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ public class Bundle extends BaseBundle /* implements IElement */{
private IntegerDt myTotalResults;
private InstantDt myUpdated;

/**
* Returns true if this bundle contains zero entries
*/
@Override
public boolean isEmpty() {
//@formatter:off
return super.isEmpty() &&
ElementUtil.isEmpty(myBundleId, myLinkBase, myLinkFirst, myLinkLast, myLinkNext, myLinkPrevious, myLinkSelf, myPublished, myTitle, myTotalResults) &&
ElementUtil.isEmpty(myEntries);
//@formatter:on
return getEntries().isEmpty();
}

/**
Expand Down
65 changes: 52 additions & 13 deletions hapi-fhir-base/src/main/java/ca/uhn/fhir/model/api/BundleEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class BundleEntry extends BaseBundle {
//@formatter:on
private TagList myCategories;
private InstantDt myDeletedAt;
private StringDt myDeletedByEmail;
private StringDt myDeletedByName;
private StringDt myDeletedComment;
private StringDt myLinkAlternate;
private StringDt myLinkSelf;
private InstantDt myPublished;
Expand All @@ -52,18 +55,6 @@ public Tag addCategory() {
return retVal;
}

@Override
public String toString() {
ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
if (getResource() != null) {
b.append("type", getResource().getClass().getSimpleName());
} else {
b.append("No resource");
}
b.append("id", getId());
return b.toString();
}

public void addCategory(Tag theTag) {
getCategories().add(theTag);
}
Expand All @@ -85,6 +76,27 @@ public InstantDt getDeletedAt() {
return myDeletedAt;
}

public StringDt getDeletedByEmail() {
if (myDeletedByEmail == null) {
myDeletedByEmail = new StringDt();
}
return myDeletedByEmail;
}

public StringDt getDeletedByName() {
if (myDeletedByName == null) {
myDeletedByName = new StringDt();
}
return myDeletedByName;
}

public StringDt getDeletedComment() {
if (myDeletedComment == null) {
myDeletedComment = new StringDt();
}
return myDeletedComment;
}

public StringDt getLinkAlternate() {
if (myLinkAlternate == null) {
myLinkAlternate = new StringDt();
Expand Down Expand Up @@ -135,7 +147,7 @@ public InstantDt getUpdated() {
public boolean isEmpty() {
//@formatter:off
return super.isEmpty() &&
ElementUtil.isEmpty(myCategories, myDeletedAt, myLinkAlternate, myLinkSelf, myPublished, myResource, mySummary, myTitle, myUpdated);
ElementUtil.isEmpty(myCategories, myDeletedAt, myLinkAlternate, myLinkSelf, myPublished, myResource, mySummary, myTitle, myUpdated, myDeletedByEmail, myDeletedByName, myDeletedComment);
//@formatter:on
}

Expand All @@ -146,6 +158,21 @@ public void setDeleted(InstantDt theDeletedAt) {
myDeletedAt = theDeletedAt;
}

public void setDeletedByEmail(StringDt theDeletedByEmail) {
myDeletedByEmail = theDeletedByEmail;
}

public void setDeletedByName(StringDt theDeletedByName) {
if (myDeletedByName == null) {
myDeletedByName = new StringDt();
}
myDeletedByName = theDeletedByName;
}

public void setDeletedComment(StringDt theDeletedComment) {
myDeletedComment = theDeletedComment;
}

public void setLinkAlternate(StringDt theLinkAlternate) {
myLinkAlternate = theLinkAlternate;
}
Expand All @@ -171,4 +198,16 @@ public void setUpdated(InstantDt theUpdated) {
myUpdated = theUpdated;
}

@Override
public String toString() {
ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
if (getResource() != null) {
b.append("type", getResource().getClass().getSimpleName());
} else {
b.append("No resource");
}
b.append("id", getId());
return b.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,14 @@ protected ProcessorResult processAttribute(Arguments theArguments, Element theEl

final IStandardExpression expression = expressionParser.parseExpression(configuration, theArguments, attributeValue);
final Object value = expression.execute(configuration, theArguments);

theElement.removeAttribute(theAttributeName);
theElement.clearChildren();

if (value == null) {
return ProcessorResult.ok();
}

Context context = new Context();
context.setVariable("resource", value);

Expand Down
50 changes: 46 additions & 4 deletions hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ public boolean verifyNamespace(String theExpect, String theActual) {
}

/**
* Invoked after any new XML event is individually processed, containing a copy of the XML event. This is basically
* intended for embedded XHTML content
* Invoked after any new XML event is individually processed, containing a copy of the XML event. This is basically intended for embedded XHTML content
*/
public void xmlEvent(XMLEvent theNextEvent) {
myState.xmlEvent(theNextEvent);
Expand Down Expand Up @@ -238,8 +237,7 @@ public void attributeValue(String theName, String theValue) throws DataFormatExc
myInstance.setScheme(theValue);
} else if ("value".equals(theName)) {
/*
* This handles XML parsing, which is odd for this quasi-resource type, since the tag has three values
* instead of one like everything else.
* This handles XML parsing, which is odd for this quasi-resource type, since the tag has three values instead of one like everything else.
*/
switch (myCatState) {
case STATE_LABEL:
Expand Down Expand Up @@ -299,6 +297,23 @@ public void attributeValue(String theName, String theValue) throws DataFormatExc
}
}

@Override
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
if ("by".equals(theLocalPart) && verifyNamespace(XmlParser.TOMBSTONES_NS, theNamespaceURI)) {
push(new AtomDeletedEntryByState(getEntry()));
} else if ("comment".equals(theLocalPart)) {
push(new AtomPrimitiveState(getEntry().getDeletedComment()));
} else if ("link".equals(theLocalPart)) {
push(new AtomLinkState(getEntry()));
} else {
if (theNamespaceURI != null) {
throw new DataFormatException("Unexpected element: {" + theNamespaceURI + "}" + theLocalPart);
} else {
throw new DataFormatException("Unexpected element: " + theLocalPart);
}
}
}

@Override
public void endingElement() throws DataFormatException {
putPlacerResourceInDeletedEntry(getEntry());
Expand All @@ -307,6 +322,33 @@ public void endingElement() throws DataFormatException {

}

public class AtomDeletedEntryByState extends BaseState {

private BundleEntry myEntry;

public AtomDeletedEntryByState(BundleEntry theEntry) {
super(null);
myEntry = theEntry;
}

@Override
public void enteringNewElement(String theNamespaceURI, String theLocalPart) throws DataFormatException {
if ("name".equals(theLocalPart)) {
push(new AtomPrimitiveState(myEntry.getDeletedByName()));
} else if ("email".equals(theLocalPart)) {
push(new AtomPrimitiveState(myEntry.getDeletedByEmail()));
} else {
throw new DataFormatException("Unexpected element in entry: " + theLocalPart);
}
}

@Override
public void endingElement() throws DataFormatException {
pop();
}

}

private class AtomDeletedJsonWhenState extends BaseState {

private String myData;
Expand Down
69 changes: 44 additions & 25 deletions hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,32 @@ public void encodeBundleToWriter(Bundle theBundle, Writer theWriter) throws Data
}

for (BundleEntry nextEntry : theBundle.getEntries()) {
boolean deleted=false;
if (nextEntry.getDeletedAt() != null && nextEntry.getDeletedAt().isEmpty()==false) {
deleted=true;
eventWriter.writeStartElement("at","deleted-entry",TOMBSTONES_NS);
boolean deleted = false;
if (nextEntry.getDeletedAt() != null && nextEntry.getDeletedAt().isEmpty() == false) {
deleted = true;
eventWriter.writeStartElement("at", "deleted-entry", TOMBSTONES_NS);
eventWriter.writeNamespace("at", TOMBSTONES_NS);
eventWriter.writeAttribute("ref", nextEntry.getId().getValueAsString());
eventWriter.writeAttribute("when", nextEntry.getDeletedAt().getValueAsString());
if (nextEntry.getDeletedByEmail().isEmpty() == false || nextEntry.getDeletedByName().isEmpty()) {
eventWriter.writeStartElement(TOMBSTONES_NS, "by");
if (nextEntry.getDeletedByName().isEmpty()==false) {
eventWriter.writeStartElement(TOMBSTONES_NS, "name");
eventWriter.writeCharacters(nextEntry.getDeletedByName().getValue());
eventWriter.writeEndElement();
}
if (nextEntry.getDeletedByEmail().isEmpty() == false) {
eventWriter.writeStartElement(TOMBSTONES_NS, "email");
eventWriter.writeCharacters(nextEntry.getDeletedByEmail().getValue());
eventWriter.writeEndElement();
}
eventWriter.writeEndElement();
}
if (nextEntry.getDeletedComment().isEmpty()==false) {
eventWriter.writeStartElement(TOMBSTONES_NS, "comment");
eventWriter.writeCharacters(nextEntry.getDeletedComment().getValue());
eventWriter.writeEndElement();
}
} else {
eventWriter.writeStartElement("entry");
}
Expand Down Expand Up @@ -377,8 +396,8 @@ private <T> T doXmlLoop(XMLEventReader streamReader, ParserState<T> parserState)
}
}

private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, XMLStreamWriter theEventWriter, IElement nextValue, String childName, BaseRuntimeElementDefinition<?> childDef, String theExtensionUrl, boolean theIncludedResource)
throws XMLStreamException, DataFormatException {
private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, XMLStreamWriter theEventWriter, IElement nextValue, String childName,
BaseRuntimeElementDefinition<?> childDef, String theExtensionUrl, boolean theIncludedResource) throws XMLStreamException, DataFormatException {
if (nextValue.isEmpty()) {
return;
}
Expand Down Expand Up @@ -442,8 +461,8 @@ private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDe

}

private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, IElement theElement, XMLStreamWriter theEventWriter, List<? extends BaseRuntimeChildDefinition> children, boolean theIncludedResource)
throws XMLStreamException, DataFormatException {
private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, IElement theElement, XMLStreamWriter theEventWriter,
List<? extends BaseRuntimeChildDefinition> children, boolean theIncludedResource) throws XMLStreamException, DataFormatException {
for (BaseRuntimeChildDefinition nextChild : children) {
if (nextChild instanceof RuntimeChildNarrativeDefinition && !theIncludedResource) {
INarrativeGenerator gen = myContext.getNarrativeGenerator();
Expand Down Expand Up @@ -475,13 +494,13 @@ private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinit
if (childDef == null) {
super.throwExceptionForUnknownChildType(nextChild, type);
}

if (nextValue instanceof ExtensionDt) {

extensionUrl = ((ExtensionDt) nextValue).getUrlAsString();
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childName, childDef, extensionUrl, theIncludedResource);
} else if (extensionUrl != null && childName.equals("extension") == false) {

} else if (extensionUrl != null && childName.equals("extension") == false) {
RuntimeChildDeclaredExtensionDefinition extDef = (RuntimeChildDeclaredExtensionDefinition) nextChild;
if (extDef.isModifier()) {
theEventWriter.writeStartElement("modifierExtension");
Expand All @@ -499,14 +518,15 @@ private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinit
}
}

private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, IElement theElement, XMLStreamWriter theEventWriter, BaseRuntimeElementCompositeDefinition<?> resDef, boolean theIncludedResource) throws XMLStreamException,
DataFormatException {
private void encodeCompositeElementToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, IElement theElement, XMLStreamWriter theEventWriter,
BaseRuntimeElementCompositeDefinition<?> resDef, boolean theIncludedResource) throws XMLStreamException, DataFormatException {
encodeExtensionsIfPresent(theResDef, theResource, theEventWriter, theElement, theIncludedResource);
encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theElement, theEventWriter, resDef.getExtensions(), theIncludedResource);
encodeCompositeElementChildrenToStreamWriter(theResDef, theResource, theElement, theEventWriter, resDef.getChildren(), theIncludedResource);
}

private void encodeExtensionsIfPresent(RuntimeResourceDefinition theResDef, IResource theResource, XMLStreamWriter theWriter, IElement theElement, boolean theIncludedResource) throws XMLStreamException, DataFormatException {
private void encodeExtensionsIfPresent(RuntimeResourceDefinition theResDef, IResource theResource, XMLStreamWriter theWriter, IElement theElement, boolean theIncludedResource)
throws XMLStreamException, DataFormatException {
if (theElement instanceof ISupportsUndeclaredExtensions) {
ISupportsUndeclaredExtensions res = (ISupportsUndeclaredExtensions) theElement;
encodeUndeclaredExtensions(theResDef, theResource, theWriter, res.getUndeclaredExtensions(), "extension", theIncludedResource);
Expand All @@ -516,11 +536,11 @@ private void encodeExtensionsIfPresent(RuntimeResourceDefinition theResDef, IRes

private void encodeResourceReferenceToStreamWriter(XMLStreamWriter theEventWriter, ResourceReferenceDt theRef) throws XMLStreamException {
String reference = theRef.getReference().getValue();
// if (StringUtils.isBlank(reference)) {
// if (theRef.getResourceType() != null && StringUtils.isNotBlank(theRef.getResourceId())) {
// reference = myContext.getResourceDefinition(theRef.getResourceType()).getName() + '/' + theRef.getResourceId();
// }
// }
// if (StringUtils.isBlank(reference)) {
// if (theRef.getResourceType() != null && StringUtils.isNotBlank(theRef.getResourceId())) {
// reference = myContext.getResourceDefinition(theRef.getResourceType()).getName() + '/' + theRef.getResourceId();
// }
// }

if (!(theRef.getDisplay().isEmpty())) {
theEventWriter.writeStartElement("display");
Expand All @@ -536,9 +556,7 @@ private void encodeResourceReferenceToStreamWriter(XMLStreamWriter theEventWrite

/**
* @param theIncludedResource
* Set to true only if this resource is an "included" resource,
* as opposed to a "root level" resource by itself or in a bundle
* entry
* Set to true only if this resource is an "included" resource, as opposed to a "root level" resource by itself or in a bundle entry
*
*/
private void encodeResourceToXmlStreamWriter(IResource theResource, XMLStreamWriter theEventWriter, boolean theIncludedResource) throws XMLStreamException, DataFormatException {
Expand Down Expand Up @@ -569,7 +587,8 @@ private void encodeResourceToXmlStreamWriter(IResource theResource, XMLStreamWri
theEventWriter.writeEndElement();
}

private void encodeUndeclaredExtensions(RuntimeResourceDefinition theResDef, IResource theResource, XMLStreamWriter theWriter, List<ExtensionDt> extensions, String tagName, boolean theIncludedResource) throws XMLStreamException, DataFormatException {
private void encodeUndeclaredExtensions(RuntimeResourceDefinition theResDef, IResource theResource, XMLStreamWriter theWriter, List<ExtensionDt> extensions, String tagName,
boolean theIncludedResource) throws XMLStreamException, DataFormatException {
for (ExtensionDt next : extensions) {
theWriter.writeStartElement(tagName);
theWriter.writeAttribute("url", next.getUrl().getValue());
Expand Down Expand Up @@ -654,7 +673,7 @@ private void encodeXhtml(XhtmlDt theDt, XMLStreamWriter theEventWriter) throws X
} else {
if (StringUtils.isBlank(se.getName().getPrefix())) {
theEventWriter.writeStartElement(se.getName().getLocalPart());
// theEventWriter.writeDefaultNamespace(se.getName().getNamespaceURI());
// theEventWriter.writeDefaultNamespace(se.getName().getNamespaceURI());
} else {
theEventWriter.writeStartElement(se.getName().getNamespaceURI(), se.getName().getLocalPart());
}
Expand Down
Loading

0 comments on commit a2a1035

Please sign in to comment.