use of org.pentaho.di.trans.steps.excelinput.ExcelInputMeta in project pentaho-kettle by pentaho.
the class ExcelInputDialog method showFiles.
private void showFiles() {
ExcelInputMeta eii = new ExcelInputMeta();
getInfo(eii);
String[] files = eii.getFilePaths(transMeta);
if (files.length > 0) {
EnterSelectionDialog esd = new EnterSelectionDialog(shell, files, BaseMessages.getString(PKG, "ExcelInputDialog.FilesRead.DialogTitle"), BaseMessages.getString(PKG, "ExcelInputDialog.FilesRead.DialogMessage"));
esd.setViewOnly();
esd.open();
} else {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "ExcelInputDialog.NoFilesFound.DialogMessage"));
mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title"));
mb.open();
}
}
use of org.pentaho.di.trans.steps.excelinput.ExcelInputMeta in project pentaho-kettle by pentaho.
the class ExcelInputDialog method getFields.
/**
* Get the list of fields in the Excel workbook and put the result in the fields table view.
*/
public void getFields() {
RowMetaInterface fields = new RowMeta();
ExcelInputMeta info = new ExcelInputMeta();
getInfo(info);
int clearFields = SWT.YES;
if (wFields.nrNonEmpty() > 0) {
MessageBox messageBox = new MessageBox(shell, SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
messageBox.setMessage(BaseMessages.getString(PKG, "ExcelInputDialog.ClearFieldList.DialogMessage"));
messageBox.setText(BaseMessages.getString(PKG, "ExcelInputDialog.ClearFieldList.DialogTitle"));
clearFields = messageBox.open();
if (clearFields == SWT.CANCEL) {
return;
}
}
FileInputList fileList = info.getFileList(transMeta);
for (FileObject file : fileList.getFiles()) {
try {
KWorkbook workbook = WorkbookFactory.getWorkbook(info.getSpreadSheetType(), KettleVFS.getFilename(file), info.getEncoding());
processingWorkbook(fields, info, workbook);
workbook.close();
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "ExcelInputDialog.ErrorReadingFile2.DialogMessage", KettleVFS.getFilename(file), e.toString()), e);
}
}
if (fields.size() > 0) {
if (clearFields == SWT.YES) {
wFields.clearAll(false);
}
for (int j = 0; j < fields.size(); j++) {
ValueMetaInterface field = fields.getValueMeta(j);
wFields.add(new String[] { field.getName(), field.getTypeDesc(), "", "", "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, "ExcelInputDialog.UnableToFindFields.DialogMessage"));
mb.setText(BaseMessages.getString(PKG, "ExcelInputDialog.UnableToFindFields.DialogTitle"));
mb.open();
}
checkAlerts();
}
use of org.pentaho.di.trans.steps.excelinput.ExcelInputMeta in project pentaho-metaverse by pentaho.
the class ExcelInputExternalResourceConsumer method getResourcesFromRow.
@Override
public Collection<IExternalResourceInfo> getResourcesFromRow(ExcelInput excelInput, RowMetaInterface rowMeta, Object[] row) {
Collection<IExternalResourceInfo> resources = new LinkedList<IExternalResourceInfo>();
ExcelInputMeta meta = (ExcelInputMeta) excelInput.getStepMetaInterface();
if (meta == null) {
meta = (ExcelInputMeta) excelInput.getStepMeta().getStepMetaInterface();
}
try {
String filename = rowMeta.getString(row, meta.getAcceptingField(), null);
if (!Const.isEmpty(filename)) {
FileObject fileObject = KettleVFS.getFileObject(filename);
resources.add(ExternalResourceInfoFactory.createFileResource(fileObject, true));
}
} catch (KettleException kve) {
// TODO throw exception or ignore?
}
return resources;
}
use of org.pentaho.di.trans.steps.excelinput.ExcelInputMeta in project pentaho-metaverse by pentaho.
the class MetaverseValidationIT method testExcelInputStep_filenameFromField.
@Test
public void testExcelInputStep_filenameFromField() throws Exception {
// this is testing a specific TextFileInputStep instance
ExcelInputStepNode excelInputStepNode = root.getExcelInputFileNameFromFieldStepNode();
assertNotNull(excelInputStepNode);
int countUses = getIterableSize(excelInputStepNode.getFileFieldNodesUses());
int countInputs = getIterableSize(excelInputStepNode.getInputStreamFields());
assertEquals(1, countUses);
int fileFieldCount = 0;
Iterable<StreamFieldNode> outFields = excelInputStepNode.getOutputStreamFields();
int countOutputs = getIterableSize(outFields);
for (StreamFieldNode outField : outFields) {
assertNotNull(outField.getKettleType());
if (!outField.getName().equals("filename")) {
FieldNode fieldPopulatesMe = outField.getFieldPopulatesMe();
assertNotNull(fieldPopulatesMe);
assertEquals(DictionaryConst.NODE_TYPE_FILE_FIELD, fieldPopulatesMe.getType());
assertEquals(excelInputStepNode, fieldPopulatesMe.getStepThatInputsMe());
fileFieldCount++;
}
}
// we should have one more input than file fields since we are reading it off of the input stream
assertEquals(countInputs - 1, fileFieldCount);
assertEquals(countOutputs - 1, fileFieldCount);
String filenameField = null;
TransMeta tm = new TransMeta(new FileInputStream(excelInputStepNode.getTransNode().getPath()), null, true, null, null);
for (StepMeta stepMeta : tm.getSteps()) {
if (stepMeta.getName().equals(excelInputStepNode.getName())) {
ExcelInputMeta meta = (ExcelInputMeta) getBaseStepMetaFromStepMeta(stepMeta);
assertTrue(meta.isAcceptingFilenames());
filenameField = meta.getAcceptingField();
assertNotNull(filenameField);
assertEquals(filenameField, excelInputStepNode.getFileFieldNodesUses().iterator().next().getName());
// this was the one we cared about...
break;
}
}
}
use of org.pentaho.di.trans.steps.excelinput.ExcelInputMeta in project pentaho-metaverse by pentaho.
the class ExcelInputStepAnalyzerTest method resourcesFromRowGotSuccessfullyWhenStepInputMetaInterfaceIsNull.
@Test
public void resourcesFromRowGotSuccessfullyWhenStepInputMetaInterfaceIsNull() throws Exception {
StepMeta mockedStepMeta = mock(StepMeta.class);
when(excelInput.getStepMetaInterface()).thenReturn(null);
when(excelInput.getStepMeta()).thenReturn(mockedStepMeta);
when(mockedStepMeta.getStepMetaInterface()).thenReturn(new ExcelInputMeta());
when(rmi.getString(Mockito.any(Object[].class), Mockito.anyString(), Mockito.anyString())).thenReturn("/path/to/row/file");
Collection<IExternalResourceInfo> resources = consumer.getResourcesFromRow(excelInput, rmi, ROW);
assertEquals(1, resources.size());
}
Aggregations