Search in sources :

Example 1 with RowTransformCollector

use of org.apache.hop.pipeline.transforms.xml.RowTransformCollector in project hop by apache.

the class XsltTest method runTestWithParams.

public void runTestWithParams(String xmlFieldname, String resultFieldname, boolean xslInField, boolean xslFileInField, String xslFileField, String xslFilename, String xslFactory) throws Exception {
    HopEnvironment.init();
    // 
    // Create a new pipeline...
    // 
    PipelineMeta pipelineMeta = new PipelineMeta();
    pipelineMeta.setName("xslt");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create an injector transform...
    // 
    String injectorTransformName = "injector transform";
    InjectorMeta im = new InjectorMeta();
    // Set the information of the injector.
    String injectorPid = registry.getPluginId(TransformPluginType.class, im);
    TransformMeta injectorTransform = new TransformMeta(injectorPid, injectorTransformName, im);
    pipelineMeta.addTransform(injectorTransform);
    // 
    // Create a XSLT transform
    // 
    String xsltName = "xslt transform";
    XsltMeta xm = new XsltMeta();
    String xsltPid = registry.getPluginId(TransformPluginType.class, xm);
    TransformMeta xsltTransform = new TransformMeta(xsltPid, xsltName, xm);
    pipelineMeta.addTransform(xsltTransform);
    TextFileInputField[] fields = new TextFileInputField[3];
    for (int idx = 0; idx < fields.length; idx++) {
        fields[idx] = new TextFileInputField();
    }
    fields[0].setName("XML");
    fields[0].setType(IValueMeta.TYPE_STRING);
    fields[0].setFormat("");
    fields[0].setLength(-1);
    fields[0].setPrecision(-1);
    fields[0].setCurrencySymbol("");
    fields[0].setDecimalSymbol("");
    fields[0].setGroupSymbol("");
    fields[0].setTrimType(IValueMeta.TRIM_TYPE_NONE);
    fields[1].setName("XSL");
    fields[1].setType(IValueMeta.TYPE_STRING);
    fields[1].setFormat("");
    fields[1].setLength(-1);
    fields[1].setPrecision(-1);
    fields[1].setCurrencySymbol("");
    fields[1].setDecimalSymbol("");
    fields[1].setGroupSymbol("");
    fields[1].setTrimType(IValueMeta.TRIM_TYPE_NONE);
    fields[2].setName("filename");
    fields[2].setType(IValueMeta.TYPE_STRING);
    fields[2].setFormat("");
    fields[2].setLength(-1);
    fields[2].setPrecision(-1);
    fields[2].setCurrencySymbol("");
    fields[2].setDecimalSymbol("");
    fields[2].setGroupSymbol("");
    fields[2].setTrimType(IValueMeta.TRIM_TYPE_NONE);
    xm.setFieldname(xmlFieldname);
    xm.setResultfieldname(resultFieldname);
    xm.setXSLField(xslInField);
    xm.setXSLFileField(xslFileField);
    xm.setXSLFieldIsAFile(xslFileInField);
    xm.setXslFilename(xslFilename);
    xm.setXSLFactory(xslFactory);
    PipelineHopMeta hi = new PipelineHopMeta(injectorTransform, xsltTransform);
    pipelineMeta.addPipelineHop(hi);
    // 
    // Create a dummy transform 1
    // 
    String dummyTransformName1 = "dummy transform 1";
    DummyMeta dm1 = new DummyMeta();
    String dummyPid1 = registry.getPluginId(TransformPluginType.class, dm1);
    TransformMeta dummyTransform1 = new TransformMeta(dummyPid1, dummyTransformName1, dm1);
    pipelineMeta.addTransform(dummyTransform1);
    PipelineHopMeta hi1 = new PipelineHopMeta(xsltTransform, dummyTransform1);
    pipelineMeta.addPipelineHop(hi1);
    // Now execute the pipeline...
    Pipeline pipeline = new LocalPipelineEngine(pipelineMeta);
    pipeline.prepareExecution();
    ITransform si = pipeline.getTransform(dummyTransformName1, 0);
    RowTransformCollector dummyRc1 = new RowTransformCollector();
    si.addRowListener(dummyRc1);
    RowProducer rp = pipeline.addRowProducer(injectorTransformName, 0);
    pipeline.startThreads();
    // add rows
    List<RowMetaAndData> inputList = createData(xslFilename);
    Iterator<RowMetaAndData> it = inputList.iterator();
    while (it.hasNext()) {
        RowMetaAndData rm = it.next();
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    pipeline.waitUntilFinished();
    // Compare the results
    List<RowMetaAndData> resultRows = dummyRc1.getRowsWritten();
    List<RowMetaAndData> goldenImageRows = createResultData1();
    checkRows(goldenImageRows, resultRows, 2);
}
Also used : DummyMeta(org.apache.hop.pipeline.transforms.dummy.DummyMeta) ITransform(org.apache.hop.pipeline.transform.ITransform) RowProducer(org.apache.hop.pipeline.RowProducer) RowTransformCollector(org.apache.hop.pipeline.transforms.xml.RowTransformCollector) InjectorMeta(org.apache.hop.pipeline.transforms.injector.InjectorMeta) TextFileInputField(org.apache.hop.core.file.TextFileInputField) PipelineHopMeta(org.apache.hop.pipeline.PipelineHopMeta) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) Pipeline(org.apache.hop.pipeline.Pipeline) LocalPipelineEngine(org.apache.hop.pipeline.engines.local.LocalPipelineEngine) RowMetaAndData(org.apache.hop.core.RowMetaAndData) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta)

