DSTU1 Atom: Add entry author to encoded xml bundle

This commit is contained in:
hnnesv 2016-09-23 13:06:21 +02:00
parent 73959e3e26
commit 92e6b6d884
No known key found for this signature in database
GPG Key ID: BCFB1E20C438A479
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;
@ -309,12 +310,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());
@ -366,6 +362,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()) {
@ -1070,6 +1068,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() {