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

more verbose error messages for parser errors

parent 7ad843d5
......@@ -21,7 +21,10 @@ package de.sekmi.histream;
*/
import java.util.function.Supplier;
import java.util.function.Supplier;
import java.util.stream.Stream;
import de.sekmi.histream.io.Streams;
/**
* Supplier of observations.
......@@ -67,6 +70,15 @@ public interface ObservationSupplier extends Supplier<Observation>, AutoCloseabl
* patient+visit combination occur in ascending order of start timestamp.
*/
public static final String META_ORDER_SORTED = "order.sorted";
/**
* Get a stream of observations. Stream will terminate on the first {@code null}
* observation.
* @return stream
*/
public default Stream<Observation> stream(){
return Streams.nonNullStream(this);
}
/**
* Retrieve meta information for this supply of observations.
......
......@@ -35,8 +35,6 @@ import java.util.Properties;
import java.util.function.Consumer;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import de.sekmi.histream.Extension;
import de.sekmi.histream.Observation;
import de.sekmi.histream.ObservationException;
......@@ -131,15 +129,21 @@ public class RunConfiguration implements Closeable{
Streams.nonNullStream(provider).forEach(destinationChain);
}
public ObservationSupplier providerForFile(File file){
public ObservationSupplier providerForFile(File file)throws IOException{
ObservationSupplier p = null;
for( int i=0; i<fileFactories.length; i++ ){
try {
p = fileFactories[i].forFile(file, factory);
break;
} catch (IOException e) {
// unable to process file
}
// if only one file factory present, pass on exception
if( fileFactories.length == 1 ){
p = fileFactories[0].forFile(file, factory);
}else{
// multiple file factories, find one which doesn't give errors
for( int i=0; i<fileFactories.length; i++ ){
try {
p = fileFactories[i].forFile(file, factory);
break;
} catch (IOException e) {
// unable to process file
}
}
}
return p;
}
......@@ -205,7 +209,9 @@ public class RunConfiguration implements Closeable{
rc.processFile(p);
p.close();
}else{
System.err.println("Unable to find parser for file "+file);
System.err.println("ERROR: Unable to find parser for file "+file);
System.err.println("exceptions reported by all "+rc.fileFactories.length+" registered parsers");
System.err.println("for detailed errors, use only a single parser");
}
}
// files specified, run in batch mode
......
package de.sekmi.histream.io;
import java.io.File;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import de.sekmi.histream.ObservationFactory;
import de.sekmi.histream.ObservationSupplier;
import de.sekmi.histream.impl.ObservationFactoryImpl;
import de.sekmi.histream.impl.SimplePatientExtension;
import de.sekmi.histream.impl.SimpleVisitExtension;
public class TestFileObservationSuppliers {
private ObservationFactory factory;
@Before
public void prepareObservationFactory(){
factory = new ObservationFactoryImpl();
factory.registerExtension(new SimplePatientExtension());
factory.registerExtension(new SimpleVisitExtension());
}
@Test
public void verifyGroupedXmlSupplier() throws Exception{
GroupedXMLProvider p = new GroupedXMLProvider(null);
ObservationSupplier s = p.forFile(new File("examples/dwh-jaxb.xml"), factory);
Assert.assertTrue( s.stream().count() > 0 );
s.close();
p.close();
}
@Test
public void verifyFlatSupplier() throws Exception{
FlatProviderFactory p = new FlatProviderFactory(null);
ObservationSupplier s = p.forFile(new File("examples/dwh-flat.txt"), factory);
Assert.assertTrue( s.stream().count() > 0 );
s.close();
p.close();
}
}
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