Example 2 with RowTransformCollector

use of org.apache.hop.pipeline.transforms.xml.RowTransformCollector in project hop by apache.

the class GetXMLDataTest method testInit.

public void testInit() throws Exception {
    HopEnvironment.init();
    // 
    // Create a new pipeline...
    // 
    PipelineMeta pipelineMeta = new PipelineMeta();
    pipelineMeta.setName("getxmldata1");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create an injector transform...
    // 
    String injectorTransformName = "injector transform";
    InjectorMeta im = new InjectorMeta();
    // Set the information of the injector.
    String injectorPid = registry.getPluginId(TransformPluginType.class, im);
    TransformMeta injectorTransform = new TransformMeta(injectorPid, injectorTransformName, im);
    pipelineMeta.addTransform(injectorTransform);
    // 
    // Create a Get XML Data transform
    // 
    String getXMLDataName = "get xml data transform";
    GetXmlDataMeta gxdm = new GetXmlDataMeta();
    String getXMLDataPid = registry.getPluginId(TransformPluginType.class, gxdm);
    TransformMeta getXMLDataTransform = new TransformMeta(getXMLDataPid, getXMLDataName, gxdm);
    pipelineMeta.addTransform(getXMLDataTransform);
    GetXmlDataField[] fields = new GetXmlDataField[5];
    for (int idx = 0; idx < fields.length; idx++) {
        fields[idx] = new GetXmlDataField();
    }
    fields[0].setName("objectid");
    fields[0].setXPath("${xml_path}");
    fields[0].setElementType(GetXmlDataField.ELEMENT_TYPE_NODE);
    fields[0].setType(IValueMeta.TYPE_STRING);
    fields[0].setFormat("");
    fields[0].setLength(-1);
    fields[0].setPrecision(-1);
    fields[0].setCurrencySymbol("");
    fields[0].setDecimalSymbol("");
    fields[0].setGroupSymbol("");
    fields[0].setTrimType(GetXmlDataField.TYPE_TRIM_NONE);
    gxdm.setEncoding("UTF-8");
    gxdm.setIsAFile(false);
    gxdm.setInFields(true);
    gxdm.setLoopXPath("Level1/Level2/Props");
    gxdm.setXMLField("field1");
    gxdm.setInputFields(fields);
    PipelineHopMeta hi = new PipelineHopMeta(injectorTransform, getXMLDataTransform);
    pipelineMeta.addPipelineHop(hi);
    // 
    // Create a dummy transform 1
    // 
    String dummyTransformName1 = "dummy transform 1";
    DummyMeta dm1 = new DummyMeta();
    String dummyPid1 = registry.getPluginId(TransformPluginType.class, dm1);
    TransformMeta dummyTransform1 = new TransformMeta(dummyPid1, dummyTransformName1, dm1);
    pipelineMeta.addTransform(dummyTransform1);
    PipelineHopMeta hi1 = new PipelineHopMeta(getXMLDataTransform, dummyTransform1);
    pipelineMeta.addPipelineHop(hi1);
    // Now execute the pipeline...
    Pipeline pipeline = new LocalPipelineEngine(pipelineMeta);
    pipeline.prepareExecution();
    ITransform si = pipeline.getTransform(dummyTransformName1, 0);
    RowTransformCollector dummyRc1 = new RowTransformCollector();
    si.addRowListener(dummyRc1);
    RowProducer rp = pipeline.addRowProducer(injectorTransformName, 0);
    pipeline.startThreads();
    // add rows
    List<RowMetaAndData> inputList = createData();
    Iterator<RowMetaAndData> it = inputList.iterator();
    while (it.hasNext()) {
        RowMetaAndData rm = it.next();
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    pipeline.waitUntilFinished();
    // Compare the results
    List<RowMetaAndData> resultRows = dummyRc1.getRowsWritten();
    List<RowMetaAndData> goldenImageRows = createResultData1();
    GetXmlDataData getXMLDataData = new GetXmlDataData();
    GetXmlData getXmlData = new GetXmlData(dummyTransform1, gxdm, getXMLDataData, 0, pipelineMeta, pipeline);
    getXmlData.setVariable("xml_path", "data/owner");
    getXmlData.init();
    assertEquals("${xml_path}", gxdm.getInputFields()[0].getXPath());
    assertEquals("data/owner", gxdm.getInputFields()[0].getResolvedXPath());
}
Also used : DummyMeta(org.apache.hop.pipeline.transforms.dummy.DummyMeta) ITransform(org.apache.hop.pipeline.transform.ITransform) RowProducer(org.apache.hop.pipeline.RowProducer) RowTransformCollector(org.apache.hop.pipeline.transforms.xml.RowTransformCollector) InjectorMeta(org.apache.hop.pipeline.transforms.injector.InjectorMeta) PipelineHopMeta(org.apache.hop.pipeline.PipelineHopMeta) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) Pipeline(org.apache.hop.pipeline.Pipeline) LocalPipelineEngine(org.apache.hop.pipeline.engines.local.LocalPipelineEngine) RowMetaAndData(org.apache.hop.core.RowMetaAndData) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta)

