Search in sources :

Example 21 with KettleException

use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.

the class SingleThreaderDialog method selectRepositoryTrans.

private void selectRepositoryTrans() {
    RepositoryObject repositoryObject = DialogHelper.selectRepositoryObject("*.ktr", log);
    try {
        if (repositoryObject != null) {
            loadRepositoryTrans(repositoryObject.getName(), repositoryObject.getRepositoryDirectory());
            String path = DialogUtils.getPath(transMeta.getRepositoryDirectory().getPath(), mappingTransMeta.getRepositoryDirectory().getPath());
            String fullPath = (path.equals("/") ? "/" : path + "/") + mappingTransMeta.getName();
            wPath.setText(fullPath);
            specificationMethod = ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME;
        }
    } catch (KettleException ke) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "SingleThreaderDialog.ErrorSelectingObject.DialogTitle"), BaseMessages.getString(PKG, "SingleThreaderDialog.ErrorSelectingObject.DialogMessage"), ke);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryObject(org.pentaho.di.repository.RepositoryObject) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog)

Example 22 with KettleException

use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.

the class SingleThreaderDialog method loadTransformation.

private void loadTransformation() throws KettleException {
    String filename = wPath.getText();
    if (repository != null) {
        specificationMethod = ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME;
    } else {
        specificationMethod = ObjectLocationSpecificationMethod.FILENAME;
    }
    switch(specificationMethod) {
        case FILENAME:
            if (Utils.isEmpty(filename)) {
                return;
            }
            if (!filename.endsWith(".ktr")) {
                filename = filename + ".ktr";
                wPath.setText(filename);
            }
            loadFileTrans(filename);
            break;
        case REPOSITORY_BY_NAME:
            if (Utils.isEmpty(filename)) {
                return;
            }
            if (filename.endsWith(".ktr")) {
                filename = filename.replace(".ktr", "");
                wPath.setText(filename);
            }
            String transPath = transMeta.environmentSubstitute(filename);
            String realTransname = transPath;
            String realDirectory = "";
            int index = transPath.lastIndexOf("/");
            if (index != -1) {
                realTransname = transPath.substring(index + 1);
                realDirectory = transPath.substring(0, index);
            }
            if (Utils.isEmpty(realDirectory) || Utils.isEmpty(realTransname)) {
                throw new KettleException(BaseMessages.getString(PKG, "SingleThreaderDialog.Exception.NoValidMappingDetailsFound"));
            }
            RepositoryDirectoryInterface repdir = repository.findDirectory(realDirectory);
            if (repdir == null) {
                throw new KettleException(BaseMessages.getString(PKG, "SingleThreaderDialog.Exception.UnableToFindRepositoryDirectory)"));
            }
            loadRepositoryTrans(realTransname, repdir);
            break;
        case REPOSITORY_BY_REFERENCE:
            // load the last version
            mappingTransMeta = repository.loadTransformation(referenceObjectId, null);
            mappingTransMeta.clearChanged();
            break;
        default:
            break;
    }
    wInjectStep.setText(getInjectorStep(mappingTransMeta));
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface)

Example 23 with KettleException

use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.

the class YamlInputDialog method preview.

// Preview the data
private void preview() {
    try {
        // Create the XML input step
        YamlInputMeta oneMeta = new YamlInputMeta();
        getInfo(oneMeta);
        TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
        EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "YamlInputDialog.NumberRows.DialogTitle"), BaseMessages.getString(PKG, "YamlInputDialog.NumberRows.DialogMessage"));
        int previewSize = numberDialog.open();
        if (previewSize > 0) {
            TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
            progressDialog.open();
            if (!progressDialog.isCancelled()) {
                Trans trans = progressDialog.getTrans();
                String loggingText = progressDialog.getLoggingText();
                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();
            }
        }
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "YamlInputDialog.ErrorPreviewingData.DialogTitle"), BaseMessages.getString(PKG, "YamlInputDialog.ErrorPreviewingData.DialogMessage"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TransPreviewProgressDialog(org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog) TransMeta(org.pentaho.di.trans.TransMeta) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) EnterNumberDialog(org.pentaho.di.ui.core.dialog.EnterNumberDialog) YamlInputMeta(org.pentaho.di.trans.steps.yamlinput.YamlInputMeta) Trans(org.pentaho.di.trans.Trans)

Example 24 with KettleException

use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.

the class ZipFileDialog method get.

