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);
}
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);
}
}
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);
}
}
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;
}
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));
}
Aggregations