Search in sources :

Example 1 with InjectorMeta

use of org.apache.hop.pipeline.transforms.injector.InjectorMeta in project hop by apache.

the class KafkaConsumerInputDialog method createSubPipelineMeta.

protected PipelineMeta createSubPipelineMeta() {
    InjectorMeta injectorMeta = new InjectorMeta();
    String[] fieldNames = getFieldNames();
    int[] fieldTypes = getFieldTypes();
    for (int i = 0; i < fieldNames.length; i++) {
        InjectorField field = new InjectorField(fieldNames[i], ValueMetaFactory.getValueMetaName(fieldTypes[i]), "", "");
        injectorMeta.getInjectorFields().add(field);
    }
    TransformMeta recsFromStream = new TransformMeta("RecordsFromStream", "Get messages from Kafka", injectorMeta);
    recsFromStream.setLocation(new Point(100, 100));
    PipelineMeta pipelineMeta = new PipelineMeta();
    pipelineMeta.addTransform(recsFromStream);
    pipelineMeta.setFilename("");
    return pipelineMeta;
}
Also used : InjectorField(org.apache.hop.pipeline.transforms.injector.InjectorField) BaseTransformMeta(org.apache.hop.pipeline.transform.BaseTransformMeta) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) InjectorMeta(org.apache.hop.pipeline.transforms.injector.InjectorMeta) Point(org.apache.hop.core.gui.Point) Point(org.apache.hop.core.gui.Point) PipelineMeta(org.apache.hop.pipeline.PipelineMeta)

Example 2 with InjectorMeta

use of org.apache.hop.pipeline.transforms.injector.InjectorMeta 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 3 with InjectorMeta

use of org.apache.hop.pipeline.transforms.injector.InjectorMeta 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 4 with InjectorMeta

use of org.apache.hop.pipeline.transforms.injector.InjectorMeta in project hop by apache.

the class TestUtilities method createInjectorTransform.

/**
 * Create an injector transform.
 *
 * @param name
 * @param pluginRegistry
 * @return TransformMeta
 */
public static synchronized TransformMeta createInjectorTransform(String name, PluginRegistry pluginRegistry) {
    // create an injector transform...
    InjectorMeta injectorMeta = new InjectorMeta();
    // Set the information of the injector
    String injectorPid = pluginRegistry.getPluginId(TransformPluginType.class, injectorMeta);
    TransformMeta injectorTransform = new TransformMeta(injectorPid, name, injectorMeta);
    return injectorTransform;
}
Also used : TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) InjectorMeta(org.apache.hop.pipeline.transforms.injector.InjectorMeta)

Example 5 with InjectorMeta

use of org.apache.hop.pipeline.transforms.injector.InjectorMeta in project hop by apache.

the class PipelineTestFactory method getInjectorTransformMeta.

static TransformMeta getInjectorTransformMeta() {
    InjectorMeta zeroMeta = new InjectorMeta();
    TransformMeta zero = new TransformMeta(registry.getPluginId(TransformPluginType.class, zeroMeta), INJECTOR_TRANSFORMNAME, zeroMeta);
    zero.setLocation(50, 50);
    // zero.setDraw( true );
    return zero;
}
Also used : TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) ITransformMeta(org.apache.hop.pipeline.transform.ITransformMeta) InjectorMeta(org.apache.hop.pipeline.transforms.injector.InjectorMeta) TransformPluginType(org.apache.hop.core.plugins.TransformPluginType)

Aggregations

InjectorMeta (org.apache.hop.pipeline.transforms.injector.InjectorMeta)10 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)8 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)6 LocalPipelineEngine (org.apache.hop.pipeline.engines.local.LocalPipelineEngine)5 PipelineHopMeta (org.apache.hop.pipeline.PipelineHopMeta)4 RowProducer (org.apache.hop.pipeline.RowProducer)4 RowMetaAndData (org.apache.hop.core.RowMetaAndData)3 PluginRegistry (org.apache.hop.core.plugins.PluginRegistry)3 IRowMeta (org.apache.hop.core.row.IRowMeta)3 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)3 Pipeline (org.apache.hop.pipeline.Pipeline)3 ITransform (org.apache.hop.pipeline.transform.ITransform)3 DummyMeta (org.apache.hop.pipeline.transforms.dummy.DummyMeta)3 InjectorField (org.apache.hop.pipeline.transforms.injector.InjectorField)3 RowTransformCollector (org.apache.hop.pipeline.transforms.xml.RowTransformCollector)3 HopException (org.apache.hop.core.exception.HopException)2 HopTransformException (org.apache.hop.core.exception.HopTransformException)2 TransformPluginType (org.apache.hop.core.plugins.TransformPluginType)2 IValueMeta (org.apache.hop.core.row.IValueMeta)2 BaseTransformMeta (org.apache.hop.pipeline.transform.BaseTransformMeta)2