Example 3 with RowTransformCollector

use of org.apache.hop.pipeline.transforms.xml.RowTransformCollector in project hop by apache.

the class GetXMLDataTest method testGetXMLDataSimple1.

/**
 * Test case for Get XML Data transform, very simple example.
 *
 * @throws Exception Upon any exception
 */
public void testGetXMLDataSimple1() throws Exception {
    HopEnvironment.init();
    // 
    // Create a new pipeline...
    // 
    PipelineMeta pipelineMeta = new PipelineMeta();
    pipelineMeta.setName("getxmldata1");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create an injector transform...
    // 
    String injectorTransformName = "injector transform";
    InjectorMeta im = new InjectorMeta();
    // Set the information of the injector.
    String injectorPid = registry.getPluginId(TransformPluginType.class, im);
    TransformMeta injectorTransform = new TransformMeta(injectorPid, injectorTransformName, im);
    pipelineMeta.addTransform(injectorTransform);
    // 
    // Create a Get XML Data transform
    // 
    String getXMLDataName = "get xml data transform";
    GetXmlDataMeta gxdm = new GetXmlDataMeta();
    String getXMLDataPid = registry.getPluginId(TransformPluginType.class, gxdm);
    TransformMeta getXMLDataTransform = new TransformMeta(getXMLDataPid, getXMLDataName, gxdm);
    pipelineMeta.addTransform(getXMLDataTransform);
    GetXmlDataField[] fields = new GetXmlDataField[5];
    for (int idx = 0; idx < fields.length; idx++) {
        fields[idx] = new GetXmlDataField();
    }
    fields[0].setName("objectid");
    fields[0].setXPath("ObjectID");
    fields[0].setElementType(GetXmlDataField.ELEMENT_TYPE_NODE);
    fields[0].setType(IValueMeta.TYPE_STRING);
    fields[0].setFormat("");
    fields[0].setLength(-1);
    fields[0].setPrecision(-1);
    fields[0].setCurrencySymbol("");
    fields[0].setDecimalSymbol("");
    fields[0].setGroupSymbol("");
    fields[0].setTrimType(GetXmlDataField.TYPE_TRIM_NONE);
    fields[1].setName("sapident");
    fields[1].setXPath("SAPIDENT");
    fields[1].setElementType(GetXmlDataField.ELEMENT_TYPE_NODE);
    fields[1].setType(IValueMeta.TYPE_STRING);
    fields[1].setFormat("");
    fields[1].setLength(-1);
    fields[1].setPrecision(-1);
    fields[1].setCurrencySymbol("");
    fields[1].setDecimalSymbol("");
    fields[1].setGroupSymbol("");
    fields[1].setTrimType(GetXmlDataField.TYPE_TRIM_NONE);
    fields[2].setName("quantity");
    fields[2].setXPath("Quantity");
    fields[2].setElementType(GetXmlDataField.ELEMENT_TYPE_NODE);
    fields[2].setType(IValueMeta.TYPE_STRING);
    fields[2].setFormat("");
    fields[2].setLength(-1);
    fields[2].setPrecision(-1);
    fields[2].setCurrencySymbol("");
    fields[2].setDecimalSymbol("");
    fields[2].setGroupSymbol("");
    fields[2].setTrimType(GetXmlDataField.TYPE_TRIM_NONE);
    fields[3].setName("merkmalname");
    fields[3].setXPath("Merkmalname");
    fields[3].setElementType(GetXmlDataField.ELEMENT_TYPE_NODE);
    fields[3].setType(IValueMeta.TYPE_STRING);
    fields[3].setFormat("");
    fields[3].setLength(-1);
    fields[3].setPrecision(-1);
    fields[3].setCurrencySymbol("");
    fields[3].setDecimalSymbol("");
    fields[3].setGroupSymbol("");
    fields[3].setTrimType(GetXmlDataField.TYPE_TRIM_NONE);
    fields[4].setName("merkmalswert");
    fields[4].setXPath("Merkmalswert");
    fields[4].setElementType(GetXmlDataField.ELEMENT_TYPE_NODE);
    fields[4].setType(IValueMeta.TYPE_STRING);
    fields[4].setFormat("");
    fields[4].setLength(-1);
    fields[4].setPrecision(-1);
    fields[4].setCurrencySymbol("");
    fields[4].setDecimalSymbol("");
    fields[4].setGroupSymbol("");
    fields[4].setTrimType(GetXmlDataField.TYPE_TRIM_NONE);
    gxdm.setEncoding("UTF-8");
    gxdm.setIsAFile(false);
    gxdm.setInFields(true);
    gxdm.setLoopXPath("Level1/Level2/Props");
    gxdm.setXMLField("field1");
    gxdm.setInputFields(fields);
    PipelineHopMeta hi = new PipelineHopMeta(injectorTransform, getXMLDataTransform);
    pipelineMeta.addPipelineHop(hi);
    // 
    // Create a dummy transform 1
    // 
    String dummyTransformName1 = "dummy transform 1";
    DummyMeta dm1 = new DummyMeta();
    String dummyPid1 = registry.getPluginId(TransformPluginType.class, dm1);
    TransformMeta dummyTransform1 = new TransformMeta(dummyPid1, dummyTransformName1, dm1);
    pipelineMeta.addTransform(dummyTransform1);
    PipelineHopMeta hi1 = new PipelineHopMeta(getXMLDataTransform, dummyTransform1);
    pipelineMeta.addPipelineHop(hi1);
    // Now execute the pipeline...
    Pipeline pipeline = new LocalPipelineEngine(pipelineMeta);
    pipeline.prepareExecution();
    ITransform si = pipeline.getTransform(dummyTransformName1, 0);
    RowTransformCollector dummyRc1 = new RowTransformCollector();
    si.addRowListener(dummyRc1);
    RowProducer rp = pipeline.addRowProducer(injectorTransformName, 0);
    pipeline.startThreads();
    // add rows
    List<RowMetaAndData> inputList = createData();
    Iterator<RowMetaAndData> it = inputList.iterator();
    while (it.hasNext()) {
        RowMetaAndData rm = it.next();
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    pipeline.waitUntilFinished();
    // Compare the results
    List<RowMetaAndData> resultRows = dummyRc1.getRowsWritten();
    List<RowMetaAndData> goldenImageRows = createResultData1();
    checkRows(goldenImageRows, resultRows);
}
Also used : DummyMeta(org.apache.hop.pipeline.transforms.dummy.DummyMeta) ITransform(org.apache.hop.pipeline.transform.ITransform) RowProducer(org.apache.hop.pipeline.RowProducer) RowTransformCollector(org.apache.hop.pipeline.transforms.xml.RowTransformCollector) InjectorMeta(org.apache.hop.pipeline.transforms.injector.InjectorMeta) PipelineHopMeta(org.apache.hop.pipeline.PipelineHopMeta) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) Pipeline(org.apache.hop.pipeline.Pipeline) LocalPipelineEngine(org.apache.hop.pipeline.engines.local.LocalPipelineEngine) RowMetaAndData(org.apache.hop.core.RowMetaAndData) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta)

Aggregations

RowMetaAndData (org.apache.hop.core.RowMetaAndData)3 PluginRegistry (org.apache.hop.core.plugins.PluginRegistry)3 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)3 Pipeline (org.apache.hop.pipeline.Pipeline)3 PipelineHopMeta (org.apache.hop.pipeline.PipelineHopMeta)3 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)3 RowProducer (org.apache.hop.pipeline.RowProducer)3 LocalPipelineEngine (org.apache.hop.pipeline.engines.local.LocalPipelineEngine)3 ITransform (org.apache.hop.pipeline.transform.ITransform)3 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)3 DummyMeta (org.apache.hop.pipeline.transforms.dummy.DummyMeta)3 InjectorMeta (org.apache.hop.pipeline.transforms.injector.InjectorMeta)3 RowTransformCollector (org.apache.hop.pipeline.transforms.xml.RowTransformCollector)3 TextFileInputField (org.apache.hop.core.file.TextFileInputField)1