Search in sources :

Example 11 with StepInterface

use of org.pentaho.di.trans.step.StepInterface in project pentaho-kettle by pentaho.

the class XsltTest method runTestWithParams.

public void runTestWithParams(String xmlFieldname, String resultFieldname, boolean xslInField, boolean xslFileInField, String xslFileField, String xslFilename, String xslFactory) throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("xslt");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create an injector step...
    // 
    String injectorStepname = "injector step";
    InjectorMeta im = new InjectorMeta();
    // Set the information of the injector.
    String injectorPid = registry.getPluginId(StepPluginType.class, im);
    StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, im);
    transMeta.addStep(injectorStep);
    // 
    // Create a XSLT step
    // 
    String xsltName = "xslt step";
    XsltMeta xm = new XsltMeta();
    String xsltPid = registry.getPluginId(StepPluginType.class, xm);
    StepMeta xsltStep = new StepMeta(xsltPid, xsltName, xm);
    transMeta.addStep(xsltStep);
    TextFileInputField[] fields = new TextFileInputField[3];
    for (int idx = 0; idx < fields.length; idx++) {
        fields[idx] = new TextFileInputField();
    }
    fields[0].setName("XML");
    fields[0].setType(ValueMetaInterface.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(ValueMetaInterface.TRIM_TYPE_NONE);
    fields[1].setName("XSL");
    fields[1].setType(ValueMetaInterface.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(ValueMetaInterface.TRIM_TYPE_NONE);
    fields[2].setName("filename");
    fields[2].setType(ValueMetaInterface.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(ValueMetaInterface.TRIM_TYPE_NONE);
    xm.setFieldname(xmlFieldname);
    xm.setResultfieldname(resultFieldname);
    xm.setXSLField(xslInField);
    xm.setXSLFileField(xslFileField);
    xm.setXSLFieldIsAFile(xslFileInField);
    xm.setXslFilename(xslFilename);
    xm.setXSLFactory(xslFactory);
    TransHopMeta hi = new TransHopMeta(injectorStep, xsltStep);
    transMeta.addTransHop(hi);
    // 
    // Create a dummy step 1
    // 
    String dummyStepname1 = "dummy step 1";
    DummyTransMeta dm1 = new DummyTransMeta();
    String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
    StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname1, dm1);
    transMeta.addStep(dummyStep1);
    TransHopMeta hi1 = new TransHopMeta(xsltStep, dummyStep1);
    transMeta.addTransHop(hi1);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(dummyStepname1, 0);
    RowStepCollector dummyRc1 = new RowStepCollector();
    si.addRowListener(dummyRc1);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    trans.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();
    trans.waitUntilFinished();
    // Compare the results
    List<RowMetaAndData> resultRows = dummyRc1.getRowsWritten();
    List<RowMetaAndData> goldenImageRows = createResultData1();
    checkRows(goldenImageRows, resultRows, 2);
}
Also used : RowProducer(org.pentaho.di.trans.RowProducer) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) TextFileInputField(org.pentaho.di.trans.steps.textfileinput.TextFileInputField) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans)

Example 12 with StepInterface

use of org.pentaho.di.trans.step.StepInterface in project pentaho-kettle by pentaho.

the class TransTestFactory method executeTestTransformationError.

public static Map<String, RowStepCollector> executeTestTransformationError(TransMeta transMeta, String injectorStepname, String testStepname, String dummyStepname, String errorStepName, List<RowMetaAndData> inputData) throws KettleException {
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    // Capture the rows that come out of the dummy step...
    // 
    StepInterface si = trans.getStepInterface(dummyStepname, 0);
    RowStepCollector dummyRc = new RowStepCollector();
    si.addRowListener(dummyRc);
    StepInterface junit = trans.getStepInterface(testStepname, 0);
    RowStepCollector dummyJu = new RowStepCollector();
    junit.addRowListener(dummyJu);
    // add error handler
    StepInterface er = trans.getStepInterface(errorStepName, 0);
    RowStepCollector erColl = new RowStepCollector();
    er.addRowListener(erColl);
    // Add a row producer...
    // 
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    // Start the steps...
    // 
    trans.startThreads();
    // Inject the actual test rows...
    // 
    List<RowMetaAndData> inputList = inputData;
    Iterator<RowMetaAndData> it = inputList.iterator();
    while (it.hasNext()) {
        RowMetaAndData rm = it.next();
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    // Wait until the transformation is finished...
    // 
    trans.waitUntilFinished();
    // 
    if (trans.getResult().getNrErrors() > 0) {
        throw new KettleException("Test transformation finished with errors. Check the log.");
    }
    // Return the result from the dummy step...
    Map<String, RowStepCollector> ret = new HashMap<String, RowStepCollector>();
    ret.put(dummyStepname, dummyRc);
    ret.put(errorStepName, erColl);
    ret.put(testStepname, dummyJu);
    return ret;
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) KettleException(org.pentaho.di.core.exception.KettleException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) HashMap(java.util.HashMap)

Example 13 with StepInterface

use of org.pentaho.di.trans.step.StepInterface in project pentaho-kettle by pentaho.

the class TransTestFactory method executeTestTransformation.

public static List<RowMetaAndData> executeTestTransformation(TransMeta transMeta, String injectorStepname, String testStepname, String dummyStepname, List<RowMetaAndData> inputData) throws KettleException {
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    // Capture the rows that come out of the dummy step...
    // 
    StepInterface si = trans.getStepInterface(dummyStepname, 0);
    RowStepCollector dummyRc = new RowStepCollector();
    si.addRowListener(dummyRc);
    // Add a row producer...
    // 
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    // Start the steps...
    // 
    trans.startThreads();
    // Inject the actual test rows...
    // 
    List<RowMetaAndData> inputList = inputData;
    Iterator<RowMetaAndData> it = inputList.iterator();
    while (it.hasNext()) {
        RowMetaAndData rm = it.next();
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    // Wait until the transformation is finished...
    // 
    trans.waitUntilFinished();
    // 
    if (trans.getResult().getNrErrors() > 0) {
        throw new KettleException("Test transformation finished with errors. Check the log.");
    }
    // 
    return dummyRc.getRowsRead();
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) KettleException(org.pentaho.di.core.exception.KettleException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData)

Example 14 with StepInterface

use of org.pentaho.di.trans.step.StepInterface in project pentaho-kettle by pentaho.

the class TransPainter method drawStepPerformanceTable.

private void drawStepPerformanceTable(StepMeta stepMeta) {
    if (stepMeta == null) {
        return;
    }
    // draw optional performance indicator
    if (trans != null) {
        Point pt = stepMeta.getLocation();
        if (pt == null) {
            pt = new Point(50, 50);
        }
        Point screen = real2screen(pt.x, pt.y);
        int x = screen.x;
        int y = screen.y;
        List<StepInterface> steps = trans.findBaseSteps(stepMeta.getName());
        // draw mouse over performance indicator
        if (trans.isRunning()) {
            if (stepMeta.isSelected()) {
                // determine popup dimensions up front
                int popupX = x;
                int popupY = y;
                int popupWidth = 0;
                int popupHeight = 1;
                gc.setFont(EFont.SMALL);
                Point p = gc.textExtent("0000000000");
                int colWidth = p.x + MINI_ICON_MARGIN;
                int rowHeight = p.y + MINI_ICON_MARGIN;
                int titleWidth = 0;
                // calculate max title width to get the colum with
                String[] titles = TransPainter.getPeekTitles();
                for (String title : titles) {
                    Point titleExtent = gc.textExtent(title);
                    titleWidth = Math.max(titleExtent.x + MINI_ICON_MARGIN, titleWidth);
                    popupHeight += titleExtent.y + MINI_ICON_MARGIN;
                }
                popupWidth = titleWidth + 2 * MINI_ICON_MARGIN;
                // determine total popup width
                popupWidth += steps.size() * colWidth;
                // determine popup position
                popupX = popupX + (iconsize - popupWidth) / 2;
                popupY = popupY - popupHeight - MINI_ICON_MARGIN;
                // draw the frame
                gc.setForeground(EColor.DARKGRAY);
                gc.setBackground(EColor.LIGHTGRAY);
                gc.setLineWidth(1);
                gc.fillRoundRectangle(popupX, popupY, popupWidth, popupHeight, 7, 7);
                // draw the title columns
                // gc.setBackground(EColor.BACKGROUND);
                // gc.fillRoundRectangle(popupX, popupY, titleWidth+MINI_ICON_MARGIN, popupHeight, 7, 7);
                gc.setBackground(EColor.LIGHTGRAY);
                gc.drawRoundRectangle(popupX, popupY, popupWidth, popupHeight, 7, 7);
                for (int i = 0, barY = popupY; i < titles.length; i++) {
                    if (i % 2 == 1) {
                        gc.setBackground(EColor.BACKGROUND);
                    } else {
                        gc.setBackground(EColor.LIGHTGRAY);
                    }
                    gc.fillRoundRectangle(popupX + 1, barY + 1, popupWidth - 2, rowHeight, 7, 7);
                    barY += rowHeight;
                }
                // draw the header column
                int rowY = popupY + MINI_ICON_MARGIN;
                int rowX = popupX + MINI_ICON_MARGIN;
                gc.setForeground(EColor.BLACK);
                gc.setBackground(EColor.BACKGROUND);
                for (int i = 0; i < titles.length; i++) {
                    if (i % 2 == 1) {
                        gc.setBackground(EColor.BACKGROUND);
                    } else {
                        gc.setBackground(EColor.LIGHTGRAY);
                    }
                    gc.drawText(titles[i], rowX, rowY);
                    rowY += rowHeight;
                }
                // draw the values for each copy of the step
                gc.setBackground(EColor.LIGHTGRAY);
                rowX += titleWidth;
                for (StepInterface step : steps) {
                    rowX += colWidth;
                    rowY = popupY + MINI_ICON_MARGIN;
                    StepStatus stepStatus = new StepStatus(step);
                    String[] fields = stepStatus.getPeekFields();
                    for (int i = 0; i < fields.length; i++) {
                        if (i % 2 == 1) {
                            gc.setBackground(EColor.BACKGROUND);
                        } else {
                            gc.setBackground(EColor.LIGHTGRAY);
                        }
                        drawTextRightAligned(fields[i], rowX, rowY);
                        rowY += rowHeight;
                    }
                }
            }
        }
    }
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) StepStatus(org.pentaho.di.trans.step.StepStatus) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

Example 15 with StepInterface

use of org.pentaho.di.trans.step.StepInterface in project pentaho-kettle by pentaho.

the class TransDebugMeta method addRowListenersToTransformation.

public synchronized void addRowListenersToTransformation(final Trans trans) {
    final TransDebugMeta self = this;
    // 
    for (final StepMeta stepMeta : stepDebugMetaMap.keySet()) {
        final StepDebugMeta stepDebugMeta = stepDebugMetaMap.get(stepMeta);
        // 
        for (StepInterface baseStep : trans.findBaseSteps(stepMeta.getName())) {
            baseStep.addRowListener(new RowAdapter() {

                public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                    try {
                        // This block of code is called whenever there is a row written by the step
                        // So we want to execute the debugging actions that are specified by the step...
                        // 
                        int rowCount = stepDebugMeta.getRowCount();
                        if (stepDebugMeta.isReadingFirstRows() && rowCount > 0) {
                            int bufferSize = stepDebugMeta.getRowBuffer().size();
                            if (bufferSize < rowCount) {
                                // This is the classic preview mode.
                                // We add simply add the row to the buffer.
                                // 
                                stepDebugMeta.setRowBufferMeta(rowMeta);
                                stepDebugMeta.getRowBuffer().add(rowMeta.cloneRow(row));
                            } else {
                                // pause the transformation...
                                // 
                                trans.pauseRunning();
                                // Also call the pause / break-point listeners on the step debugger...
                                // 
                                stepDebugMeta.fireBreakPointListeners(self);
                            }
                        } else if (stepDebugMeta.isPausingOnBreakPoint() && stepDebugMeta.getCondition() != null) {
                            // 
                            if (rowCount > 0) {
                                // Keep a number of rows in memory
                                // Store them in a reverse order to keep it intuitive for the user.
                                // 
                                stepDebugMeta.setRowBufferMeta(rowMeta);
                                stepDebugMeta.getRowBuffer().add(0, rowMeta.cloneRow(row));
                                // Only keep a number of rows in memory
                                // If we have too many, remove the last (oldest)
                                // 
                                int bufferSize = stepDebugMeta.getRowBuffer().size();
                                if (bufferSize > rowCount) {
                                    stepDebugMeta.getRowBuffer().remove(bufferSize - 1);
                                }
                            } else {
                                // 
                                if (stepDebugMeta.getRowBuffer().isEmpty()) {
                                    stepDebugMeta.getRowBuffer().add(rowMeta.cloneRow(row));
                                } else {
                                    stepDebugMeta.getRowBuffer().set(0, rowMeta.cloneRow(row));
                                }
                            }
                            // 
                            if (stepDebugMeta.getCondition().evaluate(rowMeta, row)) {
                                // We hit the break-point: pause the transformation
                                // 
                                trans.pauseRunning();
                                // Also fire off the break point listeners...
                                // 
                                stepDebugMeta.fireBreakPointListeners(self);
                            }
                        }
                    } catch (KettleException e) {
                        throw new KettleStepException(e);
                    }
                }
            });
        }
    }
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowAdapter(org.pentaho.di.trans.step.RowAdapter) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta)

Aggregations

StepInterface (org.pentaho.di.trans.step.StepInterface)150 Trans (org.pentaho.di.trans.Trans)88 StepMeta (org.pentaho.di.trans.step.StepMeta)88 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)75 TransMeta (org.pentaho.di.trans.TransMeta)73 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)69 RowStepCollector (org.pentaho.di.trans.RowStepCollector)68 TransHopMeta (org.pentaho.di.trans.TransHopMeta)67 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)66 RowProducer (org.pentaho.di.trans.RowProducer)57 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)50 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)49 Test (org.junit.Test)37 KettleException (org.pentaho.di.core.exception.KettleException)28 StepMetaDataCombi (org.pentaho.di.trans.step.StepMetaDataCombi)19 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)17 ArrayList (java.util.ArrayList)15 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)14 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)14 RowSet (org.pentaho.di.core.RowSet)13