Search in sources :

Example 46 with FileInputList

use of org.pentaho.di.core.fileinput.FileInputList in project pentaho-kettle by pentaho.

the class GetXMLDataMeta method check.

public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
    CheckResult cr;
    // See if we get input...
    if (input.length <= 0) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "GetXMLDataMeta.CheckResult.NoInputExpected"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "GetXMLDataMeta.CheckResult.NoInput"), stepMeta);
        remarks.add(cr);
    }
    // control Xpath
    if (getLoopXPath() == null || Utils.isEmpty(getLoopXPath())) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "GetXMLDataMeta.CheckResult.NoLoopXpath"), stepMeta);
        remarks.add(cr);
    }
    if (getInputFields().length <= 0) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "GetXMLDataMeta.CheckResult.NoInputField"), stepMeta);
        remarks.add(cr);
    }
    if (isInFields()) {
        if (Utils.isEmpty(getXMLField())) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "GetXMLDataMeta.CheckResult.NoField"), stepMeta);
            remarks.add(cr);
        } else {
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "GetXMLDataMeta.CheckResult.FieldOk"), stepMeta);
            remarks.add(cr);
        }
    } else {
        FileInputList fileInputList = getFiles(transMeta);
        // String files[] = getFiles();
        if (fileInputList == null || fileInputList.getFiles().size() == 0) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "GetXMLDataMeta.CheckResult.NoFiles"), stepMeta);
            remarks.add(cr);
        } else {
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "GetXMLDataMeta.CheckResult.FilesOk", "" + fileInputList.getFiles().size()), stepMeta);
            remarks.add(cr);
        }
    }
}
Also used : CheckResult(org.pentaho.di.core.CheckResult) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Example 47 with FileInputList

use of org.pentaho.di.core.fileinput.FileInputList in project pentaho-kettle by pentaho.

the class ExcelInputDialog method getSheets.

/**
 * Get the names of the sheets from the Excel workbooks and let the user select some or all of them.
 */
public void getSheets() {
    List<String> sheetnames = new ArrayList<String>();
    ExcelInputMeta info = new ExcelInputMeta();
    getInfo(info);
    FileInputList fileList = info.getFileList(transMeta);
    for (FileObject fileObject : fileList.getFiles()) {
        try {
            KWorkbook workbook = WorkbookFactory.getWorkbook(info.getSpreadSheetType(), KettleVFS.getFilename(fileObject), info.getEncoding());
            int nrSheets = workbook.getNumberOfSheets();
            for (int j = 0; j < nrSheets; j++) {
                KSheet sheet = workbook.getSheet(j);
                String sheetname = sheet.getName();
                if (Const.indexOfString(sheetname, sheetnames) < 0) {
                    sheetnames.add(sheetname);
                }
            }
            workbook.close();
        } catch (Exception e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "ExcelInputDialog.ErrorReadingFile.DialogMessage", KettleVFS.getFilename(fileObject)), e);
        }
    }
    // Put it in an array:
    String[] lst = sheetnames.toArray(new String[sheetnames.size()]);
    // Let the user select the sheet-names...
    EnterListDialog esd = new EnterListDialog(shell, SWT.NONE, lst);
    String[] selection = esd.open();
    if (selection != null) {
        for (int j = 0; j < selection.length; j++) {
            wSheetnameList.add(new String[] { selection[j], "" });
        }
        wSheetnameList.removeEmptyRows();
        wSheetnameList.setRowNums();
        wSheetnameList.optWidth(true);
        checkAlerts();
    }
}
Also used : KWorkbook(org.pentaho.di.core.spreadsheet.KWorkbook) ArrayList(java.util.ArrayList) KSheet(org.pentaho.di.core.spreadsheet.KSheet) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) EnterListDialog(org.pentaho.di.ui.core.dialog.EnterListDialog) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ExcelInputMeta(org.pentaho.di.trans.steps.excelinput.ExcelInputMeta) FileObject(org.apache.commons.vfs2.FileObject) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Example 48 with FileInputList

use of org.pentaho.di.core.fileinput.FileInputList in project pentaho-kettle by pentaho.

the class JsonInputMeta method exportResources.

/**
 * Since the exported transformation that runs this will reside in a ZIP file, we can't reference files relatively. So
 * what this does is turn the name of files into absolute paths OR it simply includes the resource in the ZIP file.
 * For now, we'll simply turn it into an absolute path and pray that the file is on a shared drive or something like
 * that.
 *
 * @param space
 *          the variable space to use
 * @param definitions
 * @param resourceNamingInterface
 * @param repository
 *          The repository to optionally load other resources from (to be converted to XML)
 * @param metaStore
 *          the metaStore in which non-kettle metadata could reside.
 *
 * @return the filename of the exported resource
 */
