Commit de030d23 authored by R.W.Majeed's avatar R.W.Majeed

allowing IOException for export writers, cleanup, documentation

parent 24de6e1a
package de.sekmi.histream.export;
import java.io.IOException;
public interface ExportWriter {
TableWriter openPatientTable();
TableWriter openVisitTable();
TableWriter openEAVTable(String id);
TableWriter openPatientTable() throws IOException;
TableWriter openVisitTable() throws IOException;
TableWriter openEAVTable(String id) throws IOException;
}
......@@ -12,6 +12,16 @@ import de.sekmi.histream.ObservationException;
import de.sekmi.histream.export.config.ExportDescriptor;
import de.sekmi.histream.export.config.ExportException;
/**
* Export visit fragments.
* <p>
* All {@link ObservationException}s generated by this class
* are caused by either {@link ExportException} or {@link IOException}.
* </p>
*
* @author R.W.Majeed
*
*/
public class FragmentExporter extends VisitFragmentParser {
TableParser patientParser;
......@@ -20,15 +30,19 @@ public class FragmentExporter extends VisitFragmentParser {
protected FragmentExporter(XPath xpath, ExportDescriptor desc, ExportWriter writer) throws ExportException, XMLStreamException, ParserConfigurationException {
super();
patientParser = desc.getPatientTable().createParser(writer.openPatientTable(), xpath);
visitParser = desc.getVisitTable().createParser(writer.openVisitTable(), xpath);
try {
patientParser = desc.getPatientTable().createParser(writer.openPatientTable(), xpath);
visitParser = desc.getVisitTable().createParser(writer.openVisitTable(), xpath);
} catch (IOException e) {
throw new ExportException("Unable to open table for writing", e);
}
}
@Override
protected void patientFragment(Node patient) throws ObservationException {
try {
patientParser.writeRow(patient);
} catch (ExportException e) {
} catch (ExportException | IOException e) {
throw new ObservationException(e);
}
}
......@@ -37,9 +51,10 @@ public class FragmentExporter extends VisitFragmentParser {
protected void visitFragment(Node visit) throws ObservationException {
try {
visitParser.writeRow(visit);
} catch (ExportException e) {
} catch (ExportException | IOException e) {
throw new ObservationException(e);
}
// TODO check for repeating concepts and write to separate parsers
}
@Override
......
......@@ -3,7 +3,6 @@ package de.sekmi.histream.export;
import java.io.IOException;
import java.util.Objects;
import javax.xml.transform.TransformerException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
......@@ -26,7 +25,7 @@ public class TableParser implements AutoCloseable{
private XPathExpression[] xpaths;
private TableWriter writer;
public TableParser(AbstractTable table, TableWriter writer, XPath xpath) throws ExportException{
public TableParser(AbstractTable table, TableWriter writer, XPath xpath) throws ExportException, IOException{
this.table = table;
this.writer = writer;
this.xpath = xpath;
......@@ -48,16 +47,12 @@ public class TableParser implements AutoCloseable{
}
}
private void writeHeaders(){
private void writeHeaders()throws IOException{
writer.header(table.getHeaders());
}
public void writeRow(Node node) throws ExportException{
try {
writer.row(valuesForFragment(node));
} catch (IOException e) {
throw new ExportException("Unable to write row", e);
}
public void writeRow(Node node) throws ExportException, IOException{
writer.row(valuesForFragment(node));
}
private String[] valuesForFragment(Node node) throws ExportException{
Column[] columns = table.getColumns();
......
......@@ -3,8 +3,8 @@ package de.sekmi.histream.export;
import java.io.IOException;
public interface TableWriter extends AutoCloseable{
void header(String[] headers);
void header(String[] headers)throws IOException;
void row(String[] columns) throws IOException;
@Override
void close() throws IOException;
}
}
\ No newline at end of file
......@@ -2,7 +2,6 @@ package de.sekmi.histream.export;
import java.util.Objects;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
......@@ -13,14 +12,11 @@ import javax.xml.transform.dom.DOMResult;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import de.sekmi.histream.ObservationException;
import de.sekmi.histream.ext.Patient;
import de.sekmi.histream.ext.Visit;
import de.sekmi.histream.impl.ObservationImpl;
import de.sekmi.histream.io.GroupedXMLWriter;
public abstract class VisitFragmentParser extends GroupedXMLWriter {
......
package de.sekmi.histream.export.config;
import java.io.IOException;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
......@@ -33,7 +35,7 @@ public abstract class AbstractTable {
return columns;
}
public TableParser createParser(TableWriter writer, XPath xpath) throws ExportException{
public TableParser createParser(TableWriter writer, XPath xpath) throws ExportException, IOException{
return new TableParser(this, writer, xpath);
}
......
......@@ -21,7 +21,7 @@ public class TestVisitFragmentParser {
public void verifyVisitFragmentContent() throws Exception{
FileObservationProviderTest t = new FileObservationProviderTest();
t.initializeObservationFactory();
final Node visitNode = null;
//final Node visitNode = null;
try( ObservationSupplier s = t.getExampleSupplier() ){
VisitFragmentSupplier sup = new VisitFragmentSupplier(s);
Node n = sup.get();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment