Search in sources :

Example 6 with CsvInputMeta

use of org.pentaho.di.trans.steps.csvinput.CsvInputMeta in project pentaho-kettle by pentaho.

the class CsvInputDialog method preview.

// Preview the data
private synchronized void preview() {
    // Create the XML input step
    CsvInputMeta oneMeta = new CsvInputMeta();
    getInfo(oneMeta);
    TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
    transMeta.getVariable("Internal.Transformation.Filename.Directory");
    previewMeta.getVariable("Internal.Transformation.Filename.Directory");
    EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "CsvInputDialog.PreviewSize.DialogTitle"), BaseMessages.getString(PKG, "CsvInputDialog.PreviewSize.DialogMessage"));
    int previewSize = numberDialog.open();
    if (previewSize > 0) {
        TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
        progressDialog.open();
        Trans trans = progressDialog.getTrans();
        String loggingText = progressDialog.getLoggingText();
        if (!progressDialog.isCancelled()) {
            if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
                EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
                etd.setReadOnly();
                etd.open();
            }
        }
        PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText);
        prd.open();
    }
}
Also used : TransPreviewProgressDialog(org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog) CsvInputMeta(org.pentaho.di.trans.steps.csvinput.CsvInputMeta) TransMeta(org.pentaho.di.trans.TransMeta) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) EnterNumberDialog(org.pentaho.di.ui.core.dialog.EnterNumberDialog) Trans(org.pentaho.di.trans.Trans)

Example 7 with CsvInputMeta

use of org.pentaho.di.trans.steps.csvinput.CsvInputMeta in project pentaho-kettle by pentaho.

the class CsvInputDialog method updatePreview.

/**
 * Load metadata from step window
 */
protected void updatePreview() {
    if (initializing) {
        return;
    }
    if (previewBusy.get()) {
        return;
    }
    try {
        previewBusy.set(true);
        CsvInputMeta meta = new CsvInputMeta();
        getInfo(meta);
        // 
        if (Utils.isEmpty(meta.getFilename())) {
            return;
        }
        if (Utils.isEmpty(meta.getInputFields())) {
            return;
        }
        String stepname = wStepname.getText();
        // StepMeta stepMeta = new StepMeta(stepname, meta);
        StringBuffer buffer = new StringBuffer();
        final List<Object[]> rowsData = new ArrayList<Object[]>();
        final RowMetaInterface rowMeta = new RowMeta();
        try {
            meta.getFields(rowMeta, stepname, null, null, transMeta, repository, metaStore);
            TransMeta previewTransMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, meta, stepname);
            final Trans trans = new Trans(previewTransMeta);
            trans.prepareExecution(null);
            StepInterface step = trans.getRunThread(stepname, 0);
            step.addRowListener(new RowAdapter() {

                @Override
                public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                    rowsData.add(row);
                    // 
                    if (rowsData.size() > PropsUI.getInstance().getDefaultPreviewSize()) {
                        trans.stopAll();
                    }
                }
            });
            trans.startThreads();
            trans.waitUntilFinished();
            if (trans.getErrors() > 0) {
                StringBuffer log = KettleLogStore.getAppender().getBuffer(trans.getLogChannelId(), false);
                buffer.append(log);
            }
            KettleLogStore.discardLines(trans.getLogChannelId(), false);
            LoggingRegistry.getInstance().removeIncludingChildren(trans.getLogChannelId());
        } catch (Exception e) {
            buffer.append(Const.getStackTracker(e));
        }
        TransGraph transGraph = Spoon.getInstance().getActiveTransGraph();
        if (transGraph != null) {
            if (!transGraph.isExecutionResultsPaneVisible()) {
                transGraph.showExecutionResults();
            }
            transGraph.extraViewTabFolder.setSelection(5);
            transGraph.transPreviewDelegate.addPreviewData(stepMeta, rowMeta, rowsData, buffer);
            transGraph.transPreviewDelegate.setSelectedStep(stepMeta);
            transGraph.transPreviewDelegate.refreshView();
        }
    } finally {
        previewBusy.set(false);
    }
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) CsvInputMeta(org.pentaho.di.trans.steps.csvinput.CsvInputMeta) ArrayList(java.util.ArrayList) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph) SWTException(org.eclipse.swt.SWTException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) StepInterface(org.pentaho.di.trans.step.StepInterface) RowAdapter(org.pentaho.di.trans.step.RowAdapter) FileObject(org.apache.commons.vfs2.FileObject) Trans(org.pentaho.di.trans.Trans)

Aggregations

CsvInputMeta (org.pentaho.di.trans.steps.csvinput.CsvInputMeta)7 TransMeta (org.pentaho.di.trans.TransMeta)5 StepMeta (org.pentaho.di.trans.step.StepMeta)4 Test (org.junit.Test)3 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)3 StepErrorMeta (org.pentaho.di.trans.step.StepErrorMeta)3 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)3 IOException (java.io.IOException)2 FileObject (org.apache.commons.vfs2.FileObject)2 SWTException (org.eclipse.swt.SWTException)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 KettleException (org.pentaho.di.core.exception.KettleException)2 KettleStepException (org.pentaho.di.core.exception.KettleStepException)2 Point (org.pentaho.di.core.gui.Point)2 Trans (org.pentaho.di.trans.Trans)2 EnterNumberDialog (org.pentaho.di.ui.core.dialog.EnterNumberDialog)2 EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)2 File (java.io.File)1