Search in sources :

Example 1 with Source

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();
}
Also used : LogSink(com.airhacks.enhydrator.out.LogSink) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) Source(com.airhacks.enhydrator.in.Source) ScriptableSource(com.airhacks.enhydrator.in.ScriptableSource) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Pump(com.airhacks.enhydrator.Pump) ScriptableSource(com.airhacks.enhydrator.in.ScriptableSource) CSVFileSink(com.airhacks.enhydrator.out.CSVFileSink) Test(org.junit.Test)

Example 2 with Source

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;
}
Also used : Path(java.nio.file.Path) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) LogSink(com.airhacks.enhydrator.out.LogSink) Reader(java.io.Reader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) Source(com.airhacks.enhydrator.in.Source) ScriptableSource(com.airhacks.enhydrator.in.ScriptableSource) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Pump(com.airhacks.enhydrator.Pump) ScriptableSource(com.airhacks.enhydrator.in.ScriptableSource)

Example 3 with Source

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)));
}
Also used : NonRecursiveTree(com.airhacks.enhydrator.functions.NonRecursiveTree) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) LogSink(com.airhacks.enhydrator.out.LogSink) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) SkipFirstRow(com.airhacks.enhydrator.transform.SkipFirstRow) SkipFirstRow(com.airhacks.enhydrator.transform.SkipFirstRow) Row(com.airhacks.enhydrator.in.Row) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) Source(com.airhacks.enhydrator.in.Source) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) Pump(com.airhacks.enhydrator.Pump) Test(org.junit.Test)

Example 4 with Source

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;
}
Also used : DestinationMapper(com.airhacks.enhydrator.transform.DestinationMapper) LogSink(com.airhacks.enhydrator.out.LogSink) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) TargetMapping(com.airhacks.enhydrator.transform.TargetMapping) NashornRowTransformer(com.airhacks.enhydrator.transform.NashornRowTransformer) NamedSink(com.airhacks.enhydrator.out.NamedSink) DatatypeIndexMapper(com.airhacks.enhydrator.transform.DatatypeIndexMapper) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) Source(com.airhacks.enhydrator.in.Source) ScriptableSource(com.airhacks.enhydrator.in.ScriptableSource) JDBCSource(com.airhacks.enhydrator.in.JDBCSource) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) ScriptableSource(com.airhacks.enhydrator.in.ScriptableSource)

Example 5 with Source

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;
}
Also used : DestinationMapper(com.airhacks.enhydrator.transform.DestinationMapper) LogSink(com.airhacks.enhydrator.out.LogSink) TargetMapping(com.airhacks.enhydrator.transform.TargetMapping) NashornRowTransformer(com.airhacks.enhydrator.transform.NashornRowTransformer) NamedSink(com.airhacks.enhydrator.out.NamedSink) DatatypeIndexMapper(com.airhacks.enhydrator.transform.DatatypeIndexMapper) CSVFileSource(com.airhacks.enhydrator.in.CSVFileSource) Source(com.airhacks.enhydrator.in.Source) ScriptableSource(com.airhacks.enhydrator.in.ScriptableSource) JDBCSource(com.airhacks.enhydrator.in.JDBCSource) VirtualSinkSource(com.airhacks.enhydrator.in.VirtualSinkSource) ScriptableSource(com.airhacks.enhydrator.in.ScriptableSource) ScriptableSink(com.airhacks.enhydrator.out.ScriptableSink)

Aggregations

Source (com.airhacks.enhydrator.in.Source)9 VirtualSinkSource (com.airhacks.enhydrator.in.VirtualSinkSource)9 LogSink (com.airhacks.enhydrator.out.LogSink)9 CSVFileSource (com.airhacks.enhydrator.in.CSVFileSource)8 Pump (com.airhacks.enhydrator.Pump)6 ScriptableSource (com.airhacks.enhydrator.in.ScriptableSource)6 Test (org.junit.Test)4 JDBCSource (com.airhacks.enhydrator.in.JDBCSource)3 NamedSink (com.airhacks.enhydrator.out.NamedSink)3 DatatypeIndexMapper (com.airhacks.enhydrator.transform.DatatypeIndexMapper)3 DestinationMapper (com.airhacks.enhydrator.transform.DestinationMapper)3 NashornRowTransformer (com.airhacks.enhydrator.transform.NashornRowTransformer)3 TargetMapping (com.airhacks.enhydrator.transform.TargetMapping)3 Row (com.airhacks.enhydrator.in.Row)2 DatatypeNameMapper (com.airhacks.enhydrator.transform.DatatypeNameMapper)2 Memory (com.airhacks.enhydrator.transform.Memory)2 SkipFirstRow (com.airhacks.enhydrator.transform.SkipFirstRow)2 NonRecursiveTree (com.airhacks.enhydrator.functions.NonRecursiveTree)1 CSVFileSink (com.airhacks.enhydrator.out.CSVFileSink)1 ScriptableSink (com.airhacks.enhydrator.out.ScriptableSink)1