private void get() {
    if (!gotPreviousFields) {
        gotPreviousFields = true;
        String source = wSourceFileNameField.getText();
        String target = wTargetFileNameField.getText();
        String base = wBaseFolderField.getText();
        try {
            wSourceFileNameField.removeAll();
            wTargetFileNameField.removeAll();
            wBaseFolderField.removeAll();
            RowMetaInterface r = transMeta.getPrevStepFields(stepname);
            if (r != null) {
                String[] fields = r.getFieldNames();
                wSourceFileNameField.setItems(fields);
                wTargetFileNameField.setItems(fields);
                wBaseFolderField.setItems(fields);
            }
        } catch (KettleException ke) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "ZipFileDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "ZipFileDialog.FailedToGetFields.DialogMessage"), ke);
        } finally {
            if (source != null) {
                wSourceFileNameField.setText(source);
            }
            if (target != null) {
                wTargetFileNameField.setText(target);
            }
            if (base != null) {
                wBaseFolderField.setText(base);
            }
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface)

Example 25 with KettleException

use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.

the class TextFileInputDialog method getFirst.

// Get the first x lines
private List<String> getFirst(int nrlines, boolean skipHeaders) throws KettleException {
    TextFileInputMeta meta = new TextFileInputMeta();
    getInfo(meta);
    FileInputList textFileList = meta.getTextFileList(transMeta);
    InputStream fi;
    CompressionInputStream f = null;
    StringBuilder lineStringBuilder = new StringBuilder(256);
    int fileFormatType = meta.getFileFormatTypeNr();
    List<String> retval = new ArrayList<String>();
    if (textFileList.nrOfFiles() > 0) {
        FileObject file = textFileList.getFile(0);
        try {
            fi = KettleVFS.getInputStream(file);
            CompressionProvider provider = CompressionProviderFactory.getInstance().createCompressionProviderInstance(meta.getFileCompression());
            f = provider.createInputStream(fi);
            InputStreamReader reader;
            if (meta.getEncoding() != null && meta.getEncoding().length() > 0) {
                reader = new InputStreamReader(f, meta.getEncoding());
            } else {
                reader = new InputStreamReader(f);
            }
            EncodingType encodingType = EncodingType.guessEncodingType(reader.getEncoding());
            int linenr = 0;
            int maxnr = nrlines + (meta.hasHeader() ? meta.getNrHeaderLines() : 0);
            if (skipHeaders) {
                // Skip the header lines first if more then one, it helps us position
                if (meta.isLayoutPaged() && meta.getNrLinesDocHeader() > 0) {
                    int skipped = 0;
                    String line = TextFileInput.getLine(log, reader, encodingType, fileFormatType, lineStringBuilder);
                    while (line != null && skipped < meta.getNrLinesDocHeader() - 1) {
                        skipped++;
                        line = TextFileInput.getLine(log, reader, encodingType, fileFormatType, lineStringBuilder);
                    }
                }
                // Skip the header lines first if more then one, it helps us position
                if (meta.hasHeader() && meta.getNrHeaderLines() > 0) {
                    int skipped = 0;
                    String line = TextFileInput.getLine(log, reader, encodingType, fileFormatType, lineStringBuilder);
                    while (line != null && skipped < meta.getNrHeaderLines() - 1) {
                        skipped++;
                        line = TextFileInput.getLine(log, reader, encodingType, fileFormatType, lineStringBuilder);
                    }
                }
            }
            String line = TextFileInput.getLine(log, reader, encodingType, fileFormatType, lineStringBuilder);
            while (line != null && (linenr < maxnr || nrlines == 0)) {
                retval.add(line);
                linenr++;
                line = TextFileInput.getLine(log, reader, encodingType, fileFormatType, lineStringBuilder);
            }
        } catch (Exception e) {
            throw new KettleException(BaseMessages.getString(PKG, "TextFileInputDialog.Exception.ErrorGettingFirstLines", "" + nrlines, file.getName().getURI()), e);
        } finally {
            try {
                if (f != null) {
                    f.close();
                }
            } catch (Exception e) {
            // Ignore errors
            }
        }
    }
    return retval;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) InputStreamReader(java.io.InputStreamReader) CompressionInputStream(org.pentaho.di.core.compress.CompressionInputStream) CompressionInputStream(org.pentaho.di.core.compress.CompressionInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) EncodingType(org.pentaho.di.trans.steps.textfileinput.EncodingType) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) CompressionProvider(org.pentaho.di.core.compress.CompressionProvider) TextFileInputMeta(org.pentaho.di.trans.steps.textfileinput.TextFileInputMeta) FileObject(org.apache.commons.vfs2.FileObject) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Aggregations

KettleException (org.pentaho.di.core.exception.KettleException)1977 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)449 KettleStepException (org.pentaho.di.core.exception.KettleStepException)438 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)317 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)316 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)233 IOException (java.io.IOException)208 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)195 FileObject (org.apache.commons.vfs2.FileObject)150 StepMeta (org.pentaho.di.trans.step.StepMeta)150 ArrayList (java.util.ArrayList)149 KettleFileException (org.pentaho.di.core.exception.KettleFileException)124 TransMeta (org.pentaho.di.trans.TransMeta)119 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)113 Test (org.junit.Test)111 KettleValueException (org.pentaho.di.core.exception.KettleValueException)100 Database (org.pentaho.di.core.database.Database)97 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)95 ObjectId (org.pentaho.di.repository.ObjectId)91 Shell (org.eclipse.swt.widgets.Shell)90