Search in sources :

Example 26 with FileInputList

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

the class LoadFileInputTest method setup.

@Before
public void setup() throws FileSystemException {
    fs = VFS.getManager();
    filesPath = '/' + this.getClass().getPackage().getName().replace('.', '/') + "/files/";
    transName = "LoadFileInput";
    transMeta = new TransMeta();
    transMeta.setName(transName);
    trans = new Trans(transMeta);
    stepMetaInterface = spy(new LoadFileInputMeta());
    stepInputFiles = new FileInputList();
    Mockito.doReturn(stepInputFiles).when(stepMetaInterface).getFiles(any(VariableSpace.class));
    String stepId = PluginRegistry.getInstance().getPluginId(StepPluginType.class, stepMetaInterface);
    stepMeta = new StepMeta(stepId, "Load File Input", stepMetaInterface);
    transMeta.addStep(stepMeta);
    stepDataInterface = new LoadFileInputData();
    stepCopyNr = 0;
    stepLoadFileInput = new LoadFileInput(stepMeta, stepDataInterface, stepCopyNr, transMeta, trans);
    assertSame(stepMetaInterface, stepMeta.getStepMetaInterface());
    runtimeSMI = stepMetaInterface;
    runtimeSDI = runtimeSMI.getStepData();
    inputField = new LoadFileInputField();
    ((LoadFileInputMeta) runtimeSMI).setInputFields(new LoadFileInputField[] { inputField });
    stepLoadFileInput.init(runtimeSMI, runtimeSDI);
}
Also used : VariableSpace(org.pentaho.di.core.variables.VariableSpace) TransMeta(org.pentaho.di.trans.TransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Trans(org.pentaho.di.trans.Trans) StepMeta(org.pentaho.di.trans.step.StepMeta) FileInputList(org.pentaho.di.core.fileinput.FileInputList) Before(org.junit.Before)

Example 27 with FileInputList

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

the class TextFileInputMeta 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;
    // See if we get input...
    if (input.length > 0) {
        if (!isAcceptingFilenames()) {
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "TextFileInputMeta.CheckResult.NoInputError"), stepMeta);
            remarks.add(cr);
        } else {
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "TextFileInputMeta.CheckResult.AcceptFilenamesOk"), stepMeta);
            remarks.add(cr);
        }
    } else {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "TextFileInputMeta.CheckResult.NoInputOk"), stepMeta);
        remarks.add(cr);
    }
    FileInputList textFileList = getTextFileList(transMeta);
    if (textFileList.nrOfFiles() == 0) {
        if (!isAcceptingFilenames()) {
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "TextFileInputMeta.CheckResult.ExpectedFilesError"), stepMeta);
            remarks.add(cr);
        }
    } else {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "TextFileInputMeta.CheckResult.ExpectedFilesOk", "" + textFileList.nrOfFiles()), stepMeta);
        remarks.add(cr);
    }
}
Also used : CheckResult(org.pentaho.di.core.CheckResult) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Example 28 with FileInputList

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

the class YamlInputMeta 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!
                // 
                fileName = newFilenames.toArray(new String[newFilenames.size()]);
                // all null since converted to absolute path.
                fileMask = new String[newFilenames.size()];
                // all null, turn to "Y" :
                fileRequired = new String[newFilenames.size()];
                for (int i = 0; i < newFilenames.size(); i++) {
                    fileRequired[i] = "Y";
                }
            }
        }
        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) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Example 29 with FileInputList

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

the class KettleAnalyzerUtil method getResourcesFromMeta.

public static Collection<IExternalResourceInfo> getResourcesFromMeta(final BaseFileInputMeta meta, final IAnalysisContext context) {
    Collection<IExternalResourceInfo> resources = Collections.emptyList();
    final StepMeta parentStepMeta = meta.getParentStepMeta();
    if (parentStepMeta != null) {
        final TransMeta parentTransMeta = parentStepMeta.getParentTransMeta();
        if (parentTransMeta != null) {
            final FileInputList inputList = meta.getFileInputList(parentTransMeta);
            if (inputList != null) {
                final String[] paths = inputList.getFileStrings();
                if (paths != null) {
                    resources = new ArrayList<>(paths.length);
                    for (final String path : paths) {
                        if (!Const.isEmpty(path)) {
                            try {
                                final IExternalResourceInfo resource = ExternalResourceInfoFactory.createFileResource(KettleVFS.getFileObject(path), true);
                                if (resource != null) {
                                    resources.add(resource);
                                } else {
                                    throw new KettleFileException("Error getting file resource!");
                                }
                            } catch (KettleFileException kfe) {
                            // TODO throw or ignore?
                            }
                        }
                    }
                }
            }
        }
    }
    return resources;
}
Also used : KettleFileException(org.pentaho.di.core.exception.KettleFileException) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) TransMeta(org.pentaho.di.trans.TransMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) FileInputList(org.pentaho.di.core.fileinput.FileInputList)

Example 30 with FileInputList

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

the class XBaseInputMeta method getFields.

@Override
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    FileInputList fileList = getTextFileList(space);
    if (fileList.nrOfFiles() == 0) {
        throw new KettleStepException(BaseMessages.getString(PKG, "XBaseInputMeta.Exception.NoFilesFoundToProcess"));
    }
    row.addRowMeta(getOutputFields(fileList, name));
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) 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