Merge pull request #455 from hnnesv/dstu1-atom-entry-author

DSTU1: Add entry author to encoded xml bundle
This commit is contained in:
James Agnew 2016-10-20 11:29:00 -04:00 committed by GitHub
commit 173d40496d
2 changed files with 32 additions and 6 deletions

View File

@ -45,6 +45,7 @@ import javax.xml.stream.events.Namespace;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import ca.uhn.fhir.model.api.BaseBundle;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.hl7.fhir.instance.model.api.IBase;
@ -317,12 +318,7 @@ public class XmlParser extends BaseParser implements IParser {
writeOptionalTagWithTextNode(eventWriter, "updated", theBundle.getUpdated());
if (StringUtils.isNotBlank(theBundle.getAuthorName().getValue())) {
eventWriter.writeStartElement("author");
writeTagWithTextNode(eventWriter, "name", theBundle.getAuthorName());
writeOptionalTagWithTextNode(eventWriter, "uri", theBundle.getAuthorUri());
eventWriter.writeEndElement();
}
writeAuthor(eventWriter, theBundle);
writeCategories(eventWriter, theBundle.getCategories());
@ -374,6 +370,8 @@ public class XmlParser extends BaseParser implements IParser {
writeOptionalTagWithTextNode(eventWriter, "updated", nextEntry.getUpdated());
writeOptionalTagWithTextNode(eventWriter, "published", nextEntry.getPublished());
writeAuthor(eventWriter, nextEntry);
writeCategories(eventWriter, nextEntry.getCategories());
if (!nextEntry.getLinkSelf().isEmpty()) {
@ -1078,6 +1076,15 @@ public class XmlParser extends BaseParser implements IParser {
return retVal;
}
private void writeAuthor(XMLStreamWriter theEventWriter, BaseBundle theBundle) throws XMLStreamException {
if (StringUtils.isNotBlank(theBundle.getAuthorName().getValue())) {
theEventWriter.writeStartElement("author");
writeTagWithTextNode(theEventWriter, "name", theBundle.getAuthorName());
writeOptionalTagWithTextNode(theEventWriter, "uri", theBundle.getAuthorUri());
theEventWriter.writeEndElement();
}
}
private void writeAtomLink(XMLStreamWriter theEventWriter, String theRel, StringDt theStringDt) throws XMLStreamException {
if (StringUtils.isNotBlank(theStringDt.getValue())) {
theEventWriter.writeStartElement("link");

View File

@ -428,6 +428,25 @@ public class XmlParserTest {
}
@Test
public void testEncodeBundleEntryAuthor() {
Bundle b = new Bundle();
BundleEntry e = b.addEntry();
e.getAuthorName().setValue("The Author");
e.setResource(new Patient());
String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
ourLog.info(val);
assertThat(val, StringContains.containsString("<name>The Author</name>"));
b = ourCtx.newXmlParser().parseBundle(val);
assertEquals(1, b.getEntries().size());
assertEquals("The Author", b.getEntries().get(0).getAuthorName().getValue());
}
@Test
public void testEncodeBundleCategory() {