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);
}
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());
}
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);
}
Aggregations