use of com.airhacks.enhydrator.in.Source in project enhydrator by AdamBien.
the class FromJsonToCSVTest method fromJSONToCSV.
@Test
public void fromJSONToCSV() throws FileNotFoundException {
Source source = new ScriptableSource(INPUT + "languages.json", INPUT + "converter.js", "UTF-8");
final CSVFileSink csvFileSink = new CSVFileSink("*", getFileName(), ";", true, false);
Pump pump = new Pump.Engine().from(source).to(new LogSink()).to(csvFileSink).build();
pump.start();
}
use of com.airhacks.enhydrator.in.Source in project enhydrator by AdamBien.
the class JSONImportTest method getSource.
VirtualSinkSource getSource(final String fileName) throws FileNotFoundException {
final Path pathToContent = Paths.get(fileName);
Reader script = new FileReader("./src/test/files/converter.js");
Source source = new ScriptableSource(pathToContent, script, "UTF-8");
VirtualSinkSource vss = new VirtualSinkSource();
Pump pump = new Pump.Engine().from(source).to(vss).to(new LogSink()).build();
pump.start();
return vss;
}
use of com.airhacks.enhydrator.in.Source in project enhydrator by AdamBien.
the class ParentTest method copy.
/**
* Name;Size;Folder
*/
@Test
public void copy() {
Source source = new CSVFileSource("./src/test/files/files.csv", ";", "UTF-8", true);
VirtualSinkSource vss = new VirtualSinkSource();
Pump pump = new Pump.Engine().from(source).startWith(new SkipFirstRow()).startWith(new NonRecursiveTree("Name", "Folder")).to(vss).to(new LogSink()).build();
pump.start();
System.out.println(vss.getRows());
int numberOfRows = vss.getNumberOfRows();
assertThat(numberOfRows, is(2));
Row parentWithChildren = vss.getRow(0);
assertNotNull(parentWithChildren);
assertThat(parentWithChildren.getNumberOfColumns(), is(3));
List<Row> children = parentWithChildren.getChildren();
assertThat(children.size(), is(2));
children.forEach(e -> assertThat(e.getNumberOfColumns(), is(2)));
}
use of com.airhacks.enhydrator.in.Source in project enhydrator by AdamBien.
the class PipelineTest method getJSONPipeline.
public static Pipeline getJSONPipeline() {
DestinationMapper targetMapper = new DestinationMapper();
targetMapper.addMapping(0, new TargetMapping("*", "*"));
DatatypeIndexMapper datatypeMapper = new DatatypeIndexMapper();
datatypeMapper.addMapping(1, Datatype.INTEGER);
Source source = new ScriptableSource("./src/test/files/languages.json", "./src/test/files/converter.js", "UTF-8");
NamedSink logSink = new LogSink();
NamedSink virtualSink = new VirtualSinkSource();
Pipeline origin = new Pipeline("json", "src/test/scripts", null, source);
origin.addSink(logSink);
origin.addSink(virtualSink);
origin.addPreRowTransformation(targetMapper);
origin.addPreRowTransformation(datatypeMapper);
origin.addPreRowTransformation(new NashornRowTransformer("src/test/scripts", "encrypt"));
origin.addPostRowTransformation(new NashornRowTransformer("src/test/scripts", "compress"));
origin.addFilter("true");
origin.addExpression("print($ROW); $ROW");
return origin;
}
use of com.airhacks.enhydrator.in.Source in project enhydrator by AdamBien.
the class PipelineTest method getJSONToNashornPipeline.
public static Pipeline getJSONToNashornPipeline() {
DestinationMapper targetMapper = new DestinationMapper();
targetMapper.addMapping(0, new TargetMapping("*", "*"));
DatatypeIndexMapper datatypeMapper = new DatatypeIndexMapper();
datatypeMapper.addMapping(1, Datatype.INTEGER);
Source source = new ScriptableSource("./src/test/files/languages.json", "./src/test/files/converter.js", "UTF-8");
NamedSink logSink = new LogSink();
NamedSink virtualSink = new ScriptableSink("./src/test/scripts/sink.js");
Pipeline origin = new Pipeline("json", "src/test/scripts", null, source);
origin.addSink(logSink);
origin.addSink(virtualSink);
origin.addPreRowTransformation(targetMapper);
origin.addPreRowTransformation(datatypeMapper);
origin.addPreRowTransformation(new NashornRowTransformer("src/test/scripts", "encrypt"));
origin.addPostRowTransformation(new NashornRowTransformer("src/test/scripts", "compress"));
origin.addFilter("true");
origin.addExpression("print($ROW); $ROW");
return origin;
}
Aggregations