@Override
public String exportResources(VariableSpace space, Map<String, ResourceDefinition> definitions, ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore) throws KettleException {
    try {
        // The object that we're modifying here is a copy of the original!
        // So let's change the filename from relative to absolute by grabbing the file object...
        // In case the name of the file comes from previous steps, forget about this!
        // 
        List<String> newFilenames = new ArrayList<String>();
        if (!isInFields()) {
            FileInputList fileList = getFiles(space);
            if (fileList.getFiles().size() > 0) {
                for (FileObject fileObject : fileList.getFiles()) {
                    // 
                    if (fileObject.exists()) {
                        // Convert to an absolute path and add it to the list.
                        // 
                        newFilenames.add(fileObject.getName().getPath());
                    }
                }
                // Still here: set a new list of absolute filenames!
                // 
                setFileName(newFilenames.toArray(new String[newFilenames.size()]));
                // all null since converted to absolute path.
                setFileMask(new String[newFilenames.size()]);
                // all null, turn to "Y" :
                setFileRequired(new String[newFilenames.size()]);
                Arrays.fill(getFileRequired(), YES);
            }
        }
        return null;
    } catch (Exception e) {
        throw new KettleException(e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ArrayList(java.util.ArrayList) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) FileObject(org.apache.commons.vfs2.FileObject) FileInputList(org.pentaho.di.core.fileinput.FileInputList) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Example 49 with FileInputList

use of org.pentaho.di.core.fileinput.FileInputList in project pentaho-kettle by pentaho.

the class JsonInputMeta method check.

@Override
public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
    CheckResult cr;
    if (!isInFields()) {
        // See if we get input...
        if (input.length <= 0) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "JsonInputMeta.CheckResult.NoInputExpected"), stepMeta);
            remarks.add(cr);
        } else {
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "JsonInputMeta.CheckResult.NoInput"), stepMeta);
            remarks.add(cr);
        }
    }
    if (getInputFields().length <= 0) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "JsonInputMeta.CheckResult.NoInputField"), stepMeta);
        remarks.add(cr);
    }
    if (isInFields()) {
        if (Utils.isEmpty(getFieldValue())) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "JsonInputMeta.CheckResult.NoField"), stepMeta);
            remarks.add(cr);
        } else {
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "JsonInputMeta.CheckResult.FieldOk"), stepMeta);
            remarks.add(cr);
        }
    } else {
        FileInputList fileInputList = getFiles(transMeta);
        // String files[] = getFiles();
        if (fileInputList == null || fileInputList.getFiles().size() == 0) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "JsonInputMeta.CheckResult.NoFiles"), stepMeta);
            remarks.add(cr);
        } else {
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "JsonInputMeta.CheckResult.FilesOk", "" + fileInputList.getFiles().size()), stepMeta);
            remarks.add(cr);
        }
    }
}
Also used : CheckResult(org.pentaho.di.core.CheckResult) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Example 50 with FileInputList

use of org.pentaho.di.core.fileinput.FileInputList in project pentaho-kettle by pentaho.

the class AccessInputDialog method get.

private void get() {
    RowMetaInterface fields = new RowMeta();
    try {
        AccessInputMeta meta = new AccessInputMeta();
        getInfo(meta);
        // Check if a table name is specified
        if (!checkInputTableName(meta)) {
            return;
        }
        FileInputList inputList = meta.getFiles(transMeta);
        if (inputList.getFiles().size() > 0) {
            // Open the file (only first file)...
            Database d = Database.open(new File(AccessInputMeta.getFilename(inputList.getFile(0))), true);
            String realTableName = transMeta.environmentSubstitute(meta.getTableName());
            Table t = null;
            if (realTableName.startsWith(AccessInputMeta.PREFIX_SYSTEM)) {
                t = d.getSystemTable(realTableName);
            } else {
                t = d.getTable(realTableName);
            }
            // Get the list of columns
            List<Column> col = t.getColumns();
            int nr = col.size();
            for (int i = 0; i < nr; i++) {
                Column c = col.get(i);
                ValueMetaInterface field = AccessInputMeta.getValueMeta(c);
                if (field != null && fields.indexOfValue(field.getName()) < 0) {
                    fields.addValueMeta(field);
                }
            }
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "AccessInputDialog.ErrorReadingFile.DialogMessage", e.toString()), e);
    }
    if (fields.size() > 0) {
        // Clear Fields Grid
        wFields.removeAll();
        for (int j = 0; j < fields.size(); j++) {
            ValueMetaInterface field = fields.getValueMeta(j);
            wFields.add(new String[] { field.getName(), field.getName(), field.getTypeDesc(), "", "-1", "", "", "", "", "none", "N" });
        }
        wFields.removeEmptyRows();
        wFields.setRowNums();
        wFields.optWidth(true);
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
        mb.setMessage(BaseMessages.getString(PKG, "AccessInputDialog.UnableToFindFields.DialogTitle"));
        mb.setText(BaseMessages.getString(PKG, "AccessInputDialog.UnableToFindFields.DialogMessage"));
        mb.open();
    }
}
Also used : Table(com.healthmarketscience.jackcess.Table) RowMeta(org.pentaho.di.core.row.RowMeta) AccessInputMeta(org.pentaho.di.trans.steps.accessinput.AccessInputMeta) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) KettleException(org.pentaho.di.core.exception.KettleException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) MessageBox(org.eclipse.swt.widgets.MessageBox) Column(com.healthmarketscience.jackcess.Column) Database(com.healthmarketscience.jackcess.Database) File(java.io.File) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Aggregations

FileInputList (org.pentaho.di.core.fileinput.FileInputList)54 KettleException (org.pentaho.di.core.exception.KettleException)25 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)22 MessageBox (org.eclipse.swt.widgets.MessageBox)18 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)16 CheckResult (org.pentaho.di.core.CheckResult)14 FileObject (org.apache.commons.vfs2.FileObject)12 FileDialog (org.eclipse.swt.widgets.FileDialog)11 EnterSelectionDialog (org.pentaho.di.ui.core.dialog.EnterSelectionDialog)11 Shell (org.eclipse.swt.widgets.Shell)10 RowMeta (org.pentaho.di.core.row.RowMeta)10 CTabFolder (org.eclipse.swt.custom.CTabFolder)9 ModifyEvent (org.eclipse.swt.events.ModifyEvent)9 ModifyListener (org.eclipse.swt.events.ModifyListener)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 ShellAdapter (org.eclipse.swt.events.ShellAdapter)9 ShellEvent (org.eclipse.swt.events.ShellEvent)9 FormAttachment (org.eclipse.swt.layout.FormAttachment)9 FormData (org.eclipse.swt.layout.FormData)9