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